FileDocCategorySizeDatePackage
GetElementsByTagNameNS.javaAPI DocAndroid 1.5 API14924Wed May 06 22:41:06 BST 2009tests.org.w3c.dom

GetElementsByTagNameNS

public final class GetElementsByTagNameNS extends DOMTestCase
The "getElementsByTagNameNS(namespaceURI,localName)" method for a Document should return a new NodeList of all Elements that have a namespace when local name is specified as ' '. Invoke method getElementsByTagNameNS(namespaceURI,localName) on this document with namespaceURI and localName as " ". Method should return a new NodeList of 37 elements.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getElBTNNS

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration2());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    
protected voidtearDown()

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestGetElementsByTagNameNS1()

        String namespaceURI = "*";
        String localName = "*";
        Document doc;
        NodeList newList;
        doc = (Document) load("staffNS", builder);
        newList = doc.getElementsByTagNameNS(namespaceURI, localName);
        // BEGIN android-changed: Was 37, but that assumed validation.
        assertEquals("throw_Size", 36, newList.getLength());
        // END android-changed
    
public voidtestGetElementsByTagNameNS10()

        Document doc;
        Element docElem;
        NodeList elementList;
        Node child;
        String childName;
        List<String> result = new ArrayList<String>();

        List<String> expectedResult = new ArrayList<String>();
        expectedResult.add("employee");
        expectedResult.add("employeeId");
        expectedResult.add("name");
        expectedResult.add("position");
        expectedResult.add("salary");
        expectedResult.add("gender");
        expectedResult.add("address");
        expectedResult.add("emp:employee");
        expectedResult.add("emp:employeeId");
        expectedResult.add("emp:position");
        expectedResult.add("emp:salary");
        expectedResult.add("emp:gender");
        expectedResult.add("emp:address");
        expectedResult.add("address");

        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        elementList = docElem
                .getElementsByTagNameNS("http://www.nist.gov", "*");
        for (int indexN1007E = 0; indexN1007E < elementList.getLength(); indexN1007E++) {
            child = (Node) elementList.item(indexN1007E);
            childName = child.getNodeName();
            result.add(childName);
        }
        assertEquals("nodeNames", expectedResult, result);
    
public voidtestGetElementsByTagNameNS11()

        Document doc;
        Element docElem;
        NodeList elementList;
        Node child;
        String childName;
        List<String> result = new ArrayList<String>();

        List<String> expectedResult = new ArrayList<String>();
        expectedResult.add("address");
        expectedResult.add("address");
        expectedResult.add("address");
        expectedResult.add("emp:address");
        expectedResult.add("address");

        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        elementList = docElem.getElementsByTagNameNS("*", "address");
        for (int indexN1005E = 0; indexN1005E < elementList.getLength(); indexN1005E++) {
            child = (Node) elementList.item(indexN1005E);
            childName = child.getNodeName();
            result.add(childName);
        }
        assertEquals("nodeNames", expectedResult, result);
    
public voidtestGetElementsByTagNameNS12()

        Document doc;
        Element docElem;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        elementList = docElem.getElementsByTagNameNS("http://www.nist.gov",
                "nomatch");
        assertEquals("size", 0, elementList.getLength());
    
public voidtestGetElementsByTagNameNS13()

        Document doc;
        Element docElem;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        elementList = docElem.getElementsByTagNameNS("http://www.nomatch.com",
                "address");
        assertEquals("matchSize", 0, elementList.getLength());
    
public voidtestGetElementsByTagNameNS14()

        Document doc;
        Element docElem;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        elementList = docElem.getElementsByTagNameNS("http://www.nist.gov",
                "address");
        assertEquals("addresses", 3, elementList.getLength());
    
public voidtestGetElementsByTagNameNS2()

        Document doc;
        NodeList newList;
        Element newElement;
        String prefix;
        String lname;
        doc = (Document) load("staffNS", builder);
        newList = doc.getElementsByTagNameNS("*", "employee");
        assertEquals("employeeCount", 5, newList.getLength());
        newElement = (Element) newList.item(3);
        prefix = newElement.getPrefix();
        assertEquals("prefix", "emp", prefix);
        lname = newElement.getLocalName();
        assertEquals("lname", "employee", lname);
    
public voidtestGetElementsByTagNameNS3()

        Document doc;
        NodeList elementList;
        Node child;
        String childName;
        List<String> result = new ArrayList<String>();

        List<String> expectedResult = new ArrayList<String>();
        expectedResult.add("employee");
        expectedResult.add("employeeId");
        expectedResult.add("name");
        expectedResult.add("position");
        expectedResult.add("salary");
        expectedResult.add("gender");
        expectedResult.add("address");
        expectedResult.add("emp:employee");
        expectedResult.add("emp:employeeId");
        expectedResult.add("emp:position");
        expectedResult.add("emp:salary");
        expectedResult.add("emp:gender");
        expectedResult.add("emp:address");
        expectedResult.add("address");

        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov", "*");
        for (int indexN10076 = 0; indexN10076 < elementList.getLength(); indexN10076++) {
            child = (Node) elementList.item(indexN10076);
            childName = child.getNodeName();
            result.add(childName);
        }
        assertEquals("nodeNames", expectedResult, result);
    
public voidtestGetElementsByTagNameNS4()

        Document doc;
        NodeList elementList;
        Node child;
        String childName;
        List<String> result = new ArrayList<String>();

        List<String> expectedResult = new ArrayList<String>();
        expectedResult.add("address");
        expectedResult.add("address");
        expectedResult.add("address");
        expectedResult.add("emp:address");
        expectedResult.add("address");

        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("*", "address");
        for (int indexN10059 = 0; indexN10059 < elementList.getLength(); indexN10059++) {
            child = (Node) elementList.item(indexN10059);
            childName = child.getNodeName();
            result.add(childName);
        }
        assertEquals("nodeNames", expectedResult, result);
    
public voidtestGetElementsByTagNameNS5()

        String namespaceURI = "http://www.nist.gov";
        String localName = "nomatch";
        Document doc;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS(namespaceURI, localName);
        assertEquals("throw_Size", 0, elementList.getLength());
    
public voidtestGetElementsByTagNameNS6()

        Document doc;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nomatch.com",
                "address");
        assertEquals("matchSize", 0, elementList.getLength());
    
public voidtestGetElementsByTagNameNS7()

        Document doc;
        NodeList elementList;
        doc = (Document) load("staffNS", builder);
        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
                "address");
        assertEquals("addresses", 3, elementList.getLength());
    
public voidtestGetElementsByTagNameNS8()

        Document doc;
        Element docElem;
        NodeList newList;
        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        newList = docElem.getElementsByTagNameNS("*", "*");
        assertEquals("listSize", 36, newList.getLength());
    
public voidtestGetElementsByTagNameNS9()

        Document doc;
        NodeList newList;
        Element newElement;
        String prefix;
        String lname;
        Element docElem;
        doc = (Document) load("staffNS", builder);
        docElem = doc.getDocumentElement();
        newList = docElem.getElementsByTagNameNS("*", "employee");
        assertEquals("employeeCount", 5, newList.getLength());
        newElement = (Element) newList.item(3);
        prefix = newElement.getPrefix();
        assertEquals("prefix", "emp", prefix);
        lname = newElement.getLocalName();
        assertEquals("lname", "employee", lname);