41 import org.xml.sax.SAXException; |
41 import org.xml.sax.SAXException; |
42 import org.xml.sax.XMLReader; |
42 import org.xml.sax.XMLReader; |
43 import org.xml.sax.ext.DefaultHandler2; |
43 import org.xml.sax.ext.DefaultHandler2; |
44 |
44 |
45 /* |
45 /* |
46 * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969 |
46 * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162 |
47 * @summary Tests basic Catalog functions. |
47 * @summary Tests basic Catalog functions. |
48 */ |
48 */ |
49 public class CatalogTest { |
49 public class CatalogTest { |
|
50 /* |
|
51 * @bug 8151162 |
|
52 * Verifies that the Catalog matches specified publicId or systemId and returns |
|
53 * results as expected. |
|
54 */ |
|
55 @Test(dataProvider = "matchWithPrefer") |
|
56 public void matchWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) { |
|
57 String catalogFile = getClass().getResource(cfile).getFile(); |
|
58 Catalog c = CatalogManager.catalog(CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(), catalogFile); |
|
59 String result; |
|
60 if (publicId != null && publicId.length() > 0) { |
|
61 result = c.matchPublic(publicId); |
|
62 } else { |
|
63 result = c.matchSystem(systemId); |
|
64 } |
|
65 Assert.assertEquals(expected, result); |
|
66 } |
|
67 |
|
68 /* |
|
69 * @bug 8151162 |
|
70 * Verifies that the CatalogResolver resolves specified publicId or systemId |
|
71 * in accordance with the prefer setting. |
|
72 * prefer "system": resolves with a system entry. |
|
73 * Exception: use the public entry when the catalog contains |
|
74 * only public entry and only publicId is specified. |
|
75 * prefer "public": attempts to resolve with a system entry; |
|
76 * attempts to resolve with a public entry if no matching |
|
77 * system entry is found. |
|
78 */ |
|
79 @Test(dataProvider = "resolveWithPrefer") |
|
80 public void resolveWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) { |
|
81 String catalogFile = getClass().getResource(cfile).getFile(); |
|
82 CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).with(CatalogFeatures.Feature.RESOLVE, "ignore").build(); |
|
83 CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile); |
|
84 String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId(); |
|
85 Assert.assertEquals(expected, result); |
|
86 } |
|
87 |
50 /** |
88 /** |
51 * @bug 8150969 |
89 * @bug 8150969 |
52 * Verifies that the defer attribute set in the catalog file takes precedence |
90 * Verifies that the defer attribute set in the catalog file takes precedence |
53 * over other settings, in which case, whether next and delegate Catalogs will |
91 * over other settings, in which case, whether next and delegate Catalogs will |
54 * be loaded is determined by the defer attribute. |
92 * be loaded is determined by the defer attribute. |
230 } catch (Exception e) { |
268 } catch (Exception e) { |
231 Assert.fail(e.getMessage()); |
269 Assert.fail(e.getMessage()); |
232 } |
270 } |
233 } |
271 } |
234 |
272 |
|
273 static String id = "http://openjdk.java.net/xml/catalog/dtd/system.dtd"; |
|
274 /* |
|
275 DataProvider: used to verify how prefer settings affect the result of the |
|
276 Catalog's matching operation. |
|
277 Data columns: |
|
278 prefer, catalog, publicId, systemId, expected result |
|
279 */ |
|
280 @DataProvider(name = "matchWithPrefer") |
|
281 Object[][] getDataForMatch() { |
|
282 return new Object[][]{ |
|
283 {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
284 {"public", "sysOnly.xml", id, "", null}, |
|
285 {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
286 {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
287 {"system", "sysOnly.xml", id, "", null}, |
|
288 {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
289 {"public", "pubOnly.xml", "", id, null}, |
|
290 {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
291 {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
292 {"system", "pubOnly.xml", "", id, null}, |
|
293 {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
294 {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
295 }; |
|
296 } |
|
297 |
|
298 /* |
|
299 DataProvider: used to verify how prefer settings affect the result of the |
|
300 CatalogResolver's resolution operation. |
|
301 Data columns: |
|
302 prefer, catalog, publicId, systemId, expected result |
|
303 */ |
|
304 @DataProvider(name = "resolveWithPrefer") |
|
305 Object[][] getDataForResolve() { |
|
306 return new Object[][]{ |
|
307 {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
308 {"system", "pubOnly.xml", "", id, null}, |
|
309 {"system", "pubOnly.xml", id, id, null}, |
|
310 {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
311 {"public", "pubOnly.xml", "", id, null}, |
|
312 {"public", "pubOnly.xml", id, id, "http://local/base/dtd/public.dtd"}, |
|
313 {"system", "sysOnly.xml", id, "", null}, |
|
314 {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
315 {"system", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
|
316 {"public", "sysOnly.xml", id, "", null}, |
|
317 {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
318 {"public", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"}, |
|
319 {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
320 {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
321 {"system", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
|
322 {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"}, |
|
323 {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"}, |
|
324 {"public", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"}, |
|
325 }; |
|
326 } |
235 /* |
327 /* |
236 DataProvider: catalogs that contain invalid next or delegate catalogs. |
328 DataProvider: catalogs that contain invalid next or delegate catalogs. |
237 The defer attribute is set to false. |
329 The defer attribute is set to false. |
238 */ |
330 */ |
239 @DataProvider(name = "invalidAltCatalogs") |
331 @DataProvider(name = "invalidAltCatalogs") |