Search in sources :

Example 6 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestGetTextAsStreamWithoutCaching method runTest.

@Override
protected void runTest() throws Throwable {
    Charset charset = Charset.forName("ascii");
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(654321, 64, 128, 20000000);
    Vector<InputStream> v = new Vector<InputStream>();
    v.add(new ByteArrayInputStream("<root><a>".getBytes(charset)));
    v.add(ds.getInputStream());
    v.add(new ByteArrayInputStream("</a><b/></root>".getBytes(charset)));
    OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, new SequenceInputStream(v.elements()), "ascii").getDocumentElement();
    OMElement child = (OMElement) root.getFirstOMChild();
    Reader in = child.getTextAsStream(false);
    IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), charset), "expected", in, "actual");
    in.close();
    // No try to access subsequent nodes
    child = (OMElement) child.getNextOMSibling();
    assertThat(child.getLocalName()).isEqualTo("b");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) SequenceInputStream(java.io.SequenceInputStream) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OMElement(org.apache.axiom.om.OMElement) Vector(java.util.Vector) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 7 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestGetTextBinary method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(99999, 1000);
    OMElement element = factory.createOMElement("elem", null);
    element.addChild(factory.createOMText(new DataHandler(ds), false));
    if (compact) {
        // Only the builder can create a compact element containing a DataHandler
        element = OMXMLBuilderFactory.createStAXOMBuilder(factory, element.getXMLStreamReader()).getDocumentElement();
        element.build();
    }
    IOTestUtils.compareStreams(ds.getInputStream(), new ByteArrayInputStream(Base64.decodeBase64(element.getText())));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) DataSource(javax.activation.DataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource)

Example 8 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestGetTextAsStreamWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
    QName qname = new QName("a");
    Charset cs = Charset.forName("ascii");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
    Reader in = element.getTextAsStream(true);
    assertFalse(in instanceof StringReader);
    IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) StringReader(java.io.StringReader) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 9 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestCloneBinary method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new RandomDataSource(600613L, 4096));
    StringReader rootPart = new StringReader("<root><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:123456@example.org'/></root>");
    DummyAttachmentAccessor attachmentAccessor = new DummyAttachmentAccessor("123456@example.org", dh);
    OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StreamSource(rootPart), attachmentAccessor).getDocumentElement();
    OMText text = (OMText) root.getFirstOMChild();
    OMCloneOptions options = new OMCloneOptions();
    options.setFetchDataHandlers(fetch);
    OMText clone = (OMText) text.clone(options);
    assertTrue(clone.isBinary());
    assertEquals(fetch, attachmentAccessor.isLoaded());
    assertSame(dh, clone.getDataHandler());
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler)

Example 10 with RandomDataSource

use of org.apache.axiom.testutils.activation.RandomDataSource in project webservices-axiom by apache.

the class TestWriteTextToWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
    QName qname = new QName("a");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
    Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
    Writer out = new CharacterStreamComparator(in);
    // cache doesn't matter here
    element.writeTextTo(out, true);
    out.close();
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) CharacterStreamComparator(org.apache.axiom.testutils.io.CharacterStreamComparator) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) Writer(java.io.Writer) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Aggregations

RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)14 DataHandler (javax.activation.DataHandler)10 DataSource (javax.activation.DataSource)10 OMFactory (org.apache.axiom.om.OMFactory)9 OMElement (org.apache.axiom.om.OMElement)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 Reader (java.io.Reader)3 StringReader (java.io.StringReader)3 QName (javax.xml.namespace.QName)3 MemoryBlob (org.apache.axiom.blob.MemoryBlob)3 OMText (org.apache.axiom.om.OMText)3 Charset (java.nio.charset.Charset)2 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)2 Text (org.w3c.dom.Text)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1