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

CreateDocument

public final class CreateDocument extends DOMTestCase
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a DOMImplementation should raise NAMESPACE_ERR DOMException if parameter qualifiedName is malformed. Retrieve the DOMImplementation on the XMLNS Document. Invoke method createDocument(namespaceURI,qualifiedName,doctype) on the retrieved DOMImplementation with namespaceURI being the literal string "http://www.ecommerce.org/", qualifiedName as "prefix::local", and doctype as null. Method should raise NAMESPACE_ERR DOMException.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
see
http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])

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

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

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestCreateDocument1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        String namespaceURI = "http://www.ecommerce.org/";
        String malformedName = "prefix::local";
        Document doc;
        DocumentType docType = null;

        DOMImplementation domImpl;

        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();

        boolean success = false;
        try {
            domImpl.createDocument(namespaceURI, malformedName, docType);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("throw_NAMESPACE_ERR", success);

    
public voidtestCreateDocument2()

        String namespaceURI = null;

        String qualifiedName = "k:local";
        Document doc;
        DocumentType docType = null;

        DOMImplementation domImpl;

        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();

        boolean success = false;
        try {
            domImpl.createDocument(namespaceURI, qualifiedName, docType);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("throw_NAMESPACE_ERR", success);

    
public voidtestCreateDocument5()

        String namespaceURI = "http://www.ecommerce.org/schema";
        String qualifiedName;
        Document doc;
        DocumentType docType = null;

        DOMImplementation domImpl;

        List<String> illegalQNames = new ArrayList<String>();
        illegalQNames.add("namespaceURI:{");
        illegalQNames.add("namespaceURI:}");
        illegalQNames.add("namespaceURI:~");
        illegalQNames.add("namespaceURI:'");
        illegalQNames.add("namespaceURI:!");
        illegalQNames.add("namespaceURI:@");
        illegalQNames.add("namespaceURI:#");
        illegalQNames.add("namespaceURI:$");
        illegalQNames.add("namespaceURI:%");
        illegalQNames.add("namespaceURI:^");
        illegalQNames.add("namespaceURI:&");
        illegalQNames.add("namespaceURI:*");
        illegalQNames.add("namespaceURI:(");
        illegalQNames.add("namespaceURI:)");
        illegalQNames.add("namespaceURI:+");
        illegalQNames.add("namespaceURI:=");
        illegalQNames.add("namespaceURI:[");
        illegalQNames.add("namespaceURI:]");
        illegalQNames.add("namespaceURI:\\");
        illegalQNames.add("namespaceURI:/");
        illegalQNames.add("namespaceURI:;");
        illegalQNames.add("namespaceURI:`");
        illegalQNames.add("namespaceURI:<");
        illegalQNames.add("namespaceURI:>");
        illegalQNames.add("namespaceURI:,");
        illegalQNames.add("namespaceURI:a ");
        illegalQNames.add("namespaceURI:\"");

        doc = (Document) load("staffNS", builder);
        for (int indexN1009A = 0; indexN1009A < illegalQNames.size(); indexN1009A++) {
            qualifiedName = (String) illegalQNames.get(indexN1009A);
            domImpl = doc.getImplementation();

            boolean success = false;
            try {
                domImpl.createDocument(namespaceURI, qualifiedName, docType);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
            }
            assertTrue("throw_INVALID_CHARACTER_ERR", success);

        }
    
public voidtestCreateDocument6()

        String namespaceURI = "http://ecommerce.org/schema";
        String qualifiedName = "xml:local";
        Document doc;
        DocumentType docType = null;

        DOMImplementation domImpl;

        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();

        boolean success = false;
        try {
            domImpl.createDocument(namespaceURI, qualifiedName, docType);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("throw_NAMESPACE_ERR", success);

    
public voidtestCreateDocument7()

        String namespaceURI = "http://www.ecommerce.org/schema";
        String qualifiedName = "y:x";
        Document doc;
        DocumentType docType = null;

        DOMImplementation domImpl;
        Document aNewDoc;
        String nodeName;
        String nodeValue;
        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();
        aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName, docType);
        nodeName = aNewDoc.getNodeName();
        nodeValue = aNewDoc.getNodeValue();
        assertEquals("nodeName", "#document", nodeName);
        assertNull("nodeValue", nodeValue);
    
public voidtestCreateDocument8()

        String namespaceURI = "http://www.example.org/schema";
        DocumentType docType = null;

        DOMImplementation domImpl;

        domImpl = builder.getDOMImplementation();

        boolean success = false;
        try {
            domImpl.createDocument(namespaceURI, "", docType);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("throw_NAMESPACE_ERR", success);