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 jaxp.library.JAXPTestUtilities.setSystemProperty; 27 28 import static catalog.CatalogTestUtils.FEATURE_FILES; 29 import static catalog.CatalogTestUtils.catalogResolver; 30 import static catalog.CatalogTestUtils.catalogUriResolver; 31 import static catalog.CatalogTestUtils.getCatalogPath; 32 import static catalog.ResolutionChecker.checkSysIdResolution; 33 import static catalog.ResolutionChecker.checkUriResolution; 34 import static javax.xml.catalog.CatalogFeatures.builder; 35 import static javax.xml.catalog.CatalogFeatures.Feature.FILES; 36 37 import javax.xml.catalog.CatalogFeatures; 38 import javax.xml.catalog.CatalogResolver; 39 import javax.xml.catalog.CatalogUriResolver; 40 41 import org.testng.annotations.Listeners; 42 import org.testng.annotations.Test; 43 44 /* 45 * @test 46 * @bug 8077931 47 * @library /javax/xml/jaxp/libs 48 * @run testng/othervm -DrunSecMngr=true catalog.SpecifyCatalogTest 49 * @run testng/othervm catalog.SpecifyCatalogTest 50 * @summary This case tests how to specify the catalog files. 51 */ 52 @Listeners({jaxp.library.FilePolicy.class}) 53 public class SpecifyCatalogTest { 54 55 private static final String ID_URI = "http://remote/dtd/uri/doc.dtd"; 56 private static final String ID_SYS = "http://remote/dtd/sys/doc.dtd"; 57 58 private static final CatalogFeatures FILES_FEATURE = createFeature( 59 "specifyCatalog-feature.xml"); 60 61 /* 62 * CatalogResolver specifies catalog via feature javax.xml.catalog.files. 63 */ 64 @Test 65 public void specifyCatalogOnEntityResolver() { 66 checkSysIdResolution(catalogResolver(FILES_FEATURE, (String[]) null), 67 ID_SYS, "http://local/base/dtd/docFeatureSys.dtd"); 68 } 69 70 /* 71 * CatalogUriResolver specifies catalog via feature javax.xml.catalog.files. 72 */ 73 @Test 74 public void specifyCatalogOnUriResolver() { 75 checkUriResolution(catalogUriResolver(FILES_FEATURE, (String[]) null), 76 ID_URI, "http://local/base/dtd/docFeatureURI.dtd"); 77 } 78 79 /* 80 * Resolver specifies catalog via system property javax.xml.catalog.files. 81 */ 82 @Test 83 public void specifyCatalogViaSysProps() { 84 setSystemProperty(FEATURE_FILES, 85 getCatalogPath("specifyCatalog-sysProps.xml")); 86 87 checkResolutionOnEntityResolver(catalogResolver((String[]) null), 88 "http://local/base/dtd/docSysPropsSys.dtd"); 89 checkResolutionOnEntityResolver( 90 catalogResolver(FILES_FEATURE, "specifyCatalog-api.xml"), 91 "http://local/base/dtd/docAPISys.dtd"); 92 93 checkResolutionOnUriResolver(catalogUriResolver((String[]) null), 94 "http://local/base/dtd/docSysPropsURI.dtd"); 95 checkResolutionOnUriResolver( 96 catalogUriResolver(FILES_FEATURE, "specifyCatalog-api.xml"), 97 "http://local/base/dtd/docAPIURI.dtd"); 98 } 99 100 private void checkResolutionOnEntityResolver(CatalogResolver resolver, 101 String matchedUri) { 102 checkSysIdResolution(resolver, ID_SYS, matchedUri); 103 } 104 105 private void checkResolutionOnUriResolver(CatalogUriResolver resolver, 106 String matchedUri) { 107 checkUriResolution(resolver, ID_URI, matchedUri); 108 } 109 110 private static CatalogFeatures createFeature(String catalogName) { 111 return builder().with(FILES, getCatalogPath(catalogName)).build(); 112 } 113 } 114