Search in sources :

Example 61 with Response

use of io.restassured.response.Response in project vertx-openshift-it by cescoffier.

the class CircuitBreakerIT method testCircuitBreakerState.

private boolean testCircuitBreakerState(CircuitBreakerState expectedState) {
    Response response = circuitBreakerResponse();
    response.then().statusCode(200);
    return response.getBody().asString().contains(expectedState.name());
}
Also used : Response(io.restassured.response.Response)

Example 62 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class JSONGetITest method supportsGettingResponseBodyWhenStatusCodeIs401.

@SuppressWarnings("unchecked")
@Test
public void supportsGettingResponseBodyWhenStatusCodeIs401() throws Exception {
    final Response response = get("/secured/hello");
    assertThat(response.getBody().asString(), allOf(containsString("401"), containsString("Unauthorized")));
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 63 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class URLEncodingITest method doesntDoubleEncodeParamsWhenDefiningUrlEncodingToTrue.

@Test
public void doesntDoubleEncodeParamsWhenDefiningUrlEncodingToTrue() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    given().urlEncodingEnabled(true).pathParam("pathParam", "path/param").formParam("formParam", "form/param").filter(new RequestLoggingFilter(captor)).filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            /*
                         * Note that Scalatra cannot handle request with path parameters containing "/" (like path/param) even though it's URL encoded.
                         * Scalatra decodes the path prior to finding the method to invoke and thus we'll get an error back (since no resource mapping to /path/param/manyParams exist).
                         */
            return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
        }
    }).then().body(equalTo("changed")).when().post("/{pathParam}/manyParams?queryParam=query/param");
    assertThat(loggedRequestPathIn(writer), equalTo("http://localhost:8080/path%2Fparam/manyParams?queryParam=query%2Fparam"));
}
Also used : Response(io.restassured.response.Response) PrintStream(java.io.PrintStream) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) StringWriter(java.io.StringWriter) Filter(io.restassured.filter.Filter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 64 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class URLITest method get_request_with_form_parameters_as_map_that_contains_collection_as_one_of_parameters.

/**
 * This test try to add form parameters as map that contains value as {@link Collection}
 * @throws Exception
 */
@Test
public void get_request_with_form_parameters_as_map_that_contains_collection_as_one_of_parameters() throws Exception {
    final List parameterValues = new ArrayList<String>() {

        {
            add("value1");
            add("value2");
        }
    };
    Map<String, Object> formParameters = new HashMap<String, Object>() {

        {
            put("list", parameterValues);
        }
    };
    Response response = given().formParams(formParameters).when().post("/multiValueParam");
    // Convert returned value to list
    List<String> paramListFromResponse = Arrays.asList(response.jsonPath().getString("list").split(","));
    Assert.assertEquals(parameterValues, paramListFromResponse);
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 65 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class OAuthITest method oauth2_works_with_non_preemptive_header_signing.

@Test
public void oauth2_works_with_non_preemptive_header_signing() {
    final String accessToken = "accessToken";
    given().auth().oauth2(accessToken).filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            AuthenticationScheme scheme = requestSpec.getAuthenticationScheme();
            assertThat(scheme, instanceOf(PreemptiveOAuth2HeaderScheme.class));
            assertThat(((PreemptiveOAuth2HeaderScheme) scheme).getAccessToken(), equalTo(accessToken));
            return new ResponseBuilder().setBody("ok").setStatusCode(200).build();
        }
    }).when().get("/somewhere").then().statusCode(200);
}
Also used : Response(io.restassured.response.Response) AuthenticationScheme(io.restassured.authentication.AuthenticationScheme) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) PreemptiveOAuth2HeaderScheme(io.restassured.authentication.PreemptiveOAuth2HeaderScheme) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

Response (io.restassured.response.Response)270 Test (org.junit.Test)209 Matchers.containsString (org.hamcrest.Matchers.containsString)43 ValidatableResponse (io.restassured.response.ValidatableResponse)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)29 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)25 HttpResponse (org.apache.http.HttpResponse)25 Matchers.emptyString (org.hamcrest.Matchers.emptyString)24 FilterContext (io.restassured.filter.FilterContext)17 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)17 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)17 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)17 Filter (io.restassured.filter.Filter)16 VerifyTest (org.apache.knox.test.category.VerifyTest)15 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 Book (org.baeldung.persistence.model.Book)13 JSONObject (org.json.simple.JSONObject)13 ResponseBuilder (io.restassured.builder.ResponseBuilder)12 IOException (java.io.IOException)11