List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:org.apache.flink.yarn.CliFrontendYarnAddressConfigurationTest.java
@AfterClass public static void restoreAfterwards() { System.setOut(OUT); System.setErr(ERR); }
From source file:org.pentaho.di.trans.steps.excelwriter.ExcelWriterStepTest.java
@Test public void testMaxSheetNameLength() throws Exception { PrintStream err = System.err; try {/*from ww w . j ava2s. co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setErr(new PrintStream(baos)); when(mockHelper.initStepMetaInterface.getSheetname()).thenReturn("12345678901234567890123456789012"); // 32 character step.init(mockHelper.initStepMetaInterface, mockHelper.initStepDataInterface); String content = baos.toString("UTF-8"); // e.g. ISO-8859-1 if (!content.contains("12345678901234567890123456789012")) { fail(); } } finally { System.setErr(err); } }
From source file:com.thoughtworks.go.agent.bootstrapper.AgentBootstrapperFunctionalTest.java
@Test public void shouldLoadAndBootstrapJarUsingAgentBootstrapCode_specifiedInAgentManifestFile() throws Exception { if (!OS_CHECKER.satisfy()) { PrintStream err = System.err; try {/*from w ww . ja v a2 s .c om*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); System.setErr(new PrintStream(os)); File agentJar = new File("agent.jar"); agentJar.delete(); new AgentBootstrapper() { @Override void jvmExit(int returnValue) { } }.go(false, new AgentBootstrapperArgs(new URL("http://" + "localhost" + ":" + server.getPort() + "/go"), null, AgentBootstrapperArgs.SslMode.NONE)); agentJar.delete(); assertThat(new String(os.toByteArray()), containsString("Hello World Fellas!")); } finally { System.setErr(err); } } }
From source file:net.sourceforge.seqware.pipeline.plugins.GenericMetadataSaverTest.java
@Before @Override//w w w . j a va 2 s . co m public void setUp() { super.setUp(); instance = new ModuleRunner(); instance.setMetadata(metadata); outStream = new ByteArrayOutputStream(); errStream = new ByteArrayOutputStream(); PrintStream pso = new PrintStream(outStream); PrintStream pse = new PrintStream(errStream) { @Override public PrintStream append(CharSequence csq) { return super.append(csq); } @Override public void print(String s) { super.print(s); } }; System.setOut(pso); System.setErr(pse); }
From source file:org.apache.hadoop.streaming.UtilTest.java
void redirectIfAntJunit() throws IOException { boolean fromAntJunit = System.getProperty("test.build.data") != null; if (fromAntJunit) { new File(antTestDir_).mkdirs(); File outFile = new File(antTestDir_, testName_ + ".log"); PrintStream out = new PrintStream(new FileOutputStream(outFile)); System.setOut(out);//from ww w . ja v a 2 s .c om System.setErr(out); } }
From source file:org.apache.tika.cli.TikaCLIBatchIT.java
@After public void tearDown() throws Exception { System.setOut(new PrintStream(out, true, UTF_8.name())); System.setErr(new PrintStream(err, true, UTF_8.name())); //TODO: refactor to use our deleteDirectory with straight path //FileUtils.deleteDirectory(tempOutputDir.toFile()); }
From source file:org.sonar.batch.mediumtest.log.LogListenerTest.java
@Before public void prepare() throws IOException { System.setOut(new PrintStream(stdOutTarget)); System.setErr(new PrintStream(stdErrTarget)); // logger from the batch might write to it asynchronously logOutput = Collections.synchronizedList(new LinkedList<LogEvent>()); logOutputStr = new StringBuilder(); tester.start();//from www . j a v a 2 s. c om baseDir = temp.getRoot(); builder = ImmutableMap.<String, String>builder().put("sonar.task", "scan") .put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project") .put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT") .put("sonar.projectDescription", "Description of Foo Project"); }
From source file:test.org.eclipse.dirigible.runtime.java.AbstractJavaExecutorTest.java
@After public void tearDown() throws Exception { if (baos != null) { baos.close();/*from w w w. ja v a 2 s. co m*/ } if (printStream != null) { printStream.close(); } System.setOut(backupOut); System.setErr(backupErr); }
From source file:org.apache.hadoop.hive.ql.session.TestClearDanglingScratchDir.java
public void redirectStdOutErr() { stdout = new ByteArrayOutputStream(); PrintStream psStdout = new PrintStream(stdout); origStdoutPs = System.out;/*from ww w . j a v a 2 s . com*/ System.setOut(psStdout); stderr = new ByteArrayOutputStream(); PrintStream psStderr = new PrintStream(stderr); origStderrPs = System.err; System.setErr(psStderr); }
From source file:org.g_node.converter.ConvCliToolControllerTest.java
/** * Tests the run method of the {@link ConvCliToolController}. * @throws Exception/* w w w . ja v a 2s . c o m*/ */ @Test public void runTest() throws Exception { // TODO check if this should be split up into different tests. // Set up environment final PrintStream stdout = System.out; final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(outStream)); final PrintStream errout = System.err; final ByteArrayOutputStream errStream = new ByteArrayOutputStream(); System.setErr(new PrintStream(errStream)); Logger rootLogger = Logger.getRootLogger(); rootLogger.setLevel(Level.INFO); rootLogger.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %m%n"))); // Create test files final String tmpRoot = System.getProperty("java.io.tmpdir"); final String testFolderName = "fileservicetest"; final String testFileName = "test.txt"; final Path testFileFolder = Paths.get(tmpRoot, testFolderName); final File currTestFile = testFileFolder.resolve(testFileName).toFile(); FileUtils.write(currTestFile, "This is a normal test file"); final String testTurtleFileName = "test.ttl"; final String testTurtleDefaultOutName = "test_out.ttl"; final File currTurtleTestFile = testFileFolder.resolve(testTurtleFileName).toFile(); FileUtils.write(currTurtleTestFile, ""); final String testInvalidFileName = "test.rdf"; final File currInvalidTestFile = testFileFolder.resolve(testInvalidFileName).toFile(); FileUtils.write(currInvalidTestFile, "I shall crash!"); final String outFileName = testFileFolder.resolve("out.ttl").toString(); final CommandLineParser parser = new DefaultParser(); final Options useOptions = this.convCont.options(); String[] args; CommandLine cmd; // Test missing argument args = new String[1]; args[0] = "-i"; try { parser.parse(useOptions, args, false); } catch (MissingArgumentException e) { assertThat(e).hasMessage("Missing argument for option: i"); } // Test non existent input file args = new String[2]; args[0] = "-i"; args[1] = "iDoNotExist"; cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains("Input file iDoNotExist does not exist"); outStream.reset(); // Test existing input file, unsupported file type args = new String[2]; args[0] = "-i"; args[1] = currTestFile.toString(); cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()) .contains(String.join("", "[ERROR] Input RDF file ", currTestFile.toString(), " cannot be read.")); outStream.reset(); // Test provide supported input file type, unsupported output RDF format args = new String[4]; args[0] = "-i"; args[1] = currTurtleTestFile.toString(); args[2] = "-f"; args[3] = "iDoNotExist"; cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains("[ERROR] Unsupported output format: 'IDONOTEXIST'"); outStream.reset(); // Test provide supported input file type, test write output file w/o providing output filename args = new String[2]; args[0] = "-i"; args[1] = currTurtleTestFile.toString(); cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains(String.join("", "[INFO ] Writing data to RDF file '", testFileFolder.resolve(testTurtleDefaultOutName).toString(), "' using format 'TTL'")); outStream.reset(); // Test invalid RDF input file args = new String[2]; args[0] = "-i"; args[1] = currInvalidTestFile.toString(); cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains("[line: 1, col: 1 ] Content is not allowed in prolog."); outStream.reset(); // Test writing to provided output file does not match provided output format args = new String[6]; args[0] = "-i"; args[1] = currTurtleTestFile.toString(); args[2] = "-o"; args[3] = outFileName; args[4] = "-f"; args[5] = "JSON-LD"; cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains(String.join("", "[INFO ] Writing data to RDF file '", outFileName, ".jsonld' using format 'JSON-LD'")); outStream.reset(); // Test writing to provided output file args = new String[4]; args[0] = "-i"; args[1] = currTurtleTestFile.toString(); args[2] = "-o"; args[3] = outFileName; cmd = parser.parse(useOptions, args, false); this.convCont.run(cmd); assertThat(outStream.toString()).contains( String.join("", "[INFO ] Writing data to RDF file '", outFileName, "' using format 'TTL'")); outStream.reset(); // Clean up if (Files.exists(testFileFolder)) { FileUtils.deleteDirectory(testFileFolder.toFile()); } rootLogger.removeAllAppenders(); System.setOut(stdout); System.setErr(errout); }