@Pact(consumer="test_consumer") public PactFragment create500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Create Request causing 500") .matchPath("/entity/default.*") .method("POST") .willRespondWith() .status(500) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment post500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("POST Request causing 500") .matchPath("/entity/default.*") .method("POST") .willRespondWith() .status(500) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment get500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("GET Request causing 500") .matchPath("/entity/default.*") .method("GET") .willRespondWith() .status(500) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment getNotFound(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Find non existent request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("GET") .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeFindNonExistentResponse()) .toFragment(); }
@Pact(consumer="sample_microservice") public RequestResponsePact createPact(PactDslWithProvider builder) throws IOException { return builder .given("weather forecast data") .uponReceiving("a request for a weather request for Hamburg") .path("/some-test-api-key/53.5511,9.9937") .method("GET") .willRespondWith() .status(200) .body(FileLoader.read("classpath:weatherApiResponse.json"), ContentType.APPLICATION_JSON) .toPact(); }
@Pact(consumer="test_consumer") public PactFragment find(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Find request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("GET") .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeFindResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment findWithTriggeringEvent(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("findWithTriggeringEvent request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .query("triggeringEventToken=myeventtoken") .method("GET") .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeFindResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment findWithTriggeringEventConflict(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("findWithTriggeringEventConflict request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .query("triggeringEventToken=myeventtoken") .method("GET") .willRespondWith() .status(409) .body(RequestResponseJsonObjects.makeDuplicateEventErrorResponse()) .toFragment(); }
@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 }
@Pact(consumer="test_consumer") public PactFragment createWithId(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Create with Id request") .path("/entity/default") .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedCreateWithIdRequest()) .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeCreateWithIdResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment updateWithOptimisticLockingExceptionFollowingRetry(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Update with Optimistic Locking request 2") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedUpdateRequest()) .willRespondWith() .status(409) .body(RequestResponseJsonObjects.makeOptimisticLockingErrorResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment createWithDuplicateId(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Create with DuplicateId request") .path("/entity/default") .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedCreateWithIdRequest() ) .willRespondWith() .status(409) .body(RequestResponseJsonObjects.makeEntityExistsErrorResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment updateWithTriggeringEventConflict(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("updateWithTriggeringEventConflict request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedUpdateRequestWithTriggeringEvent() ) .willRespondWith() .status(409) .body(RequestResponseJsonObjects.makeDuplicateEventErrorResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment create(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Create request") .path("/entity/default") .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedCreateRequest() ) .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeCreateResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment update(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Update request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedUpdateRequest() ) .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeCreateResponse()) .toFragment(); }
@Pact(consumer="test_consumer") public PactFragment updateWithTriggeringEvent(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("updateWithTriggeringEvent request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedUpdateRequestWithTriggeringEvent() ) .willRespondWith() .status(200) .body(RequestResponseJsonObjects.makeCreateResponse()) .toFragment(); } @Pact(consumer="test_consumer")
@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 }
@Pact(consumer="test_consumer") public PactFragment updateWithOptimisticLockingException(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Update with Optimistic Locking request") .path("/entity/default/" + RequestResponseJsonObjects.aggregateType + "/" + RequestResponseJsonObjects.ENTITY_ID) .method("POST") .matchHeader("Content-Type", "application/json") .body(RequestResponseJsonObjects.makeExpectedUpdateRequest() ) .willRespondWith() .status(409) .body(RequestResponseJsonObjects.makeOptimisticLockingErrorResponse()) .toFragment(); } @Pact(consumer="test_consumer")