1/*
2 This Java source file was generated by test-to-java.xsl
3 and is a derived work from the source document.
4 The source document contained the following notice:
5
6
7
8 Copyright (c) 2001 World Wide Web Consortium,
9 (Massachusetts Institute of Technology, Institut National de
10 Recherche en Informatique et en Automatique, Keio University).  All
11 Rights Reserved.  This program is distributed under the W3C's Software
12 Intellectual Property License.  This program is distributed in the
13 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE.
16
17 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
18
19
20 */
21
22package tests.org.w3c.dom;
23
24import dalvik.annotation.TestTargets;
25import dalvik.annotation.TestLevel;
26import dalvik.annotation.TestTargetNew;
27import dalvik.annotation.TestTargetClass;
28
29import java.util.ArrayList;
30import java.util.List;
31
32import org.w3c.dom.Document;
33import org.w3c.dom.DOMException;
34import org.w3c.dom.Element;
35
36import javax.xml.parsers.DocumentBuilder;
37
38/**
39 * The "createElementNS(namespaceURI,qualifiedName)" method for a Document
40 * should raise NAMESPACE_ERR DOMException if qualifiedName is malformed.
41 *
42 * Invoke method createElementNS(namespaceURI,qualifiedName) on the XMLNS
43 * Document with namespaceURI being the literal string
44 * "http://www.ecommerce.org/", and qualifiedName as "prefix::local". Method
45 * should raise NAMESPACE_ERR DOMException.
46 *
47 * @author NIST
48 * @author Mary Brady
49 * @see <a
50 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])</a>
51 * @see <a
52 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS</a>
53 * @see <a
54 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])</a>
55 */
56@TestTargetClass(Document.class)
57public final class CreateElementNS extends DOMTestCase {
58
59    DOMDocumentBuilderFactory factory;
60
61    DocumentBuilder builder;
62
63    protected void setUp() throws Exception {
64        super.setUp();
65        try {
66            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
67                    .getConfiguration1());
68            builder = factory.getBuilder();
69        } catch (Exception e) {
70            fail("Unexpected exception" + e.getMessage());
71        }
72    }
73
74    protected void tearDown() throws Exception {
75        factory = null;
76        builder = null;
77        super.tearDown();
78    }
79
80    /**
81     * Runs the test case.
82     *
83     * @throws Throwable
84     *             Any uncaught exception causes test to fail
85     */
86    @TestTargetNew(
87        level = TestLevel.PARTIAL_COMPLETE,
88        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
89        method = "createElementNS",
90        args = {java.lang.String.class, java.lang.String.class}
91    )
92    public void testCreateElementNS1() throws Throwable {
93        String namespaceURI = "http://www.ecommerce.org/";
94        String malformedName = "prefix::local";
95        Document doc;
96
97        doc = (Document) load("staffNS", builder);
98
99        {
100            boolean success = false;
101            try {
102                doc.createElementNS(namespaceURI, malformedName);
103            } catch (DOMException ex) {
104                success = (ex.code == DOMException.NAMESPACE_ERR);
105            }
106            assertTrue("throw_NAMESPACE_ERR", success);
107        }
108    }
109    @TestTargetNew(
110        level = TestLevel.PARTIAL_COMPLETE,
111        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
112        method = "createElementNS",
113        args = {java.lang.String.class, java.lang.String.class}
114    )
115    public void testCreateElementNS2() throws Throwable {
116        String namespaceURI = null;
117
118        String qualifiedName = "prefix:local";
119        Document doc;
120
121        doc = (Document) load("staffNS", builder);
122
123        {
124            boolean success = false;
125            try {
126                doc.createElementNS(namespaceURI, qualifiedName);
127            } catch (DOMException ex) {
128                success = (ex.code == DOMException.NAMESPACE_ERR);
129            }
130            assertTrue("throw_NAMESPACE_ERR", success);
131        }
132    }
133    @TestTargetNew(
134        level = TestLevel.PARTIAL_COMPLETE,
135        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
136        method = "createElementNS",
137        args = {java.lang.String.class, java.lang.String.class}
138    )
139    public void testCreateElementNS3() throws Throwable {
140        String namespaceURI = "http://www.wedding.com/";
141        String qualifiedName;
142        Document doc;
143
144        List<String> illegalQNames = new ArrayList<String>();
145        illegalQNames.add("person:{");
146        illegalQNames.add("person:}");
147        illegalQNames.add("person:~");
148        illegalQNames.add("person:'");
149        illegalQNames.add("person:!");
150        illegalQNames.add("person:@");
151        illegalQNames.add("person:#");
152        illegalQNames.add("person:$");
153        illegalQNames.add("person:%");
154        illegalQNames.add("person:^");
155        illegalQNames.add("person:&");
156        illegalQNames.add("person:*");
157        illegalQNames.add("person:(");
158        illegalQNames.add("person:)");
159        illegalQNames.add("person:+");
160        illegalQNames.add("person:=");
161        illegalQNames.add("person:[");
162        illegalQNames.add("person:]");
163        illegalQNames.add("person:\\");
164        illegalQNames.add("person:/");
165        illegalQNames.add("person:;");
166        illegalQNames.add("person:`");
167        illegalQNames.add("person:<");
168        illegalQNames.add("person:>");
169        illegalQNames.add("person:,");
170        illegalQNames.add("person:a ");
171        illegalQNames.add("person:\"");
172
173        doc = (Document) load("staffNS", builder);
174        for (int indexN10098 = 0; indexN10098 < illegalQNames.size(); indexN10098++) {
175            qualifiedName = (String) illegalQNames.get(indexN10098);
176
177            {
178                boolean success = false;
179                try {
180                    doc.createElementNS(namespaceURI, qualifiedName);
181                } catch (DOMException ex) {
182                    success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
183                }
184                assertTrue("throw_INVALID_CHARACTER_ERR", success);
185            }
186        }
187    }
188    @TestTargetNew(
189        level = TestLevel.PARTIAL_COMPLETE,
190        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
191        method = "createElementNS",
192        args = {java.lang.String.class, java.lang.String.class}
193    )
194    public void testCreateElementNS4() throws Throwable {
195        String namespaceURI = "http://www.w3.org/XML/1998/namespaces";
196        String qualifiedName = "xml:element1";
197        Document doc;
198
199        doc = (Document) load("staffNS", builder);
200
201        {
202            boolean success = false;
203            try {
204                doc.createElementNS(namespaceURI, qualifiedName);
205            } catch (DOMException ex) {
206                success = (ex.code == DOMException.NAMESPACE_ERR);
207            }
208            assertTrue("throw_NAMESPACE_ERR", success);
209        }
210    }
211    @TestTargetNew(
212        level = TestLevel.PARTIAL_COMPLETE,
213        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
214        method = "createElementNS",
215        args = {java.lang.String.class, java.lang.String.class}
216    )
217    public void testCreateElementNS5() throws Throwable {
218        String namespaceURI = "http://www.nist.gov";
219        String qualifiedName = "gov:faculty";
220        Document doc;
221        Element newElement;
222        String elementName;
223        doc = (Document) load("staffNS", builder);
224        newElement = doc.createElementNS(namespaceURI, qualifiedName);
225        elementName = newElement.getTagName();
226        assertEquals("throw_Equals", qualifiedName, elementName);
227    }
228    @TestTargetNew(
229        level = TestLevel.PARTIAL_COMPLETE,
230        notes = "Doesn't verify null as a parameters, and other types of DOMException.",
231        method = "createElementNS",
232        args = {java.lang.String.class, java.lang.String.class}
233    )
234    public void testCreateElementNS6() throws Throwable {
235        String namespaceURI = "http://www.example.com/";
236
237        Document doc;
238
239        doc = (Document) load("hc_staff", builder);
240
241        {
242            // BEGIN android-changed
243            //     Our exception priorities differ from the spec
244            try {
245                doc.createElementNS(namespaceURI, "");
246                fail();
247            } catch (DOMException ex) {
248            }
249            // END android-changed
250        }
251    }
252}
253