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

ImportNode

public final class ImportNode extends DOMTestCase
The "importNode(importedNode,deep)" method for a Document should import the given importedNode into that Document. The importedNode is of type Attr. The ownerElement is set to null. Specified flag is set to true. Children is imported. Create a new attribute whose name is "elem:attr1" in a different document. Create a child Text node with value "importedText" for the attribute node above. Invoke method importNode(importedNode,deep) on this document with importedNode being the newly created attribute. Method should return a node whose name matches "elem:attr1" and a child node whose value equals "importedText". The returned node should belong to this document whose systemId is "staff.dtd"
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
public void_testImportNode1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        Document doc;
        Document aNewDoc;
        Attr newAttr;
        Text importedChild;
        Node aNode;
        Document ownerDocument;
        Element attrOwnerElement;
        DocumentType docType;
        String system;
        boolean specified;
        NodeList childList;
        String nodeName;
        Node child;
        String childValue;
        List<String> expectedResult = new ArrayList<String>();
        expectedResult.add("elem:attr1");
        expectedResult.add("importedText");

        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        newAttr = aNewDoc.createAttribute("elem:attr1");
        importedChild = aNewDoc.createTextNode("importedText");
        aNode = newAttr.appendChild(importedChild);
        aNode = doc.importNode(newAttr, false);
        ownerDocument = aNode.getOwnerDocument();
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertNotNull("aNode", aNode);
        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        attrOwnerElement = ((Attr) /* Node */aNode).getOwnerElement();
        assertNull("ownerElement", attrOwnerElement);
        specified = ((Attr) /* Node */aNode).getSpecified();
        assertTrue("specified", specified);
        childList = aNode.getChildNodes();
        assertEquals("childList", 1, childList.getLength());
        nodeName = aNode.getNodeName();
        assertEquals("nodeName", "elem:attr1", nodeName);
        child = aNode.getFirstChild();
        childValue = child.getNodeValue();
        assertEquals("childValue", "importedText", childValue);
    
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 voidtestImportNode10()

        Document doc;
        Document aNewDoc;
        EntityReference entRef;
        Node aNode;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String name;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        entRef = aNewDoc.createEntityReference("entRef1");
        assertNotNull("createdEntRefNotNull", entRef);
        entRef.setNodeValue("entRef1Value");
        aNode = doc.importNode(entRef, false);
        ownerDocument = aNode.getOwnerDocument();
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        name = aNode.getNodeName();
        assertEquals("nodeName", "entRef1", name);
    
public voidtestImportNode14()

        Document doc;
        Document aNewDoc;
        ProcessingInstruction pi;
        ProcessingInstruction aNode;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String target;
        String data;
        
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        pi = aNewDoc.createProcessingInstruction("target1", "data1");
        aNode = (ProcessingInstruction) doc.importNode(pi, false);
        ownerDocument = aNode.getOwnerDocument();
        assertNotNull("ownerDocumentNotNull", ownerDocument);
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        target = aNode.getTarget();
        assertEquals("piTarget", "target1", target);
        data = aNode.getData();
        assertEquals("piData", "data1", data);
    
public voidtestImportNode15()

        Document doc;
        Document aNewDoc;
        Text text;
        Node aNode;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String value;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        text = aNewDoc.createTextNode("this is text data");
        aNode = doc.importNode(text, false);
        ownerDocument = aNode.getOwnerDocument();
        assertNotNull("ownerDocumentNotNull", ownerDocument);
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        value = aNode.getNodeValue();
        assertEquals("nodeValue", "this is text data", value);
    
public voidtestImportNode16()

        Document doc;
        Document anotherDoc;
        DocumentType docType;

        doc = (Document) load("staffNS", builder);
        anotherDoc = (Document) load("staffNS", builder);
        docType = anotherDoc.getDoctype();

        {
            boolean success = false;
            try {
                doc.importNode(docType, false);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_SUPPORTED_ERR);
            }
            assertTrue("throw_NOT_SUPPORTED_ERR", success);
        }
    
public voidtestImportNode17()

        Document doc;
        Document anotherDoc;

        doc = (Document) load("staffNS", builder);
        anotherDoc = (Document) load("staffNS", builder);

        {
            boolean success = false;
            try {
                doc.importNode(anotherDoc, false);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NOT_SUPPORTED_ERR);
            }
            assertTrue("throw_NOT_SUPPORTED_ERR", success);
        }
    
