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.PREFER_PUBLIC; 27 import static catalog.CatalogTestUtils.PREFER_SYSTEM; 28 import static catalog.CatalogTestUtils.catalogResolver; 29 import static javax.xml.catalog.CatalogFeatures.Feature.PREFER; 30 31 import javax.xml.catalog.CatalogException; 32 import javax.xml.catalog.CatalogFeatures; 33 import javax.xml.catalog.CatalogResolver; 34 35 import org.testng.annotations.DataProvider; 36 import org.testng.annotations.Test; 37 38 /* 39 * @test 40 * @bug 8077931 41 * @summary This case tests how does the feature affect the catalog resolution, 42 * and tests the priority between this feature and attribute prefer 43 * in catalog file. 44 * @compile ../../libs/catalog/CatalogTestUtils.java 45 */ 46 public class PreferFeatureTest { 47 48 @Test(dataProvider = "prefer-publicId-systemId", 49 expectedExceptions = CatalogException.class) 50 public void testPreferFeature(String prefer, String systemId, 51 String publicId) { 52 createResolver(prefer).resolveEntity(systemId, publicId); 53 } 54 55 @DataProvider(name = "prefer-publicId-systemId") 56 private Object[][] data() { 57 return new Object[][] { 58 // The feature prefer is system. There's a match for the 59 // specified public id, and no match for the specified system id. 60 // But the resolver cannot find the expected match, and raises a 61 // CatalogException. 62 { PREFER_SYSTEM, "-//REMOTE//DTD ALICE DOCALICE XML//EN", 63 "http://remote/dtd/alice/docAliceDummy.dtd" }, 64 65 // The feature prefer is public, and the prefer attribute of a 66 // group entry is system. There's a match for the specified 67 // public id, and no match for the specified system id. But the 68 // resolver still cannot find the expected match, and raises a 69 // CatalogException. 70 { PREFER_PUBLIC, "-//REMOTE//DTD BOB DOCBOB XML//EN", 71 "http://remote/dtd/bob/docBobDummy.dtd"} }; 72 } 73 74 private CatalogResolver createResolver(String prefer) { 75 return catalogResolver( 76 CatalogFeatures.builder().with(PREFER, prefer).build(), 77 "preferFeature.xml"); 78 } 79 }