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 static jaxp.library.JAXPTestUtilities.getSystemProperty;
27 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.io.StringReader;
32 import javax.xml.transform.Source;
33 import javax.xml.transform.TransformerException;
34 import javax.xml.transform.URIResolver;
35 import javax.xml.transform.dom.DOMSource;
36 import javax.xml.transform.sax.SAXSource;
37 import javax.xml.transform.stax.StAXSource;
38 import javax.xml.transform.stream.StreamSource;
39
40 import org.testng.annotations.AfterClass;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.DataProvider;
43 import org.testng.annotations.Listeners;
44 import org.testng.annotations.Test;
45 import org.w3c.dom.ls.LSResourceResolver;
46 import org.xml.sax.InputSource;
47 import org.xml.sax.SAXException;
48 import org.xml.sax.SAXParseException;
49
50 /*
51 * @test
52 * @bug 8158084 8162438 8162442 8163535
53 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
54 * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport3
55 * @run testng/othervm catalog.CatalogSupport3
56 * @summary extends CatalogSupport tests, verifies that the use of the Catalog may
57 * be disabled through the API property.
58 */
59
60 /**
61 * For all of the JAXP processors that support the Catalog, the use of the Catalog
62 * is turned on by default. It can then be turned off through the API and the
63 * System property.
64 *
65 * @author huizhe.wang@oracle.com
66 */
67 @Listeners({jaxp.library.FilePolicy.class, jaxp.library.NetAccessPolicy.class})
68 public class CatalogSupport3 extends CatalogSupportBase {
69 static final String TTIMEOUTREAD = "sun.net.client.defaultReadTimeout";
70 static final String TIMEOUTCONNECT = "sun.net.client.defaultConnectTimeout";
71 static String timeoutRead = getSystemProperty(TTIMEOUTREAD);
72 static String timeoutConnect = getSystemProperty(TIMEOUTCONNECT);
108
109 /*
110 Verifies the Catalog support on XInclude.
111 */
112 @Test(dataProvider = "data_XIC", expectedExceptions = SAXParseException.class)
113 public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog,
114 String xml, MyHandler handler, String expected) throws Exception {
115 testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected);
116 }
117
118 /*
119 Verifies the Catalog support on DOM parser.
120 */
121 @Test(dataProvider = "data_DOMC", expectedExceptions = IOException.class)
122 public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog,
123 String xml, MyHandler handler, String expected) throws Exception {
124 testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected);
125 }
126
127 /*
128 Verifies the Catalog support on resolving DTD, xsd import and include in
129 Schema files.
130 */
131 @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXParseException.class)
132 public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog,
133 String xsd, LSResourceResolver resolver)
134 throws Exception {
135 testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
136 }
137
138 /*
139 @bug 8158084 8162438 these tests also verifies the fix for 8162438
140 Verifies the Catalog support on the Schema Validator.
141 */
142 @Test(dataProvider = "data_ValidatorC", expectedExceptions = {SAXException.class, IOException.class})
143 public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
144 Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
145 String catalog1, String catalog2)
146 throws Exception {
147 testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
189 */
190 @DataProvider(name = "data_XIC")
191 public Object[][] getDataXIC() {
192 return new Object[][]{
193 {true, false, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog},
194 };
195 }
196
197 /*
198 DataProvider: for testing DOM parser
199 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
200 */
201 @DataProvider(name = "data_DOMC")
202 public Object[][] getDataDOMC() {
203 return new Object[][]{
204 {true, false, xml_catalog, xml_system, new MyHandler(elementInSystem), 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 {true, false, xml_catalog, xsd_xmlSchema, null},
218 // for resolving xsd import
219 {true, false, xml_catalog, xsd_xmlSchema_import, null},
220 // for resolving xsd include
221 {true, false, xml_catalog, xsd_include_company, null}
222 };
223 }
224
225
226 /*
227 DataProvider: for testing Schema Validator
228 Data: source, resolver1, resolver2, catalog1, a catalog2
229 */
230 @DataProvider(name = "data_ValidatorC")
231 public Object[][] getDataValidator() {
232 DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, 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);
238 StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id);
239
240 StreamSource source = new StreamSource(new File(xml_val_test));
241
242 return new Object[][]{
243 // use catalog disabled through factory
244 {true, false, false, ds, null, null, xml_catalog, null},
245 {true, false, false, ds, null, null, null, xml_catalog},
246 {true, false, false, ss, null, null, xml_catalog, null},
247 {true, false, false, ss, null, null, null, xml_catalog},
248 {true, false, false, stax, null, null, xml_catalog, null},
249 {true, false, false, stax1, null, null, null, xml_catalog},
250 {true, false, false, source, null, null, xml_catalog, null},
251 {true, false, false, source, null, null, null, xml_catalog},
252 // use catalog disabled through validatory
253 {false, true, false, ds, null, null, xml_catalog, null},
254 {false, true, false, ds, null, null, null, xml_catalog},
255 {false, true, false, ss, null, null, xml_catalog, null},
256 {false, true, false, ss, null, null, null, xml_catalog},
257 {false, true, false, stax, null, null, xml_catalog, null},
258 {false, true, false, stax1, null, null, null, xml_catalog},
|
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 static jaxp.library.JAXPTestUtilities.getSystemProperty;
27 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.io.StringReader;
32 import javax.xml.stream.XMLResolver;
33 import javax.xml.stream.XMLStreamException;
34 import javax.xml.transform.Source;
35 import javax.xml.transform.TransformerException;
36 import javax.xml.transform.URIResolver;
37 import javax.xml.transform.dom.DOMSource;
38 import javax.xml.transform.sax.SAXSource;
39 import javax.xml.transform.stax.StAXSource;
40 import javax.xml.transform.stream.StreamSource;
41
42 import org.testng.annotations.AfterClass;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.DataProvider;
45 import org.testng.annotations.Listeners;
46 import org.testng.annotations.Test;
47 import org.w3c.dom.ls.LSResourceResolver;
48 import org.xml.sax.InputSource;
49 import org.xml.sax.SAXException;
50 import org.xml.sax.SAXParseException;
51
52 /*
53 * @test
54 * @bug 8158084 8162438 8162442 8163535 8166220
55 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
56 * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport3
57 * @run testng/othervm catalog.CatalogSupport3
58 * @summary extends CatalogSupport tests, verifies that the use of the Catalog may
59 * be disabled through the API property.
60 */
61
62 /**
63 * For all of the JAXP processors that support the Catalog, the use of the Catalog
64 * is turned on by default. It can then be turned off through the API and the
65 * System property.
66 *
67 * @author huizhe.wang@oracle.com
68 */
69 @Listeners({jaxp.library.FilePolicy.class, jaxp.library.NetAccessPolicy.class})
70 public class CatalogSupport3 extends CatalogSupportBase {
71 static final String TTIMEOUTREAD = "sun.net.client.defaultReadTimeout";
72 static final String TIMEOUTCONNECT = "sun.net.client.defaultConnectTimeout";
73 static String timeoutRead = getSystemProperty(TTIMEOUTREAD);
74 static String timeoutConnect = getSystemProperty(TIMEOUTCONNECT);
110
111 /*
112 Verifies the Catalog support on XInclude.
113 */
114 @Test(dataProvider = "data_XIC", expectedExceptions = SAXParseException.class)
115 public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog,
116 String xml, MyHandler handler, String expected) throws Exception {
117 testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected);
118 }
119
120 /*
121 Verifies the Catalog support on DOM parser.
122 */
123 @Test(dataProvider = "data_DOMC", expectedExceptions = IOException.class)
124 public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog,
125 String xml, MyHandler handler, String expected) throws Exception {
126 testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected);
127 }
128
129 /*
130 Verifies the Catalog support on XMLStreamReader.
131 */
132 @Test(dataProvider = "data_StAXC")
133 public void testStAXC(boolean setUseCatalog, boolean useCatalog, String catalog,
134 String xml, XMLResolver resolver, String expected) throws Exception {
135 testStAXNegative(setUseCatalog, useCatalog, catalog, xml, resolver, expected);
136 }
137
138 /*
139 Verifies the Catalog support on resolving DTD, xsd import and include in
140 Schema files.
141 */
142 @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXParseException.class)
143 public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog,
144 String xsd, LSResourceResolver resolver)
145 throws Exception {
146 testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
147 }
148
149 /*
150 @bug 8158084 8162438 these tests also verifies the fix for 8162438
151 Verifies the Catalog support on the Schema Validator.
152 */
153 @Test(dataProvider = "data_ValidatorC", expectedExceptions = {SAXException.class, IOException.class})
154 public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
155 Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
156 String catalog1, String catalog2)
157 throws Exception {
158 testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
200 */
201 @DataProvider(name = "data_XIC")
202 public Object[][] getDataXIC() {
203 return new Object[][]{
204 {true, false, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog},
205 };
206 }
207
208 /*
209 DataProvider: for testing DOM parser
210 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
211 */
212 @DataProvider(name = "data_DOMC")
213 public Object[][] getDataDOMC() {
214 return new Object[][]{
215 {true, false, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}
216 };
217 }
218
219 /*
220 DataProvider: for testing the StAX parser
221 Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
222 */
223 @DataProvider(name = "data_StAXC")
224 public Object[][] getDataStAX() {
225 return new Object[][]{
226 {true, false, xml_catalog, xml_system, null, "null"},
227 };
228 }
229
230 /*
231 DataProvider: for testing Schema validation
232 Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver
233 */
234 @DataProvider(name = "data_SchemaC")
235 public Object[][] getDataSchemaC() {
236
237 return new Object[][]{
238 // for resolving DTD in xsd
239 {true, false, xml_catalog, xsd_xmlSchema, null},
240 // for resolving xsd import
241 {true, false, xml_catalog, xsd_xmlSchema_import, null},
242 // for resolving xsd include
243 {true, false, xml_catalog, xsd_include_company, null}
244 };
245 }
246
247
248 /*
249 DataProvider: for testing Schema Validator
250 Data: source, resolver1, resolver2, catalog1, a catalog2
251 */
252 @DataProvider(name = "data_ValidatorC")
253 public Object[][] getDataValidator() {
254 DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
255
256 SAXSource ss = new SAXSource(new InputSource(xml_val_test));
257 ss.setSystemId(xml_val_test_id);
258
259 StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
260 StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
261
262 StreamSource source = new StreamSource(new File(xml_val_test));
263
264 return new Object[][]{
265 // use catalog disabled through factory
266 {true, false, false, ds, null, null, xml_catalog, null},
267 {true, false, false, ds, null, null, null, xml_catalog},
268 {true, false, false, ss, null, null, xml_catalog, null},
269 {true, false, false, ss, null, null, null, xml_catalog},
270 {true, false, false, stax, null, null, xml_catalog, null},
271 {true, false, false, stax1, null, null, null, xml_catalog},
272 {true, false, false, source, null, null, xml_catalog, null},
273 {true, false, false, source, null, null, null, xml_catalog},
274 // use catalog disabled through validatory
275 {false, true, false, ds, null, null, xml_catalog, null},
276 {false, true, false, ds, null, null, null, xml_catalog},
277 {false, true, false, ss, null, null, xml_catalog, null},
278 {false, true, false, ss, null, null, null, xml_catalog},
279 {false, true, false, stax, null, null, xml_catalog, null},
280 {false, true, false, stax1, null, null, null, xml_catalog},
|