Search in sources :

Example 1 with MultiOutputStream

use of org.pentaho.platform.engine.core.output.MultiOutputStream in project pentaho-platform by pentaho.

the class CommandLineProcessorTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    OutputStream multiOut = new MultiOutputStream(new OutputStream[] { CONSOLE_BUFFER, CONSOLE_OUT });
    PrintStream ps = new PrintStream(multiOut);
    System.setOut(ps);
    MockUp<CommandLineProcessor> mock = new MockUp<CommandLineProcessor>() {

        @Mock
        public void $init(String[] args) {
        }
    };
    clpMock = new CommandLineProcessor(null);
    mock.tearDown();
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) MockUp(mockit.MockUp) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) BeforeClass(org.junit.BeforeClass)

Example 2 with MultiOutputStream

use of org.pentaho.platform.engine.core.output.MultiOutputStream in project pentaho-platform by pentaho.

the class OutputTest method testMultiStreamErrors.

public void testMultiStreamErrors() {
    ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    MockExceptionOutputStream out2 = new MockExceptionOutputStream();
    ByteArrayOutputStream out3 = new ByteArrayOutputStream();
    OutputStream[] outs = new OutputStream[] { out1, out2, out3 };
    MultiOutputStream multi = new MultiOutputStream(outs);
    byte[] in = "abcd".getBytes();
    String outStr1 = "";
    String outStr2 = "";
    try {
        multi.write('a');
    } catch (IOException e) {
        // we expect to get here
        assertEquals("IOException", "Test Exception", e.getMessage());
    }
    try {
        multi.write(in, 1, 2);
    } catch (IOException e) {
        // we expect to get here
        assertEquals("IOException", "Test Exception", e.getMessage());
    }
    try {
        multi.write(in);
    } catch (IOException e) {
        // we expect to get here
        assertEquals("IOException", "Test Exception", e.getMessage());
    }
    try {
        multi.close();
    } catch (IOException e) {
        // we expect to get here
        assertEquals("IOException", "Test Exception", e.getMessage());
    }
    outStr1 = new String(out1.toByteArray());
    outStr2 = new String(out3.toByteArray());
    assertEquals("Output stream 1", "abcabcd", outStr1);
    assertEquals("Output stream 2", "abcabcd", outStr2);
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream)

Example 3 with MultiOutputStream

use of org.pentaho.platform.engine.core.output.MultiOutputStream in project pentaho-platform by pentaho.

the class OutputTest method testMultiStream.

public void testMultiStream() {
    ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    ByteArrayOutputStream[] outs = new ByteArrayOutputStream[] { out1, out2 };
    MultiOutputStream multi = new MultiOutputStream(outs);
    byte[] in = "abcd".getBytes();
    String outStr1 = "";
    String outStr2 = "";
    try {
        multi.write('a');
        multi.write(in, 1, 2);
        multi.write(in);
        multi.close();
    } catch (IOException e) {
        // we should not get here
        assertEquals("IOException", null, e);
    }
    outStr1 = new String(out1.toByteArray());
    outStr2 = new String(out2.toByteArray());
    assertEquals("Output stream 1", "abcabcd", outStr1);
    assertEquals("Output stream 2", "abcabcd", outStr2);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MultiOutputStream (org.pentaho.platform.engine.core.output.MultiOutputStream)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)1 MockUp (mockit.MockUp)1 BeforeClass (org.junit.BeforeClass)1