Example usage for org.apache.commons.io.output NullOutputStream nullOutputStream

List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream

Introduction

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

Prototype

public static OutputStream nullOutputStream() 

Source Link

Document

Returns a new OutputStream which discards all bytes.

Usage

From source file:org.apache.taverna.scufl2.rdfxml.TestRDFXMLSerializer.java

@Test
public void workflowBundle() throws Exception {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    // To test that seeAlso URIs are stored
    serializer.workflowDoc(new NullOutputStream(), workflowBundle.getMainWorkflow(),
            URI.create(HELLOWORLD_RDF));
    serializer.profileDoc(new NullOutputStream(), workflowBundle.getProfiles().getByName("tavernaWorkbench"),
            URI.create(TAVERNAWORKBENCH_RDF));
    serializer.profileDoc(new NullOutputStream(), workflowBundle.getProfiles().getByName("tavernaServer"),
            URI.create(TAVERNASERVER_RDF));

    serializer.workflowBundleDoc(outStream, URI.create("workflowBundle.rdf"));
    //System.out.write(outStream.toByteArray());
    Document doc = parseXml(outStream);
    Element root = doc.getRootElement();

    checkRoot(root);//from   ww  w.ja  v a 2 s  .  com
    checkWorkflowBundleDocument(root);

}

From source file:org.apache.xmlgraphics.image.writer.internal.TIFFImageWriterTest.java

public void testJPEGWritingWithoutParams() throws Exception {
    //This used to generate a NPE when no ImageWriterParams were not set
    OutputStream out = new NullOutputStream();
    org.apache.xmlgraphics.image.writer.ImageWriter imageWriter = new TIFFImageWriter();
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_GRAY);
    imageWriter.writeImage(image, out);// w  w w  .j  a v a2  s.  c  om
}

From source file:org.apache.xmlgraphics.image.writer.internal.TIFFImageWriterTest.java

public void testJPEGWritingWithoutJPEGParams() throws Exception {
    //This used to generate a NPE because the JPEG encoding params were not set
    OutputStream out = new NullOutputStream();
    org.apache.xmlgraphics.image.writer.ImageWriter imageWriter = new TIFFImageWriter();
    MultiImageWriter writer = null;/*w  ww.  j a  v a 2 s  . c om*/
    try {
        writer = imageWriter.createMultiImageWriter(out);
        // retrieve writer
        if (imageWriter != null) {
            ImageWriterParams iwp = new ImageWriterParams();
            iwp.setCompressionMethod("JPEG");

            for (int pageNumber = 0; pageNumber <= 2; pageNumber++) {
                BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_GRAY);
                writer.writeImage(image, iwp);
            }
        }
    } finally {
        writer.close();
    }
}

From source file:org.apromore.canoniser.aris.ArisCanoniserUnitTest.java

/** Exercise the {@link ArisCanoniser#canonise} method. */
@Ignore/*from   w  w  w.j  a v a  2  s .c o  m*/
@Test
public void testCanonise_GI() throws Exception {

    // Skip this test if the NDA'ed dataset location wasn't configured at runtime
    if (AML_DIRECTORY == null) {
        logger.info("Property nda.data.dir not set; skipping test of NDA'ed dataset.");
        return;
    }

    ArisCanoniser canoniser = new ArisCanoniser();
    List<AnnotationsType> anfList = new ArrayList<AnnotationsType>();
    List<CanonicalProcessType> cpfList = new ArrayList<CanonicalProcessType>();
    PluginRequest request = new PluginRequestImpl();
    canoniser.canonise(new FileInputStream(new File(AML_DIRECTORY, "GI - Building Blocks - ClaimCenter.xml")),
            anfList, cpfList, request);

    assertEquals(1, cpfList.size());
    CPFSchema.marshalCanonicalFormat(new FileOutputStream(new File(OUTPUT_DIRECTORY, "GI.cpf")), cpfList.get(0),
            false);
    CPFSchema.marshalCanonicalFormat(new NullOutputStream(), cpfList.get(0), true);
}

From source file:org.apromore.canoniser.aris.ArisCanoniserUnitTest.java

/** Exercise the {@link ArisCanoniser#canonise} method. */
@Ignore//w w  w .  j a  va  2s.c  om
@Test
public void testCanoniseFragment_gp2() throws Exception {

    // Skip this test if the NDA'ed dataset location wasn't configured at runtime
    if (AML_DIRECTORY == null) {
        logger.info("Property nda.data.dir not set; skipping test of NDA'ed dataset.");
        return;
    }

    ArisCanoniser canoniser = new ArisCanoniser();
    List<AnnotationsType> anfList = new ArrayList<AnnotationsType>();
    List<CanonicalProcessType> cpfList = new ArrayList<CanonicalProcessType>();
    PluginRequest request = new PluginRequestImpl();
    canoniser.canonise(new FileInputStream(new File(AML_DIRECTORY, "Model.gp2---10----u--.xml")), anfList,
            cpfList, request);

    assertEquals(1, cpfList.size());
    CPFSchema.marshalCanonicalFormat(new FileOutputStream(new File(OUTPUT_DIRECTORY, "gp2.cpf")),
            cpfList.get(0), false);
    ANFSchema.marshalAnnotationFormat(new FileOutputStream(new File(OUTPUT_DIRECTORY, "gp2.anf")),
            anfList.get(0), false);
    CPFSchema.marshalCanonicalFormat(new NullOutputStream(), cpfList.get(0), true);
    ANFSchema.marshalAnnotationFormat(new NullOutputStream(), anfList.get(0), true);
}

