Search in sources :

Example 16 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TestBuilderDetach method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample sample = MTOMSample.SAMPLE1;
    InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
    MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    long countBeforeDetach = in.getCount();
    builder.detach();
    assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
    assertThat(in.isClosed()).isFalse();
    int binaryCount = 0;
    for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
        OMNode node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
                binaryCount++;
            }
        }
    }
    assertThat(binaryCount).isGreaterThan(0);
    in.close();
}
Also used : OMNode(org.apache.axiom.om.OMNode) MultipartBody(org.apache.axiom.mime.MultipartBody) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMText(org.apache.axiom.om.OMText) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 17 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TestCreateStAXOMBuilderFromFragment method runTest.

@Override
protected void runTest() throws Throwable {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<a><b>text</b></a>"));
    // Position the reader on the event for <b>
    while (reader.getEventType() != XMLStreamReader.START_ELEMENT || !reader.getLocalName().equals("b")) {
        reader.next();
    }
    // Check that the builder only builds the part of the document corresponding to <b>text</b>
    OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
    assertEquals("b", element.getLocalName());
    OMNode child = element.getFirstOMChild();
    assertTrue(child instanceof OMText);
    assertNull(element.getNextOMSibling());
    // Check that the original reader is now positioned on the event just following </b>
    assertEquals(XMLStreamReader.END_ELEMENT, reader.getEventType());
    assertEquals("a", reader.getLocalName());
}
Also used : OMNode(org.apache.axiom.om.OMNode) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 18 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TestInsertSibling method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    OMText child = factory.createOMText(parent, "test");
    OMComment orgSibling = altMetaFactory.getOMFactory().createOMComment(null, "test");
    if (before) {
        child.insertSiblingBefore(orgSibling);
    } else {
        child.insertSiblingAfter(orgSibling);
    }
    OMComment sibling = (OMComment) (before ? child.getPreviousOMSibling() : child.getNextOMSibling());
    assertThat(sibling).isNotSameAs(orgSibling);
    assertThat(sibling.getValue()).isEqualTo("test");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 19 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TestCreateOMTextCDATASectionWithParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("test", null);
    OMText text = factory.createOMText(parent, "cdata section content", OMNode.CDATA_SECTION_NODE);
    assertTrue(text instanceof CDATASection);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) CDATASection(org.w3c.dom.CDATASection) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 20 with OMText

use of org.apache.axiom.om.OMText in project webservices-axiom by apache.

the class TestSetText method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = metaFactory.getOMFactory().createOMElement("test", null);
    String text = "The quick brown fox jumps over the lazy dog";
    element.setText(text);
    // Check that OMElement#getText() returns a matching value
    assertEquals("Text value mismatch", text, element.getText());
    // Check that OMElement#setText() has created the expected nodes
    OMNode child = element.getFirstOMChild();
    assertTrue(child instanceof OMText);
    assertSame(element, child.getParent());
    assertEquals(text, ((OMText) child).getText());
    assertNull(child.getNextOMSibling());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMText (org.apache.axiom.om.OMText)92 OMElement (org.apache.axiom.om.OMElement)62 OMFactory (org.apache.axiom.om.OMFactory)39 DataHandler (javax.activation.DataHandler)26 OMNode (org.apache.axiom.om.OMNode)21 OMNamespace (org.apache.axiom.om.OMNamespace)10 QName (javax.xml.namespace.QName)8 OMException (org.apache.axiom.om.OMException)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 InputStream (java.io.InputStream)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 Entry (org.apache.synapse.config.Entry)6 ArrayList (java.util.ArrayList)5 DataSource (javax.activation.DataSource)5 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4