au.com.dius.pact.consumer.dsl.PactDslJsonBody Java Examples
The following examples show how to use
au.com.dius.pact.consumer.dsl.PactDslJsonBody.
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 |
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 |
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: ClientPactTest.java From pact-workshop-jvm with Apache License 2.0 | 6 votes |
@Pact(provider = "Our Provider", consumer = "Our Little Consumer") public RequestResponsePact pact(PactDslWithProvider builder) { dateTime = LocalDateTime.now(); dateResult = OffsetDateTime.now().truncatedTo(ChronoUnit.SECONDS); return builder .given("data count > 0") .uponReceiving("a request for json data") .path("/provider.json") .method("GET") .query("validDate=" + dateTime.toString()) .willRespondWith() .status(200) .body( new PactDslJsonBody() .stringValue("test", "NO") .datetime("validDate", "yyyy-MM-dd'T'HH:mm:ssXX", dateResult.toInstant()) .integerType("count", 100) ) .toPact(); }
Example #4
Source File: ExternalBookingContractTest.java From monolith with Apache License 2.0 | 6 votes |
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 #5
Source File: MessageConsumerTest.java From code-examples with MIT License | 6 votes |
@Pact(provider = "userservice", consumer = "userclient") public MessagePact userCreatedMessagePact(MessagePactBuilder builder) { PactDslJsonBody body = new PactDslJsonBody(); body.stringType("messageUuid"); body.object("user") .numberType("id", 42L) .stringType("name", "Zaphod Beeblebrox") .closeObject(); // @formatter:off return builder .expectsToReceive("a user created message") .withContent(body) .toPact(); // @formatter:on }
Example #6
Source File: UserServiceConsumerTest.java From code-examples with MIT License | 6 votes |
@Pact(state = "provider accepts a new person", provider = "userservice", consumer = "userclient") RequestResponsePact createPersonPact(PactDslWithProvider builder) { // @formatter:off return builder .given("provider accepts a new person") .uponReceiving("a request to POST a person") .path("/user-service/users") .method("POST") .willRespondWith() .status(201) .matchHeader("Content-Type", "application/json") .body(new PactDslJsonBody() .integerType("id", 42)) .toPact(); // @formatter:on }
Example #7
Source File: UserServiceConsumerTest.java From code-examples with MIT License | 6 votes |
@Pact(state = "person 42 exists", provider = "userservice", consumer = "userclient") RequestResponsePact updatePersonPact(PactDslWithProvider builder) { // @formatter:off return builder .given("person 42 exists") .uponReceiving("a request to PUT a person") .path("/user-service/users/42") .method("PUT") .willRespondWith() .status(200) .matchHeader("Content-Type", "application/json") .body(new PactDslJsonBody() .stringType("firstName", "Zaphod") .stringType("lastName", "Beeblebrox")) .toPact(); // @formatter:on }
Example #8
Source File: MemberSignedUpEventPactContracts.java From microservices-testing-examples with MIT License | 5 votes |
@Pact(consumer = WELCOME_MEMBER_EMAIL_SERVICE, provider = SPECIAL_MEMBERSHIP_SERVICE) public MessagePact newMemberTonyStark(MessagePactBuilder builder) { PactDslJsonBody body = new PactDslJsonBody() .stringValue("@type", "memberSignedUpEvent") .stringMatcher("email", ".+@.+\\..+", "[email protected]"); Map<String, String> metadata = new HashMap<>(); return builder.given("Tony Stark became a new member") .expectsToReceive("An event notifying Tony Stark's new membership") .withMetadata(metadata) .withContent(body) .toPact(); }
Example #9
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 5 votes |
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 #10
Source File: CreditScoreServicePactContracts.java From microservices-testing-examples with MIT License | 5 votes |
@Pact(provider = CREDIT_SCORE_SERVICE, consumer = SPECIAL_MEMBERSHIP_SERVICE) public RequestResponsePact tonyStarkCreditScore(PactDslWithProvider pact) { return pact.given("There is a [email protected]") .uponReceiving("A credit score request for [email protected]") .path("/credit-scores/[email protected]").method("GET") .willRespondWith() .status(200) .headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON)) .body(new PactDslJsonBody().integerType("creditScore", 850)) .toPact(); }
Example #11
Source File: PactJunitDSLJsonBodyTest.java From Pact-JVM-Example with MIT License | 5 votes |
@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 #12
Source File: ExternalBookingContractTest.java From monolith with Apache License 2.0 | 5 votes |
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 #13
Source File: ClientPactTest.java From pact-workshop-jvm with Apache License 2.0 | 5 votes |
@Pact(provider = "Our Provider", consumer = "Our Little Consumer") public RequestResponsePact pactForInvalidDateParameter(PactDslWithProvider builder) { return builder .given("data count > 0") .uponReceiving("a request with an invalid date parameter") .path("/provider.json") .method("GET") .query("validDate=This is not a date") .willRespondWith() .status(400) .body( new PactDslJsonBody().stringValue("error", "'This is not a date' is not a date") ) .toPact(); }
Example #14
Source File: ClientPactTest.java From pact-workshop-jvm with Apache License 2.0 | 5 votes |
@Pact(provider = "Our Provider", consumer = "Our Little Consumer") public RequestResponsePact pactForMissingDateParameter(PactDslWithProvider builder) { return builder .given("data count > 0") .uponReceiving("a request with a missing date parameter") .path("/provider.json") .method("GET") .willRespondWith() .status(400) .body( new PactDslJsonBody().stringValue("error", "validDate is required") ) .toPact(); }
Example #15
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 5 votes |
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 #16
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 5 votes |
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 #17
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 5 votes |
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 #18
Source File: ExternalBookingContractTest.java From monolith with Apache License 2.0 | 4 votes |
private DslPart syntheticBookingResponseBody() { PactDslJsonBody body = new PactDslJsonBody(); body .booleanType("synthetic", true); return body; }