Search in sources :

Example 16 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact in project pact-jvm by DiUS.

the class ExampleMessageWithMetadataConsumerTest 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<>();
    metadata.put("metadata1", "metadataValue1");
    metadata.put("metadata2", "metadataValue2");
    return builder.given("SomeProviderState").expectsToReceive("a test message with metadata").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) Pact(au.com.dius.pact.core.model.annotations.Pact) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact)

Example 17 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact in project pact-jvm by DiUS.

the class PactVerificationsForMultipleFragmentsTest method messagePact.

@Pact(provider = MESSAGE_PROVIDER_NAME, consumer = PACT_VERIFICATIONS_CONSUMER_NAME)
public MessagePact messagePact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value1");
    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) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Example 18 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact in project pact-jvm by DiUS.

the class PactVerificationsForMultipleHttpsAndMessagesTest method otherMessagePact.

@Pact(provider = OTHER_MESSAGE_PROVIDER_NAME, consumer = PACT_VERIFICATIONS_CONSUMER_NAME)
public MessagePact otherMessagePact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParamA", "valueA");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("contentType", "application/json");
    return builder.given("SomeOtherProviderState").expectsToReceive("another test message").withMetadata(metadata).withContent(body).toPact();
}
Also used : HashMap(java.util.HashMap) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Example 19 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact in project pact-jvm by DiUS.

the class MessageWithMetadataConsumerTest method createPact.

@Pact(consumer = "test_consumer_v3")
public MessagePact createPact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value1");
    body.stringValue("testParam2", "value2");
    return builder.given("SomeProviderState").expectsToReceive("a test message with metadata").withMetadata(md -> {
        md.add("metadata1", "metadataValue1");
        md.add("metadata2", "metadataValue2");
        md.add("metadata3", 10L);
        md.matchRegex("partitionKey", "[A-Z]{3}\\d{2}", "ABC01");
    }).withContent(body).toPact();
}
Also used : PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) Pact(au.com.dius.pact.core.model.annotations.Pact)

Example 20 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact 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.core.model.annotations.Pact) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact)

Aggregations

Pact (au.com.dius.pact.core.model.annotations.Pact)21 MessagePact (au.com.dius.pact.core.model.messaging.MessagePact)21 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)16 HashMap (java.util.HashMap)16 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)5 MessagePactBuilder (au.com.dius.pact.consumer.MessagePactBuilder)4 Method (java.lang.reflect.Method)3 ProviderState (au.com.dius.pact.core.model.ProviderState)2 Message (au.com.dius.pact.core.model.messaging.Message)2 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)1 PactDirectory (au.com.dius.pact.core.model.annotations.PactDirectory)1 PactFolder (au.com.dius.pact.core.model.annotations.PactFolder)1 MetricEvent (au.com.dius.pact.core.support.MetricEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Statement (org.junit.runners.model.Statement)1