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
8Copyright (c) 2001-2004 World Wide Web Consortium,
9(Massachusetts Institute of Technology, Institut National de
10Recherche en Informatique et en Automatique, Keio University). All
11Rights Reserved. This program is distributed under the W3C's Software
12Intellectual Property License. This program is distributed in the
13hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15PURPOSE.
16See W3C License http://www.w3.org/Consortium/Legal/ for more details.
17
18*/
19
20package org.w3c.domts.level1.core;
21
22import org.w3c.dom.*;
23
24
25import org.w3c.domts.DOMTestCase;
26import org.w3c.domts.DOMTestDocumentBuilderFactory;
27
28
29
30/**
31 * Appends a document fragment containing a CDATASection to an attribute.
32* @author Curt Arnold
33* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-637646024">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-637646024</a>
34* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-952280727">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-952280727</a>
35*/
36public final class hc_attrinsertbefore7 extends DOMTestCase {
37
38   /**
39    * Constructor.
40    * @param factory document factory, may not be null
41    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
42    */
43   public hc_attrinsertbefore7(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
44      super(factory);
45      if (factory.hasFeature("XML", null) != true) {
46         throw org.w3c.domts.DOMTestIncompatibleException.incompatibleFeature("XML", null);
47      }
48
49    //
50    //   check if loaded documents are supported for content type
51    //
52    String contentType = getContentType();
53    preload(contentType, "hc_staff", true);
54    }
55
56   /**
57    * Runs the test case.
58    * @throws Throwable Any uncaught exception causes test to fail
59    */
60   public void runTest() throws Throwable {
61      Document doc;
62      NodeList acronymList;
63      Node testNode;
64      NamedNodeMap attributes;
65      Attr titleAttr;
66      String value;
67      Text terNode;
68      Node dayNode;
69      DocumentFragment docFrag;
70      Node retval;
71      Node firstChild;
72      Node lastChild;
73      Node refChild = null;
74
75      doc = (Document) load("hc_staff", true);
76      acronymList = doc.getElementsByTagName("acronym");
77      testNode = acronymList.item(3);
78      attributes = testNode.getAttributes();
79      titleAttr = (Attr) attributes.getNamedItem("title");
80      terNode = doc.createTextNode("ter");
81
82      if (("text/html".equals(getContentType()))) {
83
84      {
85         boolean success = false;
86         try {
87            dayNode = doc.createCDATASection("day");
88          } catch (DOMException ex) {
89            success = (ex.code == DOMException.NOT_SUPPORTED_ERR);
90         }
91         assertTrue("throw_NOT_SUPPORTED_ERR", success);
92      }
93} else {
94          dayNode = doc.createCDATASection("day");
95      docFrag = doc.createDocumentFragment();
96      retval = docFrag.appendChild(terNode);
97      retval = docFrag.appendChild(dayNode);
98
99      {
100         boolean success = false;
101         try {
102            retval = titleAttr.insertBefore(docFrag, refChild);
103          } catch (DOMException ex) {
104            success = (ex.code == DOMException.HIERARCHY_REQUEST_ERR);
105         }
106         assertTrue("throw_HIERARCHY_REQUEST_ERR", success);
107      }
108}
109
110    }
111   /**
112    *  Gets URI that identifies the test.
113    *  @return uri identifier of test
114    */
115   public String getTargetURI() {
116      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore7";
117   }
118   /**
119    * Runs this test from the command line.
120    * @param args command line arguments
121    */
122   public static void main(final String[] args) {
123        DOMTestCase.doMain(hc_attrinsertbefore7.class, args);
124   }
125}
126
127