io.restassured.response.ExtractableResponse Java Examples
The following examples show how to use
io.restassured.response.ExtractableResponse.
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: ArchaiusServerTest.java From riposte with Apache License 2.0 | 7 votes |
@Test public void verify_essential_behavior() throws Exception { // given setAppAndEnvironment("archaiusserver", "compiletimetest"); int port = findFreePort(); ArchaiusServer server = generateArchaiusServer(port); assertThat(System.getProperty("org.jboss.logging.provider")).isNull(); // when server.launchServer(null); ExtractableResponse<Response> response = given() .baseUri("http://localhost") .port(port) .when() .get(SomeEndpoint.MATCHING_PATH) .then() .extract(); // then assertThat(response.statusCode()).isEqualTo(200); assertThat(response.asString()).isEqualTo("overridevalue"); assertThat(System.getProperty("org.jboss.logging.provider")).isEqualTo("slf4j"); assertThat(ResourceLeakDetector.getLevel()).isEqualTo(ResourceLeakDetector.Level.PARANOID); }
Example #2
Source File: BackstopperSpringboot2WebFluxComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_MALFORMED_REQUEST_is_thrown_when_required_data_is_missing( ServerScenario scenario ) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH + WITH_REQUIRED_QUERY_PARAM_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived( response, new ApiErrorWithMetadata( SampleCoreApiError.MALFORMED_REQUEST, Pair.of("missing_param_type", "int"), Pair.of("missing_param_name", "requiredQueryParamValue") ) ); }
Example #3
Source File: VerifyPreEndpointExecutionWorkChainComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_work_chain_stops_at_content_validator_if_content_validator_blows_up() throws IOException, InterruptedException { String fooValue = UUID.randomUUID().toString(); String postData = objectMapper.writeValueAsString(new PostObj(fooValue)); ExtractableResponse response = given() .baseUri("http://127.0.0.1") .port(serverConfig.endpointsPort()) .basePath(WorkChainEndpoint.WORK_CHAIN_MATCHING_PATH) .header(BLOW_UP_IN_CONTENT_VALIDATOR_HEADER_KEY, "true") .body(postData) .log().all() .when() .post() .then() .log().all() .extract(); Thread.sleep(10); verifyErrorReceived(response, CONTENT_VALIDATOR_API_ERROR); verifyAsyncWorkerChainExecution(1, 1, 1, false, false); }
Example #4
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_SOME_MEANINGFUL_ERROR_NAME_is_thrown_when_correct_endpoint_is_hit() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH + CORE_ERROR_WRAPPER_ENDPOINT_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.SOME_MEANINGFUL_ERROR_NAME); }
Example #5
Source File: SanityCheckComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_ERROR_THROWN_IN_SERVLET_FILTER_OUTSIDE_SPRING_returned_if_servlet_filter_trigger_occurs() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(NON_ERROR_ENDPOINT_PATH) .header("throw-servlet-filter-exception", "true") .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SanityCheckProjectApiError.ERROR_THROWN_IN_SERVLET_FILTER_OUTSIDE_SPRING); }
Example #6
Source File: VerifyRequestSizeValidationComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void should_return_expected_response_when_ContentLength_header_not_exceeding_endpoint_overridden_request_size() { ExtractableResponse response = given() .baseUri(BASE_URI) .port(serverConfig.endpointsPort()) .basePath(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH) .log().all() .body(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE)) .when() .post() .then() .log().headers() .extract(); assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.OK.code()); assertThat(response.asString()).isEqualTo(BasicEndpointWithRequestSizeValidationOverride.RESPONSE_PAYLOAD); }
Example #7
Source File: BackstopperSpringboot2WebMvcComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_SOME_MEANINGFUL_ERROR_NAME_is_thrown_when_correct_endpoint_is_hit(ServerScenario scenario) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH + CORE_ERROR_WRAPPER_ENDPOINT_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.SOME_MEANINGFUL_ERROR_NAME); }
Example #8
Source File: BackstopperSpringboot2WebFluxComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_GENERIC_SERVICE_ERROR_is_thrown_when_correct_endpoint_is_hit(ServerScenario scenario) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH + TRIGGER_UNHANDLED_ERROR_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.GENERIC_SERVICE_ERROR); }
Example #9
Source File: BackstopperSpringboot2WebFluxComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_WEBFLUX_MONO_ERROR_is_thrown_when_correct_endpoint_is_hit(ServerScenario scenario) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH + MONO_ERROR_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.WEBFLUX_MONO_ERROR); }
Example #10
Source File: BackstopperSpringboot2WebMvcComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_MANUALLY_THROWN_ERROR_is_thrown_when_requested(ServerScenario scenario) throws IOException { SampleModel requestPayload = new SampleModel("bar", "42", "RED", true); String requestPayloadAsString = objectMapper.writeValueAsString(requestPayload); ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .contentType(ContentType.JSON) .basePath(SAMPLE_PATH) .body(requestPayloadAsString) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.MANUALLY_THROWN_ERROR); // This code path also should add some custom headers to the response assertThat(response.headers().getValues("rgbColorValue")).isEqualTo(singletonList(requestPayload.rgb_color)); assertThat(response.headers().getValues("otherExtraMultivalueHeader")).isEqualTo(Arrays.asList("foo", "bar")); }
Example #11
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_WEBFLUX_MONO_ERROR_is_thrown_when_correct_endpoint_is_hit() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH + MONO_ERROR_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.WEBFLUX_MONO_ERROR); }
Example #12
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_GENERIC_SERVICE_ERROR_is_thrown_when_correct_endpoint_is_hit() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH + TRIGGER_UNHANDLED_ERROR_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.GENERIC_SERVICE_ERROR); }
Example #13
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_sample_post_fails_with_UNSUPPORTED_MEDIA_TYPE_if_passed_invalid_content_type() throws IOException { SampleModel requestPayload = randomizedSampleModel(); String requestPayloadAsString = objectMapper.writeValueAsString(requestPayload); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .body(requestPayloadAsString) .contentType(ContentType.TEXT) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.UNSUPPORTED_MEDIA_TYPE); }
Example #14
Source File: BackstopperSpringboot2WebFluxComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_sample_get_fails_with_NO_ACCEPTABLE_REPRESENTATION_if_passed_invalid_accept_header( ServerScenario scenario ) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH) .accept(ContentType.BINARY) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.NO_ACCEPTABLE_REPRESENTATION); }
Example #15
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_ERROR_THROWN_IN_SERVLET_FILTER_OUTSIDE_SPRING_returned_if_servlet_filter_trigger_occurs() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .header("throw-servlet-filter-exception", "true") .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.ERROR_THROWN_IN_SERVLET_FILTER_OUTSIDE_SPRING); }
Example #16
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 #17
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 #18
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_SOME_MEANINGFUL_ERROR_NAME_is_thrown_when_correct_endpoint_is_hit() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH + CORE_ERROR_WRAPPER_ENDPOINT_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.SOME_MEANINGFUL_ERROR_NAME); }
Example #19
Source File: VerifyPreEndpointExecutionWorkChainComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_proxy_work_chain_stops_at_downstream_content_deserialization_if_content_deserializer_blows_up() throws IOException, InterruptedException { String fooValue = UUID.randomUUID().toString(); String postData = objectMapper.writeValueAsString(new PostObj(fooValue)); ExtractableResponse response = given() .baseUri("http://127.0.0.1") .port(serverConfig.endpointsPort()) .basePath(WorkChainProxyEndpoint.PROXY_MATCHING_PATH) .header(PROXY_ROUTER_DESTINATION_PORT_HEADER_KEY, String.valueOf(downstreamServerConfig.endpointsPort())) .header(BLOW_UP_IN_CONTENT_DESERIALIZER_HEADER_KEY, "true") .body(postData) .log().all() .when() .post() .then() .log().all() .extract(); Thread.sleep(10); verifyErrorReceived(response, SampleCoreApiError.MALFORMED_REQUEST); verifyAsyncWorkerChainExecution(2, 1, 0, true, false); }
Example #20
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_basic_sample_get() throws IOException { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .log().all() .when() .get() .then() .log().all() .extract(); assertThat(response.statusCode()).isEqualTo(200); SampleModel responseBody = objectMapper.readValue(response.asString(), SampleModel.class); assertThat(responseBody).isNotNull(); assertThat(responseBody.foo).isNotEmpty(); assertThat(responseBody.range_0_to_42).isNotEmpty(); assertThat(Integer.parseInt(responseBody.range_0_to_42)).isBetween(0, 42); assertThat(responseBody.rgb_color).isNotEmpty(); assertThat(RgbColor.toRgbColor(responseBody.rgb_color)).isNotNull(); assertThat(responseBody.throw_manual_error).isFalse(); }
Example #21
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_SOME_MEANINGFUL_ERROR_NAME_is_thrown_when_correct_endpoint_is_hit() throws InterruptedException, IOException { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH + CORE_ERROR_WRAPPER_ENDPOINT_SUBPATH) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleProjectApiError.SOME_MEANINGFUL_ERROR_NAME); }
Example #22
Source File: VerifyRequestSizeValidationComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void should_return_bad_request_when_ContentLength_header_exceeds_endpoint_overridden_configured_max_request_size() throws IOException { ExtractableResponse response = given() .baseUri(BASE_URI) .port(serverConfig.endpointsPort()) .basePath(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH) .log().all() .body(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE + 1)) .when() .post() .then() .log().headers() .extract(); assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code()); assertBadRequestErrorMessageAndMetadata(response.asString()); }
Example #23
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_sample_post_fails_with_MISSING_EXPECTED_CONTENT_if_passed_empty_body() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .contentType(ContentType.JSON) .body("") .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.MISSING_EXPECTED_CONTENT); }
Example #24
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_NOT_FOUND_returned_if_unknown_path_is_requested() { ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(UUID.randomUUID().toString()) .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.NOT_FOUND); }
Example #25
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_sample_post_fails_with_UNSUPPORTED_MEDIA_TYPE_if_passed_invalid_content_type() throws InterruptedException, IOException { SampleModel requestPayload = randomizedSampleModel(); String requestPayloadAsString = objectMapper.writeValueAsString(requestPayload); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .body(requestPayloadAsString) .contentType(ContentType.TEXT) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.UNSUPPORTED_MEDIA_TYPE); }
Example #26
Source File: BackstopperSpring5WebMvcComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_TYPE_CONVERSION_ERROR_is_thrown_when_framework_cannot_convert_type( ServerScenario scenario ) { ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH + WITH_REQUIRED_QUERY_PARAM_SUBPATH) .queryParam("requiredQueryParamValue", "not-an-integer") .log().all() .when() .get() .then() .log().all() .extract(); verifyErrorReceived(response, new ApiErrorWithMetadata( SampleCoreApiError.TYPE_CONVERSION_ERROR, MapBuilder.builder("bad_property_name", (Object)"requiredQueryParamValue") .put("bad_property_value", "not-an-integer") .put("required_type", "int") .build() )); }
Example #27
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_sample_post_fails_with_MALFORMED_REQUEST_if_passed_bad_json_body() throws IOException { SampleModel originalValidPayloadObj = randomizedSampleModel(); String originalValidPayloadAsString = objectMapper.writeValueAsString(originalValidPayloadObj); @SuppressWarnings("unchecked") Map<String, Object> badRequestPayloadAsMap = objectMapper.readValue(originalValidPayloadAsString, Map.class); badRequestPayloadAsMap.put("throw_manual_error", "not-a-boolean"); String badJsonPayloadAsString = objectMapper.writeValueAsString(badRequestPayloadAsMap); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .contentType(ContentType.JSON) .body(badJsonPayloadAsString) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.MALFORMED_REQUEST); }
Example #28
Source File: ResourcesFilterITestBase.java From pay-publicapi with MIT License | 6 votes |
TypeSafeMatcher<ValidatableResponse> anErrorResponse() { return new TypeSafeMatcher<>() { @Override protected boolean matchesSafely(ValidatableResponse validatableResponse) { ExtractableResponse<Response> extract = validatableResponse.extract(); return extract.statusCode() == TOO_MANY_REQUESTS_429 && "P0900".equals(extract.body().<String>path("code")) && "Too many requests".equals(extract.body().<String>path("description")); } @Override public void describeTo(Description description) { description.appendText(" Status code: ") .appendValue(TOO_MANY_REQUESTS_429) .appendText(", error code: ") .appendValue("P0900") .appendText(", message: ") .appendValue("Too many requests") ; } }; }
Example #29
Source File: BackstopperSpring5WebMvcComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@UseDataProvider("serverScenarioDataProvider") @Test public void verify_sample_post_fails_with_UNSUPPORTED_MEDIA_TYPE_if_passed_invalid_content_type( ServerScenario scenario ) throws IOException { SampleModel requestPayload = randomizedSampleModel(); String requestPayloadAsString = objectMapper.writeValueAsString(requestPayload); ExtractableResponse response = given() .baseUri("http://localhost") .port(scenario.serverPort) .basePath(SAMPLE_PATH) .body(requestPayloadAsString) .contentType(ContentType.TEXT) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.UNSUPPORTED_MEDIA_TYPE); }
Example #30
Source File: VerifyExpectedErrorsAreReturnedComponentTest.java From backstopper with Apache License 2.0 | 6 votes |
@Test public void verify_sample_post_fails_with_MALFORMED_REQUEST_if_passed_bad_json_body() throws InterruptedException, IOException { SampleModel originalValidPayloadObj = randomizedSampleModel(); String originalValidPayloadAsString = objectMapper.writeValueAsString(originalValidPayloadObj); @SuppressWarnings("unchecked") Map<String, Object> badRequestPayloadAsMap = objectMapper.readValue(originalValidPayloadAsString, Map.class); badRequestPayloadAsMap.put("throw_manual_error", "not-a-boolean"); String badJsonPayloadAsString = objectMapper.writeValueAsString(badRequestPayloadAsMap); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .basePath(SAMPLE_PATH) .contentType(ContentType.JSON) .body(badJsonPayloadAsString) .log().all() .when() .post() .then() .log().all() .extract(); verifyErrorReceived(response, SampleCoreApiError.MALFORMED_REQUEST); }