/** * 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 PactDslRequestWithPath bodyWithSingleQuotes(String body, ContentType mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }
/** * The path of the request * * @param path string path */ public PactDslRequestWithPath path(String path) { return new PactDslRequestWithPath(consumerPactBuilder, consumerName, providerName, pactDslWithState.state, description, path, requestMethod, requestHeaders, query, requestBody, requestMatchers, requestGenerators, defaultRequestValues, defaultResponseValues); }
PactDslRequestWithPath(ConsumerPactBuilder consumerPactBuilder, PactDslRequestWithPath existing, String description, PactDslRequestWithoutPath defaultRequestValues, PactDslResponse defaultResponseValues) { super(defaultRequestValues); this.requestMethod = "GET"; this.consumerPactBuilder = consumerPactBuilder; this.consumer = existing.consumer; this.provider = existing.provider; this.state = existing.state; this.description = description; this.defaultResponseValues = defaultResponseValues; this.path = existing.path; setupDefaultValues(); }
@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 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 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(); }
/** * Match a request header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regex Regular expression to match */ public PactDslRequestWithPath matchHeader(String header, String regex) { return matchHeader(header, regex, new Generex(regex).random()); }
/** * Match a query parameter with a regex. A random query parameter value will be generated from the regex. * * @param parameter Query parameter * @param regex Regular expression to match with */ public PactDslRequestWithPath matchQuery(String parameter, String regex) { return matchQuery(parameter, regex, new Generex(regex).random()); }
/** * Sets up a file upload request. This will add the correct content type header to the request * @param partName This is the name of the part in the multipart body. * @param fileName This is the name of the file that was uploaded * @param fileContentType This is the content type of the uploaded file * @param data This is the actual file contents */ public PactDslRequestWithPath withFileUpload(String partName, String fileName, String fileContentType, byte[] data) throws IOException { setupFileUpload(partName, fileName, fileContentType, data); return this; }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
@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 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 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(); }
/** * Match a request header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regex Regular expression to match */ public PactDslRequestWithPath matchHeader(String header, String regex) { return matchHeader(header, regex, new Generex(regex).random()); }
/** * Match a query parameter with a regex. A random query parameter value will be generated from the regex. * * @param parameter Query parameter * @param regex Regular expression to match with */ public PactDslRequestWithPath matchQuery(String parameter, String regex) { return matchQuery(parameter, regex, new Generex(regex).random()); }
/** * Sets up a file upload request. This will add the correct content type header to the request * @param partName This is the name of the part in the multipart body. * @param fileName This is the name of the file that was uploaded * @param fileContentType This is the content type of the uploaded file * @param data This is the actual file contents */ public PactDslRequestWithPath withFileUpload(String partName, String fileName, String fileContentType, byte[] data) throws IOException { setupFileUpload(partName, fileName, fileContentType, data); return this; } }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
@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 get500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("GET Request causing 500") .matchPath("/entity/default.*") .method("GET") .willRespondWith() .status(500) .toFragment(); }
/** * 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 PactDslRequestWithPath bodyWithSingleQuotes(String body, String mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }