Example usage for java.io OutputStream toString

List of usage examples for java.io OutputStream toString

Introduction

In this page you can find the example usage for java.io OutputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.hadoop.mapreduce.v2.hs.webapp.TestHsJobBlock.java

@Test
public void testHsJobBlockForOversizeJobShouldDisplayWarningMessage() {
    int maxAllowedTaskNum = 100;

    Configuration config = new Configuration();
    config.setInt(JHAdminConfig.MR_HS_LOADED_JOBS_TASKS_MAX, maxAllowedTaskNum);

    JobHistory jobHistory = new JobHistoryStubWithAllOversizeJobs(maxAllowedTaskNum);
    jobHistory.init(config);/*from  w w w .  j av a  2 s  . c  o  m*/

    HsJobBlock jobBlock = new HsJobBlock(jobHistory) {
        // override this so that job block can fetch a job id.
        @Override
        public Map<String, String> moreParams() {
            Map<String, String> map = new HashMap<>();
            map.put(AMParams.JOB_ID, "job_0000_0001");
            return map;
        }
    };

    // set up the test block to render HsJobBLock to
    OutputStream outputStream = new ByteArrayOutputStream();
    HtmlBlock.Block block = createBlockToCreateTo(outputStream);

    jobBlock.render(block);

    block.getWriter().flush();
    String out = outputStream.toString();
    Assert.assertTrue("Should display warning message for jobs that have too " + "many tasks",
            out.contains("Any job larger than " + maxAllowedTaskNum + " will not be loaded"));
}

From source file:ape_test.CLITest.java

public void testHelpWithVerbose() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);//from   w w  w  .ja  v a 2 s .c om

    String[] arg = new String[2];
    arg[0] = "h";
    arg[1] = "v";
    Main.main(arg);
    System.setOut(originalOut);
    assertNotSame("", os.toString());
}

From source file:ape_test.CLITest.java

/**
 * This test just checks to see if the start of the help dialog is printed
 * Since the help dialog will continue to be updated, it's not worth constantly changing this test
 *///w  ww.  j a v a2s. c  o  m
public void testHelpDialog() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);

    String[] theArgs = new String[1];
    theArgs[0] = "-h";
    Main.main(theArgs);
    System.setOut(originalOut);
    assertEquals("usage: ape", (os.toString()).substring(0, 10));
}

From source file:ape_test.CLITest.java

public void testVersionPrint() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);//from w  w  w  .  j av a2s. com

    String[] theArgs = new String[1];
    theArgs[0] = "-V";
    Main.main(theArgs);
    assertEquals("ChaosMonkey version: " + Main.getVersion() + "\n", os.toString());

    System.setOut(originalOut);
}

From source file:org.apache.hadoop.mapreduce.v2.hs.webapp.TestHsJobBlock.java

@Test
public void testHsJobBlockForNormalSizeJobShouldNotDisplayWarningMessage() {

    Configuration config = new Configuration();
    config.setInt(JHAdminConfig.MR_HS_LOADED_JOBS_TASKS_MAX, -1);

    JobHistory jobHistory = new JobHitoryStubWithAllNormalSizeJobs();
    jobHistory.init(config);/*from   w w  w  .  j a  v  a2 s. c o m*/

    HsJobBlock jobBlock = new HsJobBlock(jobHistory) {
        // override this so that the job block can fetch a job id.
        @Override
        public Map<String, String> moreParams() {
            Map<String, String> map = new HashMap<>();
            map.put(AMParams.JOB_ID, "job_0000_0001");
            return map;
        }

        // override this to avoid view context lookup in render()
        @Override
        public ResponseInfo info(String about) {
            return new ResponseInfo().about(about);
        }

        // override this to avoid view context lookup in render()
        @Override
        public String url(String... parts) {
            return StringHelper.ujoin("", parts);
        }
    };

    // set up the test block to render HsJobBLock to
    OutputStream outputStream = new ByteArrayOutputStream();
    HtmlBlock.Block block = createBlockToCreateTo(outputStream);

    jobBlock.render(block);

    block.getWriter().flush();
    String out = outputStream.toString();

    Assert.assertTrue("Should display job overview for the job.", out.contains("ApplicationMaster"));
}

