Search in sources :

Example 6 with OMComment

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

the class TestSetOMDocumentElementNew method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMComment comment = factory.createOMComment(document, "some comment");
    OMElement documentElement = factory.createOMElement("root", null);
    document.setOMDocumentElement(documentElement);
    assertSame(documentElement, document.getOMDocumentElement());
    assertSame(document, documentElement.getParent());
    Iterator<OMNode> it = document.getChildren();
    assertTrue(it.hasNext());
    assertSame(comment, it.next());
    assertTrue(it.hasNext());
    assertSame(documentElement, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 7 with OMComment

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

the class TestSetOMDocumentElementReplace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--comment1--><root/><!--comment2-->")).getDocument();
    OMElement documentElement = factory.createOMElement("new", null);
    document.setOMDocumentElement(documentElement);
    assertSame(documentElement, document.getOMDocumentElement());
    Iterator<OMNode> it = document.getChildren();
    assertTrue(it.hasNext());
    OMNode child = it.next();
    assertTrue(child instanceof OMComment);
    assertEquals("comment1", ((OMComment) child).getValue());
    assertTrue(it.hasNext());
    assertSame(documentElement, it.next());
    assertTrue(it.hasNext());
    child = it.next();
    assertTrue(child instanceof OMComment);
    assertEquals("comment2", ((OMComment) child).getValue());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 8 with OMComment

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

the class TestDetach method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer root;
    if (document) {
        root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--a--><b/><!--c-->")).getDocument();
    } else {
        root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><!--a--><b/><!--c--></root>")).getDocumentElement();
    }
    if (build) {
        root.build();
    } else {
        assertFalse(root.isComplete());
    }
    OMComment a = (OMComment) root.getFirstOMChild();
    assertEquals("a", a.getValue());
    OMElement b = (OMElement) a.getNextOMSibling();
    assertEquals("b", b.getLocalName());
    OMNode returnValue = b.detach();
    // Detach is expected to do a "return this"
    assertSame(b, returnValue);
    assertNull(b.getParent());
    assertNull(b.getPreviousOMSibling());
    assertNull(b.getNextOMSibling());
    OMComment c = (OMComment) a.getNextOMSibling();
    assertEquals("c", c.getValue());
    assertSame(c, a.getNextOMSibling());
    assertSame(a, c.getPreviousOMSibling());
    root.close(false);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 9 with OMComment

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

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMComment comment = metaFactory.getOMFactory().createOMComment(null, "test");
    XMLStreamWriter writer = mock(XMLStreamWriter.class);
    comment.serialize(writer);
    verify(writer).writeComment(comment.getValue());
    verify(writer, atMost(1)).flush();
    verifyNoMoreInteractions(writer);
}
Also used : OMComment(org.apache.axiom.om.OMComment) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 10 with OMComment

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

the class TestGetDescendants method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer root = containerFactory.create(factory);
    OMElement child1 = factory.createOMElement("child", null, root);
    OMProcessingInstruction child2 = factory.createOMProcessingInstruction(root, "test", "data");
    OMText grandchild1 = factory.createOMText(child1, "text");
    OMComment grandchild2 = factory.createOMComment(child1, "text");
    Iterator<? extends OMSerializable> it = root.getDescendants(includeSelf);
    if (includeSelf) {
        assertThat(it.hasNext()).isTrue();
        assertThat(it.next()).isEqualTo(root);
    }
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild2);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child2);
    assertThat(it.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer)

Aggregations

OMComment (org.apache.axiom.om.OMComment)13 OMElement (org.apache.axiom.om.OMElement)8 OMFactory (org.apache.axiom.om.OMFactory)6 OMNode (org.apache.axiom.om.OMNode)6 StringReader (java.io.StringReader)4 OMText (org.apache.axiom.om.OMText)4 OMContainer (org.apache.axiom.om.OMContainer)2 OMDocument (org.apache.axiom.om.OMDocument)2 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)2 Iterator (java.util.Iterator)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 OMDocType (org.apache.axiom.om.OMDocType)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 AxiomComment (org.apache.axiom.om.impl.intf.AxiomComment)1 AxiomDocType (org.apache.axiom.om.impl.intf.AxiomDocType)1 AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)1 AxiomEntityReference (org.apache.axiom.om.impl.intf.AxiomEntityReference)1 AxiomNamespaceDeclaration (org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration)1 AxiomProcessingInstruction (org.apache.axiom.om.impl.intf.AxiomProcessingInstruction)1