Search in sources :

Example 1 with Entity

use of org.dom4j.Entity in project tmdm-studio-se by Talend.

the class XmlUtilTest method testTreeWalk.

/*
     * treeWalk(Element element, NodeProcess nodeProcess)
     */
@Test
public void testTreeWalk() {
    // $NON-NLS-1$
    String tag = "name";
    Element parent = DocumentHelper.createElement(tag);
    // $NON-NLS-1$ //$NON-NLS-2$
    Attribute attr1 = DocumentHelper.createAttribute(parent, "Attr", "Value");
    // $NON-NLS-1$
    CDATA cDATA1 = DocumentHelper.createCDATA("cdata");
    // $NON-NLS-1$
    Comment comment1 = DocumentHelper.createComment("comment");
    // $NON-NLS-1$ //$NON-NLS-2$
    Entity entity1 = DocumentHelper.createEntity("entity", "entityname");
    // $NON-NLS-1$
    Text text1 = DocumentHelper.createText("text");
    parent.add(attr1);
    parent.add(cDATA1);
    parent.add(comment1);
    parent.add(entity1);
    parent.add(text1);
    // $NON-NLS-1$
    Element childElement = DocumentHelper.createElement("child");
    parent.add(childElement);
    // $NON-NLS-1$ //$NON-NLS-2$
    Attribute attr2 = DocumentHelper.createAttribute(parent, "Attr", "Value");
    // $NON-NLS-1$
    CDATA cDATA2 = DocumentHelper.createCDATA("cdata");
    // $NON-NLS-1$
    Comment comment2 = DocumentHelper.createComment("comment");
    // $NON-NLS-1$ //$NON-NLS-2$
    Entity entity2 = DocumentHelper.createEntity("entity", "entityname");
    // $NON-NLS-1$
    Text text2 = DocumentHelper.createText("text");
    childElement.add(attr2);
    childElement.add(cDATA2);
    childElement.add(comment2);
    childElement.add(entity2);
    childElement.add(text2);
    NodeProcess mockNodeProcess = mock(NodeProcess.class);
    XmlUtil.treeWalk(parent, mockNodeProcess);
    verify(mockNodeProcess, times(0)).process(attr1);
    verify(mockNodeProcess).process(cDATA1);
    verify(mockNodeProcess).process(comment1);
    verify(mockNodeProcess).process(entity1);
    verify(mockNodeProcess).process(text1);
    verify(mockNodeProcess, times(0)).process(attr2);
    verify(mockNodeProcess).process(cDATA2);
    verify(mockNodeProcess).process(comment2);
    verify(mockNodeProcess).process(entity2);
    verify(mockNodeProcess).process(text2);
}
Also used : Comment(org.dom4j.Comment) Entity(org.dom4j.Entity) NodeProcess(com.amalto.workbench.utils.callback.NodeProcess) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Text(org.dom4j.Text) CDATA(org.dom4j.CDATA) Test(org.junit.Test)

Aggregations

NodeProcess (com.amalto.workbench.utils.callback.NodeProcess)1 Attribute (org.dom4j.Attribute)1 CDATA (org.dom4j.CDATA)1 Comment (org.dom4j.Comment)1 Element (org.dom4j.Element)1 Entity (org.dom4j.Entity)1 Text (org.dom4j.Text)1 Test (org.junit.Test)1