Search in sources :

Example 6 with RequestResponsePact

use of au.com.dius.pact.core.model.RequestResponsePact in project pact-jvm by DiUS.

the class Defect266Test method getUsersFragment2.

@Pact(provider = "266_provider", consumer = "test_consumer")
public RequestResponsePact getUsersFragment2(PactDslWithProvider builder) {
    DslPart body = new PactDslJsonArray().minArrayLike(5).uuid("id").stringType("userName").stringType("email").closeObject();
    RequestResponsePact pact = builder.given("a user with an id named 'user' exists").uponReceiving("get all users for min").path("/idm/user").method("GET").willRespondWith().status(200).body(body).toPact();
    MatchingRules matchingRules = pact.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules();
    Map<String, MatchingRuleGroup> bodyMatchingRules = matchingRules.rulesForCategory("body").getMatchingRules();
    assertThat(bodyMatchingRules.keySet(), is(equalTo(Sets.newHashSet("$[0][*].userName", "$[0][*].id", "$[0]", "$[0][*].email"))));
    assertThat(bodyMatchingRules.get("$[0][*].userName").getRules().get(0), is(equalTo(TypeMatcher.INSTANCE)));
    assertThat(bodyMatchingRules.get("$[0][*].id").getRules().get(0), is(equalTo(new RegexMatcher("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"))));
    assertThat(bodyMatchingRules.get("$[0]").getRules().get(0), is(equalTo(new MinTypeMatcher(5))));
    assertThat(bodyMatchingRules.get("$[0][*].email").getRules().get(0), is(equalTo(TypeMatcher.INSTANCE)));
    return pact;
}
Also used : MinTypeMatcher(au.com.dius.pact.core.model.matchingrules.MinTypeMatcher) MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) MatchingRules(au.com.dius.pact.core.model.matchingrules.MatchingRules) RegexMatcher(au.com.dius.pact.core.model.matchingrules.RegexMatcher) 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)

Example 7 with RequestResponsePact

use of au.com.dius.pact.core.model.RequestResponsePact in project pact-jvm by DiUS.

the class Defect266Test method getUsersFragment.

@Pact(provider = "266_provider", consumer = "test_consumer")
public RequestResponsePact getUsersFragment(PactDslWithProvider builder) {
    DslPart body = new PactDslJsonArray().maxArrayLike(5).uuid("id").stringType("userName").stringType("email").closeObject();
    RequestResponsePact pact = builder.given("a user with an id named 'user' exists").uponReceiving("get all users for max").path("/idm/user").method("GET").willRespondWith().status(200).body(body).toPact();
    MatchingRules matchingRules = pact.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules();
    Map<String, MatchingRuleGroup> bodyMatchingRules = matchingRules.rulesForCategory("body").getMatchingRules();
    assertThat(bodyMatchingRules.keySet(), is(equalTo(Sets.newHashSet("$[0][*].userName", "$[0][*].id", "$[0]", "$[0][*].email"))));
    assertThat(bodyMatchingRules.get("$[0][*].userName").getRules().get(0), is(equalTo(TypeMatcher.INSTANCE)));
    assertThat(bodyMatchingRules.get("$[0][*].id").getRules().get(0), is(equalTo(new RegexMatcher("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"))));
    assertThat(bodyMatchingRules.get("$[0]").getRules().get(0), is(equalTo(new MaxTypeMatcher(5))));
    assertThat(bodyMatchingRules.get("$[0][*].email").getRules().get(0), is(equalTo(TypeMatcher.INSTANCE)));
    return pact;
}
Also used : MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) MaxTypeMatcher(au.com.dius.pact.core.model.matchingrules.MaxTypeMatcher) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) MatchingRules(au.com.dius.pact.core.model.matchingrules.MatchingRules) RegexMatcher(au.com.dius.pact.core.model.matchingrules.RegexMatcher) 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)

Example 8 with RequestResponsePact

use of au.com.dius.pact.core.model.RequestResponsePact in project pact-jvm by DiUS.

the class ValueMatcherTest method createFragment.

