use of au.com.dius.pact.consumer.dsl.DslPart 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.DslPart 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.DslPart 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.DslPart in project pact-jvm by DiUS.
the class PactDslJsonBodyTest method guardAgainstObjectNamesThatDontConformToGatlingFields.
@Test
public void guardAgainstObjectNamesThatDontConformToGatlingFields() {
DslPart body = new PactDslJsonBody().id().object("2").id().stringValue("test", "A Test String").closeObject().array(NUMBERS).id().number(100).numberValue(101).hexValue().object().id().stringValue("name", "Rogger the Dogger").timestamp().date("dob", "MM/dd/yyyy").object(K_DEPRECIATION_BIPS).id().closeObject().closeObject().closeArray();
Set<String> expectedMatchers = new HashSet<String>(Arrays.asList("$.body.id", "$.body['2'].id", "$.body.numbers[3]", "$.body.numbers[0]", "$.body.numbers[4].timestamp", "$.body.numbers[4].dob", "$.body.numbers[4].id", "$.body.numbers[4]['10k-depreciation-bips'].id"));
assertThat(body.getMatchers().keySet(), is(equalTo(expectedMatchers)));
assertThat(((JSONObject) body.getBody()).keySet(), is(equalTo((Set) new HashSet(Arrays.asList("2", NUMBERS, "id")))));
}
use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class LambdaDslTest method testObjectWithObjects.
@Test
public void testObjectWithObjects() throws IOException {
/*
{
"propObj1": {
"foo": "Foo"
},
"propObj2": {
"bar": "Bar"
},
"someProperty": "Prop"
}
*/
// Old DSL
final String pactDslJson = new PactDslJsonBody().stringValue("someProperty", "Prop").object("propObj1").stringValue("foo", "Foo").closeObject().object("propObj2").stringValue("bar", "Bar").closeObject().getBody().toString();
// Lambda DSL
final DslPart actualPactDsl = LambdaDsl.newJsonBody((body) -> {
body.stringValue("someProperty", "Prop").object("propObj1", (o) -> {
o.stringValue("foo", "Foo");
}).object("propObj2", (o) -> {
o.stringValue("bar", "Bar");
});
}).build();
String actualJson = actualPactDsl.getBody().toString();
assertThat(actualJson, is(pactDslJson));
}
Aggregations