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