au.com.dius.pact.consumer.Pact Java Examples
The following examples show how to use
au.com.dius.pact.consumer.Pact.
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 |
@Pact(consumer = "Bonus") public RequestResponsePact createFragment(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json"); Date now = new Date(); return builder .uponReceiving("Request for order feed") .method("GET") .path("/feed") .willRespondWith() .status(200) .headers(headers) .body(feedBody(now)) .uponReceiving("Request for an order") .method("GET") .path("/order/1") .willRespondWith() .status(200) .headers(headers) .body(order(now)) .toPact(); }
Example #2
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 6 votes |
@Pact(consumer = "Shipping") public RequestResponsePact createFragment(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json"); Date now = new Date(); return builder .uponReceiving("Request for order feed") .method("GET") .path("/feed") .willRespondWith() .status(200) .headers(headers) .body(feedBody(now)) .uponReceiving("Request for an order") .method("GET") .path("/order/1") .willRespondWith() .status(200) .headers(headers) .body(order(now)) .toPact(); }
Example #3
Source File: PollingTest.java From microservice-istio with Apache License 2.0 | 6 votes |
@Pact(consumer = "Invoice") public RequestResponsePact createFragment(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json"); Date now = new Date(); return builder .uponReceiving("Request for order feed") .method("GET") .path("/feed") .willRespondWith() .status(200) .headers(headers) .body(feedBody(now)) .uponReceiving("Request for an order") .method("GET") .path("/order/1") .willRespondWith() .status(200) .headers(headers) .body(order(now)) .toPact(); }
Example #4
Source File: UserServiceConsumerPactTest.java From spring-microservice-sample with GNU General Public License v3.0 | 6 votes |
@Pact(consumer = "auth-service") public RequestResponsePact createFragment(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json"); //@formatter:off return builder .given("should return user if existed") .uponReceiving("Get a user by existing username: user") .path("/users/user") .method("GET") .willRespondWith() .headers(headers) .status(200) .body("{\"username\": \"user\", \"password\": \"password\", \"email\": \"[email protected]\" }") .given("should return error 404 if not existed") .uponReceiving("Get a user by none-existing username: noneExisting") .method("GET") .path("/users/noneExisting") .willRespondWith() .headers(headers) .status(404) .body("{\"entity\": \"USER\",\"id\": \"noneExisting\",\"code\": \"not_found\",\"message\": \"User:noneExisting was not found\"}") .toPact(); //@formatter:on }
Example #5
Source File: AuthenticationServiceFailedTest.java From ServiceComb-Company-WorkShop with Apache License 2.0 | 6 votes |
@Pact(consumer = "Manager") public PactFragment createFragment(PactDslWithProvider pactDslWithProvider) throws JsonProcessingException { Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", MediaType.TEXT_PLAIN_VALUE); return pactDslWithProvider .given("User Jack is unauthorized") .uponReceiving("a request to access from Jack") .path("/rest/validate") .body(objectMapper.writeValueAsString(new Token(token)), APPLICATION_JSON) .method("POST") .willRespondWith() .headers(headers) .status(HttpStatus.FORBIDDEN.value()) .toFragment(); }
Example #6
Source File: AuthenticationServiceHappyTest.java From ServiceComb-Company-WorkShop with Apache License 2.0 | 6 votes |
@Pact(consumer = "Manager") public PactFragment createFragment(PactDslWithProvider pactDslWithProvider) throws JsonProcessingException { Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", MediaType.TEXT_PLAIN_VALUE); return pactDslWithProvider .given("User Sean is authorized") .uponReceiving("a request to access from Sean") .path("/rest/validate") .body(objectMapper.writeValueAsString(new Token(token)), APPLICATION_JSON) .method("POST") .willRespondWith() .headers(headers) .status(HttpStatus.OK.value()) .body(username) .toFragment(); }
Example #7
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 #8
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 #9
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 #10
Source File: BeerControllerTest.java From spring-cloud-contract-samples with Apache License 2.0 | 6 votes |
@Pact(consumer="beer-api-consumer-pact") public RequestResponsePact beerNotOk(PactDslWithProvider builder) { return builder .given("") .uponReceiving("Represents a successful scenario of getting a beer") .path("/check") .method("POST") .headers("Content-Type", "application/json;charset=UTF-8") .body("{\"name\":\"marcin\",\"age\":25}") .willRespondWith() .status(200) .body("{\"status\":\"OK\"}") .headers(responseHeaders()) .given("") .uponReceiving("Represents an unsuccessful scenario of getting a beer") .path("/check") .method("POST") .headers("Content-Type", "application/json;charset=UTF-8") .body("{\"name\":\"marcin\",\"age\":10}") .willRespondWith() .status(200) .body("{\"status\":\"NOT_OK\"}") .headers(responseHeaders()) .toPact(); }
Example #11
Source File: PactConsumerDrivenContractUnitTest.java From tutorials with MIT License | 5 votes |
@Pact(consumer = "test_consumer") public RequestResponsePact createPact(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json"); return builder.given("test GET").uponReceiving("GET REQUEST").path("/pact").method("GET").willRespondWith().status(200).headers(headers).body("{\"condition\": true, \"name\": \"tom\"}").given("test POST").uponReceiving("POST REQUEST").method("POST") .headers(headers).body("{\"name\": \"Michael\"}").path("/pact").willRespondWith().status(201).toPact(); }