Search in sources :

Example 76 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method logging_is_not_overwritten_when_not_defined_in_specification.

@Test
public void logging_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    StringWriter writer = new StringWriter();
    PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(RestAssuredMockMvcConfig.newConfig().logConfig(LogConfig.logConfig().defaultStream(captor))).addQueryParam("name", "Johan").build();
    // When
    RestAssuredMockMvc.given().spec(specToMerge).log().params().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
    // Then
    assertThat(writer.toString()).isEqualTo("Request params:\t<none>\n" + "Query params:\tname=Johan\n" + "Form params:\t<none>\n" + "Path params:\t<none>\n" + "Multiparts:\t\t<none>\n");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) PrintStream(java.io.PrintStream) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) StringWriter(java.io.StringWriter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 77 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method logging_is_overwritten_when_defined_in_specification.

@Test
public void logging_is_overwritten_when_defined_in_specification() {
    // Given
    StringWriter writer = new StringWriter();
    PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(RestAssuredMockMvcConfig.newConfig().logConfig(LogConfig.logConfig().defaultStream(captor))).and().log(LogDetail.ALL).build();
    // When
    RestAssuredMockMvc.given().log().params().spec(specToMerge).standaloneSetup(new GreetingController()).when().get("/greeting?name={name}", "Johan").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
    // Then
    assertThat(writer.toString()).isEqualTo("Request method:\tGET\n" + "Request URI:\thttp://localhost:8080/greeting?name=Johan\n" + "Proxy:\t\t\t<none>\n" + "Request params:\t<none>\n" + "Query params:\t<none>\n" + "Form params:\t<none>\n" + "Path params:\t<none>\n" + "Headers:\t\t<none>\n" + "Cookies:\t\t<none>\n" + "Multiparts:\t\t<none>\n" + "Body:\t\t\t<none>\n");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) PrintStream(java.io.PrintStream) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) StringWriter(java.io.StringWriter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 78 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project cas by apereo.

the class CasTomcatBannerTests method verifyAction.

@Test
public void verifyAction() {
    val banner = new CasTomcatBanner();
    val writer = new StringWriter();
    val out = new WriterOutputStream(writer, StandardCharsets.UTF_8);
    try (val stream = new PrintStream(out, true, StandardCharsets.UTF_8)) {
        banner.printBanner(environment, CasTomcatBanner.class, stream);
    }
    val output = writer.toString();
    assertNotNull(output);
}
Also used : lombok.val(lombok.val) PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 79 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project cas by apereo.

the class CasJettyBannerTests method verifyAction.

@Test
public void verifyAction() {
    val banner = new CasJettyBanner();
    val writer = new StringWriter();
    val out = new WriterOutputStream(writer, StandardCharsets.UTF_8);
    try (val stream = new PrintStream(out, true, StandardCharsets.UTF_8)) {
        banner.printBanner(environment, CasJettyBanner.class, stream);
    }
    val output = writer.toString();
    assertNotNull(output);
}
Also used : lombok.val(lombok.val) PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 80 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project cas by apereo.

the class CasStarterBannerTests method verifyAction.

@Test
public void verifyAction() {
    val banner = new CasStarterBanner();
    val writer = new StringWriter();
    val out = new WriterOutputStream(writer, StandardCharsets.UTF_8);
    try (val stream = new PrintStream(out, true, StandardCharsets.UTF_8)) {
        banner.printBanner(environment, CasStarterBanner.class, stream);
    }
    val output = writer.toString();
    assertNotNull(output);
    assertTrue(output.contains("Starter"));
}
Also used : lombok.val(lombok.val) PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)159 StringWriter (java.io.StringWriter)150 PrintStream (java.io.PrintStream)141 Test (org.junit.Test)133 LogConfig (io.restassured.config.LogConfig)46 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)44 ResponseBuilder (io.restassured.builder.ResponseBuilder)36 Filter (io.restassured.filter.Filter)35 FilterContext (io.restassured.filter.FilterContext)35 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)35 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)35 OutputStream (java.io.OutputStream)8 IOException (java.io.IOException)7 Col (org.apache.karaf.shell.table.Col)6 ShellTable (org.apache.karaf.shell.table.ShellTable)6 InputStream (java.io.InputStream)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3