CreateAttributeNS.java revision 6b811c5daec1b28e6f63b57f98a032236f2c3cf7
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.Attr;
35
36import javax.xml.parsers.DocumentBuilder;
37
38@TestTargetClass(Document.class)
39public final class CreateAttributeNS extends DOMTestCase {
40
41    DOMDocumentBuilderFactory factory;
42
43    DocumentBuilder builder;
44
45    protected void setUp() throws Exception {
46        super.setUp();
47        try {
48            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
49                    .getConfiguration2());
50            builder = factory.getBuilder();
51        } catch (Exception e) {
52            fail("Unexpected exception" + e.getMessage());
53        }
54    }
55
56    protected void tearDown() throws Exception {
57        factory = null;
58        builder = null;
59        super.tearDown();
60    }
61
62    /**
63     * Runs the test case.
64     *
65     * @throws Throwable
66     *             Any uncaught exception causes test to fail
67     */
68    @TestTargetNew(
69        level = TestLevel.PARTIAL_COMPLETE,
70        notes = "Verifies NAMESPACE_ERR exception code.",
71        method = "createAttributeNS",
72        args = {java.lang.String.class, java.lang.String.class}
73    )
74    public void testCreateAttributeNS1() throws Throwable {
75        String namespaceURI = "http://www.ecommerce.org/";
76        String malformedName = "prefix::local";
77        Document doc;
78
79        doc = (Document) load("staffNS", builder);
80
81        {
82            boolean success = false;
83            try {
84                doc.createAttributeNS(namespaceURI, malformedName);
85            } catch (DOMException ex) {
86                success = (ex.code == DOMException.NAMESPACE_ERR);
87            }
88            assertTrue("throw_NAMESPACE_ERR", success);
89        }
90    }
91    @TestTargetNew(
92        level = TestLevel.PARTIAL_COMPLETE,
93        notes = "Verifies createAttributeNS method with null as the fisrt parameter.",
94        method = "createAttributeNS",
95        args = {java.lang.String.class, java.lang.String.class}
96    )
97    public void testCreateAttributeNS2() throws Throwable {
98        String namespaceURI = null;
99
100        String qualifiedName = "prefix:local";
101        Document doc;
102
103        doc = (Document) load("staffNS", builder);
104
105        {
106            boolean success = false;
107            try {
108                doc.createAttributeNS(namespaceURI, qualifiedName);
109            } catch (DOMException ex) {
110                success = (ex.code == DOMException.NAMESPACE_ERR);
111            }
112            assertTrue("throw_NAMESPACE_ERR", success);
113        }
114    }
115    @TestTargetNew(
116        level = TestLevel.PARTIAL_COMPLETE,
117        notes = "Verifies that createAttributeNS throws DOMException.",
118        method = "createAttributeNS",
119        args = {java.lang.String.class, java.lang.String.class}
120    )
121    public void testCreateAttributeNS3() throws Throwable {
122        String namespaceURI = "http://www.wedding.com/";
123        String qualifiedName;
124        Document doc;
125
126        List<String> illegalQNames = new ArrayList<String>();
127        illegalQNames.add("person:{");
128        illegalQNames.add("person:}");
129        illegalQNames.add("person:~");
130        illegalQNames.add("person:'");
131        illegalQNames.add("person:!");
132        illegalQNames.add("person:@");
133        illegalQNames.add("person:#");
134        illegalQNames.add("person:$");
135        illegalQNames.add("person:%");
136        illegalQNames.add("person:^");
137        illegalQNames.add("person:&");
138        illegalQNames.add("person:*");
139        illegalQNames.add("person:(");
140        illegalQNames.add("person:)");
141        illegalQNames.add("person:+");
142        illegalQNames.add("person:=");
143        illegalQNames.add("person:[");
144        illegalQNames.add("person:]");
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:a ");
153        illegalQNames.add("person:\"");
154
155        doc = (Document) load("staffNS", builder);
156        for (int indexN10090 = 0; indexN10090 < illegalQNames.size(); indexN10090++) {
157            qualifiedName = (String) illegalQNames.get(indexN10090);
158            {
159                boolean success = false;
160                try {
161                    doc.createAttributeNS(namespaceURI, qualifiedName);
162                } catch (DOMException ex) {
163                    success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
164                }
165                assertTrue("throw_INVALID_CHARACTER_ERR", success);
166            }
167        }
168    }
169    @TestTargetNew(
170        level = TestLevel.PARTIAL_COMPLETE,
171        notes = "Doesn't verify exceptions.",
172        method = "createAttributeNS",
173        args = {java.lang.String.class, java.lang.String.class}
174    )
175    public void testCreateAttributeNS4() throws Throwable {
176        String namespaceURI = "http://www.w3.org/XML/1998/namespaces";
177        String qualifiedName = "xml:attr1";
178        Document doc;
179
180        doc = (Document) load("staffNS", builder);
181
182        {
183            boolean success = false;
184            try {
185                doc.createAttributeNS(namespaceURI, qualifiedName);
186            } catch (DOMException ex) {
187                success = (ex.code == DOMException.NAMESPACE_ERR);
188            }
189            assertTrue("throw_NAMESPACE_ERR", success);
190        }
191    }
192    @TestTargetNew(
193        level = TestLevel.PARTIAL_COMPLETE,
194        notes = "Doesn't verify exceptions.",
195        method = "createAttributeNS",
196        args = {java.lang.String.class, java.lang.String.class}
197    )
198    public void testCreateAttributeNS5() throws Throwable {
199        String namespaceURI = "http://www.ecommerce.org/";
200        String qualifiedName = "econm:local";
201        Document doc;
202        Attr newAttr;
203        String attrName;
204        doc = (Document) load("staffNS", builder);
205        newAttr = doc.createAttributeNS(namespaceURI, qualifiedName);
206        attrName = newAttr.getName();
207        assertEquals("throw_Equals", qualifiedName, attrName);
208    }
209    @TestTargetNew(
210        level = TestLevel.PARTIAL_COMPLETE,
211        notes = "",
212        method = "createAttributeNS",
213        args = {java.lang.String.class, java.lang.String.class}
214    )
215    public void testCreateAttributeNS6() throws Throwable {
216        String namespaceURI = "http://www.example.com/";
217        Document doc;
218
219        doc = (Document) load("hc_staff", builder);
220
221        // BEGIN android-changed
222        //     Our exception priorities differ from the spec
223        try {
224            doc.createAttributeNS(namespaceURI, "");
225            fail();
226        } catch (DOMException ex) {
227        }
228        // END android-changed
229    }
230}
231