List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file, Charset charset) throws IOException
From source file:com.sap.prd.mobile.ios.mios.ForkerTest.java
@Test public void testStraightForward() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream log = new PrintStream(out, true); try {/*from w ww . java2 s .c o m*/ Forker.forkProcess(log, new File(".").getAbsoluteFile(), "echo", "Hello World"); } finally { log.close(); } Assert.assertEquals("Hello World\n", new String(out.toByteArray())); }
From source file:net.jperf.LoggingStopWatchTest.java
protected void setUp() throws Exception { realErr = System.err;/*from w w w . java 2 s . co m*/ fakeErr = new ByteArrayOutputStream(); System.setErr(new PrintStream(fakeErr, true /*autoflush*/)); }
From source file:io.restassured.itest.java.GivenWhenThenLoggingITest.java
@Test public void logsEverythingResponseUsingGivenWhenThenSyntax() throws Exception { final StringWriter writer = new StringWriter(); final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); given().config(RestAssuredConfig.config() .logConfig(LogConfig.logConfig().defaultStream(captor).and().enablePrettyPrinting(false))) .pathParam("firstName", "John").pathParam("lastName", "Doe").when().get("/{firstName}/{lastName}") .then().log().all().body("fullName", equalTo("John Doe")); 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{\"firstName\":\"John\",\"lastName\":\"Doe\",\"fullName\":\"John Doe\"}" + LINE_SEPARATOR));//from w ww.j av a 2 s . c o m }
From source file:net.officefloor.tutorial.exceptionhttpserver.ExceptionHttpServerTest.java
public void testExceptionHandling() throws Exception { // Override stderr ByteArrayOutputStream error = new ByteArrayOutputStream(); System.setErr(new PrintStream(error, true)); // Start server WoofOfficeFloorSource.start();// w w w . ja v a 2 s . co m // Clear setup log error.reset(); // Submit to trigger the exception this.client.execute(new HttpGet("http://localhost:7878/template-submit.woof")); // Ensure handling by logging the failure String log = new String(error.toByteArray()).trim(); assertEquals("Should log error", "Test", log); }
From source file:com.jayway.restassured.itest.java.GivenWhenThenLoggingITest.java
@Test public void logsEverythingResponseUsingGivenWhenThenSyntax() throws Exception { final StringWriter writer = new StringWriter(); final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); given().config(config().logConfig(logConfig().defaultStream(captor).and().enablePrettyPrinting(false))) .pathParam("firstName", "John").pathParam("lastName", "Doe").when().get("/{firstName}/{lastName}") .then().log().all().body("fullName", equalTo("John Doe")); 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{\"firstName\":\"John\",\"lastName\":\"Doe\",\"fullName\":\"John Doe\"}" + LINE_SEPARATOR));/*from w ww . j av a 2 s . c o m*/ }
From source file:com.jayway.restassured.module.mockmvc.RequestLoggingTest.java
@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)); }
From source file:io.restassured.module.mockmvc.PutTest.java
@Test public void doesnt_automatically_adds_x_www_form_urlencoded_as_content_type_when_putting_params() { StringWriter writer = new StringWriter(); PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); RestAssuredMockMvc.given().config(newConfig().logConfig(new LogConfig(captor, true))).param("name", "Johan") .when().put("/greetingPut").then().log().all().statusCode(415); assertThat(writer.toString(),/*from w w w . j a v a 2s . c om*/ equalTo("415 Content type 'null' not supported\nAccept: application/x-www-form-urlencoded\n")); }
From source file:com.voa.weixin.utils.LogUtil.java
/** Returns a stream that, when written to, adds log lines. */ private static PrintStream getLogStream(final Log logger, final Method method) { return new PrintStream(new ByteArrayOutputStream() { private int scan = 0; private boolean hasNewline() { for (; scan < count; scan++) { if (buf[scan] == '\n') return true; }//ww w . jav a 2 s . c o m return false; } @Override public void flush() throws IOException { if (!hasNewline()) return; try { method.invoke(logger, new Object[] { toString().trim() }); } catch (Exception e) { if (LOG.isFatalEnabled()) { LOG.fatal("Cannot log with method [" + method + "]", e); } } reset(); scan = 0; } }, true); }
From source file:com.sap.prd.mobile.ios.mios.ForkerTest.java
@Test(expected = IllegalArgumentException.class) public void testMissingArguments_1() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream log = new PrintStream(out, true); try {/*from www . ja va 2 s . co m*/ Forker.forkProcess(log, new File(".").getAbsoluteFile(), (String[]) null); } finally { log.close(); } }
From source file:com.jayway.restassured.module.mockmvc.LoggingIfValidationFailsTest.java
@Before public void given_writer_and_captor_is_initialized() { writer = new StringWriter(); captor = new PrintStream(new WriterOutputStream(writer), true); }