KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > XmlValidateTest


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

17 package org.apache.tools.ant.taskdefs.optional;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.BuildFileTest;
21
22 /**
23  * Tests the XMLValidate optional task, by running targets in the test script
24  * <code>src/etc/testcases/taskdefs/optional/xmlvalidate.xml</code>
25  * <p>
26  *
27  * @see XmlValidateCatalogTest
28  * @since Ant 1.5
29  */

30 public class XmlValidateTest extends BuildFileTest {
31
32     /**
33      * where tasks run
34      */

35     private final static String JavaDoc TASKDEFS_DIR =
36         "src/etc/testcases/taskdefs/optional/";
37
38     /**
39      * Constructor
40      *
41      * @param name testname
42      */

43     public XmlValidateTest(String JavaDoc name) {
44         super(name);
45     }
46
47     /**
48      * The JUnit setup method
49      */

50     public void setUp() {
51         configureProject(TASKDEFS_DIR + "xmlvalidate.xml");
52     }
53
54     /**
55      * The teardown method for JUnit
56      */

57     public void tearDown() {}
58
59     /**
60      * Basic inline 'dtd' element test.
61      */

62     public void testValidate() throws Exception JavaDoc {
63         executeTarget("testValidate");
64     }
65
66     /**
67      * Test indirect validation.
68      */

69     public void testDeepValidate() throws Exception JavaDoc {
70         executeTarget("testDeepValidate");
71     }
72
73     /**
74      *
75      */

76     public void testXmlCatalog() {
77         executeTarget("xmlcatalog");
78     }
79
80     /**
81      *
82      */

83     public void testXmlCatalogViaRefid() {
84         executeTarget("xmlcatalogViaRefid");
85     }
86
87     /**
88      * Test that the nested dtd element is used when resolver.jar is not
89      * present. This test should pass either way.
90      */

91     public void testXmlCatalogFiles() {
92         executeTarget("xmlcatalogfiles-override");
93     }
94
95     /**
96      * Test nested catalogpath.
97      * Test that the nested dtd element is used when resolver.jar is not
98      * present. This test should pass either way.
99      */

100     public void testXmlCatalogPath() {
101         executeTarget("xmlcatalogpath-override");
102     }
103
104     /**
105      * Test nested xmlcatalog definitions
106      */

107     public void testXmlCatalogNested() {
108         executeTarget("xmlcatalognested");
109     }
110
111     /**
112      * Test xml schema validation
113      */

114     public void testXmlSchemaGood() throws BuildException {
115         try {
116             executeTarget("testSchemaGood");
117         } catch (BuildException e) {
118             if (e
119                 .getMessage()
120                 .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
121                 || e.getMessage().endsWith(
122                     " doesn't support feature http://apache.org/xml/features/validation/schema")) {
123                 System.err.println(" skipped, parser doesn't support schema");
124             } else {
125                 throw e;
126             }
127         }
128     }
129     /**
130      * Test xml schema validation
131      */

132     public void testXmlSchemaBad() {
133         try {
134             executeTarget("testSchemaBad");
135             fail("Should throw BuildException because 'Bad Schema Validation'");
136
137             expectBuildExceptionContaining(
138                 "testSchemaBad",
139                 "Bad Schema Validation",
140                 "not a valid XML document");
141         } catch (BuildException e) {
142             if (e
143                 .getMessage()
144                 .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
145                 || e.getMessage().endsWith(
146                     " doesn't support feature http://apache.org/xml/features/validation/schema")) {
147                 System.err.println(" skipped, parser doesn't support schema");
148             } else {
149                 assertTrue(
150                     e.getMessage().indexOf("not a valid XML document") > -1);
151             }
152         }
153     }
154
155     /**
156      * iso-2022-jp.xml is valid but wouldn't get recognized on systems
157      * with a different native encoding.
158      *
159      * Bug 11279
160      */

161     public void testIso2022Jp() {
162         executeTarget("testIso2022Jp");
163     }
164
165     /**
166      * utf-8.xml is invalid as it contains non-UTF-8 characters, but
167      * would pass on systems with a native iso-8859-1 (or similar)
168      * encoding.
169      *
170      * Bug 11279
171      */

172     public void testUtf8() {
173         expectBuildException("testUtf8", "invalid characters in file");
174     }
175
176     // Tests property element, using XML schema properties as an example.
177

178     public void testPropertySchemaForValidXML() {
179         executeTarget("testProperty.validXML");
180     }
181
182     public void testPropertySchemaForInvalidXML() {
183         expectBuildException(
184             "testProperty.invalidXML",
185             "XML file does not satisfy schema.");
186     }
187
188 }
189
Popular Tags