Java 类org.apache.catalina.ssi.ByteArrayServletOutputStream 实例源码

项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
@Test
public void shouldSearchInFiles() throws Exception {
    // given
    String sep = System.lineSeparator();
    createFile("A.log", "A-line1" + sep + "A-line2" + sep + "A-line3", now - 1);
    createFile("B.log", "B-line1" + sep + "B-line2" + sep + "B-line3", now);
    ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

    // when
    logViewEndpoint.search("line2", response);

    // then
    String output = new String(outputStream.toByteArray());
    assertThat(output, containsString("[A.log] A-line2"));
    assertThat(output, containsString("[B.log] B-line2"));
    assertThat(output, not(containsString("line1")));
    assertThat(output, not(containsString("line3")));
}
项目:cacheonix-core    文件:CachingHttpServletResponseWrapperTest.java   
public void setUp() throws Exception {

      super.setUp();

      httpServletResponse = mock(HttpServletResponse.class);
      when(httpServletResponse.getOutputStream()).thenReturn(new ByteArrayServletOutputStream());
      when(httpServletResponse.getWriter()).thenReturn(new PrintWriter(new ByteArrayServletOutputStream()));

      final ServletOutputWrapperFactory servletOutputWrapperFactory = new ServletOutputWrapperFactoryImpl();
      cachingHttpServletResponseWrapper = new CachingHttpServletResponseWrapper(httpServletResponse,
              servletOutputWrapperFactory);
   }
项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
@Test
public void shouldViewZipFileContent() throws Exception {
    // given
    createZipArchive("file.zip", "A.log", "content");
    ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

    // when
    logViewEndpoint.view("A.log", "file.zip", null, response);

    // then
    assertThat(new String(outputStream.toByteArray()), is("content"));
}
项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
@Test
public void shouldViewTarGzFileContent() throws Exception {
    // given
    createTarGzArchive("file.tar.gz", "A.log", "content");
    ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

    // when
    logViewEndpoint.view("A.log", "file.tar.gz", null, response);

    // then
    assertThat(new String(outputStream.toByteArray()), is("content"));
}
项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
@Test
public void shouldViewFile() throws Exception {
    // given
    createFile("file.log", "abc", now);
    ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

    // when
    logViewEndpoint.view("file.log", null, null, response);

    // then
    assertThat(new String(outputStream.toByteArray()), is("abc"));
}
项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
@Test
public void shouldTailViewOnlyLastLine() throws Exception {
    // given
    createFile("file.log", "line1" + System.lineSeparator() + "line2" + System.lineSeparator(), now);
    ByteArrayServletOutputStream outputStream = mockResponseOutputStream();

    // when
    logViewEndpoint.view("file.log", null, 1, response);

    // then
    assertThat(new String(outputStream.toByteArray()), not(containsString("line1")));
    assertThat(new String(outputStream.toByteArray()), containsString("line2"));
}
项目:spring-boot-actuator-logview    文件:LogViewEndpointTest.java   
private ByteArrayServletOutputStream mockResponseOutputStream() throws Exception {
    ByteArrayServletOutputStream outputStream = new ByteArrayServletOutputStream();
    when(response.getOutputStream()).thenReturn(outputStream);
    return outputStream;
}