use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class PactDslJsonBodyArrayLikeTest method createPact.
@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
DslPart body = new PactDslJsonBody().id().object("data").eachLike("array1").id().stringType("name").date("dob").closeObject().closeArray().minArrayLike("array2", 1).ipAddress("address").stringType("name").closeObject().closeArray().array("array3").maxArrayLike(5).integerType("itemCount").equalTo("V", "test").closeObject().closeArray().closeArray().closeObject();
RequestResponsePact pact = builder.uponReceiving("java test interaction with an array like matcher").path("/").method("GET").willRespondWith().status(200).body(body).toPact();
MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "body", "$.id", "$.data.array1", "$.data.array1[*].id", "$.data.array1[*].name", "$.data.array1[*].dob", "$.data.array2", "$.data.array2[*].address", "$.data.array2[*].name", "$.data.array3[0]", "$.data.array3[0][*].itemCount", "$.data.array3[0][*].V");
MatcherTestUtils.assertResponseKeysEqualTo(pact, "/data", "/data/array1", "/data/array1/0/dob", "/data/array1/0/id", "/data/array1/0/name", "/data/array2", "/data/array2/0/address", "/data/array2/0/name", "/data/array3/0/0/V", "/data/array3/0/0/itemCount", "/data/array3", "/id");
return pact;
}
use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class EventsRepositoryDictionaryNestedArrayConsumerTest method createPact.
@Pact(provider = "EventsProvider", consumer = "EventsConsumerDictionaryNestedArray")
public RequestResponsePact createPact(PactDslWithProvider builder) {
DslPart body = new PactDslJsonBody().object("events").eachKeyMappedToAnArrayLike(// broken, see pact-jvm issue 401
"ant").stringType("title", "ant");
RequestResponsePact pact = builder.given("initialStateForEventsTest").uponReceiving("a request to get events keyed by title").path("/dictionaryNestedArray").headers("Accept", ContentType.APPLICATION_JSON.toString()).method("GET").willRespondWith().status(200).body(body).toPact();
MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "body", "$.events", "$.events.*[*].title");
HashMap<String, MatchingRuleGroup> matchingRules = new HashMap<>();
matchingRules.put("$.events", new MatchingRuleGroup(Collections.singletonList(ValuesMatcher.INSTANCE)));
matchingRules.put("$.events.*[*].title", new MatchingRuleGroup(Collections.singletonList(TypeMatcher.INSTANCE)));
assertThat(pact.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules().rulesForCategory("body").getMatchingRules(), is(equalTo(matchingRules)));
return pact;
}
Aggregations