use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationImpl method mergeConfig.
private static void mergeConfig(MockMvcRequestSpecificationImpl thisOne, MockMvcRequestSpecificationImpl other) {
RestAssuredMockMvcConfig thisConfig = thisOne.getRestAssuredMockMvcConfig();
RestAssuredMockMvcConfig otherConfig = other.getRestAssuredMockMvcConfig();
boolean thisIsUserConfigured = thisConfig.isUserConfigured();
boolean otherIsUserConfigured = otherConfig.isUserConfigured();
if (thisIsUserConfigured && otherIsUserConfigured) {
if (otherConfig.getDecoderConfig().isUserConfigured()) {
thisConfig = thisConfig.decoderConfig(otherConfig.getDecoderConfig());
}
if (otherConfig.getEncoderConfig().isUserConfigured()) {
thisConfig = thisConfig.encoderConfig(otherConfig.getEncoderConfig());
}
if (otherConfig.getHeaderConfig().isUserConfigured()) {
thisConfig = thisConfig.headerConfig(otherConfig.getHeaderConfig());
}
if (otherConfig.getJsonConfig().isUserConfigured()) {
thisConfig = thisConfig.jsonConfig(otherConfig.getJsonConfig());
}
if (otherConfig.getLogConfig().isUserConfigured()) {
thisConfig = thisConfig.logConfig(otherConfig.getLogConfig());
}
if (otherConfig.getObjectMapperConfig().isUserConfigured()) {
thisConfig = thisConfig.objectMapperConfig(otherConfig.getObjectMapperConfig());
}
if (otherConfig.getSessionConfig().isUserConfigured()) {
thisConfig = thisConfig.sessionConfig(otherConfig.getSessionConfig());
}
if (otherConfig.getXmlConfig().isUserConfigured()) {
thisConfig = thisConfig.xmlConfig(otherConfig.getXmlConfig());
}
if (otherConfig.getAsyncConfig().isUserConfigured()) {
thisConfig = thisConfig.asyncConfig(otherConfig.getAsyncConfig());
}
if (otherConfig.getMultiPartConfig().isUserConfigured()) {
thisConfig = thisConfig.multiPartConfig(otherConfig.getMultiPartConfig());
}
if (otherConfig.getMockMvcConfig().isUserConfigured()) {
thisConfig = thisConfig.mockMvcConfig(otherConfig.getMockMvcConfig());
}
if (otherConfig.getParamConfig().isUserConfigured()) {
thisConfig = thisConfig.paramConfig(otherConfig.getParamConfig());
}
thisOne.config(thisConfig);
} else if (!thisIsUserConfigured && otherIsUserConfigured) {
thisOne.config(otherConfig);
}
}
use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.
the class RestAssuredMockMvc method enableLoggingOfRequestAndResponseIfValidationFails.
/**
* Enable logging of both the request and the response if REST Assureds test validation fails with the specified log detail.
* <p/>
* <p>
* This is just a shortcut for:
* </p>
* <pre>
* RestAssured.config = new RestAssuredMockMvcConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
* </pre>
*
* @param logDetail The log detail to show in the log
*/
public static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail) {
config = config == null ? new RestAssuredMockMvcConfig() : config;
config = config.logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
// Note that request spec also influence response spec when it comes to logging if validation fails due to the way filters work
if (requestSpecification != null && requestSpecification instanceof MockMvcRequestSpecificationImpl) {
RestAssuredMockMvcConfig restAssuredConfig = ((MockMvcRequestSpecificationImpl) requestSpecification).getRestAssuredMockMvcConfig();
if (restAssuredConfig == null) {
restAssuredConfig = config;
} else {
LogConfig logConfigForRequestSpec = restAssuredConfig.getLogConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail);
restAssuredConfig = restAssuredConfig.logConfig(logConfigForRequestSpec);
}
requestSpecification.config(restAssuredConfig);
}
}
use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.
the class RequestLoggingTest method given_config_is_stored_in_writer.
@Before
public void given_config_is_stored_in_writer() {
writer = new StringWriter();
PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true));
}
use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.
the class LoggingIfValidationFailsTest method doesnt_log_if_request_or_response_when_validation_succeeds_when_request_and_response_logging_if_validation_fails_is_enabled.
@Test
public void doesnt_log_if_request_or_response_when_validation_succeeds_when_request_and_response_logging_if_validation_fails_is_enabled() {
RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true).enableLoggingOfRequestAndResponseIfValidationFails());
given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
assertThat(writer.toString(), isEmptyString());
}
use of io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig in project rest-assured by rest-assured.
the class LoggingIfValidationFailsTest method logging_is_applied_when_using_non_static_response_specifications.
@Test
public void logging_is_applied_when_using_non_static_response_specifications() {
RestAssuredMockMvc.config = new RestAssuredMockMvcConfig().logConfig(new LogConfig(captor, true).enableLoggingOfRequestAndResponseIfValidationFails());
try {
given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().spec(new ResponseSpecBuilder().expectBody("id", equalTo(2)).expectBody("content", equalTo("Hello, Johan2!")).build());
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), not(isEmptyOrNullString()));
}
}
Aggregations