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());
}
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());
}
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);
}
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);
}
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();
}
Aggregations