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);
}
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"));
}
}
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"));
}
}
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);
}
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);
}
Aggregations