From source file:com.redhat.rhn.taskomatic.task.repomd.FilelistsXmlWriter.java

/**
 *
 * @param pkgDto pkg info to add to xml/*from www . jav a 2  s.  c  om*/
 */
public void addPackage(PackageDto pkgDto) {
    try {
        String xml = pkgDto.getFilelistXml();
        if (ConfigDefaults.get().useDBRepodata() && !StringUtils.isEmpty(xml)) {
            if (xml != null) {
                handler.addCharacters(xml);
                return;
            }
        }

        OutputStream st = new ByteArrayOutputStream();
        SimpleContentHandler tmpHandler = getTemporaryHandler(st);

        tmpHandler.startDocument();
        addPackageBoilerplate(tmpHandler, pkgDto);
        addPackageFiles(pkgDto, tmpHandler);
        tmpHandler.endElement("package");
        tmpHandler.endDocument();

        String pkg = st.toString();
        PackageManager.updateRepoFileList(pkgDto.getId(), pkg);
        handler.addCharacters(pkg);

    } catch (SAXException e) {
        throw new RepomdRuntimeException(e);
    }

}

From source file:com.github.cherimojava.data.spring._EntityConverter.java

@Test
public void writeInternal() throws IOException {
    HttpOutputMessage hom = mock(HttpOutputMessage.class);
    OutputStream os = new ByteArrayOutputStream();
    when(hom.getBody()).thenReturn(os);/*from   w w w .ja  v  a  2 s.c  om*/
    EntityConverter conv = new EntityConverter(mock);
    SimpleEntity se = EntityFactory.instantiate(SimpleEntity.class);
    se.setString("SomeString");
    conv.writeInternal(se, hom);
    assertEquals("{ \"string\" : \"SomeString\" }", os.toString());
}

From source file:uk.org.lidalia.sysoutslf4j.integration.TestSysOutOverSlf4J.java

@Test
public void systemOutNoLongerGoesToSystemOut() throws Exception {
    OutputStream sysOutMock = setUpMockSystemOutput(SystemOutput.OUT);
    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

    System.out.println("Hello again");

    assertThat(sysOutMock.toString(), not(containsString("Hello again")));
}

From source file:org.jboss.pnc.causeway.ImportedBuildJsonConversionIT.java

private String convertToJson(Object object) throws IOException {
    OutputStream stream = new ByteArrayOutputStream();
    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE));

    mapper.writeValue(stream, object);/*from   w w  w .  j  a v a2 s.  c  o m*/
    stream.close();
    return stream.toString();
}

From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

@Test
public void testORMapDisco() throws RMapException, RMapDefectiveArgumentException {
    InputStream stream = new ByteArrayInputStream(discoRDF.getBytes(StandardCharsets.UTF_8));
    RioRDFHandler handler = new RioRDFHandler();
    Set<Statement> stmts = handler.convertRDFToStmtList(stream, RDFType.RDFXML, "");
    ORMapDiSCO disco = new ORMapDiSCO(stmts);
    assertEquals(14, disco.getRelatedStatementsAsList().size());
    OutputStream os = handler.disco2Rdf(disco, RDFType.RDFXML);
    String output = os.toString();
    assertTrue(output.contains("Yonggang Wen"));
    stream = new ByteArrayInputStream(discoRDFdcterms.getBytes(StandardCharsets.UTF_8));
    stmts = handler.convertRDFToStmtList(stream, RDFType.RDFXML, "");
    ;/* ww  w  .j  a v a  2s . co m*/
    try {
        disco = new ORMapDiSCO(stmts);
        assertTrue(true);
    } catch (RMapException e) {
        fail("should have handled dcTerms");
    }
}