Search in sources :

Example 1 with PactDslJsonBody

use of au.com.dius.pact.consumer.dsl.PactDslJsonBody 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;
}
Also used : PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart)

Example 2 with PactDslJsonBody

use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.

the class AsyncMessageTest method createPact2.

@Pact(provider = "test_provider", consumer = "test_consumer_v3")
public MessagePact createPact2(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value3");
    body.stringValue("testParam2", "value4");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("contentType", "application/json");
    return builder.given("SomeProviderState2").expectsToReceive("a test message").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) Pact(au.com.dius.pact.consumer.Pact) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact)

Example 3 with PactDslJsonBody

use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.

the class AsyncMessageTest method createPact.

@Pact(provider = "test_provider", consumer = "test_consumer_v3")
public MessagePact createPact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value1");
    body.stringValue("testParam2", "value2");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("contentType", "application/json");
    return builder.given("SomeProviderState").expectsToReceive("a test message").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) Pact(au.com.dius.pact.consumer.Pact) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact)

Example 4 with PactDslJsonBody

use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.

the class Defect371Test method createPact2.

@Pact(provider = "provider2", consumer = "Defect371")
public MessagePact createPact2(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value3");
    body.stringValue("testParam2", "value4");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("contentType", "application/json");
    return builder.given("Some Other Provider State").expectsToReceive("a test message").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) Pact(au.com.dius.pact.consumer.Pact) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact)

Example 5 with PactDslJsonBody

use of au.com.dius.pact.consumer.dsl.PactDslJsonBody in project pact-jvm by DiUS.

the class ExampleMessageConsumerTest method createPact.

@Pact(provider = "test_provider", consumer = "test_consumer_v3")
public MessagePact createPact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value1");
    body.stringValue("testParam2", "value2");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("contentType", "application/json");
    return builder.given("SomeProviderState").expectsToReceive("a test message").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) Pact(au.com.dius.pact.consumer.Pact) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact)

Aggregations

PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)27 HashMap (java.util.HashMap)14 Pact (au.com.dius.pact.consumer.Pact)12 MessagePact (au.com.dius.pact.model.v3.messaging.MessagePact)12 DslPart (au.com.dius.pact.consumer.dsl.DslPart)11 Test (org.junit.Test)11 RequestResponsePact (au.com.dius.pact.model.RequestResponsePact)9 HashSet (java.util.HashSet)7 JSONObject (org.json.JSONObject)6 ConsumerPactRunnerKt.runConsumerTest (au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest)4 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)1 Date (java.util.Date)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1