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 24package catalog; 25 26import static catalog.CatalogTestUtils.catalogResolver; 27import static catalog.CatalogTestUtils.catalogUriResolver; 28import static catalog.ResolutionChecker.checkPubIdResolution; 29import static catalog.ResolutionChecker.checkSysIdResolution; 30import static catalog.ResolutionChecker.checkUriResolution; 31 32import javax.xml.catalog.CatalogResolver; 33 34import org.testng.annotations.DataProvider; 35import org.testng.annotations.Listeners; 36import org.testng.annotations.Test; 37 38/* 39 * @test 40 * @bug 8077931 41 * @library /javax/xml/jaxp/libs 42 * @run testng/othervm -DrunSecMngr=true catalog.NormalizationTest 43 * @run testng/othervm catalog.NormalizationTest 44 * @summary Before matching identifiers and URI references, it has to normalize 45 * the passed identifiers and URI references. And then the catalog 46 * resolver uses the normalized stuff to search the counterparts in 47 * catalog files. 48 */ 49@Listeners({jaxp.library.FilePolicy.class}) 50public class NormalizationTest { 51 52 private static final String CATALOG_NORMALIZATION = "normalization.xml"; 53 54 @Test(dataProvider = "systemId_uri-matchedUri") 55 public void testNormalizationOnSysId(String sytemId, String matchedUri) { 56 checkSysIdResolution(createEntityResolver(), sytemId, matchedUri); 57 } 58 59 @Test(dataProvider = "publicId-matchedUri") 60 public void testNormalizationOnPubId(String publicId, String matchedUri) { 61 checkPubIdResolution(createEntityResolver(), publicId, matchedUri); 62 } 63 64 @Test(dataProvider = "systemId_uri-matchedUri") 65 public void testNormalizationOnUri(String uri, String matchedUri) { 66 checkUriResolution(createUriResolver(), uri, matchedUri); 67 } 68 69 @DataProvider(name = "systemId_uri-matchedUri") 70 public Object[][] dataOnSysIdAndUri() { 71 return new Object[][] { 72 // The specified system id/URI reference contains spaces. And 73 // the counterparts in system/uri entries also contain spaces. 74 { " http://remote/dtd/alice/docAlice.dtd ", 75 "http://local/base/dtd/docAliceSys.dtd" }, 76 77 // The specified system id/URI reference doesn't contain space. 78 // But the counterparts in system/uri entries contain spaces. 79 { "http://remote/dtd/alice/docAlice.dtd", 80 "http://local/base/dtd/docAliceSys.dtd" }, 81 82 // The specified system id/URI reference contains special chars. 83 { "http://remote/dtd/bob/docBob<>\\^`{|}.dtd", 84 "http://local/base/dtd/docBobSys.dtd" }, 85 86 // The specified system identifier/uri contains normalized chars. 87 { "http://remote/dtd/bob/docBob%3C%3E%5C%5E%60%7B%7C%7D.dtd", 88 "http://local/base/dtd/docBobSys.dtd" } }; 89 } 90 91 @DataProvider(name = "publicId-matchedUri") 92 public Object[][] dataOnPubId() { 93 return new Object[][] { 94 // The specified public id contains spaces. And the counterparts 95 // in public entry also contains spaces. 96 { " -//REMOTE//DTD ALICE DOCALICE XML//EN ", 97 "http://local/base/dtd/docAlicePub.dtd" }, 98 99 // The specified public id doesn't contain space. But the 100 // counterpart in public entry contains spaces. 101 { "-//REMOTE//DTD ALICE DOCALICE XML//EN", 102 "http://local/base/dtd/docAlicePub.dtd" }, 103 104 // The specified public id contains spaces. 105 { " -//REMOTE//DTD BOB DOCBOB XML//EN", 106 "http://local/base/dtd/docBobPub.dtd" } }; 107 } 108 109 private CatalogResolver createEntityResolver() { 110 return catalogResolver(CATALOG_NORMALIZATION); 111 } 112 113 private CatalogResolver createUriResolver() { 114 return catalogUriResolver(CATALOG_NORMALIZATION); 115 } 116} 117