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 34 import org.testng.annotations.DataProvider; 35 import org.testng.annotations.Listeners; 36 import org.testng.annotations.Test; 37 38 /* 39 * @test 40 * @bug 8077931 41 * @library /javax/xml/jaxp/libs 42 * @run testng/othervm -DrunSecMngr=true catalog.GroupTest 43 * @run testng/othervm catalog.GroupTest 44 * @summary Get matched URIs from system, public and uri entries respectively, 45 * and some of the entries are enclosed by group entries. 46 */ 47 @Listeners({jaxp.library.FilePolicy.class}) 48 public class GroupTest { 49 50 private static final String CATALOG_GROUP = "group.xml"; 51 52 @Test(dataProvider = "systemId-matchedUri") 53 public void testMatchOnSysId(String uri, String matchedUri) { 54 checkSysIdResolution(createResolver(), uri, matchedUri); 55 } 56 57 @DataProvider(name = "systemId-matchedUri") 58 public Object[][] dataOnSysId() { 59 return new Object[][] { 60 // The matched URI of the specified system id is enclosed by a 61 // group entry. 62 { "http://remote/dtd/sys/alice/docAlice.dtd", 63 "http://local/base/dtd/docAliceSys.dtd" }, 64 65 // The matched URI of the specified system id is enclosed by a 66 // group entry, which defines another base. 67 { "http://remote/dtd/sys/bob/docBob.dtd", 68 "http://local/bobBase/dtd/docBobSys.dtd" }, 69 70 // The catalog file defines a set of system entries. Some of 71 // them are enclosed by a group entry, and others are out of the 72 // group entry. All of them can match the specified system id. 73 // But the returned matched URI should be in the first one. 74 { "http://remote/dtd/sys/carl/docCarl.dtd", 75 "http://local/base/dtd/docCarlSys1.dtd" } }; 76 } 77 78 @Test(dataProvider = "publicId-matchedUri") 79 public void testMatchOnPubId(String uri, String matchedUri) { 80 checkPubIdResolution(createResolver(), uri, matchedUri); 81 } 82 83 @DataProvider(name = "publicId-matchedUri") 84 public Object[][] dataOnPubId() { 85 return new Object[][] { 86 // The matched URI of the specified public id is enclosed by a 87 // group entry. 88 { "-//REMOTE//DTD ALICE DOCALICE XML//EN", 89 "http://local/base/dtd/docAlicePub.dtd" }, 90 91 // The matched URI of the specified public id is enclosed by a 92 // group entry, which defines another base. 93 { "-//REMOTE//DTD BOB DOCBOB XML//EN", 94 "http://local/bobBase/dtd/docBobPub.dtd" }, 95 96 // The catalog file defines a set of public entries. Some of 97 // them are enclosed by a group entry, and others are out of the 98 // group entry. All of them can match the specified public id. 99 // But the returned matched URI should be in the first one. 100 { "-//REMOTE//DTD CARL DOCCARL XML//EN", 101 "http://local/base/dtd/docCarlPub1.dtd" } }; 102 } 103 104 @Test(dataProvider = "uri-matchedUri") 105 public void testMatchOnUri(String uri, String matchedUri) { 106 checkUriResolution(catalogUriResolver(CATALOG_GROUP), uri, matchedUri); 107 } 108 109 @DataProvider(name = "uri-matchedUri") 110 public Object[][] dataOnUri() { 111 return new Object[][] { 112 // The matched URI of the specified URI reference is enclosed by 113 // a group entry. 114 { "http://remote/dtd/uri/alice/docAlice.dtd", 115 "http://local/base/dtd/docAliceURI.dtd" }, 116 117 // The matched URI of the specified URI reference is enclosed by 118 // a group entry, which defines another base. 119 { "http://remote/dtd/uri/bob/docBob.dtd", 120 "http://local/bobBase/dtd/docBobURI.dtd" }, 121 122 // The catalog file defines a set of uri entries. Some of 123 // them are enclosed by a group entry, and others are out of the 124 // group entry. All of them can match the specified URI reference. 125 // But the returned matched URI should be in the first one. 126 { "http://remote/dtd/uri/alice/docAlice.dtd", 127 "http://local/base/dtd/docAliceURI.dtd" } }; 128 } 129 130 private CatalogResolver createResolver() { 131 return catalogResolver(CATALOG_GROUP); 132 } 133 } 134