From source file:org.apromore.canoniser.bpmn.bpmn.BpmnDefinitionsUnitTest.java

/**
 * Common code for decanonisation tests.
 *
 * This method validates the CPF and ANF source files, decanonises them to produce a BPMN file, writes it out and validates it.
 *
 * @param filename  the filename for the input CPF and ANF files and for the output BPMN file,
 *     minus the respective <code>.cpf</code>, <code>.anf</code> and <code>.bpmn.xml</code> file extensions
 * @return the decanonised BPMN model/*from   w  w w. j  av  a 2  s . c  om*/
 */
private BpmnDefinitions testDecanonise(final String filename)
        throws CanoniserException, FileNotFoundException, JAXBException, SAXException, TransformerException {

    // Read the CPF source file
    CpfCanonicalProcessType cpf = CpfCanonicalProcessType
            .newInstance(new FileInputStream(new File(CANONICAL_MODELS_DIR, filename + ".cpf")), true);

    AnnotationsType anf = null;
    File anfFile = new File(CANONICAL_MODELS_DIR, filename + ".anf");
    if (anfFile.exists()) {
        // Read the ANF source file
        anf = AnfAnnotationsType
                .newInstance(new FileInputStream(new File(CANONICAL_MODELS_DIR, filename + ".anf")), true);
    }

    // Obtain the test instance
    BpmnDefinitions definitions = BpmnDefinitions.newInstance(cpf, anf);

    // Serialize the test instance for offline inspection
    definitions.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".cpf+anf.bpmn")), false);

    // Validate the test instance
    definitions.marshal(new NullOutputStream(), true);

    // Round-trip the test instance from BPMN back to the original CPF
    CpfCanonicalProcessType cpf2 = new CpfCanonicalProcessType(definitions);
    cpf2.setUri("dummy");
    cpf2.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".cpf+anf.bpmn.cpf")), false);
    cpf2.marshal(new NullOutputStream(), true);

    if (anfFile.exists()) {
        assertEquals(1, definitions.getBPMNDiagram().size());

        // Confirm constraints that can't be expressed in the CPF or ANF schemas
        assertEquals(cpf.getUri(), anf.getUri());

        AnfAnnotationsType anf2 = new AnfAnnotationsType(definitions, definitions.getBPMNDiagram().get(0));
        anf2.setUri("dummy");
        anf2.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".cpf+anf.bpmn.anf")), false);
        anf2.marshal(new NullOutputStream(), true);
    }

    return definitions;
}

From source file:org.apromore.canoniser.bpmn.bpmn.BpmnDefinitionsUnitTest.java

/**
 * Test {@link BpmnDefinitions#rewriteImplicitGatewaysExplicitly} against
 * <a href="{@docRoot}/../../../src/test/resources/BPMN_models/ImplicitJoin.bpmn">ImplicitJoin.bpmn</a>.
 *
 * <div><img src="{@docRoot}/../../../src/test/resources/BPMN_models/ImplicitJoin.svg"/></div>
 *//*from  w w  w.  ja v  a  2 s.c om*/
@Test
public final void testRewriteImplicitJoin() throws Exception {

    // Obtain the test instance
    BpmnDefinitions definitions = BpmnDefinitions
            .newInstance(new FileInputStream(new File(BPMN_MODELS_DIR, "ImplicitJoin.bpmn")), true);

    BpmnProcess process = (BpmnProcess) definitions.findElement(
            new QName(definitions.getTargetNamespace(), "sid-8f7af173-d650-4513-9abf-c5874363bff5"));
    assertEquals(7, process.getFlowElement().size());

    BpmnTask task = (BpmnTask) definitions.findElement(
            new QName(definitions.getTargetNamespace(), "sid-DD6A3F22-DDB8-4395-ACF3-FB933393BA7A"));
    assertEquals(2, task.getIncoming().size());

    // Exercise the rewriting method
    definitions.rewriteImplicitGatewaysExplicitly();

    // Validate the rewritten model, and write it out for inspection
    definitions.marshal(new FileOutputStream(new File(OUTPUT_DIR, "ImplicitJoin-rewritten.bpmn")), false);
    definitions.marshal(new NullOutputStream(), true);

    // Confirm that the rewriting took place
    assertEquals(9, process.getFlowElement().size());
    assertEquals(1, task.getIncoming().size());
}

From source file:org.apromore.canoniser.bpmn.bpmn.BpmnDefinitionsUnitTest.java

