Search in sources :

Example 1 with MatchingRules

use of au.com.dius.pact.core.model.matchingrules.MatchingRules 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 2 with MatchingRules

use of au.com.dius.pact.core.model.matchingrules.MatchingRules 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 3 with MatchingRules

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

the class MatcherTestUtils method assertMessageMatcherKeysEqualTo.

public static void assertMessageMatcherKeysEqualTo(MessagePact messagePact, String category, String... matcherKeys) {
    MatchingRules matchingRules = messagePact.getMessages().get(0).getMatchingRules();
    Map<String, MatchingRuleGroup> matchers = matchingRules.rulesForCategory(category).getMatchingRules();
    assertEquals(asSet(matcherKeys), new TreeSet<String>(matchers.keySet()));
}
Also used : MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) MatchingRules(au.com.dius.pact.core.model.matchingrules.MatchingRules)

Example 4 with MatchingRules

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

the class MatcherTestUtils method assertResponseMatcherKeysEqualTo.

public static void assertResponseMatcherKeysEqualTo(RequestResponsePact pact, String category, String... matcherKeys) {
    MatchingRules matchingRules = pact.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules();
    Map<String, MatchingRuleGroup> matchers = matchingRules.rulesForCategory(category).getMatchingRules();
    assertEquals(asSet(matcherKeys), new TreeSet<>(matchers.keySet()));
}
Also used : MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) MatchingRules(au.com.dius.pact.core.model.matchingrules.MatchingRules)

Aggregations

MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)4 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)4 DslPart (au.com.dius.pact.consumer.dsl.DslPart)2 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)2 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)2 Pact (au.com.dius.pact.core.model.annotations.Pact)2 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)2 MaxTypeMatcher (au.com.dius.pact.core.model.matchingrules.MaxTypeMatcher)1 MinTypeMatcher (au.com.dius.pact.core.model.matchingrules.MinTypeMatcher)1