use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class PactDslJsonBodyTest method nestedObjectMatcherTest.
@Test
public void nestedObjectMatcherTest() {
DslPart body = new PactDslJsonBody().object(FIRST).stringType(LEVEL_1, L_1_EXAMPLE).stringType("@level1").object(SECOND).stringType(LEVEL_2, L_2_EXAMPLE).object(THIRD).stringType("level3", "l3example").object("fourth").stringType("level4", "l4example").closeObject().closeObject().closeObject().closeObject();
Set<String> expectedMatchers = new HashSet<>(Arrays.asList(".first.second.@third.fourth.level4", ".first.second.@third.level3", ".first.second.level2", ".first.level1", ".first.@level1"));
assertThat(body.getMatchers().getMatchingRules().keySet(), is(equalTo(expectedMatchers)));
assertThat(body.getBody().asObject().get(FIRST).get(LEVEL_1).asString(), is(equalTo(L_1_EXAMPLE)));
assertThat(body.getBody().asObject().get(FIRST).get(SECOND).get(LEVEL_2).asString(), is(equalTo(L_2_EXAMPLE)));
assertThat(body.getBody().asObject().get(FIRST).get(SECOND).get(THIRD).get("level3").asString(), is(equalTo("l3example")));
assertThat(body.getBody().asObject().get(FIRST).get(SECOND).get(THIRD).get("fourth").get("level4").asString(), is(equalTo("l4example")));
}
use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class LambdaDslTest method testArrayMinLike.
@Test
public void testArrayMinLike() {
/*
[
{
"foo": "string"
},
{
"foo": "string"
}
]
*/
String pactDslJson = PactDslJsonArray.arrayMinLike(2).stringType("foo").close().getBody().toString();
DslPart actualPactDsl = LambdaDsl.newJsonArrayMinLike(2, o -> o.object(oo -> oo.stringType("foo"))).build();
String actualJson = actualPactDsl.getBody().toString();
assertThat(actualJson, is(pactDslJson));
}
use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class LambdaDslTest method testNumberValue.
@Test
public void testNumberValue() {
DslPart dslPart = LambdaDsl.newJsonBody(o -> o.numberValue("number", 1)).build();
assertThat(dslPart.getBody().toString(), is("{\"number\":1}"));
}
use of au.com.dius.pact.consumer.dsl.DslPart in project pact-jvm by DiUS.
the class LambdaDslTest method testObjectWithComplexStructure.
@Test
public void testObjectWithComplexStructure() throws IOException {
/*
{
"propObj1": {
"foo": "Foo",
"someProperty": 1
},
"someArray": [
{
"arrayObj1Prop1": "ao1p1"
},
{
"arrayObj1Prop2Obj": {
"arrayObj1Prop2ObjProp1": "ao1p2op1"
},
"arrayObj2Prop1": "ao2p1"
}
]
}
*/
// Old DSL
final String pactDslJson = new PactDslJsonBody().object("propObj1").stringValue("foo", "Foo").numberValue("someProperty", 1L).closeObject().array("someArray").object().stringValue("arrayObj1Prop1", "ao1p1").closeObject().object().stringValue("arrayObj2Prop1", "ao2p1").object("arrayObj1Prop2Obj").stringValue("arrayObj1Prop2ObjProp1", "ao1p2op1").closeObject().closeObject().closeArray().getBody().toString();
// Lambda DSL
final DslPart actualPactDsl = LambdaDsl.newJsonBody((body) -> {
body.object("propObj1", (o) -> {
o.stringValue("foo", "Foo");
o.numberValue("someProperty", 1L);
}).array("someArray", (a) -> {
a.object((oo) -> oo.stringValue("arrayObj1Prop1", "ao1p1"));
a.object((oo) -> {
oo.stringValue("arrayObj2Prop1", "ao2p1");
oo.object("arrayObj1Prop2Obj", (ooo) -> ooo.stringValue("arrayObj1Prop2ObjProp1", "ao1p2op1"));
});
});
}).build();
String actualJson = actualPactDsl.getBody().toString();
assertThat(actualJson, is(pactDslJson));
}
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", "$[0].name", "$[0].dob", "$[1].id", "$[1].name", "$[1].dob", "$[2].id", "$[2].name", "$[2].dob");
return pact;
}
Aggregations