Search in sources :

Example 6 with RestAssuredMockMvcConfig

use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method configurations_are_merged.

@Test
public void configurations_are_merged() {
    // Given
    RestAssuredMockMvcConfig cfg1 = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(cfg1).build();
    // When
    RestAssuredMockMvcConfig cfg2 = new RestAssuredMockMvcConfig().sessionConfig(sessionConfig().sessionIdName("php"));
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().config(cfg2).spec(specToMerge);
    // Then
    RestAssuredConfig mergedConfig = implOf(spec).getRestAssuredConfig();
    assertThat(mergedConfig.getSessionConfig().sessionIdName()).isEqualTo("php");
    assertThat(mergedConfig.getJsonConfig().numberReturnType()).isEqualTo(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) RestAssuredConfig(io.restassured.config.RestAssuredConfig) Test(org.junit.Test)

Example 7 with RestAssuredMockMvcConfig

use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.

the class LoggingIfValidationFailsTest method logging_of_both_request_and_response_validation_works_when_test_fails.

@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails() {
    RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true).enableLoggingOfRequestAndResponseIfValidationFails());
    try {
        given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
        fail("Should throw AssertionError");
    } catch (AssertionError e) {
        assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/greetingPost\nProxy:\t\t\t<none>\nRequest params:\tname=Johan\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>\n\n" + "" + "200\nContent-Type: application/json;charset=UTF-8\n\n{\n    \"id\": 1,\n    \"content\": \"Hello, Johan!\"\n}\n"));
    }
}
Also used : RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) PostController(io.restassured.module.mockmvc.http.PostController) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 8 with RestAssuredMockMvcConfig

use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.

the class LoggingIfValidationFailsTest method logging_of_both_request_and_response_validation_works_when_test_fails_when_configured_with_log_detail.

@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_configured_with_log_detail() {
    RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true).enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS));
    try {
        given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
        fail("Should throw AssertionError");
    } catch (AssertionError e) {
        assertThat(writer.toString(), equalTo("Headers:\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\n\n" + "Content-Type: application/json;charset=UTF-8\n"));
    }
}
Also used : RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) PostController(io.restassured.module.mockmvc.http.PostController) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 9 with RestAssuredMockMvcConfig

use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method configs_of_same_type_are_overwritten_when_defined_in_specification.

@Test
public void configs_of_same_type_are_overwritten_when_defined_in_specification() {
    // Given
    RestAssuredMockMvcConfig otherConfig = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL));
    RestAssuredMockMvcConfig thisConfig = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(otherConfig).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().config(thisConfig).spec(specToMerge);
    // Then
    assertThat(implOf(spec).getRestAssuredMockMvcConfig().getJsonConfig().numberReturnType()).isEqualTo(JsonPathConfig.NumberReturnType.BIG_DECIMAL);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 10 with RestAssuredMockMvcConfig

use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method config_is_not_overwritten_when_not_defined_in_specification.

@Test
public void config_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    RestAssuredMockMvcConfig thisConfig = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().config(thisConfig).spec(specToMerge);
    // Then
    // This assertion is commented out since for some reason it fails during the release process
    // assertThat(implOf(spec).getRestAssuredMockMvcConfig()).isSameAs(thisConfig);
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
    assertThat(implOf(spec).getRestAssuredMockMvcConfig().getJsonConfig().numberReturnType()).isEqualTo(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Aggregations

RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)11 LogConfig (io.restassured.config.LogConfig)7 Test (org.junit.Test)7 PostController (io.restassured.module.mockmvc.http.PostController)4 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)3 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)3 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 Before (org.junit.Before)2 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 MockMvcRequestSpecificationImpl (io.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl)1