2017-11-17 2 views
0

응답 본문을 동적으로 검증하려고합니다. 사용자 권한에 따라 다른 본문을 반환하는 종점이 있습니다. 예를 들어 :Gatling의 동적 체크 빌드

user: a 
{ 
    "one": "a", 
    "two": "b" 
} 

user: b 
{ 
    "one": "a", 
    "three": "c" 
} 

내가 한 JSON 필드가 이런 방식으로 존재인지 아닌지 검증하는 jsonPath를 사용할 수 있다는 것을 알고, 내가 공급 장치를 사용하여, 그것은 구성 만들고 싶어하지만

http("Request") 
    .get(url) 
    .header(user_a_token) 
    .check(jsonPath("one").exists) 
    .check(jsonPath("two").exists) 
    .check(jsonPath("three").notExists) 

또는 다음과 같습니다.

http("Request") 
    .get(url) 
    .header(user_token) 
    // iterate a list of Strings with the json field names 

생각 하시겠습니까?

답변

0

이 요구 사항을 처리하는 방법을 마침내 발견했습니다. 사용 후

val jsonPathChecks: List[HttpCheck] = List(jsonPath("one").exists, jsonPath("two").exists, jsonPath("three").exists) 

그리고 :

http("Request") 
    .get(url) 
    .header(user_token) 
    .check(jsonPathChecks: _*) 

_ * 연산자는 마법이 발생하고 담당하는 모든

첫째, 당신은 검사 목록을 정의 할 필요가있다.