2014-10-02 5 views
1

테스트 프레임 워크 RESTITO와 내용이 정확히 일치하지 않는 REST 요청 콘텐츠를 찾을 수 있습니까? 내가 요청한 타임 스탬프를 가지고 있다고 말할 수는 있지만이 특정 값과 일치하지 않기를 원합니다 (어쨌든 그것을 모르는 경우)?요청과 부분 일치 RESTITO

답변

3

다음에 당신이 할 수있는

http://example.com/api/endpoint?weight=100&timestamp=1413108487

처럼 URL이 보이는 경우 : 그것은 단지 모든 타임 스탬프를 무시합니다

match(get("/api/endpoint"), parameter("weight", "100")) 

. 타임 스탬프는 URI의 일부인 경우 :

http://example.com/api/endpoint/1413108487/bla

은 당신이 사용할 수있는 matchesUri() 예 :

match(method(Method.GET), matchesUri(new Regexp("/api/endpoint/[0-9]+/bla"))) 

물론 당신은 항상 당신이 요청에 어떤 검사를 할 수있는 custom condition을 쓸 수 있습니다 예 :

Predicate<Call> uriEndsWithA = new Predicate<Call>() { 
    @Override 
    public boolean apply(final Call input) { 
     return input.getUri().endsWith("a"); 
    } 
}; 
whenHttp(server).match(custom(uriEndsWithA)).then(ok());