use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WebhookActionInvokerTest method test.
@Test
void test() throws InterruptedException {
wireMockServer.stubFor(post(urlEqualTo(TEST_WEBHOOK_PATH)).willReturn(aResponse().withStatus(200)));
CountDownLatch latch = new CountDownLatch(1);
addUpdateRequestListener(TEST_WEBHOOK_PATH, RequestMethod.POST, latch);
String testSinkEndpoint = webhookSinkUrl + TEST_WEBHOOK_PATH;
WebhookActionInvoker invoker = new WebhookActionInvoker(testSinkEndpoint, WebClient.create(vertx));
invoker.onEvent(TEST_EVENT, TEST_HEADERS);
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlEqualTo(TEST_WEBHOOK_PATH)).withRequestBody(equalToJson(TEST_EVENT, true, true)).withHeader("Content-Type", equalTo("application/json"));
for (Map.Entry<String, String> testHeader : TEST_HEADERS.entrySet()) {
requestPatternBuilder = requestPatternBuilder.withHeader("x-" + testHeader.getKey(), equalTo(testHeader.getValue()));
}
wireMockServer.verify(requestPatternBuilder);
}
use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WebhookActionInvokerTest method testBasicAuth.
@Test
void testBasicAuth() throws InterruptedException {
wireMockServer.stubFor(post(urlEqualTo(TEST_WEBHOOK_PATH)).willReturn(aResponse().withStatus(200)));
CountDownLatch latch = new CountDownLatch(1);
addUpdateRequestListener(TEST_WEBHOOK_PATH, RequestMethod.POST, latch);
String testSinkEndpoint = webhookSinkUrl + TEST_WEBHOOK_PATH;
WebhookActionInvoker invoker = new WebhookActionInvoker(testSinkEndpoint, WebClient.create(vertx), "username", "password");
invoker.onEvent(TEST_EVENT, TEST_HEADERS);
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlEqualTo(TEST_WEBHOOK_PATH)).withRequestBody(equalToJson(TEST_EVENT, true, true)).withHeader("Content-Type", equalTo("application/json")).withHeader("Authorization", equalTo("Basic dXNlcm5hbWU6cGFzc3dvcmQ="));
for (Map.Entry<String, String> testHeader : TEST_HEADERS.entrySet()) {
requestPatternBuilder = requestPatternBuilder.withHeader("x-" + testHeader.getKey(), equalTo(testHeader.getValue()));
}
wireMockServer.verify(requestPatternBuilder);
}
use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sonar-java by SonarSource.
the class WireMockTest method verify.
@Test
public void verify() {
// Compliant
RequestPatternBuilder requestPatternBuilder = new RequestPatternBuilder().allRequests().withUrl("/hello/world/*");
WireMock.verify(requestPatternBuilder);
}
use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sonar-java by SonarSource.
the class WireMockTest method verifyServer.
@Test
public void verifyServer() {
// Compliant
RequestPatternBuilder requestPatternBuilder = new RequestPatternBuilder().allRequests().withUrl("/hello/world/*");
wireMockServer.verify(requestPatternBuilder);
}
use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project triplea by triplea-game.
the class HttpClientTesting method sendServiceCallToWireMock.
private static <T> T sendServiceCallToWireMock(final ServiceCallArgs<T> args, final int returnCode) {
args.wireMockServer.stubFor(post(urlEqualTo(args.expectedRequestPath)).withHeader(HttpHeaders.ACCEPT, equalTo(HttpClientTesting.CONTENT_TYPE_JSON)).willReturn(aResponse().withStatus(returnCode).withHeader(HttpHeaders.CONTENT_TYPE, HttpClientTesting.CONTENT_TYPE_JSON).withBody(args.serverReturnValue)));
WireMock.configureFor("localhost", args.wireMockServer.port());
final URI hostUri = URI.create(args.wireMockServer.url(""));
final T response = args.serviceCall.apply(hostUri);
RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlMatching(args.expectedRequestPath));
for (final String content : args.expectedBodyContents) {
requestPatternBuilder = requestPatternBuilder.withRequestBody(containing(content));
}
verify(requestPatternBuilder.withHeader(HttpHeaders.CONTENT_TYPE, matching(HttpClientTesting.CONTENT_TYPE_JSON)));
return response;
}
Aggregations