1 /* 2 * Copyright (c) 2015, 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 static catalog.CatalogTestUtils.catalogResolver; 27 import static catalog.CatalogTestUtils.catalogUriResolver; 28 import static catalog.ResolutionChecker.checkPubIdResolution; 29 import static catalog.ResolutionChecker.checkSysIdResolution; 30 import static catalog.ResolutionChecker.checkUriResolution; 31 32 import javax.xml.catalog.CatalogResolver; 33 import javax.xml.catalog.CatalogUriResolver; 34 35 import org.testng.annotations.DataProvider; 36 import org.testng.annotations.Listeners; 37 import org.testng.annotations.Test; 38 39 /* 40 * @test 41 * @bug 8077931 42 * @library /javax/xml/jaxp/libs 43 * @run testng/othervm -DrunSecMngr=true catalog.NextCatalogTest 44 * @run testng/othervm catalog.NextCatalogTest 45 * @summary Get matched URIs from system, public and uri entries respectively, 46 * but some of the entries are defined in none-current catalog files. 47 */ 48 @Listeners({jaxp.library.FilePolicy.class}) 49 public class NextCatalogTest { 50 51 private static final String CATALOG_NEXTCATALOGLEFT 52 = "nextCatalog-left.xml"; 53 private static final String CATALOG_NEXTCATALOGRIGHT 54 = "nextCatalog-right.xml"; 55 56 @Test(dataProvider = "systemId-matchedUri") 57 public void testNextCatalogOnSysId(String sytemId, String matchedUri) { 58 checkSysIdResolution(createEntityResolver(), sytemId, matchedUri); 59 } 60 61 @DataProvider(name = "systemId-matchedUri") 62 public Object[][] dataOnSysId() { 63 return new Object[][] { 64 // This matched URI of the specified system id is defined in a 65 // next catalog file. 66 { "http://remote/dtd/sys/docAlice.dtd", 67 "http://local/base/dtd/docAliceNextLeftSys.dtd" }, 68 69 // There are two matches of the specified system id. One is in 70 // the current catalog file, and the other is in a next catalog 71 // file. But finally, the returned matched URI is the one in the 72 // current catalog file. 73 { "http://remote/dtd/sys/docBob.dtd", 74 "http://local/base/dtd/docBobLeftSys.dtd" }, 75 76 // The matched URI of the specified system id is defined in a 77 // two-level next catalog file. 78 { "http://remote/dtd/sys/docCarl.dtd", 79 "http://local/base/dtd/docCarlSys.dtd" }, 80 81 // Multiple catalog files, which are defined as next catalog, 82 // have the matched system entries of the specified system id. 83 // But finally, the returned matched URI is the first found. 84 { "http://remote/dtd/sys/docDuplicate.dtd", 85 "http://local/base/dtd/docDuplicateLeftSys.dtd" } }; 86 } 87 88 @Test(dataProvider = "publicId-matchedUri") 89 public void testNextCatalogOnPubId(String publicId, String matchedUri) { 90 checkPubIdResolution(createEntityResolver(), publicId, matchedUri); 91 } 92 93 @DataProvider(name = "publicId-matchedUri") 94 public Object[][] dataOnPubId() { 95 return new Object[][] { 96 // This matched URI of the specified public id is defined in a 97 // next catalog file. 98 { "-//REMOTE//DTD ALICE DOCALICE XML//EN", 99 "http://local/base/dtd/docAliceNextLeftPub.dtd" }, 100 101 // There are two matches of the specified public id. One is in 102 // the current catalog file, and the other is in a next catalog 103 // file. But finally, the returned matched URI is the one in the 104 // current catalog file. 105 { "-//REMOTE//DTD BOB DOCBOB XML//EN", 106 "http://local/base/dtd/docBobLeftPub.dtd" }, 107 108 // The matched URI of the specified public id is defined in a 109 // two-level next catalog file. 110 { "-//REMOTE//DTD CARL DOCCARL XML//EN", 111 "http://local/base/dtd/docCarlPub.dtd" }, 112 113 // Multiple catalog files, which are defined as next catalog, 114 // have the matched public entries of the specified public id. 115 // But finally, the returned matched URI is the first found. 116 { "-//REMOTE//DTD DUPLICATE DOCDUPLICATE XML//EN", 117 "http://local/base/dtd/docDuplicateLeftPub.dtd" } }; 118 } 119 120 @Test(dataProvider = "uri-matchedUri") 121 public void testNextCatalogOnUri(String uri, String matchedUri) { 122 checkUriResolution(createUriResolver(), uri, matchedUri); 123 } 124 125 @DataProvider(name = "uri-matchedUri") 126 public Object[][] dataOnUri() { 127 return new Object[][] { 128 // This matched URI of the specified URI reference is defined in 129 // a next catalog file. 130 { "http://remote/dtd/uri/docAlice.dtd", 131 "http://local/base/dtd/docAliceNextLeftURI.dtd" }, 132 133 // There are two matches of the specified URI reference. One is 134 // in the current catalog file, and the other is in a next 135 // catalog file. But finally, the returned matched URI is the 136 // one in the current catalog file. 137 { "http://remote/dtd/uri/docBob.dtd", 138 "http://local/base/dtd/docBobLeftURI.dtd" }, 139 140 // The matched URI of the specified URI reference is defined in 141 // a two-level next catalog file. 142 { "http://remote/dtd/uri/docCarl.dtd", 143 "http://local/base/dtd/docCarlURI.dtd" }, 144 145 // Multiple catalog files, which are defined as next catalog, 146 // have the matched uri entries of the specified URI reference. 147 // But finally, the returned matched URI is the first found. 148 { "http://remote/dtd/uri/docDuplicate.dtd", 149 "http://local/base/dtd/docDuplicateLeftURI.dtd" } }; 150 } 151 152 private CatalogResolver createEntityResolver() { 153 return catalogResolver(CATALOG_NEXTCATALOGLEFT, 154 CATALOG_NEXTCATALOGRIGHT); 155 } 156 157 private CatalogUriResolver createUriResolver() { 158 return catalogUriResolver(CATALOG_NEXTCATALOGLEFT, 159 CATALOG_NEXTCATALOGRIGHT); 160 } 161 } 162