Java Code Examples for io.restassured.response.ExtractableResponse#header()
The following examples show how to use
io.restassured.response.ExtractableResponse#header() .
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: VerifyPayloadHandlingComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_byte_array_response_payload_is_sent_as_is_with_no_modifications() throws IOException, InterruptedException { ExtractableResponse response = given() .baseUri("http://127.0.0.1") .port(serverConfig.endpointsPort()) .basePath(ByteArrayPayloadReturner.MATCHING_PATH) .log().all() .when() .post() .then() .log().headers() .statusCode(200) .extract(); byte[] responsePayload = response.asByteArray(); String expectedHash = response.header(RESPONSE_PAYLOAD_HASH_HEADER_KEY); String actualHash = getHashForPayload(responsePayload); assertThat(actualHash).isEqualTo(expectedHash); }
Example 2
Source File: VerifyPayloadHandlingComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_CharSequence_response_payload_is_sent_as_is_with_no_modifications() throws IOException, InterruptedException { ExtractableResponse response = given() .baseUri("http://127.0.0.1") .port(serverConfig.endpointsPort()) .basePath(CharSequencePayloadReturner.MATCHING_PATH) .log().all() .when() .post() .then() .log().all() .statusCode(200) .extract(); String responsePayload = response.asString(); String expectedHash = response.header(RESPONSE_PAYLOAD_HASH_HEADER_KEY); String actualHash = getHashForPayload(responsePayload.getBytes(CharsetUtil.UTF_8)); assertThat(actualHash).isEqualTo(expectedHash); }
Example 3
Source File: VerifyPayloadHandlingComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_SerializedObject_response_payload_is_sent_as_serialized_json() throws IOException, InterruptedException { ExtractableResponse response = given() .baseUri("http://127.0.0.1") .port(serverConfig.endpointsPort()) .basePath(SerializableObjectPayloadReturner.MATCHING_PATH) .log().all() .when() .post() .then() .log().all() .statusCode(200) .extract(); String responsePayload = response.asString(); String expectedHash = response.header(RESPONSE_PAYLOAD_HASH_HEADER_KEY); String actualHash = getHashForPayload(responsePayload.getBytes(CharsetUtil.UTF_8)); assertThat(actualHash).isEqualTo(expectedHash); }
Example 4
Source File: VerifyErrorResponsePayloadHandlingComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void should_return_default_payload_when_default_error_handling_occurs() throws IOException { ObjectMapper mapper = new ObjectMapper(); ExtractableResponse response = given() .baseUri(BASE_URI) .port(serverConfig.endpointsPort()) .basePath(DefaultErrorContractEndpoint.MATCHING_PATH) .log().all() .when() .get() .then() .log().headers() .extract(); verifyErrorReceived(response.asString(), INTERNAL_SERVER_ERROR.code(), GENERIC_SERVICE_ERROR); DefaultErrorContractDTO errorContract = mapper.readValue(response.asString(), DefaultErrorContractDTO.class); String errorUidResponseHeader = response.header("error_uid"); assertThat(errorUidResponseHeader).isNotEmpty(); assertThat(errorContract.error_id).isEqualTo(errorUidResponseHeader); UUID errorUidAsUuid = UUID.fromString(errorUidResponseHeader); assertThat(errorUidAsUuid).isNotNull(); }
Example 5
Source File: WingtipsSpringWebfluxComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse( ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan ) { // We can have a race condition where the response is sent and we try to verify here before the server // has had a chance to complete the span. Wait a few milliseconds to give the server time to finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 6
Source File: RequestTracingFilterComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse( ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan ) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 7
Source File: RequestTracingFilterOldServletComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private void verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } }
Example 8
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 9
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the WebFilter // has had a chance to complete the span. Wait a few milliseconds to give the WebFilter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 10
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 11
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 12
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 6 votes |
private Span verifySingleSpanCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(1); assertThat(spanRecorder.completedSpans).hasSize(1); Span completedSpan = spanRecorder.completedSpans.get(0); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); assertThat(TimeUnit.NANOSECONDS.toMillis(completedSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(completedSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(completedSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } return completedSpan; }
Example 13
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 5 votes |
private void verifyMultipleSpansCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, int expectedNumSpansCompleted, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(expectedNumSpansCompleted); assertThat(spanRecorder.completedSpans).hasSize(expectedNumSpansCompleted); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); spanRecorder.completedSpans.forEach( completedSpan -> { assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); } ); // Find the span with the longest duration - this is the outermost request span. Span outerRequestSpan = spanRecorder.completedSpans.stream() .max(Comparator.comparing(Span::getDurationNanos)) .get(); assertThat(TimeUnit.NANOSECONDS.toMillis(outerRequestSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(outerRequestSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(outerRequestSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } }
Example 14
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 5 votes |
@SuppressWarnings("SameParameterValue") private void verifyMultipleSpansCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, int expectedNumSpansCompleted, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the WebFilter // has had a chance to complete the span. Wait a few milliseconds to give the WebFilter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(expectedNumSpansCompleted); assertThat(spanRecorder.completedSpans).hasSize(expectedNumSpansCompleted); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); spanRecorder.completedSpans.forEach( completedSpan -> { assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); } ); // Find the span with the longest duration - this is the outermost request span. @SuppressWarnings("OptionalGetWithoutIsPresent") Span outerRequestSpan = spanRecorder.completedSpans.stream() .max(Comparator.comparing(Span::getDurationNanos)) .get(); assertThat(TimeUnit.NANOSECONDS.toMillis(outerRequestSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(outerRequestSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(outerRequestSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } }
Example 15
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 5 votes |
private void verifyMultipleSpansCompletedAndReturnedInResponse(ExtractableResponse response, long expectedMinSpanDurationMillis, int expectedNumSpansCompleted, Span expectedUpstreamSpan) { // We can have a race condition where the response is sent and we try to verify here before the servlet filter // has had a chance to complete the span. Wait a few milliseconds to give the servlet filter time to // finish. waitUntilSpanRecorderHasExpectedNumSpans(expectedNumSpansCompleted); assertThat(spanRecorder.completedSpans).hasSize(expectedNumSpansCompleted); String traceIdFromResponse = response.header(TraceHeaders.TRACE_ID); assertThat(traceIdFromResponse).isNotNull(); spanRecorder.completedSpans.forEach( completedSpan -> { assertThat(completedSpan.getTraceId()).isEqualTo(traceIdFromResponse); assertThat(completedSpan.getSpanName()).doesNotContain("?"); } ); // Find the span with the longest duration - this is the outermost request span. Span outerRequestSpan = spanRecorder.completedSpans.stream() .max(Comparator.comparing(Span::getDurationNanos)) .get(); assertThat(TimeUnit.NANOSECONDS.toMillis(outerRequestSpan.getDurationNanos())) .isGreaterThanOrEqualTo(expectedMinSpanDurationMillis); if (expectedUpstreamSpan != null) { assertThat(outerRequestSpan.getTraceId()).isEqualTo(expectedUpstreamSpan.getTraceId()); assertThat(outerRequestSpan.getParentSpanId()).isEqualTo(expectedUpstreamSpan.getSpanId()); } }