Search in sources :

Example 6 with Pact

use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.

the class TodoXmlTest method projects.

// body: <?xml version="1.0" encoding="UTF-8"?>
// <projects foo="bar">
// <project id="1" name="Project 1" due="2016-02-11T09:46:56.023Z">
// <tasks>
// <task id="1" name="Do the laundry" done="true"/>
// <task id="2" name="Do the dishes" done="false"/>
// <task id="3" name="Do the backyard" done="false"/>
// <task id="4" name="Do nothing" done="false"/>
// </tasks>
// </project>
// <project/>
// </projects>
@Pact(provider = "TodoProvider", consumer = "TodoConsumer")
public RequestResponsePact projects(PactDslWithProvider builder) {
    return builder.given("i have a list of projects").uponReceiving("a request for projects in XML").path("/projects").query("from=today").headers(mapOf("Accept", "application/xml")).willRespondWith().headers(mapOf("Content-Type", "application/xml")).status(200).body(new PactXmlBuilder("projects", "http://some.namespace/and/more/stuff").build(root -> {
        root.setAttributes(mapOf("id", "1234"));
        root.eachLike("project", 2, mapOf("id", integer(), "type", "activity", "name", string("Project 1"), "due", timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSX", "2016-02-11T09:46:56.023Z")), project -> {
            project.appendElement("tasks", Collections.emptyMap(), task -> {
                task.eachLike("task", 5, mapOf("id", integer(), "name", string("Task 1"), "done", bool(true)));
            });
        });
    })).toPact();
}
Also used : PactXmlBuilder(au.com.dius.pact.consumer.xml.PactXmlBuilder) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Example 7 with Pact

use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.

the class AsyncMessageTest method createPact2.

@Pact(provider = "MessageProvider", consumer = "test_consumer_v3")
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("Content-Type", "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) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) Pact(au.com.dius.pact.core.model.annotations.Pact)

Example 8 with Pact

use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.

the class AsyncMessageTest method createPact.

@Pact(consumer = "test_consumer_v3")
MessagePact createPact(MessagePactBuilder builder) {
    PactDslJsonBody body = new PactDslJsonBody();
    body.stringValue("testParam1", "value1");
    body.stringValue("testParam2", "value2");
    Map<String, Object> metadata = new HashMap<>();
    metadata.put("destination", Matchers.regexp("\\w+\\d+", "X001"));
    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)

Example 9 with Pact

use of au.com.dius.pact.core.model.annotations.Pact in project pact-jvm by DiUS.

the class Issue1176Test method validCredentials.

@Pact(provider = "config-service", consumer = "test-integration")
public RequestResponsePact validCredentials(PactDslWithProvider builder) {
    Map<String, String> headers = Collections.singletonMap("Content-Type", ContentType.TEXT.toString());
    RequestResponsePact pact = builder.uponReceiving("valid configuration").path(CONFIG_URL).method("GET").headers(headers).body("text").willRespondWith().status(200).body("{\"data\":\"\", \"status\":\"success\"}").toPact();
    return pact;
}
Also used : RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) Pact(au.com.dius.pact.core.model.annotations.Pact) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact)

Example 10 with Pact

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

Aggregations

Pact (au.com.dius.pact.core.model.annotations.Pact)31 MessagePact (au.com.dius.pact.core.model.messaging.MessagePact)21 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)19 HashMap (java.util.HashMap)18 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)14 Method (java.lang.reflect.Method)5 MessagePactBuilder (au.com.dius.pact.consumer.MessagePactBuilder)4 DslPart (au.com.dius.pact.consumer.dsl.DslPart)4 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)3 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)2 BasePact (au.com.dius.pact.core.model.BasePact)2 ProviderState (au.com.dius.pact.core.model.ProviderState)2 PactDirectory (au.com.dius.pact.core.model.annotations.PactDirectory)2 PactFolder (au.com.dius.pact.core.model.annotations.PactFolder)2 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)2 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)2 Message (au.com.dius.pact.core.model.messaging.Message)2 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)1