KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > RemoveAttributeTest


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom;
19
20 import org.w3c.dom.*;
21
22 import java.io.*;
23 import java.net.*;
24 import org.apache.batik.dom.util.*;
25 import org.apache.batik.util.*;
26
27 import org.apache.batik.test.*;
28
29 /**
30  * This class tests the removeAttribute method.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: RemoveAttributeTest.java,v 1.4 2004/08/18 07:16:40 vhardy Exp $
34  */

35 public class RemoveAttributeTest extends AbstractTest {
36     public static String JavaDoc ERROR_GET_ELEMENT_BY_ID_FAILED
37         = "error.get.element.by.id.failed";
38
39     public static String JavaDoc ENTRY_KEY_ID
40         = "entry.key.id";
41
42     protected String JavaDoc testFileName;
43     protected String JavaDoc rootTag;
44     protected String JavaDoc targetId;
45     protected String JavaDoc targetAttr;
46
47     public RemoveAttributeTest(String JavaDoc file,
48                                String JavaDoc root,
49                                String JavaDoc id,
50                                String JavaDoc attr) {
51         testFileName = file;
52         rootTag = root;
53         targetId = id;
54         targetAttr = attr;
55     }
56
57     public TestReport runImpl() throws Exception JavaDoc {
58         String JavaDoc parser =
59             XMLResourceDescriptor.getXMLParserClassName();
60
61         DocumentFactory df
62             = new SAXDocumentFactory
63             (GenericDOMImplementation.getDOMImplementation(), parser);
64
65         File f = (new File(testFileName));
66         URL url = f.toURL();
67         Document doc = df.createDocument(null,
68                                          rootTag,
69                                          url.toString(),
70                                          url.openStream());
71
72         
73         Element e = doc.getElementById(targetId);
74
75         if (e == null){
76             DefaultTestReport report = new DefaultTestReport(this);
77             report.setErrorCode(ERROR_GET_ELEMENT_BY_ID_FAILED);
78             report.addDescriptionEntry(ENTRY_KEY_ID,
79                                        targetId);
80             report.setPassed(false);
81             return report;
82         }
83
84         try {
85             e.removeAttribute(targetAttr);
86         } catch (DOMException ex) {
87             DefaultTestReport report = new DefaultTestReport(this);
88             report.setErrorCode(TestReport.ERROR_TEST_FAILED);
89             report.addDescriptionEntry("exception.message",
90                                        ex.getMessage());
91             report.setPassed(false);
92             return report;
93         }
94         return reportSuccess();
95     }
96 }
97
Popular Tags