Wiesław Bondyra
05/27/2022, 11:05 AM@Pact(consumer = CONSUMER_NAME, provider = PROVIDER_NAME)
public RequestResponsePact createPactForWiesaTest(PactDslWithProvider pactDslWithProvider) {
MultipartEntityBuilder multipart2 = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.setContentType(ContentType.APPLICATION_FORM_URLENCODED)
.addBinaryBody("file", "1,2,3".getBytes(), ContentType.create("text/csv"), "data.csv")
.addTextBody("textPart", "sample text");
PactDslResponse builder = pactDslWithProvider
.given("Check buildId")
.uponReceiving("Request to get wiesa buildId")
.path("/wiesabuild")
.body(multipart2)
.method("POST")
.willRespondWith()
.status(HttpStatus.OK.getCode())
.body("is OK", MediaType.TEXT_PLAIN);
return builder.toPact();
}
@Test
@PactTestFor(providerName = "WiesaMultipartService", pactMethod = "createPactForWiesaTest")
void testWiesaMultipartService(MockServer mockServer) throws MalformedURLException {
String url = mockServer.getUrl();
String response;
MultipartEntityBuilder multipart2 = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.STRICT)
.setContentType(ContentType.APPLICATION_FORM_URLENCODED)
.addBinaryBody("file", "1,2,3".getBytes(), ContentType.create("text/csv"), "data.csv")
.addTextBody("textPart", "sample text");
try (RxHttpClient rxHttpClient = RxHttpClient.create(new URL(url))) {
response = rxHttpClient.toBlocking().retrieve(
<http://HttpRequest.POST|HttpRequest.POST>("/wiesabuild", multipart2)
.contentType(APPLICATION_FORM_URLENCODED)
.accept(APPLICATION_FORM_URLENCODED),
String.class
);
assertThat(response).as("body should be with simple is OK statement").isEqualToIgnoringWhitespace("is OK");
}
}
What might be wrong in this example?Wiesław Bondyra
05/27/2022, 11:54 AM