use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationImpl method when.
public MockMvcRequestAsyncSender when() {
LogConfig logConfig = cfg.getLogConfig();
if (requestLoggingFilter == null && logConfig.isLoggingOfRequestAndResponseIfValidationFailsEnabled()) {
log().ifValidationFails(logConfig.logDetailOfRequestAndResponseIfValidationFails(), logConfig.isPrettyPrintingEnabled());
}
MockMvc mockMvc = mockMvcFactory.build(cfg.getMockMvcConfig());
return new MockMvcRequestSenderImpl(mockMvc, params, queryParams, formParams, attributes, cfg, requestBody, requestHeaders, cookies, sessionAttributes, multiParts, requestLoggingFilter, resultHandlers, requestPostProcessors, interceptor, basePath, responseSpecification, authentication, logRepository);
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method doesntLogUsingGivenWhenThenSyntaxWhenValidationSucceeds.
@Test
public void doesntLogUsingGivenWhenThenSyntaxWhenValidationSucceeds() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).pathParam("firstName", "John").pathParam("lastName", "Doe").when().get("/{firstName}/{lastName}").then().log().ifValidationFails(LogDetail.BODY).body("fullName", equalTo("John Doe"));
assertThat(writer.toString(), isEmptyString());
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method worksForResponseSpecificationsUsingGivenWhenThenSyntax.
@Test
public void worksForResponseSpecificationsUsingGivenWhenThenSyntax() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
try {
RestAssured.given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).pathParam("firstName", "John").pathParam("lastName", "Doe").when().get("/{firstName}/{lastName}").then().log().ifValidationFails(LogDetail.BODY).body("fullName", equalTo("John Doe2"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("{\"firstName\":\"John\",\"lastName\":\"Doe\",\"fullName\":\"John Doe\"}" + LINE_SEPARATOR));
}
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LoggingITest method logAllWhenBasePathAndBasePortAndBaseURIIsDefinedUsingRequestLogSpec.
@Test
public void logAllWhenBasePathAndBasePortAndBaseURIIsDefinedUsingRequestLogSpec() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.baseURI = "http://localhost";
RestAssured.port = 8080;
RestAssured.basePath = "/reflect";
try {
given().config(config().logConfig(new LogConfig(captor, true))).log().all().body("hello").when().post("/");
} finally {
RestAssured.reset();
}
assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/reflect/\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=text/plain; charset=" + RestAssured.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\nhello" + LINE_SEPARATOR));
}
use of io.restassured.config.LogConfig in project rest-assured by rest-assured.
the class LoggingITest method logAllWithPrettyPrintingWhenJson.
@Test
public void logAllWithPrettyPrintingWhenJson() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).pathParam("firstName", "John").pathParam("lastName", "Doe").expect().log().all().body("fullName", equalTo("John Doe")).when().get("/{firstName}/{lastName}");
assertThat(writer.toString(), equalTo("HTTP/1.1 200 OK\nContent-Type: application/json;charset=utf-8\nContent-Length: 59\nServer: Jetty(9.3.2.v20150730)\n\n{\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"fullName\": \"John Doe\"\n}" + LINE_SEPARATOR));
}
Aggregations