1
我可以将REST请求内容与测试框架RESTITO内容完全匹配吗?可以说我从我的请求中现在有一个时间戳,但我不想匹配这个特定的值(我可能还不知道它)?请求与RESTITO的部分匹配
我可以将REST请求内容与测试框架RESTITO内容完全匹配吗?可以说我从我的请求中现在有一个时间戳,但我不想匹配这个特定的值(我可能还不知道它)?请求与RESTITO的部分匹配
如果你的URL看起来像
http://example.com/api/endpoint?weight=100×tamp=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());