use of au.com.dius.pact.core.model.matchingrules.RegexMatcher in project pact-jvm by DiUS.
the class MessageWithMetadataConsumerTest method test.
@Test
void test(List<Message> messages) {
assertThat(messages, is(not(empty())));
Message message = messages.get(0);
Map<String, Object> metaData = message.getMetadata();
assertThat(metaData.entrySet(), is(not(empty())));
assertThat(metaData.get("metadata1"), is("metadataValue1"));
assertThat(metaData.get("metadata2"), is("metadataValue2"));
assertThat(metaData.get("metadata3"), is(10L));
assertThat(metaData.get("partitionKey"), is("ABC01"));
assertThat(message.getMatchingRules().rulesForCategory("metadata").allMatchingRules(), is(Collections.singletonList(new RegexMatcher("[A-Z]{3}\\d{2}"))));
}
use of au.com.dius.pact.core.model.matchingrules.RegexMatcher 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;
}
use of au.com.dius.pact.core.model.matchingrules.RegexMatcher 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;
}
use of au.com.dius.pact.core.model.matchingrules.RegexMatcher in project pact-jvm by DiUS.
the class PactDslRootValueTest method rootValueTest.
@Test
public void rootValueTest() {
PactDslRootValue rootValueBody = new PactDslRootValue();
rootValueBody.setValue("Brent");
rootValueBody.setMatcher(new RegexMatcher(".{5}"));
PactDslWithProvider dsl = new PactDslWithProvider(new ConsumerPactBuilder("consumer"), "provider");
Map<String, String> headers = new HashMap<String, String>() {
{
put("Content-Type", "text/plain");
}
};
RequestResponsePact frag = dsl.given("I am testing root values").uponReceiving("A request for text/plain").path("/some/blah/path").headers(headers).willRespondWith().headers(headers).status(200).body(rootValueBody).toPact().asRequestResponsePact().component1();
Assert.assertEquals(1, frag.getInteractions().size());
assertThat(frag.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getBody().valueAsString(), is("Brent"));
Map<String, MatchingRuleGroup> matchingGroups = frag.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules().rulesForCategory("body").getMatchingRules();
List<MatchingRule> rules = matchingGroups.get("$").getRules();
Assert.assertEquals(1, rules.size());
Assert.assertEquals(".{5}", rules.get(0).toMap(PactSpecVersion.V3).get("regex"));
}
Aggregations