@Pact(provider = "ValueMatcherProvider", consumer = "ValueMatcherConsumer")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
    DslPart body = new PactDslJsonBody().eachLike("articles").eachLike("variants").eachKeyMappedToAnArrayLike("001").eachLike("bundles").eachKeyLike("001-A").stringType("description", "Some Description").eachLike("referencedArticles").id("bundleId", 23456L).eachKeyLike("001-A-1", PactDslJsonRootValue.id(12345L)).closeObject().closeArray().closeObject().closeObject().closeArray().closeObject().closeArray().closeObject().closeArray().closeObject().closeArray().object("foo").eachKeyLike("001", PactDslJsonRootValue.numberType(42)).closeObject();
    RequestResponsePact pact = builder.uponReceiving("a request for an article").path("/").method("GET").willRespondWith().status(200).body(body).toPact();
    MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "body", "$.articles", "$.articles[*].variants", "$.articles[*].variants[*]", "$.articles[*].variants[*].*[*].bundles", "$.articles[*].variants[*].*[*].bundles[*]", "$.articles[*].variants[*].*[*].bundles[*].*.description", "$.articles[*].variants[*].*[*].bundles[*].*.referencedArticles", "$.articles[*].variants[*].*[*].bundles[*].*.referencedArticles[*]", "$.articles[*].variants[*].*[*].bundles[*].*.referencedArticles[*].*", "$.articles[*].variants[*].*[*].bundles[*].*.referencedArticles[*].bundleId", "$.foo", "$.foo.*");
    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) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Example 9 with RequestResponsePact

use of au.com.dius.pact.core.model.RequestResponsePact in project pact-jvm by DiUS.

the class PactDslJsonArrayTest method createPact.

@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
    DslPart body = new PactDslJsonArray().includesStr("test").equalsTo("Test").object().id().stringValue("name", "Rogger the Dogger").includesStr("v1", "test").datetime("timestamp").date("dob", "MM/dd/yyyy").closeObject().object().id().stringValue("name", "Cat in the Hat").datetime("timestamp").date("dob", "MM/dd/yyyy").array("things").valueFromProviderState("thingName", "Thing 1").closeArray().closeObject();
    RequestResponsePact pact = builder.uponReceiving("java test interaction with a DSL array body").path("/").method("GET").willRespondWith().status(200).body(body).toPact();
    MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "body", "$[0]", "$[1]", "$[2].id", "$[2].timestamp", "$[2].dob", "$[2].v1", "$[3].id", "$[3].timestamp", "$[3].dob", "$[3].things[0]");
    MatcherTestUtils.assertResponseGeneratorKeysEqualTo(pact, "body", "$[2].id", "$[2].timestamp", "$[2].dob", "$[3].id", "$[3].timestamp", "$[3].dob", "$[3].things[0]");
    return pact;
}
Also used : PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) DslPart(au.com.dius.pact.consumer.dsl.DslPart)

Example 10 with RequestResponsePact

use of au.com.dius.pact.core.model.RequestResponsePact in project pact-jvm by DiUS.

the class PactDslJsonBodyTest method createPact.

@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
    DslPart body = new PactDslJsonBody().id().object("2").id().stringValue("test", (String) null).includesStr("v1", "test").closeObject().array("numbers").id().number(100).numberValue(101).hexValue().object().id().stringValue("full_name", "Rogger the Dogger").datetime("timestamp").date("date_of_birth", "MM/dd/yyyy").closeObject().closeArray();
    RequestResponsePact pact = builder.uponReceiving("java test interaction with a DSL body").path("/").method("GET").willRespondWith().status(200).body(body).toPact();
    MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "body", "$.id", "$.2.id", "$.2.v1", "$.numbers[0]", "$.numbers[3]", "$.numbers[4].id", "$.numbers[4].timestamp", "$.numbers[4].date_of_birth");
    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)

Aggregations

RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)15 DslPart (au.com.dius.pact.consumer.dsl.DslPart)8 Pact (au.com.dius.pact.core.model.annotations.Pact)7 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)5 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)4 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)4 MockProviderConfig (au.com.dius.pact.consumer.model.MockProviderConfig)3 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ConsumerPactRunnerKt.runConsumerTest (au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest)2 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)2 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)2 PactMismatchesException (au.com.dius.pact.consumer.PactMismatchesException)1 PactDslRootValue (au.com.dius.pact.consumer.dsl.PactDslRootValue)1 PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)1 ProviderClient (au.com.dius.pact.consumer.junit.exampleclients.ProviderClient)1 PactXmlBuilder (au.com.dius.pact.consumer.xml.PactXmlBuilder)1 MatchingRule (au.com.dius.pact.core.model.matchingrules.MatchingRule)1 MaxTypeMatcher (au.com.dius.pact.core.model.matchingrules.MaxTypeMatcher)1