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