Search in sources :

Example 31 with DslPart

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;
}
Also used : RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart)

Example 32 with DslPart

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;
}
Also used : MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) HashMap(java.util.HashMap) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Aggregations

DslPart (au.com.dius.pact.consumer.dsl.DslPart)32 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)26 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)15 Test (org.junit.Test)10 HashSet (java.util.HashSet)9 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)8 LambdaDsl (au.com.dius.pact.consumer.dsl.LambdaDsl)7 RequestResponsePact (au.com.dius.pact.model.RequestResponsePact)7 IOException (java.io.IOException)7 CoreMatchers.is (org.hamcrest.CoreMatchers.is)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Test (org.junit.jupiter.api.Test)7 Pact (au.com.dius.pact.core.model.annotations.Pact)4 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)3 Map (java.util.Map)3 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)2 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)2 JsonValue (au.com.dius.pact.core.support.json.JsonValue)2 JsonSlurper (groovy.json.JsonSlurper)2 MaxTypeMatcher (au.com.dius.pact.core.model.matchingrules.MaxTypeMatcher)1