use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.
the class MatchingTest method testMatchingByTypeOnBody.
@Test
public void testMatchingByTypeOnBody() {
PactDslJsonBody body = new PactDslJsonBody().stringType("name").booleanType("happy").hexValue("hexCode").id().ipAddress("localAddress").numberValue("age", 100).numberType("ageAverage", 150.0).integerType("age2", 200).timestamp();
PactDslJsonBody responseBody = new PactDslJsonBody();
HashMap expectedResponse = new HashMap();
runTest(buildPactFragment(body, responseBody, "a test interaction that requires type matching"), new JSONObject().put("name", "Giggle and Hoot").put("happy", true).put("hexCode", "abcdef0123456789").put("id", 1234567890).put("localAddress", "192.168.0.1").put("age", 100).put("ageAverage", 150.0).put("age2", 200).put("timestamp", DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date())).toString(), expectedResponse, HELLO);
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.
the class MatchingTest method testRegexpMatchingOnBody.
@Test
public void testRegexpMatchingOnBody() {
PactDslJsonBody body = new PactDslJsonBody().stringMatcher("name", "\\w+", HARRY).stringMatcher("position", "staff|contactor");
PactDslJsonBody responseBody = new PactDslJsonBody().stringMatcher("name", "\\w+", HARRY);
HashMap<String, String> expectedResponse = new HashMap<String, String>();
expectedResponse.put("name", HARRY);
runTest(buildPactFragment(body, responseBody, "a test interaction that requires regex matching"), "{\"name\": \"Arnold\", \"position\": \"staff\"}", expectedResponse, HELLO);
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.
the class MimeTypeTest method testMatchingJson.
@Test
public void testMatchingJson() {
String body = new PactDslJsonBody().object("person").stringValue("name", "fred").numberValue("age", 100).closeObject().toString();
String responseBody = "{\"status\": \"OK\"}";
runTest(buildPact(body, responseBody, "a test interaction with json", ContentType.APPLICATION_JSON), body, responseBody, ContentType.APPLICATION_JSON);
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.
the class PactDslJsonBodyTest method eachLikeMatcherTest.
@Test
public void eachLikeMatcherTest() {
DslPart body = new PactDslJsonBody().eachLike("ids").id().closeObject().closeArray();
Set<String> expectedMatchers = new HashSet<String>(Arrays.asList("$.body.ids", "$.body.ids[*].id"));
assertThat(body.getMatchers().keySet(), is(equalTo(expectedMatchers)));
assertThat(((JSONObject) body.getBody()).keySet(), is(equalTo((Set) new HashSet(Arrays.asList("ids")))));
}
use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.
the class PactDslJsonBodyTest method nestedArrayMatcherTest.
@Test
public void nestedArrayMatcherTest() {
DslPart body = new PactDslJsonBody().array(FIRST).stringType(L_1_EXAMPLE).array().stringType(L_2_EXAMPLE).closeArray().closeArray();
Set<String> expectedMatchers = new HashSet<String>(Arrays.asList("$.body.first[0]", "$.body.first[1][0]"));
assertThat(body.getMatchers().keySet(), is(equalTo(expectedMatchers)));
assertThat(((JSONObject) body.getBody()).getJSONArray(FIRST).getString(0), is(equalTo(L_1_EXAMPLE)));
assertThat(((JSONObject) body.getBody()).getJSONArray(FIRST).getJSONArray(1).getString(0), is(equalTo(L_2_EXAMPLE)));
}
Aggregations