Package org.apache.axiom.testutils.activation

Examples of org.apache.axiom.testutils.activation.TestDataSource


        test(dh, new StAXOMBuilder(blob.getInputStream()), false, false, true);
    }
   
    @Test
    public void testWithDataHandlerReaderExtension() throws Exception {
        DataHandler dh = new DataHandler(new TestDataSource('X', Integer.MAX_VALUE));
        OMElement document = createTestDocument(dh);
        test(dh, new StAXOMBuilder(document.getXMLStreamReader()), true, true, false);
    }
View Full Code Here


import org.apache.axiom.testutils.activation.TestDataSource;

public class XOPRoundtripTest extends TestCase {
    public void test() {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        DataHandler dh = new DataHandler(new TestDataSource('x', Runtime.getRuntime().maxMemory()));
        OMElement element1 = factory.createOMElement(new QName("test"));
        element1.addChild(factory.createOMText(dh, true));
        XMLStreamReader originalReader = element1.getXMLStreamReader();
        XOPEncodingStreamReader encodedReader = new XOPEncodingStreamReader(originalReader,
                ContentIDGenerator.DEFAULT, OptimizationPolicy.DEFAULT);
View Full Code Here

        OMFactory factory = metaFactory.getOMFactory();
        OMElement elem = factory.createOMElement("test", null);
        // Create a data source that would eat up all memory when loaded. If the test
        // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
        // supports streaming.
        DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
        OMText text = factory.createOMText(new DataHandler(ds), false);
        elem.addChild(text);
        elem.serialize(new NullOutputStream());
    }
View Full Code Here

        addTestProperty("buildSOAPPart", String.valueOf(buildSOAPPart));
        this.buildSOAPPart = buildSOAPPart;
    }

    protected void runTest() throws Throwable {
        DataSource ds1 = new TestDataSource('A', Runtime.getRuntime().maxMemory());
        DataSource ds2 = new TestDataSource('B', Runtime.getRuntime().maxMemory());
       
        // Programmatically create the original message
        SOAPFactory factory = metaFactory.getSOAP12Factory();
        final SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope();
        SOAPBody orgBody = factory.createSOAPBody(orgEnvelope);
        OMElement orgBodyElement = factory.createOMElement("test", factory.createOMNamespace("urn:test", "p"), orgBody);
        OMElement orgData1 = factory.createOMElement("data", null, orgBodyElement);
        orgData1.addChild(factory.createOMText(new DataHandler(ds1), true));
        OMElement orgData2 = factory.createOMElement("data", null, orgBodyElement);
        orgData2.addChild(factory.createOMText(new DataHandler(ds2), true));
       
        final OMOutputFormat format = new OMOutputFormat();
        format.setDoOptimize(true);
        format.setSOAP11(false);
        final String contentType = format.getContentType();
       
        final PipedOutputStream pipe1Out = new PipedOutputStream();
        final PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
       
        // Create the producer thread (simulating the client sending the MTOM message)
        Thread producerThread = new Thread(new Runnable() {
            public void run() {
                try {
                    try {
                        orgEnvelope.serialize(pipe1Out, format);
                    } finally {
                        pipe1Out.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        producerThread.start();
       
        final PipedOutputStream pipe2Out = new PipedOutputStream();
        PipedInputStream pipe2In = new PipedInputStream(pipe2Out);
       
        // Create the forwarder thread (simulating the mediation engine that forwards the message)
        Thread forwarderThread = new Thread(new Runnable() {
            public void run() {
                try {
                    try {
                        Attachments attachments = new Attachments(pipe1In, contentType);
                        SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, attachments).getSOAPEnvelope();
                        // The code path executed by serializeAndConsume is significantly different if
                        // the element is built. Therefore we need two different test executions.
                        if (buildSOAPPart) {
                            envelope.build();
                        }
                        // Usage of serializeAndConsume should enable streaming
                        envelope.serializeAndConsume(pipe2Out, format);
                    } finally {
                        pipe2Out.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        forwarderThread.start();
       
        try {
            Attachments attachments = new Attachments(pipe2In, contentType);
            SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, attachments).getSOAPEnvelope();
            OMElement bodyElement = envelope.getBody().getFirstElement();
            Iterator it = bodyElement.getChildElements();
            OMElement data1 = (OMElement)it.next();
            OMElement data2 = (OMElement)it.next();
           
            IOTestUtils.compareStreams(ds1.getInputStream(),
                    ((DataHandlerExt)((OMText)data1.getFirstOMChild()).getDataHandler()).readOnce());
            IOTestUtils.compareStreams(ds2.getInputStream(),
                    ((DataHandlerExt)((OMText)data2.getFirstOMChild()).getDataHandler()).readOnce());
        } finally {
            pipe2In.close();
        }
    }
View Full Code Here

        OMFactory factory = metaFactory.getOMFactory();
        OMElement elem = factory.createOMElement("test", null);
        // Create a data source that would eat up all memory when loaded. If the test
        // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
        // supports streaming.
        DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
        OMText text = factory.createOMText(new DataHandler(ds), false);
        elem.addChild(text);
        elem.serialize(new NullOutputStream());
    }
View Full Code Here

        test(dh, new StAXOMBuilder(blob.getInputStream()), false, false, true);
    }
   
    @Test
    public void testWithDataHandlerReaderExtension() throws Exception {
        DataHandler dh = new DataHandler(new TestDataSource('X', Integer.MAX_VALUE));
        OMElement document = createTestDocument(dh);
        test(dh, new StAXOMBuilder(document.getXMLStreamReader()), true, true, false);
    }
View Full Code Here

import org.apache.axiom.testutils.activation.TestDataSource;

public class XOPRoundtripTest extends TestCase {
    public void test() {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        DataHandler dh = new DataHandler(new TestDataSource('x', Runtime.getRuntime().maxMemory()));
        OMElement element1 = factory.createOMElement(new QName("test"));
        element1.addChild(factory.createOMText(dh, true));
        XMLStreamReader originalReader = element1.getXMLStreamReader();
        XOPEncodingStreamReader encodedReader = new XOPEncodingStreamReader(originalReader,
                ContentIDGenerator.DEFAULT, OptimizationPolicy.DEFAULT);
View Full Code Here

        OMFactory factory = omMetaFactory.getOMFactory();
        OMElement elem = factory.createOMElement("test", null);
        // Create a data source that would eat up all memory when loaded. If the test
        // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
        // supports streaming.
        DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
        OMText text = factory.createOMText(new DataHandler(ds), false);
        elem.addChild(text);
        elem.serialize(new NullOutputStream());
    }
View Full Code Here

TOP

Related Classes of org.apache.axiom.testutils.activation.TestDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.