Search in sources :

Example 21 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyMiscellaneousFunctionalityComponentTest method verify_proxy_router_response_modification_works_as_expected.

@Test
public void verify_proxy_router_response_modification_works_as_expected() throws IOException, InterruptedException {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(ProxyRouterResponseModificationEndpoint.MATCHING_PATH).log().all().when().get().then().log().headers().extract();
    ApiError unmodifiedError = EmptyMetadataErrorThrower.ERROR_NO_METADATA;
    assertThat(response.statusCode()).isEqualTo(ProxyRouterResponseModificationEndpoint.MODIFIED_HTTP_STATUS_RESPONSE_CODE);
    assertThat(response.header(ProxyRouterResponseModificationEndpoint.ORIG_HTTP_STATUS_CODE_RESPONSE_HEADER_KEY)).isEqualTo(String.valueOf(unmodifiedError.getHttpStatusCode()));
    ApiError expectedModifiedError = new ApiErrorBase(unmodifiedError.getName(), unmodifiedError.getErrorCode(), unmodifiedError.getMessage(), ProxyRouterResponseModificationEndpoint.MODIFIED_HTTP_STATUS_RESPONSE_CODE);
    verifyErrorReceived(response, expectedModifiedError);
    assertThat(response.asString()).doesNotContain("metadata");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) ApiErrorBase(com.nike.backstopper.apierror.ApiErrorBase) ApiError(com.nike.backstopper.apierror.ApiError) Test(org.junit.Test)

Example 22 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyBeforeAndAfterSecurityRequestAndResponseFiltersComponentTest method shouldOnlyExecuteBeforeSecurityRequestFilterWhenSecurityErrorThrown.

@Test
public void shouldOnlyExecuteBeforeSecurityRequestFilterWhenSecurityErrorThrown() {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(BasicEndpoint.MATCHING_PATH).header(FORCE_SECURITY_ERROR_HEADER_KEY, "true").log().all().when().get().then().log().headers().extract();
    // Validate that the security validator was called and that it threw an exception.
    assertThat(response.statusCode()).isEqualTo(401);
    assertThat(response.header(SECURITY_VALIDATOR_EXECUTED_HEADER_KEY)).isEqualTo("true");
    assertThat(response.header(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY)).isEqualTo("true");
    // Validate request filter methods were called.
    assertThat(response.header(BEFORE_SECURITY_FIRST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("true");
    assertThat(response.header(BEFORE_SECURITY_LAST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("false");
    assertThat(response.header(AFTER_SECURITY_FIRST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("false");
    assertThat(response.header(AFTER_SECURITY_LAST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("false");
    // Validate response filter method was called.
    assertThat(response.header(BEFORE_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_KEY)).isEqualTo(BEFORE_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_PAYLOAD);
    assertThat(response.header(AFTER_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_KEY)).isEqualTo(AFTER_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_PAYLOAD);
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 23 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyMiscellaneousFunctionalityComponentTest method verify_populated_metadata_is_returned_in_error_contract.

@Test
public void verify_populated_metadata_is_returned_in_error_contract() throws IOException, InterruptedException {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(WithMetadataErrorThrower.MATCHING_PATH).log().all().when().get().then().log().headers().extract();
    verifyErrorReceived(response, WithMetadataErrorThrower.ERROR_WITH_METADATA);
    assertThat(response.asString()).contains("\"metadata\":{");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 24 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyMiscellaneousFunctionalityComponentTest method verify_empty_metadata_is_stripped_from_error_contract.

@Test
public void verify_empty_metadata_is_stripped_from_error_contract() throws IOException, InterruptedException {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(EmptyMetadataErrorThrower.MATCHING_PATH).log().all().when().get().then().log().headers().extract();
    verifyErrorReceived(response, EmptyMetadataErrorThrower.ERROR_NO_METADATA);
    assertThat(response.asString()).doesNotContain("metadata");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 25 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class ServerAsynchronousProcessingComponentTest method sendServerRequest.

protected static Future<Map<String, String>> sendServerRequest(String endpointUrl) {
    return executor.submit(() -> {
        long start = System.currentTimeMillis();
        ExtractableResponse<Response> response1 = given().when().get(endpointUrl).then().extract();
        long end = System.currentTimeMillis();
        String s = response1.asString();
        logger.info("********* server call to {} returned {} in {} millis *************", endpointUrl, s, (end - start));
        int statusCode = response1.statusCode();
        assertEquals(200, statusCode);
        return mapper.readValue(s, Map.class);
    });
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Response(io.restassured.response.Response) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Endpoint(com.nike.riposte.server.http.Endpoint)

Aggregations

ExtractableResponse (io.restassured.response.ExtractableResponse)32 Test (org.junit.Test)30 Endpoint (com.nike.riposte.server.http.Endpoint)5 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)5 Response (io.restassured.response.Response)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 ApiError (com.nike.backstopper.apierror.ApiError)1 ApiErrorBase (com.nike.backstopper.apierror.ApiErrorBase)1 SimpleProxyRouterEndpoint (com.nike.riposte.server.http.impl.SimpleProxyRouterEndpoint)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1