8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package catalog;
25
26 import java.io.File;
27 import java.io.StringReader;
28 import javax.xml.transform.Source;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.transform.URIResolver;
31 import javax.xml.transform.dom.DOMSource;
32 import javax.xml.transform.sax.SAXSource;
33 import javax.xml.transform.stax.StAXSource;
34 import javax.xml.transform.stream.StreamSource;
35 import org.testng.annotations.AfterClass;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Listeners;
39 import org.testng.annotations.Test;
40 import org.w3c.dom.ls.LSResourceResolver;
41 import org.xml.sax.InputSource;
42 import org.xml.sax.SAXException;
43
44 /*
45 * @test
46 * @bug 8158084 8163232
47 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
48 * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport5
49 * @run testng/othervm catalog.CatalogSupport5
50 * @summary extends CatalogSupport tests, verifies that when errors occur,
51 * relevant checked Exceptions are returned.
52 */
53 /**
54 * The CatalogResolver will throw CatalogException when there is no match and
55 * the resolve property is strict. The Exception should be caught with the existing
56 * mechanisms so that the checked Exception corresponding to the process can be
57 * returned.
58 *
59 * @author huizhe.wang@oracle.com
60 */
61 @Listeners({jaxp.library.FilePolicy.class, jaxp.library.NetAccessPolicy.class})
62 public class CatalogSupport5 extends CatalogSupportBase {
63
64 /*
65 * Initializing fields
66 */
90
91 /*
92 Verifies the Catalog support on XInclude.
93 */
94 @Test(dataProvider = "data_XIC", expectedExceptions = SAXException.class)
95 public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog,
96 String xml, MyHandler handler, String expected) throws Exception {
97 testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected);
98 }
99
100 /*
101 Verifies the Catalog support on DOM parser.
102 */
103 @Test(dataProvider = "data_DOMC", expectedExceptions = SAXException.class)
104 public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog,
105 String xml, MyHandler handler, String expected) throws Exception {
106 testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected);
107 }
108
109 /*
110 Verifies the Catalog support on resolving DTD, xsd import and include in
111 Schema files.
112 */
113 @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXException.class)
114 public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog,
115 String xsd, LSResourceResolver resolver)
116 throws Exception {
117 testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
118 }
119
120 @Test(dataProvider = "data_ValidatorC", expectedExceptions = SAXException.class)
121 public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
122 Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
123 String catalog1, String catalog2)
124 throws Exception {
125 testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
126 resolver1, resolver2, catalog1, catalog2);
127 }
128
129 /*
166 */
167 @DataProvider(name = "data_XIC")
168 public Object[][] getDataXIC() {
169 return new Object[][]{
170 {false, true, xml_bogus_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog},
171 };
172 }
173
174 /*
175 DataProvider: for testing DOM parser
176 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
177 */
178 @DataProvider(name = "data_DOMC")
179 public Object[][] getDataDOMC() {
180 return new Object[][]{
181 {false, true, xml_bogus_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}
182 };
183 }
184
185 /*
186 DataProvider: for testing Schema validation
187 Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver
188 */
189 @DataProvider(name = "data_SchemaC")
190 public Object[][] getDataSchemaC() {
191
192 return new Object[][]{
193 // for resolving DTD in xsd
194 {false, true, xml_bogus_catalog, xsd_xmlSchema, null},
195 // for resolving xsd import
196 {false, true, xml_bogus_catalog, xsd_xmlSchema_import, null},
197 // for resolving xsd include
198 {false, true, xml_bogus_catalog, xsd_include_company, null}
199 };
200 }
201
202 /*
203 DataProvider: for testing Schema Validator
204 Data: setUseCatalog1, setUseCatalog2, useCatalog, source, resolver1, resolver2,
205 catalog1, catalog2
206 */
207 @DataProvider(name = "data_ValidatorC")
208 public Object[][] getDataValidator() {
209 DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
210
211 SAXSource ss = new SAXSource(new InputSource(xml_val_test));
212 ss.setSystemId(xml_val_test_id);
213
214 StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id);
215 StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id);
216
217 StreamSource source = new StreamSource(new File(xml_val_test));
218
219 return new Object[][]{
220 // use catalog
221 {false, false, true, ds, null, null, xml_bogus_catalog, null},
222 {false, false, true, ds, null, null, null, xml_bogus_catalog},
223 {false, false, true, ss, null, null, xml_bogus_catalog, null},
224 {false, false, true, ss, null, null, null, xml_bogus_catalog},
225 {false, false, true, stax, null, null, xml_bogus_catalog, null},
226 {false, false, true, stax1, null, null, null, xml_bogus_catalog},
227 {false, false, true, source, null, null, xml_bogus_catalog, null},
228 {false, false, true, source, null, null, null, xml_bogus_catalog},
229 };
230 }
231
232 /*
233 DataProvider: for testing XSL import and include
234 Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected
235 */
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package catalog;
25
26 import java.io.File;
27 import java.io.StringReader;
28 import javax.xml.stream.XMLResolver;
29 import javax.xml.stream.XMLStreamException;
30 import javax.xml.transform.Source;
31 import javax.xml.transform.TransformerException;
32 import javax.xml.transform.URIResolver;
33 import javax.xml.transform.dom.DOMSource;
34 import javax.xml.transform.sax.SAXSource;
35 import javax.xml.transform.stax.StAXSource;
36 import javax.xml.transform.stream.StreamSource;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Listeners;
41 import org.testng.annotations.Test;
42 import org.w3c.dom.ls.LSResourceResolver;
43 import org.xml.sax.InputSource;
44 import org.xml.sax.SAXException;
45
46 /*
47 * @test
48 * @bug 8158084 8163232 8166220
49 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
50 * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport5
51 * @run testng/othervm catalog.CatalogSupport5
52 * @summary extends CatalogSupport tests, verifies that when errors occur,
53 * relevant checked Exceptions are returned.
54 */
55 /**
56 * The CatalogResolver will throw CatalogException when there is no match and
57 * the resolve property is strict. The Exception should be caught with the existing
58 * mechanisms so that the checked Exception corresponding to the process can be
59 * returned.
60 *
61 * @author huizhe.wang@oracle.com
62 */
63 @Listeners({jaxp.library.FilePolicy.class, jaxp.library.NetAccessPolicy.class})
64 public class CatalogSupport5 extends CatalogSupportBase {
65
66 /*
67 * Initializing fields
68 */
92
93 /*
94 Verifies the Catalog support on XInclude.
95 */
96 @Test(dataProvider = "data_XIC", expectedExceptions = SAXException.class)
97 public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog,
98 String xml, MyHandler handler, String expected) throws Exception {
99 testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected);
100 }
101
102 /*
103 Verifies the Catalog support on DOM parser.
104 */
105 @Test(dataProvider = "data_DOMC", expectedExceptions = SAXException.class)
106 public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog,
107 String xml, MyHandler handler, String expected) throws Exception {
108 testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected);
109 }
110
111 /*
112 Verifies the Catalog support on XMLStreamReader.
113 */
114 @Test(dataProvider = "data_StAXC", expectedExceptions = XMLStreamException.class)
115 public void testStAXC(boolean setUseCatalog, boolean useCatalog, String catalog,
116 String xml, XMLResolver resolver, String expected) throws Exception {
117 testStAX(setUseCatalog, useCatalog, catalog, xml, resolver, expected);
118 }
119
120 /*
121 Verifies the Catalog support on resolving DTD, xsd import and include in
122 Schema files.
123 */
124 @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXException.class)
125 public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog,
126 String xsd, LSResourceResolver resolver)
127 throws Exception {
128 testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
129 }
130
131 @Test(dataProvider = "data_ValidatorC", expectedExceptions = SAXException.class)
132 public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
133 Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
134 String catalog1, String catalog2)
135 throws Exception {
136 testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
137 resolver1, resolver2, catalog1, catalog2);
138 }
139
140 /*
177 */
178 @DataProvider(name = "data_XIC")
179 public Object[][] getDataXIC() {
180 return new Object[][]{
181 {false, true, xml_bogus_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog},
182 };
183 }
184
185 /*
186 DataProvider: for testing DOM parser
187 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
188 */
189 @DataProvider(name = "data_DOMC")
190 public Object[][] getDataDOMC() {
191 return new Object[][]{
192 {false, true, xml_bogus_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}
193 };
194 }
195
196 /*
197 DataProvider: for testing the StAX parser
198 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
199 */
200 @DataProvider(name = "data_StAXC")
201 public Object[][] getDataStAX() {
202
203 return new Object[][]{
204 {false, true, xml_bogus_catalog, xml_system, null, expectedWCatalog},
205 };
206 }
207
208 /*
209 DataProvider: for testing Schema validation
210 Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver
211 */
212 @DataProvider(name = "data_SchemaC")
213 public Object[][] getDataSchemaC() {
214
215 return new Object[][]{
216 // for resolving DTD in xsd
217 {false, true, xml_bogus_catalog, xsd_xmlSchema, null},
218 // for resolving xsd import
219 {false, true, xml_bogus_catalog, xsd_xmlSchema_import, null},
220 // for resolving xsd include
221 {false, true, xml_bogus_catalog, xsd_include_company, null}
222 };
223 }
224
225 /*
226 DataProvider: for testing Schema Validator
227 Data: setUseCatalog1, setUseCatalog2, useCatalog, source, resolver1, resolver2,
228 catalog1, catalog2
229 */
230 @DataProvider(name = "data_ValidatorC")
231 public Object[][] getDataValidator() {
232 DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
233
234 SAXSource ss = new SAXSource(new InputSource(xml_val_test));
235 ss.setSystemId(xml_val_test_id);
236
237 StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
238 StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
239
240 StreamSource source = new StreamSource(new File(xml_val_test));
241
242 return new Object[][]{
243 // use catalog
244 {false, false, true, ds, null, null, xml_bogus_catalog, null},
245 {false, false, true, ds, null, null, null, xml_bogus_catalog},
246 {false, false, true, ss, null, null, xml_bogus_catalog, null},
247 {false, false, true, ss, null, null, null, xml_bogus_catalog},
248 {false, false, true, stax, null, null, xml_bogus_catalog, null},
249 {false, false, true, stax1, null, null, null, xml_bogus_catalog},
250 {false, false, true, source, null, null, xml_bogus_catalog, null},
251 {false, false, true, source, null, null, null, xml_bogus_catalog},
252 };
253 }
254
255 /*
256 DataProvider: for testing XSL import and include
257 Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected
258 */
|