Special Values

http.get("/end-point") { price.should == 100 assert price instanceof DataNode } Values that you access inside validation block are special values of DataNode type. When you assert them using should statement they act as proxies that record every assertion that you do.

Extracting Values

As you have seen in HTTP/CRUD CRUD example you can return values back from a validation block. def id = http.get("/end-point") { return id } assert id == 10 assert id.getClass() == Integer When you return a value from a validation block, it automatically gets converted to its correspondent primitive.Note: asserting that value after returning will not track and associated assertions with the call anymore. Use it only to get values required for consequent test calls.

Properties On Lists

If you have a list of objects like complexList above, you can access all its children property value with complexList.k2 . http.get("/end-point") { complexList.k2.should == [30, 40] }

Path based properties access

Primarily for Java users, webtau supports the ability to query properties of a DataNode via a path instead of chaining get(String name) calls. For example, to obtain a simple property: http.get("/end-point", (header, body) -> { body.get("object.k1").should(equal("v1")); }); It is also possible to query arrays, including the ability to query for the Nth element from the end: http.get("/end-point", (header, body) -> { body.get("complexList[0].k1").should(equal("v1")); body.get("complexList[-1].k1").should(equal("v11")); }); Similarly to the Groovy example in HTTP/data-node#properties-on-lists Properties On Lists, it is possible to access all children property values: http.get("/end-point", (header, body) -> { body.get("complexList.k1").should(equal(Arrays.asList("v1", "v11"))); });

If-Else Logic

Even though values that you access inside validation block are special values of DataNode type, you can still perform simple if-else like logic checks on them. Accessing the values will mark them as "touched" for data coverage statistic. def zipCode = http.get("/address") { return addressType == "complex" ? address.zipCode : "NA" } zipCode.should == "12345" Warning: Comparison of complex values is not properly implemented due to current Groovy API implementation details

Each

Special values inside assertion block have convenient methods each to iterate over a list http.get("/end-point") { list.each { it.shouldBe > 0 } } http.get("/end-point") { complexList.each { k2.shouldBe > 0 } }

Find

find to find a single value def found = http.get("/end-point") { return list.find { it > 1 } } assert found == 2 assert found.getClass() == Integer and findAll to find all the values matching predicate def found = http.get("/end-point") { return list.findAll { it > 1 } } assert found == [2, 3] assert found[0].getClass() == Integer Note: While values inside a predicate are normal values, the result of find and findAll is still DataNode def id = http.get("/end-point") { def found = complexList.find { assert k1.getClass() == String k1 == 'v1' } assert found.getClass() == GroovyDataNode return found.id } assert id.getClass() == String

Collect

Use collect to transform a collection of items def transformed = http.get("/end-point") { return list.collect { "world#${it}" } } assert transformed == ['world#1', 'world#2', 'world#3'] assert transformed[0] instanceof GString

Combine

Methods find and collect can be chained def sum = http.get("/end-point") { return complexList .findAll { k1.startsWith('v1') } .collect { k2 } .sum() } assert sum == 70