Response Lazy Value

WebTau has a way to define a lazy value associated with HTTP GET response. After that it can be used in multiple tests, should and waitTo on it. Value can be associated with static urls like /info or dynamic urls like /price/:ticker Groovy private final def livePrice = http.resource("/prices/:ticker").price ... livePrice.of("IBM").waitToBe > 115 Check HTTP/import-and-dependencies Import And Dependencies for prerequisites. Java private final HttpLazyResponseValue livePrice = http.resource("/prices/:ticker").get("price"); ... livePrice.of("IBM").waitToBe(greaterThan(115))); Check HTTP/import-and-dependencies Import And Dependencies for prerequisites. > waiting for value of /prices/IBM: price to be greater than 115 > [1/3] executing HTTP GET http://localhost:35275/prices/IBM . header.statusCode equals 200 (0ms) response (application/json): { "price": **100** } . [1/3] executed HTTP GET http://localhost:35275/prices/IBM (4ms) > [3/3] executing HTTP GET http://localhost:35275/prices/IBM . header.statusCode equals 200 (0ms) response (application/json): { "price": ~~120~~ } . [3/3] executed HTTP GET http://localhost:35275/prices/IBM (3ms) . value of /prices/IBM: price greater than 115 (213ms)

Full Body

Use .body to define a resource matching the whole response: Groovy private final def livePriceBody = http.resource("/prices/:ticker").body ... livePriceBody.of("IBM").waitTo == [price: greaterThan(115)] Java private final HttpLazyResponseValue livePriceBody = http.resource("/prices/:ticker").body; ... livePriceBody.of("IBM").waitTo(equal(map("price", greaterThan(115))))); > waiting for value of /prices/IBM: to equal {"price": <greater than 115>} > [1/3] executing HTTP GET http://localhost:35275/prices/IBM . header.statusCode equals 200 (1ms) response (application/json): { "price": **100** } . [1/3] executed HTTP GET http://localhost:35275/prices/IBM (3ms) > [3/3] executing HTTP GET http://localhost:35275/prices/IBM . header.statusCode equals 200 (0ms) response (application/json): { "price": __120__ } . [3/3] executed HTTP GET http://localhost:35275/prices/IBM (3ms) . value of /prices/IBM: equals {"price": <greater than 115>} (210ms)

Complex Value Path

Value path supports multiple nesting level and arrays indexing: Groovy private final def complexListFirstId = http.resource("/end-point").complexList[0].id ... complexListFirstId.should == "id1" Java private final HttpLazyResponseValue complexListFirstId = http.resource("/end-point").get("complexList[0].id"); ... complexListFirstId.should(equal("id1"))); > expecting value of /end-point: complexList[0].id to equal "id1" > executing HTTP GET http://localhost:35275/end-point . header.statusCode equals 200 (0ms) response (application/json): { "id": 10, "price": 100, "amount": 30, "list": [1, 2, 3], "object": {"k1": "v1", "k2": "v2", "k3": "v3"}, "complexList": [{"id": __"id1"__, "k1": "v1", "k2": 30}, {"id": "id2", "k1": "v11", "k2": 40}] } . executed HTTP GET http://localhost:35275/end-point (7ms) . value of /end-point: complexList[0].id equals "id1" (8ms)

Multiple URL Parameters

Use vararg, or pass a map to of to provide multiple URL parameters to your resource: Groovy private final def myObj = http.resource("/end-point/:param1/:param2").object ... myObj.of([param1: 10, param2: 20]).should == [k1: "v1_", k2: "v2_", k3: "v3_"] Java private final HttpLazyResponseValue myObj = http.resource("/end-point/:param1/:param2").get("object"); ... myObj.of("param1", "10", "param2", "20").should(equal(map("k1", "v1_", "k2", "v2_", "k3", "v3_")))); > expecting value of /end-point/10/20: object to equal {"k1": "v1_", "k2": "v2_", "k3": "v3_"} > executing HTTP GET http://localhost:35275/end-point/10/20 . header.statusCode equals 200 (0ms) response (application/json): { "id": 10, "price": 120, "amount": 30, "list": [1, 2, 3], "object": {"k1": __"v1_"__, "k2": __"v2_"__, "k3": __"v3_"__}, "complexList": [{"id": "id1", "k1": "v1", "k2": 30}, {"id": "id2", "k1": "v11", "k2": 40}] } . executed HTTP GET http://localhost:35275/end-point/10/20 (3ms) . value of /end-point/10/20: object equals {"k1": "v1_", "k2": "v2_", "k3": "v3_"} (3ms)

Full Text Response

Use to extract full original response: Groovy String responseAsText = http.resource("/prices/IBM").fullTextResponse() responseAsText.should == "{\"price\": 100}" Java String responseAsText = http.resource("/prices/IBM").fullTextResponse(); actual(responseAsText, "response").should(equal("{\"price\": 100}"));

HTTP Header

Use http.resource optional second parameter to pass HTTP header: Groovy def responseValue = http.resource("/end-point", http.header("x-prop", "x-value")).path Java HttpLazyResponseValue responseValue = http.resource("/end-point", http.header("path", "x-value")).get("path");