/** * The body of the request with possible single quotes as delimiters * and using {@link QuoteUtil} to convert single quotes to double quotes if required. * * @param body Request body in string form */ public PactDslResponse bodyWithSingleQuotes(String body) { if (body != null) { body = QuoteUtil.convert(body); } return body(body); }
/** * Response body to return * * @param body body in string form * @param mimeType the Content-Type response header value */ public PactDslResponse body(String body, ContentType mimeType) { return body(body, mimeType.toString()); }
/** * The body of the request * * @param body Response body in Java Functional Interface Supplier that must return a string * @param mimeType the Content-Type response header value */ public PactDslResponse body(Supplier<String> body, ContentType mimeType) { return body(body, mimeType.toString()); }
/** * The body of the request * * @param body Response body in Java Functional Interface Supplier that must return a string * @param mimeType the Content-Type response header value */ public PactDslResponse body(Supplier<String> body, ContentType mimeType) { return body(body, mimeType.toString()); }
/** * The body of the request with possible single quotes as delimiters * and using {@link QuoteUtil} to convert single quotes to double quotes if required. * * @param body Request body in string form */ public PactDslResponse bodyWithSingleQuotes(String body) { if (body != null) { body = QuoteUtil.convert(body); } return body(body); }
/** * Response body to return * * @param body body in string form * @param mimeType the Content-Type response header value */ public PactDslResponse body(String body, ContentType mimeType) { return body(body, mimeType.toString()); }
/** * The body of the request with possible single quotes as delimiters * and using {@link QuoteUtil} to convert single quotes to double quotes if required. * * @param body Request body in string form * @param mimeType the Content-Type response header value */ public PactDslResponse bodyWithSingleQuotes(String body, String mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }
/** * The body of the request with possible single quotes as delimiters * and using {@link QuoteUtil} to convert single quotes to double quotes if required. * * @param body Request body in string form * @param mimeType the Content-Type response header value */ public PactDslResponse bodyWithSingleQuotes(String body, String mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }
@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 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="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 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 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 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 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(); }