Search in sources :

Example 16 with RequestPatternBuilder

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);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) AbstractWireMockTest(com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)

Example 17 with 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);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) AbstractWireMockTest(com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)

Example 18 with 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);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.Test)

Example 19 with 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);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.Test)

Example 20 with 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;
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) URI(java.net.URI)

Aggregations

RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)37 Test (org.junit.jupiter.api.Test)13 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)11 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)9 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)6 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)5 Map (java.util.Map)5 Test (org.junit.Test)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 VerificationResult (com.github.tomakehurst.wiremock.verification.VerificationResult)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 AbstractWireMockTest (com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)2 Request (com.github.tomakehurst.wiremock.http.Request)2 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)2