use of au.com.dius.pact.core.model.matchingrules.MinTypeMatcher 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.MinTypeMatcher in project pact-jvm by DiUS.
the class LambdaDsl method newJsonArrayMinLike.
/**
* DSL function to simplify creating a {@link DslPart} generated from a {@link LambdaDslJsonArray} where a minimum base array size is specified
*/
public static LambdaDslJsonArray newJsonArrayMinLike(Integer size, Consumer<LambdaDslJsonArray> array) {
final PactDslJsonArray pactDslJsonArray = new PactDslJsonArray("", "", null, true);
pactDslJsonArray.setNumberExamples(size);
pactDslJsonArray.getMatchers().addRule(new MinTypeMatcher(size));
final LambdaDslJsonArray dslArray = new LambdaDslJsonArray(pactDslJsonArray);
array.accept(dslArray);
return dslArray;
}
Aggregations