2014-10-02 48 views
1

我可以將REST請求內容與測試框架RESTITO內容完全匹配嗎?可以說我從我的請求中現在有一個時間戳,但我不想匹配這個特定的值(我可能還不知道它)?請求與RESTITO的部分匹配

回答

3

如果你的URL看起來像

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

那麼你可以到以下幾點:

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());