use of au.com.dius.pact.consumer.dsl.PactDslJsonArray in project pact-jvm by DiUS.
the class Defect266Test method getUsersFragment.
@Pact(provider = "266_provider", consumer = "test_consumer")
public RequestResponsePact getUsersFragment(PactDslWithProvider builder) {
Map<String, Map<String, Object>> matchers = (Map<String, Map<String, Object>>) new JsonSlurper().parseText("{" + "\"$.body[0][*].userName\": {\"match\": \"type\"}," + "\"$.body[0][*].id\": {\"match\": \"regex\", \"regex\": \"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\"}," + "\"$.body[0]\": {\"match\": \"type\", \"max\": 5}," + "\"$.body[0][*].email\": {\"match\": \"type\"}" + "}");
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();
assertThat(pact.getInteractions().get(0).getResponse().getMatchingRules(), is(equalTo(matchers)));
return pact;
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonArray in project pact-jvm by DiUS.
the class Defect266Test method getUsersFragment2.
@Pact(provider = "266_provider", consumer = "test_consumer")
public RequestResponsePact getUsersFragment2(PactDslWithProvider builder) {
Map<String, Map<String, Object>> matchers = (Map<String, Map<String, Object>>) new JsonSlurper().parseText("{" + "\"$.body[0][*].userName\": {\"match\": \"type\"}," + "\"$.body[0][*].id\": {\"match\": \"regex\", \"regex\": \"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\"}," + "\"$.body[0]\": {\"match\": \"type\", \"min\": 5}," + "\"$.body[0][*].email\": {\"match\": \"type\"}" + "}");
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();
assertThat(pact.getInteractions().get(0).getResponse().getMatchingRules(), is(equalTo(matchers)));
return pact;
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonArray in project pact-jvm by DiUS.
the class PactDslJsonArrayTemplateTest method createPact.
@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
DslPart personTemplate = new PactDslJsonBody().id().stringType("name").date("dob");
DslPart body = new PactDslJsonArray().template(personTemplate, 3);
RequestResponsePact pact = builder.uponReceiving("java test interaction with a DSL array body with templates").path("/").method("GET").willRespondWith().status(200).body(body).toPact();
MatcherTestUtils.assertResponseMatcherKeysEqualTo(pact, "$.body[0].id", "$.body[0].name", "$.body[0].dob", "$.body[1].id", "$.body[1].name", "$.body[1].dob", "$.body[2].id", "$.body[2].name", "$.body[2].dob");
return pact;
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonArray in project pact-jvm by DiUS.
the class ExampleMessageConsumerWithRootArrayTest method createPact.
@Pact(provider = "test_provider", consumer = "test_consumer_v3")
public MessagePact createPact(MessagePactBuilder builder) {
PactDslJsonArray body = new PactDslJsonArray().decimalType(100.10).stringType("Should be in an array");
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("contentType", "application/json");
return builder.given("SomeProviderState").expectsToReceive("a test message with an array").withMetadata(metadata).withContent(body).toPact();
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonArray in project pact-jvm by DiUS.
the class PactDslJsonArrayTest method createPact.
@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
DslPart body = new PactDslJsonArray().object().id().stringValue("name", "Rogger the Dogger").timestamp().date("dob", "MM/dd/yyyy").closeObject().object().id().stringValue("name", "Cat in the Hat").timestamp().date("dob", "MM/dd/yyyy").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].id", "$.body[0].timestamp", "$.body[0].dob", "$.body[1].id", "$.body[1].timestamp", "$.body[1].dob");
return pact;
}
Aggregations