Examples of OMSourcedElement


Examples of org.apache.axiom.om.OMSourcedElement

        return TextFileDataSource.createOMSourcedElement(tmp, charset);
    }
   
    public void testWithXMLChars() throws Exception {
        String testString = "Test string with ampersand (&)";
        OMSourcedElement element = createSourcedElement(testString, UTF8);
        assertEquals(testString, element.getText());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        OMSourcedElement element = createSourcedElement(testString, UTF8);
        assertEquals(testString, element.getText());
    }
   
    public void testSerializeToBytes() throws Exception {
        OMSourcedElement element = createSourcedElement("test", UTF8);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        element.serialize(baos);
        byte[] actual = baos.toByteArray();
        baos.reset();
        // We validate the result by creating an equivalent OMElement
        // and calling serialize on it. The two results must be identical.
        element.cloneOMElement().serialize(baos);
        byte[] expected = baos.toByteArray();
        assertTrue(Arrays.equals(expected, actual));
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        byte[] expected = baos.toByteArray();
        assertTrue(Arrays.equals(expected, actual));
    }
   
    public void testSerializeToChars() throws Exception {
        OMSourcedElement element = createSourcedElement("test", UTF8);
        StringWriter sw = new StringWriter();
        element.serialize(sw);
        String actual = sw.toString();
        sw.getBuffer().setLength(0);
        // Compare with the behavior of an equivalent OMElement
        element.cloneOMElement().serialize(sw);
        String expected = sw.toString();
        assertEquals(expected, actual);
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        // Create a payload
        String text = "<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>";
        String encoding = "UTF-8";
        ByteArrayDataSource bads = new ByteArrayDataSource(text.getBytes(encoding), encoding);
        OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
        OMSourcedElement omse =body.getOMFactory().createOMElement(bads, "payload", ns);
        body.addChild(omse);
        copyAndCheck(sourceEnv);
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("axis2:input"));
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("This is some text"));
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("Some Other Text"));
       
        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString.contains("Hello World"));
       
        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);

        // Now use StreamingOMSerializer to write the input stream to the output stream
        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
        SOAPBody body = env.getBody();
        OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
       
        StreamingOMSerializer serializer = new StreamingOMSerializer();
        serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
                             writer);
        writer.flush();

        String outputString = new String(byteArrayOutputStream.toByteArray());
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                outputString != null && !"".equals(outputString) && outputString.length() > 1);
        int indexHelloWorld = outputString.indexOf("Hello World");
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                indexHelloWorld > 0);
        int indexHelloWorld2 = outputString.indexOf("Hello World", indexHelloWorld+1);
        assertTrue("Expected output was incorrect.  Received:" + outputString,
                indexHelloWorld2 < 0);

        assertTrue("Expectation is that an OMSourcedElement was created for the payload",
                omse != null);
        assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
                !omse.isExpanded());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("", "");
        OMSourcedElement element = factory.createOMElement(new CharArrayDataSource(
                "<element>content</element>".toCharArray()), "element", ns);
        // This actually returns the "declared" namespace because the sourced element is not
        // expanded yet. Nevertheless the value should have been normalized to null.
        assertNull(element.getNamespace());
        // Now expand the element and check getNamespace() again
        element.getFirstOMChild();
        assertNull(element.getNamespace());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMSourcedElement omse = factory.createOMElement(new ByteArrayDataSource("<sourcedelement/>".getBytes("utf-8"), "utf-8"));
        OMElement parent = factory.createOMElement(new QName("parent"));
        parent.addChild(omse);
        // Cause expansion of the sourced element without building it completely
        omse.getLocalName();
        assertTrue(omse.isExpanded());
        assertFalse(omse.isComplete());
        // Call getNextOMSibling(); this should not build the element
        omse.getNextOMSibling();
        assertFalse(omse.isComplete());
    }
View Full Code Here

Examples of org.apache.axiom.om.OMSourcedElement

        ByteArrayDataSource bads1 = new ByteArrayDataSource(payload1.getBytes(encoding), encoding);
       
        // Set an empty MustUnderstand property on the data source
        bads1.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
       
        OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, bads1);
        soapHeader.addChild(omse);
        OMNode firstChild = soapHeader.getFirstOMChild();
        assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
        SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
        assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.