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 package catalog;
24
25 import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
26 import static jaxp.library.JAXPTestUtilities.getSystemProperty;
27 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
28
29 import java.io.FilePermission;
30 import java.io.IOException;
31 import java.nio.file.Paths;
32 import java.util.PropertyPermission;
33
34 import javax.xml.catalog.Catalog;
35 import javax.xml.catalog.CatalogException;
36 import javax.xml.catalog.CatalogFeatures;
37 import javax.xml.catalog.CatalogFeatures.Feature;
38 import javax.xml.catalog.CatalogManager;
39 import javax.xml.catalog.CatalogResolver;
40 import javax.xml.catalog.CatalogUriResolver;
41 import javax.xml.parsers.ParserConfigurationException;
42 import javax.xml.parsers.SAXParser;
43 import javax.xml.parsers.SAXParserFactory;
44 import javax.xml.transform.Source;
45
46 import jaxp.library.JAXPTestUtilities;
47
48 import org.testng.Assert;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.DataProvider;
51 import org.testng.annotations.Listeners;
52 import org.testng.annotations.Test;
53 import org.xml.sax.Attributes;
54 import org.xml.sax.ErrorHandler;
55 import org.xml.sax.InputSource;
56 import org.xml.sax.SAXException;
57 import org.xml.sax.XMLReader;
58 import org.xml.sax.ext.DefaultHandler2;
59
60 /*
61 * @test
62 * @bug 8081248 8144966 8146606 8146237 8151154 8150969 8151162 8152527 8154220
63 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
64 * @run testng/othervm -DrunSecMngr=true catalog.CatalogTest
65 * @run testng/othervm catalog.CatalogTest
66 * @summary Tests basic Catalog functions.
67 */
68 @Listeners({jaxp.library.FilePolicy.class})
69 public class CatalogTest {
70 static final String KEY_FILES = "javax.xml.catalog.files";
71
72 public String filepath;
73
74 /*
75 * Initializing fields
76 */
77 @BeforeClass
78 public void setUpClass() throws Exception {
79 String file1 = getClass().getResource("first_cat.xml").getFile();
80 if (getSystemProperty("os.name").contains("Windows")) {
81 filepath = file1.substring(1, file1.lastIndexOf("/") + 1);
82 } else {
83 filepath = file1.substring(0, file1.lastIndexOf("/") + 1);
84 }
85 }
86
87 /*
88 * @bug 8150187
89 * NPE is expected if the systemId is null. The specification for systemId
90 * is as follows:
91 * A system identifier is required on all external entities. XML
92 * requires a system identifier on all external entities, so this value is
93 * always specified.
94 */
95 @Test(expectedExceptions = NullPointerException.class)
96 public void sysIdCantBeNull() {
97 CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
98 InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null);
99 }
100
101 /*
102 * @bug 8156845
103 * Verifies that an URI reference with a urn:publicid is correctly resolved
104 * with an uri entry with a publicId.
105 *
106 * @param expectedFile is not used in this test, it's kept since we're
107 * copying the JCK test and its dataProvider. This test may be reused for
108 * other cases in that test.
109 */
110 @Test(dataProvider = "resolveUri")
111 public void testMatch1(String cFile, String href, String expectedFile, String expectedUri, String msg) {
112 String catalogFile = getClass().getResource(cFile).getFile();
113 CatalogUriResolver cur = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalogFile);
114 Source source = cur.resolve(href, null);
115 Assert.assertNotNull(source, "Source returned is null");
116 Assert.assertEquals(expectedUri, source.getSystemId(), msg);
117 }
118
119 /*
120 * @bug 8154220
121 * Verifies that the file input is validated properly. Valid input includes
122 * multiple file paths separated by semicolon.
123 */
124 @Test(dataProvider = "hierarchyOfCatFilesData")
125 public void hierarchyOfCatFiles2(String systemId, String expectedUri) {
126 String file1 = getClass().getResource("first_cat.xml").getFile();
127 String file2 = getClass().getResource("second_cat.xml").getFile();
128 String files = file1 + ";" + file2;
129
130 try {
131 setSystemProperty(KEY_FILES, files);
132 CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
133 String sysId = catalogResolver.resolveEntity(null, systemId).getSystemId();
258 try {
259 CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
260 String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId();
261 Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
262 } catch (Exception e) {
263 Assert.fail(e.getMessage());
264 }
265
266 }
267
268 /*
269 @bug 8146606
270 Verifies that the resulting systemId does not contain duplicate slashes
271 */
272 @Test
273 public void testRewriteUri() {
274 String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
275
276 try {
277
278 CatalogUriResolver resolver = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalog);
279 String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId();
280 Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
281 } catch (Exception e) {
282 Assert.fail(e.getMessage());
283 }
284 }
285
286 /*
287 @bug 8144966
288 Verifies that passing null as CatalogFeatures will result in a NPE.
289 */
290 @Test(expectedExceptions = NullPointerException.class)
291 public void testFeatureNull() {
292 CatalogResolver resolver = CatalogManager.catalogResolver(null, "");
293
294 }
295
296 /*
297 @bug 8144966
298 Verifies that passing null as the path will result in a NPE.
366 .with(Feature.PREFER, "public")
367 .with(Feature.DEFER, "true")
368 .with(Feature.RESOLVE, "ignore")
369 .build();
370
371 String test = "testInvalidCatalog";
372 try {
373 CatalogResolver resolver = CatalogManager.catalogResolver(f, "");
374 String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId();
375 System.out.println("testIgnoreInvalidCatalog: expected [null]");
376 System.out.println("testIgnoreInvalidCatalog: expected [null]");
377 System.out.println("actual [" + actualSystemId + "]");
378 Assert.assertEquals(actualSystemId, null);
379 } catch (Exception e) {
380 Assert.fail(e.getMessage());
381 }
382 }
383
384
385 /*
386 DataProvider: used to verify CatalogUriResolver's resolve function.
387 Data columns:
388 catalog, uri or publicId, expectedFile, expectedUri, msg
389
390 This DataProvider is copied from JCK ResolveTests' dataMatch1
391 */
392 @DataProvider(name = "resolveUri")
393 public Object[][] getDataForUriResolver() {
394 return new Object[][]{
395 {"uri.xml", "urn:publicid:-:Acme,+Inc.:DTD+Book+Version+1.0", null, "http://local/base/dtd/book.dtd", "Uri in publicId namespace is incorrectly unwrapped"},
396 };
397 }
398
399 /*
400 DataProvider: used to verify hierarchical catalogs. Refer to JCK test
401 hierarchyOfCatFiles2.
402 */
403 @DataProvider(name = "hierarchyOfCatFilesData")
404 public Object[][] getHierarchyOfCatFilesData() {
405 return new Object[][]{
406 {"http://www.oracle.com/sequence.dtd", "first.dtd"},
554 }
555
556 @Override
557 public void startElement(String uri, String localName, String qName, Attributes attributes)
558 throws SAXException {
559 textContent.delete(0, textContent.length());
560 try {
561 System.out.println("Element: " + uri + ":" + localName + " " + qName);
562 } catch (Exception e) {
563 throw new SAXException(e);
564 }
565
566 }
567
568 @Override
569 public void characters(char ch[], int start, int length) throws SAXException {
570 textContent.append(ch, start, length);
571 }
572 }
573 }
574
|
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 package catalog;
24
25 import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
26 import static jaxp.library.JAXPTestUtilities.getSystemProperty;
27 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
28
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.FilePermission;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.StringReader;
35 import java.io.StringWriter;
36 import java.nio.file.Paths;
37 import java.util.PropertyPermission;
38 import javax.xml.XMLConstants;
39 import javax.xml.catalog.Catalog;
40 import javax.xml.catalog.CatalogException;
41 import javax.xml.catalog.CatalogFeatures;
42 import javax.xml.catalog.CatalogFeatures.Feature;
43 import javax.xml.catalog.CatalogManager;
44 import javax.xml.catalog.CatalogResolver;
45 import javax.xml.parsers.ParserConfigurationException;
46 import javax.xml.parsers.SAXParser;
47 import javax.xml.parsers.SAXParserFactory;
48 import javax.xml.stream.XMLInputFactory;
49 import javax.xml.stream.XMLStreamConstants;
50 import javax.xml.stream.XMLStreamReader;
51 import javax.xml.transform.Source;
52 import javax.xml.transform.Transformer;
53 import javax.xml.transform.TransformerFactory;
54 import javax.xml.transform.sax.SAXSource;
55 import javax.xml.transform.stream.StreamResult;
56 import javax.xml.transform.stream.StreamSource;
57 import javax.xml.validation.Schema;
58 import javax.xml.validation.SchemaFactory;
59 import javax.xml.validation.Validator;
60 import jaxp.library.JAXPTestUtilities;
61
62 import org.testng.Assert;
63 import org.testng.annotations.BeforeClass;
64 import org.testng.annotations.DataProvider;
65 import org.testng.annotations.Listeners;
66 import org.testng.annotations.Test;
67 import org.xml.sax.Attributes;
68 import org.xml.sax.ErrorHandler;
69 import org.xml.sax.InputSource;
70 import org.xml.sax.SAXException;
71 import org.xml.sax.XMLReader;
72 import org.xml.sax.ext.DefaultHandler2;
73
74 /*
75 * @test
76 * @bug 8081248 8144966 8146606 8146237 8151154 8150969 8151162 8152527 8154220 8163232
77 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
78 * @run testng/othervm -DrunSecMngr=true catalog.CatalogTest
79 * @run testng/othervm catalog.CatalogTest
80 * @summary Tests basic Catalog functions.
81 */
82 @Listeners({jaxp.library.FilePolicy.class})
83 public class CatalogTest extends CatalogSupportBase {
84 static final String KEY_FILES = "javax.xml.catalog.files";
85
86
87 /*
88 * Initializing fields
89 */
90 @BeforeClass
91 public void setUpClass() throws Exception {
92 super.setUp();
93 }
94
95
96 /*
97 * @bug 8163232
98 * Verifies that the CatalogResolver supports the following XML Resolvers:
99 javax.xml.stream.XMLResolver
100 javax.xml.transform.URIResolver
101 org.w3c.dom.ls.LSResourceResolver
102 org.xml.sax.EntityResolver
103 *
104 * Plus, system and uri entries can equally be used.
105 */
106
107 /*
108 * Verifies the support for org.xml.sax.EntityResolver.
109 * Expected: the parser returns the expected string.
110 */
111 @Test(dataProvider = "supportXMLResolver")
112 public void supportEntityResolver(String catalogFile, String xml, String expected) throws Exception {
113 String xmlSource = getClass().getResource(xml).getFile();
114
115 CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
116 MyCatalogHandler handler = new MyCatalogHandler(cr, elementInSystem);
117 SAXParser parser = getSAXParser(false, true, null);
118 parser.parse(xmlSource, handler);
119
120 Assert.assertEquals(handler.getResult().trim(), expected);
121 }
122
123 /*
124 * Verifies the support for javax.xml.stream.XMLResolver.
125 * Expected: the parser returns the expected string.
126 */
127 @Test(dataProvider = "supportXMLResolver")
128 public void supportXMLResolver(String catalogFile, String xml, String expected) throws Exception {
129 String xmlSource = getClass().getResource(xml).getFile();
130
131 CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
132
133 XMLInputFactory xifactory = XMLInputFactory.newInstance();
134 xifactory.setProperty(XMLInputFactory.IS_COALESCING, true);
135 xifactory.setProperty(XMLInputFactory.RESOLVER, cr);
136 File file = new File(xmlSource);
137 String systemId = file.toURI().toString();
138 InputStream entityxml = new FileInputStream(file);
139 XMLStreamReader streamReader = xifactory.createXMLStreamReader(systemId, entityxml);
140 String result = null;
141 while (streamReader.hasNext()) {
142 int eventType = streamReader.next();
143 if (eventType == XMLStreamConstants.START_ELEMENT) {
144 eventType = streamReader.next();
145 if (eventType == XMLStreamConstants.CHARACTERS) {
146 result = streamReader.getText();
147 }
148 }
149 }
150 System.out.println(": expected [" + expected + "] <> actual [" + result.trim() + "]");
151
152 Assert.assertEquals(result.trim(), expected);
153 }
154
155 /*
156 * Verifies the support for org.w3c.dom.ls.LSResourceResolver by ShemaFactory.
157 * Success: parsing goes through with no error
158 * Fail: throws Exception if references are not resolved (by the CatalogResolver)
159 */
160 @Test(dataProvider = "supportLSResourceResolver")
161 public void supportLSResourceResolver(String catalogFile, Source schemaSource) throws SAXException {
162
163 CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
164
165 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
166 factory.setResourceResolver(cr);
167 Schema schema = factory.newSchema(schemaSource);
168
169 }
170
171 /*
172 * Verifies the support for org.w3c.dom.ls.LSResourceResolver by Validator.
173 * Success: parsing goes through with no error
174 * Fail: throws Exception if references are not resolved (by the CatalogResolver)
175 */
176 @Test(dataProvider = "supportLSResourceResolver1")
177 public void supportLSResourceResolver1(String catalogFile, Source source) throws Exception {
178
179 CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
180
181 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
182 Validator validator = factory.newSchema().newValidator();
183 validator.setResourceResolver(cr);
184 validator.validate(source);
185 }
186
187 /*
188 * Verifies the support for javax.xml.transform.URIResolver.
189 * Success: parsing goes through with no error
190 * Fail: throws Exception if references are not resolved (by the CatalogResolver)
191 */
192 @Test(dataProvider = "supportURIResolver")
193 public void supportURIResolver(String catalogFile, Source xsl, Source xml, String expected) throws Exception {
194
195 CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
196
197 TransformerFactory factory = TransformerFactory.newInstance();
198 factory.setURIResolver(cr);
199 Transformer transformer = factory.newTransformer(xsl);
200 StringWriter out = new StringWriter();
201 transformer.transform(xml, new StreamResult(out));
202 if (expected != null) {
203 Assert.assertTrue(out.toString().contains(expected), "supportURIResolver");
204 }
205 }
206
207 /*
208 DataProvider: used to verify the support of XML Resolvers.
209 Data columns:
210 catalog filepath, xml source file, expected result
211 */
212 @DataProvider(name = "supportXMLResolver")
213 public Object[][] supportXMLResolver() {
214 String catalogFile = getClass().getResource("catalog.xml").getFile();
215 String catalogFileUri = getClass().getResource("catalog_uri.xml").getFile();
216
217 return new Object[][]{
218 {catalogFile, "system.xml", "Test system entry"},
219 {catalogFile, "rewritesystem.xml", "Test rewritesystem entry"},
220 {catalogFile, "rewritesystem1.xml", "Test rewritesystem entry"},
221 {catalogFile, "systemsuffix.xml", "Test systemsuffix entry"},
222 {catalogFile, "delegatesystem.xml", "Test delegatesystem entry"},
223 {catalogFile, "public.xml", "Test public entry"},
224 {catalogFile, "delegatepublic.xml", "Test delegatepublic entry"},
225 // using uri entries
226 {catalogFileUri, "system.xml", "Test system entry"},
227 {catalogFileUri, "rewritesystem.xml", "Test rewritesystem entry"},
228 {catalogFileUri, "rewritesystem1.xml", "Test rewritesystem entry"},
229 {catalogFileUri, "systemsuffix.xml", "Test systemsuffix entry"},
230 {catalogFileUri, "delegateuri.xml", "Test delegateuri entry"},
231 {catalogFileUri, "public.xml", "Test public entry"},
232 };
233 }
234
235 /*
236 DataProvider: used to verify the support of LSResourceResolver by SchemaFactory.
237 Data columns:
238 catalog filepath, schema source file
239 */
240 @DataProvider(name = "supportLSResourceResolver")
241 public Object[][] supportLSResourceResolver() {
242 String catalogFile = getClass().getResource("CatalogSupport.xml").getFile();
243 String catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").getFile();
244
245 /*
246 * XMLSchema.xsd has a reference to XMLSchema.dtd which in turn refers to
247 * datatypes.dtd
248 */
249 return new Object[][]{
250 {catalogFile, new StreamSource(new StringReader(xsd_xmlSchema))},
251 {catalogFile, new StreamSource(new StringReader(xsd_xmlSchema_import))},
252 {catalogFile, new StreamSource(new StringReader(xsd_include_company))},
253 {catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema))},
254 {catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema_import))},
255 {catalogFileUri, new StreamSource(new StringReader(xsd_include_company))},
256 };
257 }
258
259 /*
260 DataProvider: used to verify the support of LSResourceResolver by Validator.
261 Data columns:
262 catalog filepath, source file
263 */
264 @DataProvider(name = "supportLSResourceResolver1")
265 public Object[][] supportLSResourceResolver1() {
266 String catalogFile = getClass().getResource("CatalogSupport.xml").getFile();
267 String catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").getFile();
268
269 /*
270 * val_test.xml has a reference to system.dtd and val_test.xsd
271 */
272 SAXSource ss = new SAXSource(new InputSource(xml_val_test));
273 ss.setSystemId(xml_val_test_id);
274
275 return new Object[][]{
276 {catalogFile, ss},
277 {catalogFileUri, ss},
278 };
279 }
280
281
282 /*
283 DataProvider: used to verify the support of LSResourceResolver by Validator.
284 Data columns:
285 catalog filepath, xsl source, xml source file
286 */
287 @DataProvider(name = "supportURIResolver")
288 public Object[][] supportURIResolver() {
289 String catalogFile = getClass().getResource("CatalogSupport.xml").getFile();
290 String catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").getFile();
291 SAXSource xslSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString()));
292
293 /*
294 * val_test.xml has a reference to system.dtd and val_test.xsd
295 */
296 SAXSource ss = new SAXSource(new InputSource(xml_val_test));
297 ss.setSystemId(xml_val_test_id);
298
299 return new Object[][]{
300 {catalogFile, new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())),
301 new StreamSource(new File(xml_doc)), "Resolved by a catalog"},
302 {catalogFileUri, new SAXSource(new InputSource(new StringReader(xsl_include))),
303 new StreamSource(new StringReader(xml_xsl)), null},
304 };
305 }
306
307 /*
308 * @bug 8150187
309 * NPE is expected if the systemId is null. The specification for systemId
310 * is as follows:
311 * A system identifier is required on all external entities. XML
312 * requires a system identifier on all external entities, so this value is
313 * always specified.
314 */
315 @Test(expectedExceptions = NullPointerException.class)
316 public void sysIdCantBeNull() {
317 CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
318 InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null);
319 }
320
321 /*
322 * @bug 8156845
323 * Verifies that an URI reference with a urn:publicid is correctly resolved
324 * with an uri entry with a publicId.
325 *
326 * @param expectedFile is not used in this test, it's kept since we're
327 * copying the JCK test and its dataProvider. This test may be reused for
328 * other cases in that test.
329 */
330 @Test(dataProvider = "resolveUri")
331 public void testMatch1(String cFile, String href, String expectedFile, String expectedUri, String msg) {
332 String catalogFile = getClass().getResource(cFile).getFile();
333 CatalogResolver cur = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
334 Source source = cur.resolve(href, null);
335 Assert.assertNotNull(source, "Source returned is null");
336 Assert.assertEquals(expectedUri, source.getSystemId(), msg);
337 }
338
339 /*
340 * @bug 8154220
341 * Verifies that the file input is validated properly. Valid input includes
342 * multiple file paths separated by semicolon.
343 */
344 @Test(dataProvider = "hierarchyOfCatFilesData")
345 public void hierarchyOfCatFiles2(String systemId, String expectedUri) {
346 String file1 = getClass().getResource("first_cat.xml").getFile();
347 String file2 = getClass().getResource("second_cat.xml").getFile();
348 String files = file1 + ";" + file2;
349
350 try {
351 setSystemProperty(KEY_FILES, files);
352 CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
353 String sysId = catalogResolver.resolveEntity(null, systemId).getSystemId();
478 try {
479 CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
480 String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId();
481 Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
482 } catch (Exception e) {
483 Assert.fail(e.getMessage());
484 }
485
486 }
487
488 /*
489 @bug 8146606
490 Verifies that the resulting systemId does not contain duplicate slashes
491 */
492 @Test
493 public void testRewriteUri() {
494 String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
495
496 try {
497
498 CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
499 String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId();
500 Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
501 } catch (Exception e) {
502 Assert.fail(e.getMessage());
503 }
504 }
505
506 /*
507 @bug 8144966
508 Verifies that passing null as CatalogFeatures will result in a NPE.
509 */
510 @Test(expectedExceptions = NullPointerException.class)
511 public void testFeatureNull() {
512 CatalogResolver resolver = CatalogManager.catalogResolver(null, "");
513
514 }
515
516 /*
517 @bug 8144966
518 Verifies that passing null as the path will result in a NPE.
586 .with(Feature.PREFER, "public")
587 .with(Feature.DEFER, "true")
588 .with(Feature.RESOLVE, "ignore")
589 .build();
590
591 String test = "testInvalidCatalog";
592 try {
593 CatalogResolver resolver = CatalogManager.catalogResolver(f, "");
594 String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId();
595 System.out.println("testIgnoreInvalidCatalog: expected [null]");
596 System.out.println("testIgnoreInvalidCatalog: expected [null]");
597 System.out.println("actual [" + actualSystemId + "]");
598 Assert.assertEquals(actualSystemId, null);
599 } catch (Exception e) {
600 Assert.fail(e.getMessage());
601 }
602 }
603
604
605 /*
606 DataProvider: used to verify CatalogResolver's resolve function.
607 Data columns:
608 catalog, uri or publicId, expectedFile, expectedUri, msg
609
610 This DataProvider is copied from JCK ResolveTests' dataMatch1
611 */
612 @DataProvider(name = "resolveUri")
613 public Object[][] getDataForUriResolver() {
614 return new Object[][]{
615 {"uri.xml", "urn:publicid:-:Acme,+Inc.:DTD+Book+Version+1.0", null, "http://local/base/dtd/book.dtd", "Uri in publicId namespace is incorrectly unwrapped"},
616 };
617 }
618
619 /*
620 DataProvider: used to verify hierarchical catalogs. Refer to JCK test
621 hierarchyOfCatFiles2.
622 */
623 @DataProvider(name = "hierarchyOfCatFilesData")
624 public Object[][] getHierarchyOfCatFilesData() {
625 return new Object[][]{
626 {"http://www.oracle.com/sequence.dtd", "first.dtd"},
774 }
775
776 @Override
777 public void startElement(String uri, String localName, String qName, Attributes attributes)
778 throws SAXException {
779 textContent.delete(0, textContent.length());
780 try {
781 System.out.println("Element: " + uri + ":" + localName + " " + qName);
782 } catch (Exception e) {
783 throw new SAXException(e);
784 }
785
786 }
787
788 @Override
789 public void characters(char ch[], int start, int length) throws SAXException {
790 textContent.append(ch, start, length);
791 }
792 }
793 }
|