39907
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
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.FileNotFoundException;
|
|
28 |
import java.io.StringReader;
|
|
29 |
import java.net.SocketTimeoutException;
|
|
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.Test;
|
|
41 |
import org.w3c.dom.ls.LSResourceResolver;
|
|
42 |
import org.xml.sax.InputSource;
|
|
43 |
import org.xml.sax.SAXException;
|
|
44 |
import org.xml.sax.SAXParseException;
|
|
45 |
|
|
46 |
/*
|
|
47 |
* @bug 8158084 8162438 8162442
|
|
48 |
* @summary extends CatalogSupport tests, verifies that the use of the Catalog may
|
|
49 |
* be disabled through the System property.
|
|
50 |
*/
|
|
51 |
|
|
52 |
/**
|
|
53 |
* For all of the JAXP processors that support the Catalog, the use of the Catalog
|
|
54 |
* is turned on by default. It can then be turned off through the API and the
|
|
55 |
* System property.
|
|
56 |
*
|
|
57 |
* @author huizhe.wang@oracle.com
|
|
58 |
*/
|
|
59 |
public class CatalogSupport2 extends CatalogSupportBase {
|
|
60 |
static final String TTIMEOUTREAD = "sun.net.client.defaultReadTimeout";
|
|
61 |
static final String TIMEOUTCONNECT = "sun.net.client.defaultConnectTimeout";
|
|
62 |
static String timeoutRead = System.getProperty(TTIMEOUTREAD);
|
|
63 |
static String timeoutConnect = System.getProperty(TIMEOUTCONNECT);
|
|
64 |
|
|
65 |
/*
|
|
66 |
* Initializing fields
|
|
67 |
*/
|
|
68 |
@BeforeClass
|
|
69 |
public void setUpClass() throws Exception {
|
|
70 |
setUp();
|
|
71 |
System.setProperty(SP_USE_CATALOG, "false");
|
|
72 |
timeoutRead = System.getProperty(TTIMEOUTREAD);
|
|
73 |
timeoutConnect = System.getProperty(TIMEOUTCONNECT);
|
|
74 |
System.setProperty(TTIMEOUTREAD, "1000");
|
|
75 |
System.setProperty(TIMEOUTCONNECT, "1000");
|
|
76 |
}
|
|
77 |
|
|
78 |
@AfterClass
|
|
79 |
public void tearDownClass() throws Exception {
|
|
80 |
System.clearProperty(SP_USE_CATALOG);
|
|
81 |
System.setProperty(TIMEOUTCONNECT, "-1");
|
|
82 |
System.setProperty(TTIMEOUTREAD, "-1");
|
|
83 |
}
|
|
84 |
|
|
85 |
/*
|
|
86 |
Verifies the Catalog support on SAXParser.
|
|
87 |
*/
|
|
88 |
@Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class)
|
|
89 |
public void testSAXC(boolean setUseCatalog, boolean useCatalog, String catalog, String
|
|
90 |
xml, MyHandler handler, String expected) throws Exception {
|
|
91 |
testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected);
|
|
92 |
}
|
|
93 |
|
|
94 |
/*
|
|
95 |
Verifies the Catalog support on XMLReader.
|
|
96 |
*/
|
|
97 |
@Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class)
|
|
98 |
public void testXMLReaderC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
99 |
String xml, MyHandler handler, String expected) throws Exception {
|
|
100 |
testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected);
|
|
101 |
}
|
|
102 |
|
|
103 |
/*
|
|
104 |
Verifies the Catalog support on XInclude.
|
|
105 |
*/
|
|
106 |
@Test(dataProvider = "data_XIC", expectedExceptions = SAXParseException.class)
|
|
107 |
public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
108 |
String xml, MyHandler handler, String expected) throws Exception {
|
|
109 |
testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected);
|
|
110 |
}
|
|
111 |
|
|
112 |
/*
|
|
113 |
Verifies the Catalog support on DOM parser.
|
|
114 |
*/
|
|
115 |
@Test(dataProvider = "data_DOMC", expectedExceptions = {FileNotFoundException.class, SocketTimeoutException.class})
|
|
116 |
public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
117 |
String xml, MyHandler handler, String expected) throws Exception {
|
|
118 |
testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected);
|
|
119 |
}
|
|
120 |
|
|
121 |
/*
|
|
122 |
Verifies the Catalog support on resolving DTD, xsd import and include in
|
|
123 |
Schema files.
|
|
124 |
*/
|
|
125 |
@Test(dataProvider = "data_SchemaC", expectedExceptions = SAXParseException.class)
|
|
126 |
public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
127 |
String xsd, LSResourceResolver resolver)
|
|
128 |
throws Exception {
|
|
129 |
testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
|
|
130 |
}
|
|
131 |
|
|
132 |
@Test(dataProvider = "data_ValidatorC", expectedExceptions = {SAXException.class, FileNotFoundException.class})
|
|
133 |
public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
|
|
134 |
Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
|
|
135 |
String catalog1, String catalog2)
|
|
136 |
throws Exception {
|
|
137 |
testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
|
|
138 |
resolver1, resolver2, catalog1, catalog2);
|
|
139 |
}
|
|
140 |
|
|
141 |
/*
|
|
142 |
Verifies the Catalog support on resolving DTD, xsl import and include in
|
|
143 |
XSL files.
|
|
144 |
*/
|
|
145 |
@Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class)
|
|
146 |
public void testXSLImportC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
147 |
SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) throws Exception {
|
|
148 |
|
|
149 |
testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected);
|
|
150 |
}
|
|
151 |
|
|
152 |
/*
|
|
153 |
@bug 8158084 8162442
|
|
154 |
Verifies the Catalog support on resolving DTD, xsl import and include in
|
|
155 |
XSL files.
|
|
156 |
*/
|
|
157 |
@Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class)
|
|
158 |
public void testXSLImportWTemplatesC(boolean setUseCatalog, boolean useCatalog, String catalog,
|
|
159 |
SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) throws Exception {
|
|
160 |
testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected);
|
|
161 |
}
|
|
162 |
|
|
163 |
/*
|
|
164 |
DataProvider: for testing the SAX parser
|
|
165 |
Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
|
|
166 |
*/
|
|
167 |
@DataProvider(name = "data_SAXC")
|
|
168 |
Object[][] getDataSAXC() {
|
|
169 |
return new Object[][]{
|
|
170 |
{false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}
|
|
171 |
|
|
172 |
};
|
|
173 |
}
|
|
174 |
|
|
175 |
/*
|
|
176 |
DataProvider: for testing XInclude
|
|
177 |
Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
|
|
178 |
*/
|
|
179 |
@DataProvider(name = "data_XIC")
|
|
180 |
Object[][] getDataXIC() {
|
|
181 |
return new Object[][]{
|
|
182 |
{false, true, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog},
|
|
183 |
};
|
|
184 |
}
|
|
185 |
|
|
186 |
/*
|
|
187 |
DataProvider: for testing DOM parser
|
|
188 |
Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string
|
|
189 |
*/
|
|
190 |
@DataProvider(name = "data_DOMC")
|
|
191 |
Object[][] getDataDOMC() {
|
|
192 |
return new Object[][]{
|
|
193 |
{false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}
|
|
194 |
};
|
|
195 |
}
|
|
196 |
|
|
197 |
/*
|
|
198 |
DataProvider: for testing Schema validation
|
|
199 |
Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver
|
|
200 |
*/
|
|
201 |
@DataProvider(name = "data_SchemaC")
|
|
202 |
Object[][] getDataSchemaC() {
|
|
203 |
|
|
204 |
return new Object[][]{
|
|
205 |
// for resolving DTD in xsd
|
|
206 |
{false, true, xml_catalog, xsd_xmlSchema, null},
|
|
207 |
// for resolving xsd import
|
|
208 |
{false, true, xml_catalog, xsd_xmlSchema_import, null},
|
|
209 |
// for resolving xsd include
|
|
210 |
{false, true, xml_catalog, xsd_include_company, null}
|
|
211 |
};
|
|
212 |
}
|
|
213 |
|
|
214 |
|
|
215 |
/*
|
|
216 |
DataProvider: for testing Schema Validator
|
|
217 |
Data: source, resolver1, resolver2, catalog1, a catalog2
|
|
218 |
*/
|
|
219 |
@DataProvider(name = "data_ValidatorC")
|
|
220 |
Object[][] getDataValidator() {
|
|
221 |
DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
|
|
222 |
|
|
223 |
SAXSource ss = new SAXSource(new InputSource(xml_val_test));
|
|
224 |
ss.setSystemId(xml_val_test_id);
|
|
225 |
|
|
226 |
StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id);
|
|
227 |
StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id);
|
|
228 |
|
|
229 |
StreamSource source = new StreamSource(new File(xml_val_test));
|
|
230 |
|
|
231 |
return new Object[][]{
|
|
232 |
// use catalog
|
|
233 |
{false, false, true, ds, null, null, xml_catalog, null},
|
|
234 |
{false, false, true, ds, null, null, null, xml_catalog},
|
|
235 |
{false, false, true, ss, null, null, xml_catalog, null},
|
|
236 |
{false, false, true, ss, null, null, null, xml_catalog},
|
|
237 |
{false, false, true, stax, null, null, xml_catalog, null},
|
|
238 |
{false, false, true, stax1, null, null, null, xml_catalog},
|
|
239 |
{false, false, true, source, null, null, xml_catalog, null},
|
|
240 |
{false, false, true, source, null, null, null, xml_catalog},
|
|
241 |
};
|
|
242 |
}
|
|
243 |
|
|
244 |
/*
|
|
245 |
DataProvider: for testing XSL import and include
|
|
246 |
Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected
|
|
247 |
*/
|
|
248 |
@DataProvider(name = "data_XSLC")
|
|
249 |
Object[][] getDataXSLC() {
|
|
250 |
SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD)));
|
|
251 |
StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD));
|
|
252 |
|
|
253 |
SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString()));
|
|
254 |
StreamSource xmlDocSource = new StreamSource(new File(xml_doc));
|
|
255 |
return new Object[][]{
|
|
256 |
// for resolving DTD, import and include in xsl
|
|
257 |
{false, true, xml_catalog, xslSourceDTD, xmlSourceDTD, null, ""},
|
|
258 |
// for resolving reference by the document function
|
|
259 |
{false, true, xml_catalog, xslDocSource, xmlDocSource, null, "Resolved by a catalog"},
|
|
260 |
};
|
|
261 |
}
|
|
262 |
}
|