Search in sources :

Example 36 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project neo4j by neo4j.

the class HttpCopierTest method shouldHandleUnexpectedResponseFromInitiateUploadTargetRequest.

@Test
void shouldHandleUnexpectedResponseFromInitiateUploadTargetRequest() throws IOException {
    HttpCopier copier = new HttpCopier(ctx, 2, 2);
    Path source = createDump();
    String authorizationTokenResponse = "abc";
    wireMock.stubFor(authenticationRequest(false).willReturn(successfulAuthorizationResponse(authorizationTokenResponse)));
    wireMock.stubFor(initiateUploadTargetRequest(authorizationTokenResponse).willReturn(aResponse().withStatus(HTTP_BAD_GATEWAY)));
    // when
    assertThrows(CommandFailedException.class, allOf(containsString("Unexpected response"), containsString("Initiating upload target")), () -> authenticateAndCopy(copier, source, 1234, true, "user", "pass".toCharArray()));
    // 1 initial call plus 2 retries are 3 expected calls
    wireMock.verify(3, new RequestPatternBuilder(RequestMethod.ANY, UrlPattern.fromOneOf("/import", null, null, null)));
    // increase maximum retries
    HttpCopier copier2 = new HttpCopier(ctx, 20, 2);
    // and call it again.
    assertThrows(CommandFailedException.class, allOf(containsString("Unexpected response"), containsString("Initiating upload target")), () -> authenticateAndCopy(copier2, source, 1234, true, "user", "pass".toCharArray()));
    // 24 = 3 from previous copier + 1 initial call + 20 retries
    wireMock.verify(24, new RequestPatternBuilder(RequestMethod.ANY, UrlPattern.fromOneOf("/import", null, null, null)));
}
Also used : Path(java.nio.file.Path) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) CoreMatchers.containsString(wiremock.org.hamcrest.CoreMatchers.containsString) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 37 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project mule-oauth-module by mulesoft.

the class AbstractOAuthAuthorizationTestCase method verifyRequestDoneToTokenUrlForClientCredentials.

protected void verifyRequestDoneToTokenUrlForClientCredentials(String scope, boolean encodeInBody, boolean requestThroughProxy) throws UnsupportedEncodingException {
    final RequestPatternBuilder verification = postRequestedFor(urlEqualTo(TOKEN_PATH)).withRequestBody(containing(GRANT_TYPE_PARAMETER + "=" + encode(GRANT_TYPE_CLIENT_CREDENTIALS, UTF_8.name())));
    if (encodeInBody == true) {
        verification.withRequestBody(containing(CLIENT_ID_PARAMETER + "=" + encode(clientId.getValue(), UTF_8.name()))).withRequestBody(containing(CLIENT_SECRET_PARAMETER + "=" + encode(clientSecret.getValue(), UTF_8.name())));
    } else {
        verification.withHeader(AUTHORIZATION, containing("Basic " + encodeBase64String(format("%s:%s", clientId.getValue(), clientSecret.getValue()).getBytes())));
    }
    if (requestThroughProxy) {
        verification.withHeader(PROXY_CONNECTION_HEADER, containing(KEEP_ALIVE));
        proxyWireMockRule.verify(postRequestedFor(urlEqualTo(TOKEN_PATH)));
    }
    if (scope != null) {
        verification.withRequestBody(containing(SCOPE_PARAMETER + "=" + encode(scope, UTF_8.name())));
    }
    wireMockRule.verify(verification);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

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