1
2/*
3This Java source file was generated by test-to-java.xsl
4and is a derived work from the source document.
5The source document contained the following notice:
6
7
8
9Copyright (c) 2001 World Wide Web Consortium,
10(Massachusetts Institute of Technology, Institut National de
11Recherche en Informatique et en Automatique, Keio University).  All
12Rights Reserved.  This program is distributed under the W3C's Software
13Intellectual Property License.  This program is distributed in the
14hope that it will be useful, but WITHOUT ANY WARRANTY; without even
15the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16PURPOSE.
17
18See W3C License http://www.w3.org/Consortium/Legal/ for more details.
19
20
21*/
22
23package org.w3c.domts.level2.core;
24
25import org.w3c.dom.*;
26
27
28import org.w3c.domts.DOMTestCase;
29import org.w3c.domts.DOMTestDocumentBuilderFactory;
30
31
32
33/**
34 *     The "setAttributeNodeNS(newAttr)" method raises an
35 *    "WRONG_DOCUMENT_ERR DOMException if the "newAttr"
36 *    was created from a different document than the one that
37 *    created this document.
38 *
39 *    Retrieve the first emp:address and attempt to set a new
40 *    attribute node.  The new
41 *    attribute was created from a document other than the
42 *    one that created this element, therefore a
43 *    WRONG_DOCUMENT_ERR DOMException should be raised.
44 *    This test uses the "createAttributeNS(newAttr)" method
45 *    from the Document interface.
46* @author NIST
47* @author Mary Brady
48* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])</a>
49* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS</a>
50* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAtNodeNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAtNodeNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])</a>
51*/
52public final class setAttributeNodeNS05 extends DOMTestCase {
53
54   /**
55    * Constructor.
56    * @param factory document factory, may not be null
57    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
58    */
59   public setAttributeNodeNS05(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
60      super(factory);
61
62    //
63    //   check if loaded documents are supported for content type
64    //
65    String contentType = getContentType();
66    preload(contentType, "staffNS", true);
67    preload(contentType, "staffNS", true);
68    }
69
70   /**
71    * Runs the test case.
72    * @throws Throwable Any uncaught exception causes test to fail
73    */
74   public void runTest() throws Throwable {
75      String namespaceURI = "http://www.newattr.com";
76      String qualifiedName = "emp:newAttr";
77      Document doc1;
78      Document doc2;
79      Attr newAttr;
80      NodeList elementList;
81      Node testAddr;
82      Attr setAttr1;
83      doc1 = (Document) load("staffNS", true);
84      doc2 = (Document) load("staffNS", true);
85      newAttr = doc2.createAttributeNS(namespaceURI, qualifiedName);
86      elementList = doc1.getElementsByTagName("emp:address");
87      testAddr = elementList.item(0);
88
89      {
90         boolean success = false;
91         try {
92            setAttr1 = ((Element) /*Node */testAddr).setAttributeNodeNS(newAttr);
93          } catch (DOMException ex) {
94            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
95         }
96         assertTrue("throw_WRONG_DOCUMENT_ERR", success);
97      }
98}
99   /**
100    *  Gets URI that identifies the test.
101    *  @return uri identifier of test
102    */
103   public String getTargetURI() {
104      return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNodeNS05";
105   }
106   /**
107    * Runs this test from the command line.
108    * @param args command line arguments
109    */
110   public static void main(final String[] args) {
111        DOMTestCase.doMain(setAttributeNodeNS05.class, args);
112   }
113}
114
115