3 This Java source file was generated by test-to-java.xsl
4 and is a derived work from the source document.
5 The source document contained the following notice:
9 Copyright (c) 2001 World Wide Web Consortium,
10 (Massachusetts Institute of Technology, Institut National de
11 Recherche en Informatique et en Automatique, Keio University). All
12 Rights Reserved. This program is distributed under the W3C's Software
13 Intellectual Property License. This program is distributed in the
14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
23 package org.w3c.domts.level2.core;
28 import org.w3c.domts.DOMTestCase;
29 import org.w3c.domts.DOMTestDocumentBuilderFactory;
34 * The method hasAttributes returns whether this node (if it is an element) has any attributes.
35 * Create a new Document, Element and Attr node. Add the Attr to the Element and append the
36 * Element to the Document. Retreive the newly created element node from the document and check
37 * if it has attributes using hasAttributes.
40 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeHasAttrs">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeHasAttrs</a>
42 public final class nodehasattributes04 extends DOMTestCase {
46 * @param factory document factory, may not be null
47 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
49 public nodehasattributes04(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException {
51 org.w3c.domts.DocumentBuilderSetting[] settings =
52 new org.w3c.domts.DocumentBuilderSetting[] {
53 org.w3c.domts.DocumentBuilderSetting.namespaceAware
55 DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
56 setFactory(testFactory);
59 // check if loaded documents are supported for content type
61 String contentType = getContentType();
62 preload(contentType, "staffNS", false);
67 * @throws Throwable Any uncaught exception causes test to fail
69 public void runTest() throws Throwable {
72 DocumentType docType = null;
74 DOMImplementation domImpl;
82 boolean hasAttributes;
83 doc = (Document) load("staffNS", false);
84 domImpl = doc.getImplementation();
85 newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "test", docType);
86 element = newDoc.createElementNS("http://www.w3.org/DOM/Test", "dom:elem");
87 attribute = newDoc.createAttribute("attr");
88 setNode = element.setAttributeNode(attribute);
89 elementDoc = newDoc.getDocumentElement();
90 appendedChild = elementDoc.appendChild(element);
91 elementList = newDoc.getElementsByTagNameNS("http://www.w3.org/DOM/Test", "elem");
92 elementTest = (Element) elementList.item(0);
93 hasAttributes = elementTest.hasAttributes();
94 assertTrue("nodehasattributes04", hasAttributes);
97 * Gets URI that identifies the test.
98 * @return uri identifier of test
100 public String getTargetURI() {
101 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodehasattributes04";
104 * Runs this test from the command line.
105 * @param args command line arguments
107 public static void main(final String[] args) {
108 DOMTestCase.doMain(nodehasattributes04.class, args);