author | joehw |
Tue, 12 Apr 2016 14:44:23 -0700 | |
changeset 37382 | c7d898d8da12 |
parent 36984 | 4d76e25cb8d3 |
child 37384 | 04a4a89d81b9 |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33542 | 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 |
package catalog; |
|
24 |
||
25 |
import java.io.IOException; |
|
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
26 |
import javax.xml.catalog.Catalog; |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
27 |
import javax.xml.catalog.CatalogException; |
33542 | 28 |
import javax.xml.catalog.CatalogFeatures; |
29 |
import javax.xml.catalog.CatalogFeatures.Feature; |
|
30 |
import javax.xml.catalog.CatalogManager; |
|
31 |
import javax.xml.catalog.CatalogResolver; |
|
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
32 |
import javax.xml.catalog.CatalogUriResolver; |
33542 | 33 |
import javax.xml.parsers.ParserConfigurationException; |
34 |
import javax.xml.parsers.SAXParser; |
|
35 |
import javax.xml.parsers.SAXParserFactory; |
|
36 |
import org.testng.Assert; |
|
37 |
import org.testng.annotations.DataProvider; |
|
38 |
import org.testng.annotations.Test; |
|
39 |
import org.xml.sax.Attributes; |
|
40 |
import org.xml.sax.ErrorHandler; |
|
41 |
import org.xml.sax.SAXException; |
|
42 |
import org.xml.sax.XMLReader; |
|
43 |
import org.xml.sax.ext.DefaultHandler2; |
|
44 |
||
45 |
/* |
|
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
46 |
* @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162 |
33542 | 47 |
* @summary Tests basic Catalog functions. |
48 |
*/ |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
49 |
public class CatalogTest { |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
50 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
51 |
* @bug 8151162 |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
52 |
* Verifies that the Catalog matches specified publicId or systemId and returns |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
53 |
* results as expected. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
54 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
55 |
@Test(dataProvider = "matchWithPrefer") |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
56 |
public void matchWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
57 |
String catalogFile = getClass().getResource(cfile).getFile(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
58 |
Catalog c = CatalogManager.catalog(CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(), catalogFile); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
59 |
String result; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
60 |
if (publicId != null && publicId.length() > 0) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
61 |
result = c.matchPublic(publicId); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
62 |
} else { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
63 |
result = c.matchSystem(systemId); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
64 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
65 |
Assert.assertEquals(expected, result); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
66 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
67 |
|
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
68 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
69 |
* @bug 8151162 |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
70 |
* Verifies that the CatalogResolver resolves specified publicId or systemId |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
71 |
* in accordance with the prefer setting. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
72 |
* prefer "system": resolves with a system entry. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
73 |
* Exception: use the public entry when the catalog contains |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
74 |
* only public entry and only publicId is specified. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
75 |
* prefer "public": attempts to resolve with a system entry; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
76 |
* attempts to resolve with a public entry if no matching |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
77 |
* system entry is found. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
78 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
79 |
@Test(dataProvider = "resolveWithPrefer") |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
80 |
public void resolveWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
81 |
String catalogFile = getClass().getResource(cfile).getFile(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
82 |
CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).with(CatalogFeatures.Feature.RESOLVE, "ignore").build(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
83 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
84 |
String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
85 |
Assert.assertEquals(expected, result); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
86 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
87 |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
88 |
/** |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
89 |
* @bug 8150969 |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
90 |
* Verifies that the defer attribute set in the catalog file takes precedence |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
91 |
* over other settings, in which case, whether next and delegate Catalogs will |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
92 |
* be loaded is determined by the defer attribute. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
93 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
94 |
@Test(dataProvider = "invalidAltCatalogs", expectedExceptions = CatalogException.class) |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
95 |
public void testDeferAltCatalogs(String file) { |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
96 |
String catalogFile = getClass().getResource(file).getFile(); |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
97 |
CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "true").build(); |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
98 |
/* |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
99 |
Since the defer attribute is set to false in the specified catalog file, |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
100 |
the parent catalog will try to load the alt catalog, which will fail |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
101 |
since it points to an invalid catalog. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
102 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
103 |
Catalog catalog = CatalogManager.catalog(features, catalogFile); |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
104 |
} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
105 |
|
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
106 |
/** |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
107 |
* @bug 8151154 |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
108 |
* Verifies that the CatalogFeatures' builder throws IllegalArgumentException |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
109 |
* on invalid file inputs. |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
110 |
* @param file the file path |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
111 |
*/ |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
112 |
@Test(dataProvider = "invalidPaths", expectedExceptions = IllegalArgumentException.class) |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
113 |
public void testFileInput(String file) { |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
114 |
CatalogFeatures features = CatalogFeatures.builder() |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
115 |
.with(CatalogFeatures.Feature.FILES, file) |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
116 |
.build(); |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
117 |
} |
33542 | 118 |
|
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
119 |
/** |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
120 |
* @bug 8146237 |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
121 |
* PREFER from Features API taking precedence over catalog file |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
122 |
*/ |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
123 |
@Test |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
124 |
public void testJDK8146237() { |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
125 |
String catalogFile = getClass().getResource("JDK8146237_catalog.xml").getFile(); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
126 |
|
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
127 |
try { |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
128 |
CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, "system").build(); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
129 |
Catalog catalog = CatalogManager.catalog(features, catalogFile); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
130 |
CatalogResolver catalogResolver = CatalogManager.catalogResolver(catalog); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
131 |
String actualSystemId = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", "http://www.oracle.com/alt1sys.dtd").getSystemId(); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
132 |
Assert.assertTrue(actualSystemId.contains("dummy.dtd"), "Resulting id should contain dummy.dtd, indicating a match by publicId"); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
133 |
|
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
134 |
} catch (Exception e) { |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
135 |
Assert.fail(e.getMessage()); |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
136 |
} |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
137 |
} |
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
138 |
|
33542 | 139 |
/* |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
140 |
@bug 8146606 |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
141 |
Verifies that the resulting systemId does not contain duplicate slashes |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
142 |
*/ |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
143 |
@Test |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
144 |
public void testRewriteSystem() { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
145 |
String catalog = getClass().getResource("rewriteCatalog.xml").getFile(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
146 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
147 |
try { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
148 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
149 |
String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
150 |
Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes"); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
151 |
} catch (Exception e) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
152 |
Assert.fail(e.getMessage()); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
153 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
154 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
155 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
156 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
157 |
/* |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
158 |
@bug 8146606 |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
159 |
Verifies that the resulting systemId does not contain duplicate slashes |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
160 |
*/ |
36029
a847c5a7e22d
8146237: PREFER from Features API taking precedence over catalog file
joehw
parents:
34985
diff
changeset
|
161 |
@Test |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
162 |
public void testRewriteUri() { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
163 |
String catalog = getClass().getResource("rewriteCatalog.xml").getFile(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
164 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
165 |
try { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
166 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
167 |
CatalogUriResolver resolver = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalog); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
168 |
String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId(); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
169 |
Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes"); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
170 |
} catch (Exception e) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
171 |
Assert.fail(e.getMessage()); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
172 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
173 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
174 |
|
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
34984
diff
changeset
|
175 |
/* |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
176 |
@bug 8144966 |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
177 |
Verifies that passing null as CatalogFeatures will result in a NPE. |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
178 |
*/ |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
179 |
@Test(expectedExceptions = NullPointerException.class) |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
180 |
public void testFeatureNull() { |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
181 |
CatalogResolver resolver = CatalogManager.catalogResolver(null, ""); |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
182 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
183 |
} |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
184 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
185 |
/* |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
186 |
@bug 8144966 |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
187 |
Verifies that passing null as the path will result in a NPE. |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
188 |
*/ |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
189 |
@Test(expectedExceptions = NullPointerException.class) |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
190 |
public void testPathNull() { |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
191 |
String path = null; |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
192 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), path); |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
193 |
} |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
194 |
|
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
195 |
/* |
33542 | 196 |
Tests basic catalog feature by using a CatalogResolver instance to |
197 |
resolve a DTD reference to a locally specified DTD file. If the resolution |
|
198 |
is successful, the Handler shall return the value of the entity reference |
|
199 |
that matches the expected value. |
|
200 |
*/ |
|
201 |
@Test(dataProvider = "catalog") |
|
202 |
public void testCatalogResolver(String test, String expected, String catalogFile, String xml, SAXParser saxParser) { |
|
203 |
String catalog = null; |
|
204 |
if (catalogFile != null) { |
|
205 |
catalog = getClass().getResource(catalogFile).getFile(); |
|
206 |
} |
|
207 |
String url = getClass().getResource(xml).getFile(); |
|
208 |
try { |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
209 |
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
33542 | 210 |
XMLReader reader = saxParser.getXMLReader(); |
211 |
reader.setEntityResolver(cr); |
|
212 |
MyHandler handler = new MyHandler(saxParser); |
|
213 |
reader.setContentHandler(handler); |
|
214 |
reader.parse(url); |
|
215 |
System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]"); |
|
216 |
Assert.assertEquals(handler.getResult(), expected); |
|
217 |
} catch (SAXException | IOException e) { |
|
218 |
Assert.fail(e.getMessage()); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
/* |
|
223 |
Verifies that when there's no match, in this case only an invalid |
|
224 |
catalog is provided, the resolver will throw an exception by default. |
|
225 |
*/ |
|
226 |
@Test |
|
227 |
public void testInvalidCatalog() { |
|
228 |
String catalog = getClass().getResource("catalog_invalid.xml").getFile(); |
|
229 |
||
230 |
String test = "testInvalidCatalog"; |
|
231 |
try { |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
232 |
CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); |
33542 | 233 |
String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId(); |
234 |
} catch (Exception e) { |
|
235 |
String msg = e.getMessage(); |
|
236 |
if (msg != null) { |
|
237 |
if (msg.contains("No match found for publicId")) { |
|
238 |
Assert.assertEquals(msg, "No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'."); |
|
239 |
System.out.println(test + ": expected [No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'.]"); |
|
240 |
System.out.println("actual [" + msg + "]"); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
/* |
|
247 |
Verifies that if resolve is "ignore", an empty InputSource will be returned |
|
248 |
when there's no match. The systemId is then null. |
|
249 |
*/ |
|
250 |
@Test |
|
251 |
public void testIgnoreInvalidCatalog() { |
|
252 |
String catalog = getClass().getResource("catalog_invalid.xml").getFile(); |
|
253 |
CatalogFeatures f = CatalogFeatures.builder() |
|
254 |
.with(Feature.FILES, catalog) |
|
255 |
.with(Feature.PREFER, "public") |
|
256 |
.with(Feature.DEFER, "true") |
|
257 |
.with(Feature.RESOLVE, "ignore") |
|
258 |
.build(); |
|
259 |
||
260 |
String test = "testInvalidCatalog"; |
|
261 |
try { |
|
262 |
CatalogResolver resolver = CatalogManager.catalogResolver(f, ""); |
|
263 |
String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId(); |
|
264 |
System.out.println("testIgnoreInvalidCatalog: expected [null]"); |
|
265 |
System.out.println("testIgnoreInvalidCatalog: expected [null]"); |
|
266 |
System.out.println("actual [" + actualSystemId + "]"); |
|
267 |
Assert.assertEquals(actualSystemId, null); |
|
268 |
} catch (Exception e) { |
|
269 |
Assert.fail(e.getMessage()); |
|
270 |
} |
|
271 |
} |
|
272 |
||
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
273 |
static String id = "http://openjdk.java.net/xml/catalog/dtd/system.dtd"; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
274 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
275 |
DataProvider: used to verify how prefer settings affect the result of the |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
276 |
Catalog's matching operation. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
277 |
Data columns: |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
278 |
prefer, catalog, publicId, systemId, expected result |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
279 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
280 |
@DataProvider(name = "matchWithPrefer") |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
281 |
Object[][] getDataForMatch() { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
282 |
return new Object[][]{ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
283 |
{"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
284 |
{"public", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
285 |
{"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
286 |
{"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
287 |
{"system", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
288 |
{"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
289 |
{"public", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
290 |
{"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
291 |
{"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
292 |
{"system", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
293 |
{"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
294 |
{"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
295 |
}; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
296 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
297 |
|
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
298 |
/* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
299 |
DataProvider: used to verify how prefer settings affect the result of the |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
300 |
CatalogResolver's resolution operation. |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
301 |
Data columns: |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
302 |
prefer, catalog, publicId, systemId, expected result |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
303 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
304 |
@DataProvider(name = "resolveWithPrefer") |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
305 |
Object[][] getDataForResolve() { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
306 |
return new Object[][]{ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
307 |
{"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
308 |
{"system", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
309 |
{"system", "pubOnly.xml", id, id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
310 |
{"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
311 |
{"public", "pubOnly.xml", "", id, null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
312 |
{"public", "pubOnly.xml", id, id, "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
313 |
{"system", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
314 |
{"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
315 |
{"system", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
316 |
{"public", "sysOnly.xml", id, "", null}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
317 |
{"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
318 |
{"public", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
319 |
{"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
320 |
{"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
321 |
{"system", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
322 |
{"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
323 |
{"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
324 |
{"public", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
325 |
}; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36984
diff
changeset
|
326 |
} |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
327 |
/* |
36984
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
328 |
DataProvider: catalogs that contain invalid next or delegate catalogs. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
329 |
The defer attribute is set to false. |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
330 |
*/ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
331 |
@DataProvider(name = "invalidAltCatalogs") |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
332 |
Object[][] getCatalogs() { |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
333 |
return new Object[][]{ |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
334 |
{"defer_false_2.xml"}, |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
335 |
{"defer_del_false.xml"} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
336 |
}; |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
337 |
} |
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
338 |
|
4d76e25cb8d3
8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents:
36700
diff
changeset
|
339 |
/* |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
340 |
DataProvider: for testing the verification of file paths by |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
341 |
the CatalogFeatures builder |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
342 |
*/ |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
343 |
@DataProvider(name = "invalidPaths") |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
344 |
Object[][] getFiles() { |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
345 |
return new Object[][]{ |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
346 |
{null}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
347 |
{""}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
348 |
{"file:a/b\\c"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
349 |
{"file:/../../.."}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
350 |
{"c:/te:t"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
351 |
{"c:/te?t"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
352 |
{"c/te*t"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
353 |
{"in|valid.txt"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
354 |
{"shema:invalid.txt"}, |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
355 |
}; |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
36029
diff
changeset
|
356 |
} |
33542 | 357 |
|
358 |
/* |
|
359 |
DataProvider: provides test name, expected string, the catalog, and XML |
|
360 |
document. |
|
361 |
*/ |
|
362 |
@DataProvider(name = "catalog") |
|
363 |
Object[][] getCatalog() { |
|
364 |
return new Object[][]{ |
|
365 |
{"testSystem", "Test system entry", "catalog.xml", "system.xml", getParser()}, |
|
366 |
{"testRewriteSystem", "Test rewritesystem entry", "catalog.xml", "rewritesystem.xml", getParser()}, |
|
367 |
{"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()}, |
|
368 |
{"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()}, |
|
369 |
{"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()}, |
|
370 |
{"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()}, |
|
371 |
{"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()}, |
|
372 |
}; |
|
373 |
} |
|
374 |
||
375 |
SAXParser getParser() { |
|
376 |
SAXParser saxParser = null; |
|
377 |
try { |
|
378 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
|
379 |
factory.setNamespaceAware(true); |
|
380 |
saxParser = factory.newSAXParser(); |
|
381 |
} catch (ParserConfigurationException | SAXException e) { |
|
382 |
} |
|
383 |
||
384 |
return saxParser; |
|
385 |
} |
|
386 |
||
387 |
||
388 |
/** |
|
389 |
* SAX handler |
|
390 |
*/ |
|
391 |
public class MyHandler extends DefaultHandler2 implements ErrorHandler { |
|
392 |
||
393 |
StringBuilder textContent = new StringBuilder(); |
|
394 |
SAXParser saxParser; |
|
395 |
||
396 |
MyHandler(SAXParser saxParser) { |
|
397 |
textContent.setLength(0); |
|
398 |
this.saxParser = saxParser; |
|
399 |
} |
|
400 |
||
401 |
String getResult() { |
|
402 |
return textContent.toString(); |
|
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
|
407 |
textContent.delete(0, textContent.length()); |
|
408 |
try { |
|
409 |
System.out.println("Element: " + uri + ":" + localName + " " + qName); |
|
410 |
} catch (Exception e) { |
|
411 |
throw new SAXException(e); |
|
412 |
} |
|
413 |
||
414 |
} |
|
415 |
||
416 |
@Override |
|
417 |
public void characters(char ch[], int start, int length) throws SAXException { |
|
418 |
textContent.append(ch, start, length); |
|
419 |
} |
|
420 |
} |
|
421 |
} |