use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.
the class MessagePactProviderRule method conformsToSignature.
/**
* validates method signature as described at {@link Pact}
*/
private boolean conformsToSignature(Method m) {
Pact pact = m.getAnnotation(Pact.class);
boolean conforms = pact != null && MessagePact.class.isAssignableFrom(m.getReturnType()) && m.getParameterTypes().length == 1 && m.getParameterTypes()[0].isAssignableFrom(MessagePactBuilder.class);
if (!conforms && pact != null) {
throw new UnsupportedOperationException("Method " + m.getName() + " does not conform required method signature 'public MessagePact xxx(MessagePactBuilder builder)'");
}
return conforms;
}
use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.
the class DefaultValuesTest method createPact.
@Pact(consumer = "DefaultValuesConsumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
RequestResponsePact pact = builder.given("status200").uponReceiving("Get object").path("/path").willRespondWith().status(200).uponReceiving("Download").path("/path2").matchQuery("source_filename", "[\\S\\s]+[\\S]+", "filename").willRespondWith().status(200).toPact();
assertThat(pact.getInteractions().get(0).asSynchronousRequestResponse().getRequest().getHeaders(), hasEntry("Content-Type", Collections.singletonList("application/json")));
assertThat(pact.getInteractions().get(1).asSynchronousRequestResponse().getRequest().getHeaders(), hasEntry("Content-Type", Collections.singletonList("application/json")));
return pact;
}
use of au.com.dius.pact.core.model.annotations.Pact 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.annotations.Pact 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.annotations.Pact 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;
}
Aggregations