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)));
}
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);
}
Aggregations