Search in sources :

Example 26 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project box-java-sdk by box.

the class BoxAPIRequestTest method requestSendsXBoxUAHeader.

@Test
public void requestSendsXBoxUAHeader() throws MalformedURLException {
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200)));
    BoxAPIConnection api = new BoxAPIConnection("");
    BoxAPIRequest request = new BoxAPIRequest(api, boxMockUrl(), "GET");
    request.send();
    String headerRegex = "agent=box-java-sdk/\\d\\.\\d+\\.\\d+(-[a-zA-Z]+)?; env=Java/\\d+\\.\\d+\\.\\d+.*";
    RequestPatternBuilder requestPatternBuilder = RequestPatternBuilder.newRequestPattern().withHeader("X-Box-UA", matching(headerRegex));
    verify(requestPatternBuilder);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.Test)

Example 27 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WebhookActionInvokerTest method testBearerToken.

@Test
void testBearerToken() 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;
    AbstractOidcClient abstractOidcClient = mock(AbstractOidcClient.class);
    when(abstractOidcClient.getToken()).thenReturn("token");
    WebhookActionInvoker invoker = new WebhookActionInvoker(testSinkEndpoint, WebClient.create(vertx), abstractOidcClient);
    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("Bearer token"));
    for (Map.Entry<String, String> testHeader : TEST_HEADERS.entrySet()) {
        requestPatternBuilder = requestPatternBuilder.withHeader("x-" + testHeader.getKey(), equalTo(testHeader.getValue()));
    }
    wireMockServer.verify(requestPatternBuilder);
}
Also used : AbstractOidcClient(com.redhat.service.smartevents.infra.auth.AbstractOidcClient) 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 28 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sda-dropwizard-commons by SDA-SE.

the class OpaClassExtension method verify.

@Override
void verify(int count, StubBuilder builder) {
    RequestPatternBuilder requestPattern = buildRequestPattern(builder);
    wireMockExtension.verify(count, requestPattern);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 29 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project junit-servers by mjeanroy.

the class WireMockTestUtils method assertRequestWithBody.

/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param body Request body.
 */
static void assertRequestWithBody(String endpoint, HttpMethod method, String body) {
    UrlPattern urlPattern = urlEqualTo(endpoint);
    RequestMethod rqMethod = new RequestMethod(method.name());
    RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
    rq.withRequestBody(equalTo(body));
    WireMock.verify(1, rq);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern)

Example 30 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project junit-servers by mjeanroy.

the class WireMockTestUtils method assertRequestWithCookies.

/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param cookies Cookies sent in HTTP request.
 */
static void assertRequestWithCookies(String endpoint, HttpMethod method, Iterable<Pair> cookies) {
    UrlPattern urlPattern = urlEqualTo(endpoint);
    RequestMethod rqMethod = new RequestMethod(method.name());
    RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
    for (Pair cookie : cookies) {
        String cookieName = cookie.getO1();
        String cookieValue = cookie.getO2().get(0);
        rq.withCookie(cookieName, equalTo(cookieValue));
    }
    WireMock.verify(1, rq);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Pair(com.github.mjeanroy.junit.servers.utils.commons.Pair)

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