au.com.dius.pact.consumer.dsl.DslPart Java Examples

The following examples show how to use au.com.dius.pact.consumer.dsl.DslPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 6 votes vote down vote up
public DslPart order(Date now) {
	return new PactDslJsonBody().numberType("id", 1)
								.numberType("numberOfLines", 1)
								.stringType("deliveryService", "Hermes")
								.object("customer")
								.numberType("customerId", 1)
								.stringType("name", "Wolff")
								.stringType("firstname", "Eberhard")
								.stringType("email", "[email protected]")
								.closeObject()
								.object("shippingAddress")
								.stringType("street", "Krischerstr. 100")
								.stringType("zip", "40789")
								.stringType("city", "Monheim am Rhein")
								.closeObject()
								.array("orderLine")
								.object()
								.numberType("count", 42)
								.object("item")
								.numberType("itemId", 1)
								.stringType("name", "iPod")
								.closeObject()
								.closeArray();
}
 
Example #2
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 6 votes vote down vote up
public DslPart order(Date now) {
	return new PactDslJsonBody()
								.numberType("id", 1)
								.numberType("numberOfLines", 1)
								.object("customer")
								.numberType("customerId", 1)
								.stringType("name", "Wolff")
								.stringType("firstname", "Eberhard")
								.stringType("email", "[email protected]")
								.closeObject()
								.object("billingAddress")
								.stringType("street", "Krischerstr. 100")
								.stringType("zip", "40789")
								.stringType("city", "Monheim am Rhein")
								.closeObject()
								.array("orderLine")
								.object()
								.numberType("count", 42)
								.object("item")
								.numberType("itemId", 1)
								.stringType("name", "iPod")
								.numberType("price", 23)
								.closeObject()
								.closeArray();
}
 
Example #3
Source File: ExternalBookingContractTest.java    From monolith with Apache License 2.0 6 votes vote down vote up
private DslPart bookingResponseBody() {
    PactDslJsonBody body = new PactDslJsonBody();
    body.id()
            .booleanType("synthetic", true)
            .minArrayLike("tickets", 1)
                .id()
                    .object("seat")
                        .integerType("rowNumber")
                        .integerType("number")
                        .object("section")
                            .id()
                            .stringType("name")
                            .stringType("description")
                            .integerType("numberOfRows")
                            .integerType("rowCapacity")
                            .integerType("capacity")
                        .closeObject()
                    .closeObject()
                .closeObject()
            .closeArray()


    ;
    return body;
}
 
Example #4
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 5 votes vote down vote up
private DslPart feedBody(Date now) {
	return new PactDslJsonBody().date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.eachLike("orders")
								.numberType("id", 1)
								.stringType("link", "http://localhost:8081/order/1")
								.date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.closeArray();
}
 
Example #5
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 5 votes vote down vote up
public DslPart order(Date now) {
	return new PactDslJsonBody()
								.numberType("id", 1)
								.numberType("numberOfLines", 1)
								.numberType("revenue", 42)
								.object("customer")
								.numberType("customerId", 1)
								.stringType("name", "Wolff")
								.stringType("firstname", "Eberhard")
								.stringType("email", "[email protected]")
								.closeObject();
}
 
Example #6
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 5 votes vote down vote up
private DslPart feedBody(Date now) {
	return new PactDslJsonBody().date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.eachLike("orders")
								.numberType("id", 1)
								.stringType("link", "http://localhost:8081/order/1")
								.date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.closeArray();
}
 
Example #7
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 5 votes vote down vote up
private DslPart feedBody(Date now) {
	return new PactDslJsonBody().date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.eachLike("orders")
								.numberType("id", 1)
								.stringType("link", "http://localhost:8081/order/1")
								.date("updated", "yyyy-MM-dd'T'kk:mm:ss.SSS+0000", now)
								.closeArray();
}
 
Example #8
Source File: ExternalBookingContractTest.java    From monolith with Apache License 2.0 5 votes vote down vote up
private DslPart bookingRequestBody(){
    PactDslJsonBody body = new PactDslJsonBody();
    body
            .integerType("performance", 1)
            .booleanType("synthetic", true)
            .stringType("email", "[email protected]")
                .minArrayLike("ticketRequests", 1)
                    .integerType("ticketPrice", 1)
                    .integerType("quantity")
                .closeObject()
            .closeArray();


    return body;
}
 