public voidtestImportNode2()

        Document doc;
        Document aNewDoc;
        CDATASection cDataSec;
        Node aNode;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String value;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        cDataSec = aNewDoc.createCDATASection("this is CDATASection data");
        aNode = doc.importNode(cDataSec, false);
        ownerDocument = aNode.getOwnerDocument();
        assertNotNull("ownerDocumentNotNull", ownerDocument);
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("dtdSystemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        value = aNode.getNodeValue();
        assertEquals("nodeValue", "this is CDATASection data", value);
    
public voidtestImportNode3()

        Document doc;
        Document aNewDoc;
        Comment comment;
        Node aNode;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String value;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        comment = aNewDoc.createComment("this is a comment");
        aNode = doc.importNode(comment, false);
        ownerDocument = aNode.getOwnerDocument();
        assertNotNull("ownerDocumentNotNull", ownerDocument);
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        value = aNode.getNodeValue();
        assertEquals("nodeValue", "this is a comment", value);
    
public voidtestImportNode4()

        Document doc;
        Document aNewDoc;
        DocumentFragment docFrag;
        Comment comment;
        Node aNode;
        NodeList children;
        Node child;
        String childValue;
        doc = (Document) load("staff", builder);
        aNewDoc = (Document) load("staff", builder);
        docFrag = aNewDoc.createDocumentFragment();
        comment = aNewDoc.createComment("descendant1");
        aNode = docFrag.appendChild(comment);
        aNode = doc.importNode(docFrag, true);
        children = aNode.getChildNodes();
        assertEquals("throw_Size", 1, children.getLength());
        child = aNode.getFirstChild();
        childValue = child.getNodeValue();
        assertEquals("descendant1", "descendant1", childValue);
    
public voidtestImportNode5()

        Document doc;
        Document aNewDoc;
        Element element;
        Node aNode;
        boolean hasChild;
        Document ownerDocument;
        DocumentType docType;
        String system;
        String name;
        NodeList addresses;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        addresses = aNewDoc.getElementsByTagName("emp:address");
        element = (Element) addresses.item(0);
        assertNotNull("empAddressNotNull", element);
        aNode = doc.importNode(element, false);
        hasChild = aNode.hasChildNodes();
        assertFalse("hasChild", hasChild);
        ownerDocument = aNode.getOwnerDocument();
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("dtdSystemId", null, null, null, "staffNS.dtd", null,
                null, null, null, system);
        name = aNode.getNodeName();
        assertEquals("nodeName", "emp:address", name);
    
public voidtestImportNode6()

        Document doc;
        Document aNewDoc;
        Element element;
        Node aNode;
        boolean hasChild;
        String name;
        Node child;
        String value;
        NodeList addresses;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        addresses = aNewDoc.getElementsByTagName("emp:address");
        element = (Element) addresses.item(0);
        assertNotNull("empAddressNotNull", element);
        aNode = doc.importNode(element, true);
        hasChild = aNode.hasChildNodes();
        assertTrue("throw_True", hasChild);
        name = aNode.getNodeName();
        assertEquals("nodeName", "emp:address", name);
        child = aNode.getFirstChild();
        value = child.getNodeValue();
        assertEquals("nodeValue", "27 South Road. Dallas, texas 98556", value);
    
public voidtestImportNode8()

        Document doc;
        Document aNewDoc;
        DocumentFragment docFrag;
        Node aNode;
        boolean hasChild;
        Document ownerDocument;
        DocumentType docType;
        String system;
        doc = (Document) load("staffNS", builder);
        aNewDoc = (Document) load("staffNS", builder);
        docFrag = aNewDoc.createDocumentFragment();
        aNode = doc.importNode(docFrag, false);
        hasChild = aNode.hasChildNodes();
        assertFalse("hasChild", hasChild);
        ownerDocument = aNode.getOwnerDocument();
        docType = ownerDocument.getDoctype();
        system = docType.getSystemId();
        assertURIEquals("system", null, null, null, "staffNS.dtd", null, null,
                null, null, system);