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.CATALOG_SYSTEM; 27 import static catalog.CatalogTestUtils.CATALOG_URI; 28 import static catalog.CatalogTestUtils.catalogResolver; 29 import static catalog.CatalogTestUtils.catalogUriResolver; 30 import static catalog.ResolutionChecker.checkSysIdResolution; 31 import static catalog.ResolutionChecker.checkUriResolution; 32 33 import javax.xml.catalog.CatalogException; 34 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.ValidateCatalogTest 43 * @run testng/othervm catalog.ValidateCatalogTest 44 * @summary A legal catalog file must be well-formed XML, the root element 45 * must be catalog, and the naming space of the root element must be 46 * urn:oasis:names:tc:entity:xmlns:xml:catalog. 47 */ 48 @Listeners({jaxp.library.FilePolicy.class}) 49 public class ValidateCatalogTest { 50 51 private static final String CATALOG_WRONGROOT = "validateCatalog-wrongRoot.xml"; 52 private static final String CATALOG_MALFORMED = "validateCatalog-malformed.xml"; 53 54 /* 55 * EntityResolver tries to load catalog with wrong root, 56 * it should throw CatalogException. 57 */ 58 @Test(expectedExceptions = CatalogException.class) 59 public void validateWrongRootCatalogOnEntityResolver() { 60 catalogResolver(CATALOG_WRONGROOT); 61 } 62 63 /* 64 * URIResolver tries to load catalog with wrong root, 65 * it should throw CatalogException. 66 */ 67 @Test(expectedExceptions = CatalogException.class) 68 public void validateWrongRootCatalogOnUriResolver() { 69 catalogUriResolver(CATALOG_WRONGROOT); 70 } 71 72 /* 73 * EntityResolver tries to load malformed catalog, 74 * it should throw RuntimeException. 75 */ 76 @Test(expectedExceptions = RuntimeException.class) 77 public void validateMalformedCatalogOnEntityResolver() { 78 catalogResolver(CATALOG_MALFORMED); 79 } 80 81 /* 82 * UriResolver tries to load malformed catalog, 83 * it should throw RuntimeException. 84 */ 85 @Test(expectedExceptions = RuntimeException.class) 86 public void validateMalformedCatalogOnUriResolver() { 87 catalogUriResolver(CATALOG_MALFORMED); 88 } 89 90 /* 91 * Resolver should ignore the catalog which doesn't declare the correct 92 * naming space. 93 */ 94 @Test 95 public void validateWrongNamingSpaceCatalog() { 96 String catalogName = "validateCatalog-noNamingSpace.xml"; 97 checkSysIdResolution(catalogResolver(catalogName, CATALOG_SYSTEM), 98 "http://remote/dtd/alice/docAlice.dtd", 99 "http://local/dtd/docAliceSys.dtd"); 100 checkUriResolution(catalogUriResolver(catalogName, CATALOG_URI), 101 "http://remote/dtd/alice/docAlice.dtd", 102 "http://local/dtd/docAliceURI.dtd"); 103 } 104 } 105