FileDocCategorySizeDatePackage
XMLFragmentTest.javaAPI DocApache Ant 1.703191Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util

XMLFragmentTest

public class XMLFragmentTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
Constructors Summary
public XMLFragmentTest(String name)

        super(name);
    
Methods Summary
public voidsetUp()

        configureProject("src/etc/testcases/types/xmlfragment.xml");
    
public voidtestNestedChildren()

        XMLFragment x =
            (XMLFragment) getProject().getReference("with-children");
        assertNotNull(x);
        Node n = x.getFragment();
        assertTrue("No attributes", !n.hasAttributes());
        NodeList nl = n.getChildNodes();
        assertEquals(3, nl.getLength());

        assertEquals(Node.ELEMENT_NODE, nl.item(0).getNodeType());
        Element child1 = (Element) nl.item(0);
        assertEquals("child1", child1.getTagName());
        assertTrue(!child1.hasAttributes());
        NodeList nl2 = child1.getChildNodes();
        assertEquals(1, nl2.getLength());
        assertEquals(Node.TEXT_NODE, nl2.item(0).getNodeType());
        assertEquals("foo", nl2.item(0).getNodeValue());

        assertEquals(Node.ELEMENT_NODE, nl.item(1).getNodeType());
        Element child2 = (Element) nl.item(1);
        assertEquals("child2", child2.getTagName());
        assertTrue(child2.hasAttributes());
        nl2 = child2.getChildNodes();
        assertEquals(0, nl2.getLength());
        assertEquals("bar", child2.getAttribute("foo"));

        assertEquals(Node.ELEMENT_NODE, nl.item(2).getNodeType());
        Element child3 = (Element) nl.item(2);
        assertEquals("child3", child3.getTagName());
        assertTrue(!child3.hasAttributes());
        nl2 = child3.getChildNodes();
        assertEquals(1, nl2.getLength());
        assertEquals(Node.ELEMENT_NODE, nl2.item(0).getNodeType());
        assertEquals("child4", ((Element) nl2.item(0)).getTagName());
    
public voidtestNestedText()

        XMLFragment x = (XMLFragment) getProject().getReference("nested-text");
        assertNotNull(x);
        Node n = x.getFragment();
        assertTrue("No attributes", !n.hasAttributes());
        NodeList nl = n.getChildNodes();
        assertEquals(1, nl.getLength());
        assertEquals(Node.TEXT_NODE, nl.item(0).getNodeType());
        assertEquals("foo", nl.item(0).getNodeValue());