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