Example usage for org.apache.commons.io.output DeferredFileOutputStream write

List of usage examples for org.apache.commons.io.output DeferredFileOutputStream write

Introduction

In this page you can find the example usage for org.apache.commons.io.output DeferredFileOutputStream write.

Prototype

public void write(int b) throws IOException 

Source Link

Document

Writes the specified byte to this output stream.

Usage

From source file:org.apache.maven.plugin.surefire.report.StatelessXMLReporterTest.java

public void testAllFieldsSerialized() throws IOException {
    File reportDir = new File(".");
    String testName = "aTestMethod";
    String testName2 = "bTestMethod";
    reportEntry = new SimpleReportEntry(this.getClass().getName(), testName, 12);
    WrappedReportEntry testSetReportEntry = new WrappedReportEntry(reportEntry, ReportEntryType.success, 12,
            null, null);/*from w  ww. j a va  2 s. com*/
    File expectedReportFile = new File(reportDir, "TEST-" + testName + ".xml");

    stats.testSucceeded(testSetReportEntry);
    StackTraceWriter stackTraceWriter = new DeserializedStacktraceWriter("A fud msg", "trimmed", "fail at foo");
    DeferredFileOutputStream s = new DeferredFileOutputStream(1000000, "fds", "fdx", new File(""));
    String expected = "st]]>d-o\u00DCt<null>!";
    s.write(expected.getBytes("UTF-8"));
    DeferredFileOutputStream s1 = new DeferredFileOutputStream(1000000, "fds", "fdx", new File(""));
    byte[] bytes = "std-\u0115rr?&-&amp;&#163;".getBytes("UTF-8");
    s1.write(bytes);
    WrappedReportEntry t2 = new WrappedReportEntry(
            new SimpleReportEntry(Inner.class.getName(), testName2, stackTraceWriter, 13),
            ReportEntryType.error, 13, s, s1);

    stats.testSucceeded(t2);
    StatelessXmlReporter reporter = new StatelessXmlReporter(new File("."), null, false);
    reporter.testSetCompleted(testSetReportEntry, stats);

    FileInputStream fileInputStream = new FileInputStream(expectedReportFile);

    Xpp3Dom testSuite = Xpp3DomBuilder.build(new InputStreamReader(fileInputStream, "UTF-8"));
    assertEquals("testsuite", testSuite.getName());
    Xpp3Dom properties = testSuite.getChild("properties");
    assertEquals(System.getProperties().size(), properties.getChildCount());
    Xpp3Dom child = properties.getChild(1);
    assertFalse(StringUtils.isEmpty(child.getAttribute("value")));
    assertFalse(StringUtils.isEmpty(child.getAttribute("name")));

    Xpp3Dom[] testcase = testSuite.getChildren("testcase");
    Xpp3Dom tca = testcase[0];
    assertEquals(testName, tca.getAttribute("name")); // Hopefully same order on jdk5
    assertEquals("0.012", tca.getAttribute("time"));
    assertEquals(this.getClass().getName(), tca.getAttribute("classname"));

    Xpp3Dom tcb = testcase[1];
    assertEquals(testName2, tcb.getAttribute("name"));
    assertEquals("0.013", tcb.getAttribute("time"));
    assertEquals(Inner.class.getName(), tcb.getAttribute("classname"));
    Xpp3Dom errorNode = tcb.getChild("error");
    assertNotNull(errorNode);
    assertEquals("A fud msg", errorNode.getAttribute("message"));
    assertEquals("fail at foo", errorNode.getAttribute("type"));
    assertEquals(expected, tcb.getChild("system-out").getValue());
    assertEquals("std-\u0115rr?&-&amp;&#163;", tcb.getChild("system-err").getValue());

    expectedReportFile.delete();
}