com.github.tomakehurst.wiremock.verification.LoggedRequest Java Examples
The following examples show how to use
com.github.tomakehurst.wiremock.verification.LoggedRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpMethodEndpointTest.java From RoboZombie with Apache License 2.0 | 6 votes |
/** * <p>Test for the request method PUT.</p> * * @since 1.3.0 */ @Test public final void testPutMethod() { Robolectric.getFakeHttpLayer().interceptHttpRequests(false); String path = "/putrequest"; stubFor(put(urlEqualTo(path)) .willReturn(aResponse() .withStatus(200))); String user = "{ '_id':1, 'alias':'Black Bolt' }"; httpMethodEndpoint.putRequest(user); List<LoggedRequest> requests = findAll(putRequestedFor(urlMatching(path))); assertFalse(requests == null); assertFalse(requests.isEmpty()); LoggedRequest request = requests.get(0); assertTrue(request.getMethod().equals(RequestMethod.PUT)); String body = request.getBodyAsString(); assertTrue(body.contains(user)); }
Example #2
Source File: HttpMethodEndpointTest.java From RoboZombie with Apache License 2.0 | 6 votes |
/** * <p>Test for the request method GET.</p> * * @since 1.3.0 */ @Test public final void testGetMethod() { Robolectric.getFakeHttpLayer().interceptHttpRequests(false); String name = "James-Howlett", age = "116", location = "X-Mansion"; String path = "/getrequest?name=" + name + "&age=" + age + "&location=" + location; stubFor(get(urlEqualTo(path)) .willReturn(aResponse() .withStatus(200))); httpMethodEndpoint.getRequest(name, age, location); List<LoggedRequest> requests = findAll(getRequestedFor(urlEqualTo(path))); assertFalse(requests == null); assertFalse(requests.isEmpty()); LoggedRequest request = requests.get(0); assertTrue(request.getMethod().equals(RequestMethod.GET)); }
Example #3
Source File: RemoteUrlTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testAuthorizationHeaderWithNonMatchingUrl() throws Exception { final String expectedBody = setupStub(); final String headerValue = "foobar"; String authorization = "Authorization"; final AuthorizationValue authorizationValue = new AuthorizationValue(authorization, headerValue, "header", u -> false); final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue)); assertEquals(actualBody, expectedBody); List<LoggedRequest> requests = WireMock.findAll(getRequestedFor(urlEqualTo("/v2/pet/1"))); assertEquals(1, requests.size()); assertFalse(requests.get(0).containsHeader(authorization)); }
Example #4
Source File: WireMockExtension.java From wiremock-extension with MIT License | 6 votes |
private void checkForUnmatchedRequests(final WireMockServer server) { final boolean mustCheck = Optional.of(server) .filter(ManagedWireMockServer.class::isInstance) .map(ManagedWireMockServer.class::cast) .map(ManagedWireMockServer::failOnUnmatchedRequests) .orElse(generalFailOnUnmatchedRequests); if (mustCheck) { final List<LoggedRequest> unmatchedRequests = server.findAllUnmatchedRequests(); if (!unmatchedRequests.isEmpty()) { final List<NearMiss> nearMisses = server.findNearMissesForAllUnmatchedRequests(); throw nearMisses.isEmpty() ? VerificationException.forUnmatchedRequests(unmatchedRequests) : VerificationException.forUnmatchedNearMisses(nearMisses); } } }
Example #5
Source File: AmbariInfraWithStormLogSearchTest.java From streamline with Apache License 2.0 | 5 votes |
@Test public void testEventSearchWithMinimumParameters() throws Exception { stubSolrUrl(); EventSearchCriteria eventSearchCriteria = new EventSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).build(); EventSearchResult result = logSearch.searchEvent(eventSearchCriteria); verifyEventSearchResults(result); // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching... String dateRangeValue = "%s:[%s+TO+%s]"; Instant fromInstant = Instant.ofEpochMilli(TEST_FROM); Instant toInstant = Instant.ofEpochMilli(TEST_TO); dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString()); List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH))); assertEquals(1, requests.size()); LoggedRequest request = requests.get(0); QueryParameter qParam = request.queryParameter("q"); assertTrue(qParam.containsValue(COLUMN_NAME_STREAMLINE_EVENT_ID + ":*")); QueryParameter fqParam = request.queryParameter("fq"); assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_EVENT)); assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID)); assertTrue(fqParam.containsValue(dateRangeValue)); assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_COMPONENT_NAME))); assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ID))); assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET))); assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET))); QueryParameter sortParam = request.queryParameter("sort"); assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+asc")); }
Example #6
Source File: QueryParamsAssertion.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private List<NameValuePair> parseNameValuePairsFromQuery(LoggedRequest actual) { String queryParams = URI.create(actual.getUrl()).getQuery(); if (StringUtils.isEmpty(queryParams)) { return Collections.emptyList(); } return URLEncodedUtils.parse(queryParams, StandardCharsets.UTF_8); }
Example #7
Source File: MarshallingAssertion.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Asserts on the marshalled request. * * @param actual Marshalled request * @throws AssertionError If any assertions fail */ public final void assertMatches(LoggedRequest actual) throws AssertionError { // Catches the exception to play nicer with lambda's try { doAssert(actual); } catch (Exception e) { throw new RuntimeException(e); } }
Example #8
Source File: HeadersAssertion.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected void doAssert(LoggedRequest actual) throws Exception { if (contains != null) { assertHeadersContains(actual.getHeaders()); } if (doesNotContain != null) { assertDoesNotContainHeaders(actual.getHeaders()); } }
Example #9
Source File: MarshallingTestRunner.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
void runTest(TestCase testCase) throws Exception { resetWireMock(); ShapeModelReflector shapeModelReflector = createShapeModelReflector(testCase); if (!model.getShapes().get(testCase.getWhen().getOperationName() + "Request").isHasStreamingMember()) { clientReflector.invokeMethod(testCase, shapeModelReflector.createShapeObject()); } else { clientReflector.invokeMethod(testCase, shapeModelReflector.createShapeObject(), RequestBody.fromString(shapeModelReflector.getStreamingMemberValue())); } LoggedRequest actualRequest = getLoggedRequest(); testCase.getThen().getMarshallingAssertion().assertMatches(actualRequest); }
Example #10
Source File: SdkTransactionIdInHeaderTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void assertTransactionIdIsUnchangedAcrossRetries() { String previousTransactionId = null; for (LoggedRequest request : findAll(getRequestedFor(urlEqualTo(RESOURCE_PATH)))) { final String currentTransactionId = request.getHeader(ApplyTransactionIdStage.HEADER_SDK_TRANSACTION_ID); // Transaction ID should always be set assertNotNull(currentTransactionId); // Transaction ID should be the same across retries if (previousTransactionId != null) { assertEquals(previousTransactionId, currentTransactionId); } previousTransactionId = currentTransactionId; } }
Example #11
Source File: SdkTransactionIdInHeaderTest.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
private void assertTransactionIdIsUnchangedAcrossRetries() { String previousTransactionId = null; for (LoggedRequest request : findAll(getRequestedFor(urlEqualTo(RESOURCE_PATH)))) { final String currentTransactionId = request.getHeader(HEADER_SDK_TRANSACTION_ID); // Transaction ID should always be set assertNotNull(currentTransactionId); // Transaction ID should be the same across retries if (previousTransactionId != null) { assertEquals(previousTransactionId, currentTransactionId); } previousTransactionId = currentTransactionId; } }
Example #12
Source File: IronTestUtils.java From irontest with Apache License 2.0 | 5 votes |
public static void addMixInsForWireMock(ObjectMapper objectMapper) { objectMapper.addMixIn(StubMapping.class, StubMappingMixIn.class); objectMapper.addMixIn(RequestPattern.class, RequestPatternMixIn.class); objectMapper.addMixIn(StringValuePattern.class, StringValuePatternMixIn.class); objectMapper.addMixIn(ResponseDefinition.class, ResponseDefinitionMixIn.class); objectMapper.addMixIn(ContentPattern.class, ContentPatternMixIn.class); objectMapper.addMixIn(LoggedResponse.class, LoggedResponseMixIn.class); objectMapper.addMixIn(ServeEvent.class, ServeEventMixIn.class); objectMapper.addMixIn(LoggedRequest.class, LoggedRequestMixIn.class); }
Example #13
Source File: AmbariInfraWithStormLogSearchTest.java From streamline with Apache License 2.0 | 5 votes |
@Test public void testLogSearchWithMinimumParameters() throws Exception { stubSolrUrl(); LogSearchCriteria logSearchCriteria = new LogSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO).build(); LogSearchResult result = logSearch.search(logSearchCriteria); verifyLogSearchResults(result); // please note that space should be escaped to '+' since Wiremock doesn't handle it when matching... String dateRangeValue = "%s:[%s+TO+%s]"; Instant fromInstant = Instant.ofEpochMilli(TEST_FROM); Instant toInstant = Instant.ofEpochMilli(TEST_TO); dateRangeValue = String.format(dateRangeValue, COLUMN_NAME_LOG_TIME, fromInstant.toString(), toInstant.toString()); String expectedLogLevels = "(" + String.join("+OR+", AmbariInfraWithStormLogSearch.DEFAULT_LOG_LEVELS) + ")"; List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH))); assertEquals(1, requests.size()); LoggedRequest request = requests.get(0); QueryParameter qParam = request.queryParameter("q"); assertTrue(qParam.containsValue(COLUMN_NAME_LOG_MESSAGE + ":*")); QueryParameter fqParam = request.queryParameter("fq"); assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID + ":" + TEST_APP_ID)); assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_WORKER_LOG)); assertTrue(fqParam.containsValue(dateRangeValue)); assertTrue(fqParam.containsValue(COLUMN_NAME_LOG_LEVEL + ":" + expectedLogLevels)); assertFalse(fqParam.hasValueMatching(ValuePattern.containing(COLUMN_NAME_STREAMLINE_COMPONENT_NAME))); QueryParameter sortParam = request.queryParameter("sort"); assertTrue(sortParam.containsValue(COLUMN_NAME_LOG_TIME + "+asc")); }
Example #14
Source File: AmbariInfraWithStormLogSearchTest.java From streamline with Apache License 2.0 | 5 votes |
@Test public void testLogSearchWithSingleComponentNameAndLogLevelParameters() throws Exception { stubSolrUrl(); int testStart = 100; int testLimit = 2000; List<String> testLogLevels = Collections.singletonList("INFO"); String testSearchString = "helloworld"; List<String> testComponentNames = Collections.singletonList("testComponent"); LogSearchCriteria logSearchCriteria = new LogSearchCriteria.Builder(TEST_APP_ID, TEST_FROM, TEST_TO) .setLogLevels(testLogLevels) .setSearchString(testSearchString) .setComponentNames(testComponentNames) .setStart(testStart) .setLimit(testLimit) .build(); LogSearchResult result = logSearch.search(logSearchCriteria); // note that the result doesn't change given that we just provide same result from file verifyLogSearchResults(result); // others are covered from testLogSearchWithFullParameters() List<LoggedRequest> requests = wireMockRule.findAll(getRequestedFor(urlPathEqualTo(STUB_REQUEST_API_PATH))); assertEquals(1, requests.size()); LoggedRequest request = requests.get(0); QueryParameter fqParam = request.queryParameter("fq"); assertTrue(fqParam.containsValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME + ":" + testComponentNames.get(0))); assertTrue(fqParam.containsValue(COLUMN_NAME_TYPE + ":" + COLUMN_VALUE_TYPE_WORKER_LOG)); assertTrue(fqParam.containsValue(COLUMN_NAME_LOG_LEVEL + ":" + testLogLevels.get(0))); }
Example #15
Source File: AbstractHttpClientInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
private void verifyTraceContextHeaders(Span span, String path) { Map<String, String> headerMap = new HashMap<>(); span.propagateTraceContext(headerMap, TextHeaderMapAccessor.INSTANCE); assertThat(headerMap).isNotEmpty(); List<LoggedRequest> loggedRequests = wireMockRule.findAll(anyRequestedFor(urlPathEqualTo(path))); assertThat(loggedRequests).isNotEmpty(); loggedRequests.forEach(request -> { assertThat(TraceContext.containsTraceContextTextHeaders(request, new HeaderAccessor())).isTrue(); headerMap.forEach((key, value) -> assertThat(request.getHeader(key)).isEqualTo(value)); }); }
Example #16
Source File: HttpMethodEndpointTest.java From RoboZombie with Apache License 2.0 | 5 votes |
/** * <p>Test for the request method POST.</p> * * @since 1.3.0 */ @Test public final void testPostMethod() { Robolectric.getFakeHttpLayer().interceptHttpRequests(false); String path = "/postrequest"; stubFor(post(urlEqualTo(path)) .willReturn(aResponse() .withStatus(200))); String name = "DoctorWho", age = "953", location = "Tardis"; httpMethodEndpoint.postRequest(name, age, location); List<LoggedRequest> requests = findAll(postRequestedFor(urlMatching(path))); assertFalse(requests == null); assertFalse(requests.isEmpty()); LoggedRequest request = requests.get(0); assertTrue(request.getMethod().equals(RequestMethod.POST)); String body = request.getBodyAsString(); assertTrue(body.contains("name=" + name)); assertTrue(body.contains("age=" + age)); assertTrue(body.contains("location=" + location)); }
Example #17
Source File: GoogleHttpClientEdgeGridInterceptorIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test public void testInterceptor() throws URISyntaxException, IOException, RequestSigningException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); HttpRequestFactory requestFactory = createSigningRequestFactory(); URI uri = URI.create("https://endpoint.net/billing-usage/v1/reportSources"); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri)); // Mimic what the library does to process the interceptor. request.setFollowRedirects(true).execute(); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"), Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization")))); }
Example #18
Source File: ApacheHttpClientEdgeGridInterceptorIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test public void testInterceptor() throws URISyntaxException, IOException, RequestSigningException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(getHost())) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(getHost())) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); HttpGet request = new HttpGet("http://endpoint.net/billing-usage/v1/reportSources"); HttpClient client = HttpClientSetup.getHttpClientWithRelaxedSsl() .addInterceptorFirst(new ApacheHttpClientEdgeGridInterceptor(credential)) .setRoutePlanner(new ApacheHttpClientEdgeGridRoutePlanner(credential)) .build(); client.execute(request); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"), Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization")))); }
Example #19
Source File: RestAssuredIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test public void signAgainFollowedRedirects() throws URISyntaxException, IOException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); getBaseRequestSpecification() .get("/billing-usage/v1/reportSources") .then().statusCode(200); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"), Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization")))); }
Example #20
Source File: RestAssuredIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test public void replaceProvidedHostHeaderOnlyInApacheClient() throws URISyntaxException, IOException, RequestSigningException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .willReturn(aResponse() .withStatus(200))); getBaseRequestSpecification() .header("Host", "ignored-hostname.com") .filter(new Filter() { @Override public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { MatcherAssert.assertThat(requestSpec.getHeaders().getList("Host").size(), CoreMatchers.equalTo(1)); MatcherAssert.assertThat(requestSpec.getHeaders().get("Host").getValue(), CoreMatchers.equalTo("ignored-hostname.com")); return ctx.next(requestSpec, responseSpec); } }) .get("/billing-usage/v1/reportSources"); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Host"), CoreMatchers.equalTo(SERVICE_MOCK)); }
Example #21
Source File: RestAssuredEdgeGridFilterTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test // Due to limitations of REST-assured we cannot sign again followed redirects // https://github.com/akamai-open/AkamaiOPEN-edgegrid-java/issues/21 public void cannotSignAgainFollowedRedirects() throws URISyntaxException, IOException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); RestAssured.given() .relaxedHTTPSValidation() .filter(new RestAssuredEdgeGridFilter(credential)) .get("/billing-usage/v1/reportSources") .then().statusCode(200); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"), CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization"))); }
Example #22
Source File: RestAssuredEdgeGridFilterIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
@Test // Due to limitations of REST-assured we cannot sign again followed redirects // https://github.com/akamai-open/AkamaiOPEN-edgegrid-java/issues/21 public void cannotSignAgainFollowedRedirects() throws URISyntaxException, IOException { wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) .withHeader("Host", equalTo(SERVICE_MOCK)) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("<response>Some content</response>"))); RestAssured.given() .relaxedHTTPSValidation() .filter(new RestAssuredEdgeGridFilter(credential)) .get("/billing-usage/v1/reportSources") .then().statusCode(200); List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern .everything()).getRequests(); MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Authorization"), CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization"))); }
Example #23
Source File: HttpMessageTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testWithDefaultURLWithPut() { stubFor(put(urlEqualTo("/items")) .willReturn(aResponse() .withStatus(204))); stubFor(post(urlEqualTo("/items")) .willReturn(aResponse() .withStatus(404))); stubFor(post(urlPathMatching("/record?.*")) .willReturn(aResponse() .withStatus(404))); String uuid = UUID.randomUUID().toString(); HttpMessage<String> message = HttpMessage.HttpMessageBuilder.<String> create() .withHeader("X-foo", "value") .withHeader("X-foo", "value-2") .withMethod("PUT") .withPayload(uuid) .build(); assertThat(message.getMethod()).isEqualTo("PUT"); assertThat(message.getHeaders()).containsExactly(entry("X-foo", Arrays.asList("value", "value-2"))); assertThat(message.getPayload()).isEqualTo(uuid); assertThat(message.getQuery()).isEmpty(); assertThat(message.getUrl()).isNull(); sink.send(message).subscribeAsCompletionStage(); awaitForRequest(); assertThat(bodies("/items")).hasSize(1); LoggedRequest request = requests("/items").get(0); assertThat(request.getBodyAsString()).isEqualTo(uuid); assertThat(request.getHeaders().getHeader("X-foo").values()).containsExactly("value", "value-2"); assertThat(request.getMethod().getName()).isEqualToIgnoringCase("PUT"); }
Example #24
Source File: PresignRequestWireMockTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public void verifyMethodCallSendsPresignedUrl(Runnable methodCall, String actionName) { stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody("<body/>"))); methodCall.run(); List<LoggedRequest> requests = findAll(anyRequestedFor(anyUrl())); assertThat(requests).isNotEmpty(); LoggedRequest lastRequest = requests.get(0); String lastRequestBody = new String(lastRequest.getBody(), UTF_8); assertThat(lastRequestBody).contains("PreSignedUrl=https%3A%2F%2Frds.us-west-2.amazonaws.com%3FAction%3D" + actionName + "%26Version%3D2014-10-31%26DestinationRegion%3Dus-east-1%26"); }
Example #25
Source File: ClockSkewAdjustmentTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void assertAdjusts(Instant serviceTime, int statusCode, String errorCode, Supplier<AllTypesResponse> methodCall) { stubForClockSkewFailureThenSuccess(serviceTime, statusCode, errorCode); assertThat(methodCall.get().stringMember()).isEqualTo("foo"); List<LoggedRequest> requests = getRecordedRequests(); assertThat(requests.size()).isEqualTo(2); assertSigningDateApproximatelyEquals(requests.get(1), serviceTime); }
Example #26
Source File: HttpMessageTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testHeadersAndUrlAndQueryOnRawMessage() { stubFor(post(urlEqualTo("/items")) .willReturn(aResponse() .withStatus(404))); stubFor(post(urlPathMatching("/record?.*")) .willReturn(aResponse() .withStatus(204))); String uuid = UUID.randomUUID().toString(); Message<String> message = Message.of(uuid).withMetadata(Metadata.of( HttpResponseMetadata.builder() .withUrl("http://localhost:8089/record") .withHeader("X-foo", "value") .withQueryParameter("name", "clement").build())); sink.send(message).subscribeAsCompletionStage(); awaitForRequest(); assertThat(bodies("/record?name=clement")).hasSize(1); LoggedRequest request = requests("/record?name=clement").get(0); assertThat(request.getBodyAsString()).isEqualTo(uuid); assertThat(request.getHeader("X-foo")).isEqualTo("value"); assertThat(request.getMethod().getName()).isEqualToIgnoringCase("POST"); QueryParameter name = request.getQueryParams().get("name"); assertThat(name).isNotNull(); assertThat(name.isSingleValued()).isTrue(); assertThat(name.firstValue()).isEqualToIgnoringCase("clement"); }
Example #27
Source File: HttpMessageTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Test public void testHeadersAndUrlAndQuery() { stubFor(post(urlEqualTo("/items")) .willReturn(aResponse() .withStatus(404))); stubFor(post(urlPathMatching("/record?.*")) .willReturn(aResponse() .withStatus(204))); String uuid = UUID.randomUUID().toString(); HttpMessage<String> message = HttpMessage.HttpMessageBuilder.<String> create() .withHeader("X-foo", "value") .withUrl("http://localhost:8089/record") .withQueryParameter("name", "clement") .withPayload(uuid) .build(); sink.send(message).subscribeAsCompletionStage(); awaitForRequest(); assertThat(bodies("/record?name=clement")).hasSize(1); LoggedRequest request = requests("/record?name=clement").get(0); assertThat(request.getBodyAsString()).isEqualTo(uuid); assertThat(request.getHeader("X-foo")).isEqualTo("value"); assertThat(request.getMethod().getName()).isEqualToIgnoringCase("POST"); QueryParameter name = request.getQueryParams().get("name"); assertThat(name).isNotNull(); assertThat(name.isSingleValued()).isTrue(); assertThat(name.firstValue()).isEqualToIgnoringCase("clement"); }
Example #28
Source File: AbstractHttpClientInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Override public <S> void forEach(String headerName, LoggedRequest loggedRequest, S state, HeaderConsumer<String, S> consumer) { HttpHeaders headers = loggedRequest.getHeaders(); if (headers != null) { HttpHeader header = headers.getHeader(headerName); if (header != null) { List<String> values = header.values(); for (int i = 0, size = values.size(); i < size; i++) { consumer.accept(values.get(i), state); } } } }
Example #29
Source File: ApmServerConfigurationSourceTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Test public void testLoadRemoteConfig() throws Exception { configurationSource.fetchConfig(config); assertThat(configurationSource.getValue("foo")).isEqualTo("bar"); mockApmServer.verify(postRequestedFor(urlEqualTo("/config/v1/agents"))); configurationSource.fetchConfig(config); mockApmServer.verify(postRequestedFor(urlEqualTo("/config/v1/agents")).withHeader("If-None-Match", equalTo("foo"))); for (LoggedRequest request : WireMock.findAll(newRequestPattern(RequestMethod.POST, urlEqualTo("/config/v1/agents")))) { final JsonNode jsonNode = new ObjectMapper().readTree(request.getBodyAsString()); assertThat(jsonNode.get("service")).isNotNull(); assertThat(jsonNode.get("system")).isNotNull(); assertThat(jsonNode.get("process")).isNotNull(); } }
Example #30
Source File: HttpTestBase.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
public List<String> bodies(String path) { return requests().stream().filter(req -> req.getUrl().equalsIgnoreCase(path)) .map(LoggedRequest::getBodyAsString).collect(Collectors.toList()); }