/** * Description of the request that is expected to be received * * @param description request description */ public PactDslRequestWithoutPath uponReceiving(String description) { return new PactDslRequestWithoutPath(consumerPactBuilder, this, description, defaultRequestValues, defaultResponseValues); }
/** * 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 PactDslRequestWithoutPath bodyWithSingleQuotes(String body, ContentType mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }
public PactDslRequestWithoutPath(ConsumerPactBuilder consumerPactBuilder, PactDslWithState pactDslWithState, String description, PactDslRequestWithoutPath defaultRequestValues, PactDslResponse defaultResponseValues) { super(defaultRequestValues); this.consumerPactBuilder = consumerPactBuilder; this.pactDslWithState = pactDslWithState; this.description = description; this.consumerName = pactDslWithState.consumerName; this.providerName = pactDslWithState.providerName; this.defaultResponseValues = defaultResponseValues; setupDefaultValues(); }
@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(); }
/** * 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()); }
/** * 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 PactDslRequestWithoutPath withFileUpload(String partName, String fileName, String fileContentType, byte[] data) throws IOException { setupFileUpload(partName, fileName, fileContentType, data); return this; }
@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(); }
/** * 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()); }
/** * 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 PactDslRequestWithoutPath withFileUpload(String partName, String fileName, String fileContentType, byte[] data) throws IOException { setupFileUpload(partName, fileName, fileContentType, data); return this; }
@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 create500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("Create Request causing 500") .matchPath("/entity/default.*") .method("POST") .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 PactDslRequestWithoutPath bodyWithSingleQuotes(String body) { if (body != null) { body = QuoteUtil.convert(body); } return body(body); }
/** * Description of the request that is expected to be received * * @param description request description */ public PactDslRequestWithoutPath uponReceiving(String description) { return new PactDslRequestWithoutPath(consumerPactBuilder, this, description, defaultRequestValues, defaultResponseValues); }
public PactDslRequestWithoutPath(ConsumerPactBuilder consumerPactBuilder, PactDslWithState pactDslWithState, String description, PactDslRequestWithoutPath defaultRequestValues, PactDslResponse defaultResponseValues) { super(defaultRequestValues); this.consumerPactBuilder = consumerPactBuilder; this.pactDslWithState = pactDslWithState; this.description = description; this.consumerName = pactDslWithState.consumerName; this.providerName = pactDslWithState.providerName; this.defaultResponseValues = defaultResponseValues; setupDefaultValues(); }
@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 post500(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("POST Request causing 500") .matchPath("/entity/default.*") .method("POST") .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 PactDslRequestWithoutPath bodyWithSingleQuotes(String body, String mimeType) { if (body != null) { body = QuoteUtil.convert(body); } return body(body, mimeType); }
@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(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 * * @param body Request body in string form */ public PactDslRequestWithoutPath body(String body, ContentType mimeType) { return body(body, mimeType.toString()); }