/**
 * Test {@link BpmnDefinitions#rewriteImplicitGatewaysExplicitly} against
 * <a href="{@docRoot}/../../../src/test/resources/BPMN_models/ImplicitSplit.bpmn">ImplicitSplit.bpmn</a>.
 *
 * <div><img src="{@docRoot}/../../../src/test/resources/BPMN_models/ImplicitSplit.svg"/></div>
 *///w w  w.  j  a  v  a  2 s . com
@Test
public final void testRewriteImplicitSplit() throws Exception {

    // Obtain the test instance
    BpmnDefinitions definitions = BpmnDefinitions
            .newInstance(new FileInputStream(new File(BPMN_MODELS_DIR, "ImplicitSplit.bpmn")), true);

    BpmnProcess process = (BpmnProcess) definitions.findElement(
            new QName(definitions.getTargetNamespace(), "sid-ebf93c68-5e38-44d0-a9be-10befb2f9160"));
    assertEquals(7, process.getFlowElement().size());

    BpmnTask task = (BpmnTask) definitions.findElement(
            new QName(definitions.getTargetNamespace(), "sid-B8464973-138F-4E6A-8880-AC5664D2E417"));
    assertEquals(2, task.getOutgoing().size());

    // Exercise the rewriting method
    definitions.rewriteImplicitGatewaysExplicitly();

    // Validate the rewritten model, and write it out for inspection
    definitions.marshal(new FileOutputStream(new File(OUTPUT_DIR, "ImplicitSplit-rewritten.bpmn")), false);
    definitions.marshal(new NullOutputStream(), true);

    // Confirm that the rewriting took place
    assertEquals(9, process.getFlowElement().size());
    assertEquals(1, task.getOutgoing().size());
}

From source file:org.apromore.canoniser.bpmn.cpf.CpfCanonicalProcessTypeUnitTest.java

/**
 * Common canonisation test code./* ww  w  .j  av  a  2  s  .  c om*/
 *
 * Parses <code>filename</code> and validates the resulting CPF.
 *
 * @param filename  the source filename within the {@link #TEST_MODELS} directory
 * @return a validated CPF that's been written out for inspection
 * @throws Exception if anything goes amiss setting up the test
 */
private CpfCanonicalProcessType testCanonise(String filename) throws Exception {

    // Obtain the test instance
    BpmnDefinitions definitions = BpmnDefinitions
            .newInstance(new FileInputStream(new File(BPMN_MODELS_DIR, filename)), true);

    // Validate and serialize the canonised documents to be inspected offline
    CpfCanonicalProcessType cpf = new CpfCanonicalProcessType(definitions);
    cpf.setUri("dummy");

    assertEquals(1, definitions.getBPMNDiagram().size());

    AnfAnnotationsType anf = new AnfAnnotationsType(definitions, definitions.getBPMNDiagram().get(0));
    anf.setUri("dummy");

    // Output the CPF
    cpf.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".cpf")), false);
    anf.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".anf")), false);

    // Validate the CPF
    cpf.marshal(new NullOutputStream(), true);
    anf.marshal(new NullOutputStream(), true);

    // Round-trip the CPF back into BPMN
    BpmnDefinitions definitions2 = BpmnDefinitions.newInstance(cpf, anf);
    definitions2.marshal(new FileOutputStream(new File(OUTPUT_DIR, filename + ".cpf+anf.bpmn")), false);
    definitions2.marshal(new NullOutputStream(), true);

    return cpf;
}

From source file:org.apromore.canoniser.epml.AbstractTest.java

/**
 * @param resource  the name of a resource within the <code>EPML/</code> directory of the classpath, minus its <code>.epml</code> extension
 */// www  . j  a  v  a 2s .com
public void testCanonise(final String resource) throws CanoniserException, PropertyException, JAXBException,
        SAXException, FileNotFoundException, IOException {
    EPML20Canoniser c = new EPML20Canoniser();
    ArrayList<AnnotationsType> anfList = new ArrayList<>();
    ArrayList<CanonicalProcessType> cpfList = new ArrayList<>();
    c.canonise(ClassLoader.getSystemResourceAsStream("EPML/" + resource + ".epml"), anfList, cpfList,
            new PluginRequestImpl());

    assertFalse(anfList.isEmpty());
    assertFalse(cpfList.isEmpty());

    try (FileOutputStream cpfOut = new FileOutputStream("target/" + resource + ".epml.cpf");
            FileOutputStream anfOut = new FileOutputStream("target/" + resource + ".epml.anf")) {

        // Unvalidated write to the target directory           
        CPFSchema.marshalCanonicalFormat(cpfOut, cpfList.get(0), false);
        ANFSchema.marshalAnnotationFormat(anfOut, anfList.get(0), false);

        // Validation pass
        CPFSchema.marshalCanonicalFormat(new NullOutputStream(), cpfList.get(0), true);
        ANFSchema.marshalAnnotationFormat(new NullOutputStream(), anfList.get(0), true);
    }
}