2

我可以匹配没有完全匹配内容的 REST 请求内容与测试框架 RESTITO 吗?假设我的请求中有一个从现在开始的时间戳,但我不想匹配这个特定的值(我可能不知道)?

4

1 回答 1

4

如果您的网址看起来像

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")))

当然,您始终可以编写自定义条件,您可以在其中对您想要的请求进行任何检查并返回一个布尔值,例如:

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());
于 2014-10-12T10:19:49.867 回答