1 /* 2 * Copyright (c) 2015, 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 static catalog.CatalogTestUtils.CATALOG_PUBLIC; 27 import static catalog.CatalogTestUtils.CATALOG_SYSTEM; 28 import static catalog.CatalogTestUtils.CATALOG_URI; 29 import static catalog.CatalogTestUtils.catalogResolver; 30 import static catalog.CatalogTestUtils.catalogUriResolver; 31 import static catalog.ResolutionChecker.checkSysIdResolution; 32 import static catalog.ResolutionChecker.checkUriResolution; 33 34 import javax.xml.catalog.CatalogException; 35 import javax.xml.catalog.CatalogResolver; 36 import javax.xml.catalog.CatalogUriResolver; 37 38 import org.testng.annotations.DataProvider; 39 import org.testng.annotations.Test; 40 41 /* 42 * @test 43 * @bug 8077931 44 * @summary When catalog resolver loads catalog files, the current catalog file 45 * and the catalog files specified by the nextCatalog entries may not 46 * accessible. This case tests how does the resolver handle this issue. 47 * @compile ../../libs/catalog/CatalogTestUtils.java 48 * @compile ../../libs/catalog/ResolutionChecker.java 49 */ 50 public class LoadCatalogTest { 51 52 private static final String CATALOG_LOADCATALOGFILES = "loadCatalogFiles.xml"; 53 private static final String CATALOG_DUMMY = "dummy.xml"; 54 55 private static final String ID_ALICE = "http://remote/dtd/alice/docAlice.dtd"; 56 private static final String ID_DUMMY = "http://remote/dtd/doc.dtd"; 57 58 @Test(dataProvider = "entityResolver") 59 public void testMatchOnEntityResolver(CatalogResolver resolver) { 60 checkSysIdResolution(resolver, ID_ALICE, 61 "http://local/dtd/docAliceSys.dtd"); 62 } 63 64 @DataProvider(name = "entityResolver") 65 private Object[][] entityResolver() { 66 return new Object[][] { 67 // This EntityResolver loads multiple catalog files one by one. 68 // All of the files are available. 69 { catalogResolver(CATALOG_PUBLIC, CATALOG_URI, 70 CATALOG_SYSTEM) }, 71 72 // This EntityResolver loads multiple catalog files one by one, 73 // but the middle one isn't existing. 74 { catalogResolver(CATALOG_PUBLIC, CATALOG_DUMMY, 75 CATALOG_SYSTEM) } }; 76 } 77 78 @Test(dataProvider = "uriResolver") 79 public void testMatchOnUriResolver(CatalogUriResolver resolver) { 80 checkUriResolution(resolver, ID_ALICE, 81 "http://local/dtd/docAliceURI.dtd"); 82 } 83 84 @DataProvider(name = "uriResolver") 85 private Object[][] uriResolver() { 86 return new Object[][] { 87 // This URIResolver loads multiple catalog files one by one. 88 // All of the files are available. 89 { catalogUriResolver(CATALOG_PUBLIC, CATALOG_SYSTEM, 90 CATALOG_URI) }, 91 92 // This URIResolver loads multiple catalog files one by one, 93 // but the middle one isn't existing. 94 { catalogUriResolver(CATALOG_PUBLIC, CATALOG_DUMMY, 95 CATALOG_URI) } }; 96 } 97 98 @Test(dataProvider = "catalogName", 99 expectedExceptions = CatalogException.class) 100 public void testExceptionOnEntityResolver(String[] catalogName) { 101 catalogResolver(catalogName).resolveEntity(null, ID_DUMMY); 102 } 103 104 @Test(dataProvider = "catalogName", 105 expectedExceptions = CatalogException.class) 106 public void testExceptionOnUriResolver(String[] catalogName) { 107 catalogUriResolver(catalogName).resolve(ID_DUMMY, null); 108 } 109 110 @DataProvider(name = "catalogName") 111 private Object[][] catalogName() { 112 return new Object[][] { 113 // This catalog file set includes null catalog files. 114 { (String[]) null }, 115 116 // This catalog file set includes one catalog file, but this 117 // catalog defines a non-existing next catalog. 118 { new String[] { CATALOG_LOADCATALOGFILES } } }; 119 } 120 }