Example #9
Source File: PactJunitDSLJsonBodyTest.java    From Pact-JVM-Example with MIT License 5 votes vote down vote up
@Test
public void testWithPactDSLJsonBody() {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    DslPart body = new PactDslJsonBody()
            .numberType("salary", 45000)
            .stringType("name", "Hatsune Miku")
            .stringType("nationality", "Japan")
            .object("contact")
            .stringValue("Email", "[email protected]")
            .stringValue("Phone Number", "9090950")
            .closeObject();

    RequestResponsePact pact = ConsumerPactBuilder
            .consumer("JunitDSLJsonBodyConsumer")
            .hasPactWith("ExampleProvider")
            .given("")
            .uponReceiving("Query name is Miku")
            .path("/information")
            .query("name=Miku")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body(body)
            .toPact();

    MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3);
    PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
        providerService.setBackendURL(mockServer.getUrl());
        Information information = providerService.getInformation();
        assertEquals(information.getName(), "Hatsune Miku");
        return null;
    });

    checkResult(result);
}
 
Example #10
Source File: PactJunitDSLJsonBodyTest.java    From Pact-JVM-Example with MIT License 5 votes vote down vote up
@Test
public void testWithLambdaDSLJsonBody() {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    DslPart body = newJsonBody((root) -> {
        root.numberValue("salary", 45000);
        root.stringValue("name", "Hatsune Miku");
        root.stringValue("nationality", "Japan");
        root.object("contact", (contactObject) -> {
            contactObject.stringMatcher("Email", ".*@ariman.com", "[email protected]");
            contactObject.stringType("Phone Number", "9090950");
        });
    }).build();

    RequestResponsePact pact = ConsumerPactBuilder
            .consumer("JunitDSLLambdaJsonBodyConsumer")
            .hasPactWith("ExampleProvider")
            .given("")
            .uponReceiving("Query name is Miku")
            .path("/information")
            .query("name=Miku")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body(body)
            .toPact();

    MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3);
    PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
        providerService.setBackendURL(mockServer.getUrl());
        Information information = providerService.getInformation();
        assertEquals(information.getName(), "Hatsune Miku");
        return null;
    });

    checkResult(result);
}
 
Example #11
Source File: NationalityPactTest.java    From Pact-JVM-Example with MIT License 5 votes vote down vote up
@Test
public void testWithNationality() {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    DslPart body = newJsonBody((root) -> {
        root.numberType("salary");
        root.stringValue("name", "Takamachi Nanoha");
        root.stringValue("nationality", "Japan");
        root.object("contact", (contactObject) -> {
            contactObject.stringMatcher("Email", ".*@ariman.com", "[email protected]");
            contactObject.stringType("Phone Number", "9090940");
        });
    }).build();

    RequestResponsePact pact = ConsumerPactBuilder
            .consumer("ConsumerNanohaWithNationality")
            .hasPactWith("ExampleProvider")
            .given("")
            .uponReceiving("Query name is Nanoha")
            .path("/information")
            .query("name=Nanoha")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body(body)
            .toPact();

    MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3);
    PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
        providerService.setBackendURL(mockServer.getUrl());
        Information information = providerService.getInformation();
        assertEquals(information.getName(), "Takamachi Nanoha");
        assertEquals(information.getNationality(), "Japan");
        return null;
    });

    checkResult(result);
}
 
Example #12
Source File: NationalityPactTest.java    From Pact-JVM-Example with MIT License 5 votes vote down vote up
@Test
public void testNoNationality() {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    DslPart body = newJsonBody((root) -> {
        root.numberType("salary");
        root.stringValue("name", "Takamachi Nanoha");
        root.stringValue("nationality", null);
        root.object("contact", (contactObject) -> {
            contactObject.stringMatcher("Email", ".*@ariman.com", "[email protected]");
            contactObject.stringType("Phone Number", "9090940");
        });
    }).build();

    RequestResponsePact pact = ConsumerPactBuilder
            .consumer("ConsumerNanohaNoNationality")
            .hasPactWith("ExampleProvider")
            .given("No nationality")
            .uponReceiving("Query name is Nanoha")
            .path("/information")
            .query("name=Nanoha")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body(body)
            .toPact();

    MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3);
    PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
        providerService.setBackendURL(mockServer.getUrl());
        Information information = providerService.getInformation();
        assertEquals(information.getName(), "Takamachi Nanoha");
        assertNull(information.getNationality());
        return null;
    });

    checkResult(result);
}
 
Example #13
Source File: ExternalBookingContractTest.java    From monolith with Apache License 2.0 4 votes vote down vote up
private DslPart syntheticBookingResponseBody() {
    PactDslJsonBody body = new PactDslJsonBody();
    body
            .booleanType("synthetic", true);
    return body;
}