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.catalogResolver; 27 import static catalog.ResolutionChecker.checkExtIdResolution; 28 29 import javax.xml.catalog.CatalogResolver; 30 31 import org.testng.annotations.DataProvider; 32 import org.testng.annotations.Listeners; 33 import org.testng.annotations.Test; 34 35 /* 36 * @test 37 * @bug 8077931 38 * @summary Get matched URIs from system and public family entries, which 39 * specify the prefer attribute. It tests how does the prefer attribute 40 * affect the resolution procedure. The test rule is based on OASIS 41 * Standard V1.1 section 4.1.1. "The prefer attribute". 42 * @compile ../../libs/catalog/CatalogTestUtils.java 43 * @compile ../../libs/catalog/ResolutionChecker.java 44 */ 45 @Listeners({jaxp.library.FilePolicy.class}) 46 public class PreferTest { 47 48 @Test(dataProvider = "publicId-systemId-matchedUri") 49 public void testPrefer(String publicId, String systemId, 50 String expected) { 51 checkExtIdResolution(createResolver(), publicId, systemId, expected); 52 } 53 54 @DataProvider(name = "publicId-systemId-matchedUri") 55 private Object[][] data() { 56 return new Object[][] { 57 // The prefer attribute is public. Both of the specified public 58 // id and system id have matches in the catalog file. But 59 // finally, the returned URI is the system match. 60 { "-//REMOTE//DTD ALICE DOCALICE XML//EN", 61 "http://remote/dtd/alice/docAlice.dtd", 62 "http://local/base/dtd/docAliceSys.dtd" }, 63 64 // The prefer attribute is public, and only the specified system 65 // id has match. The returned URI is the system match. 66 { "-//REMOTE//DTD ALICE DOCALICEDUMMY XML//EN", 67 "http://remote/dtd/alice/docAlice.dtd", 68 "http://local/base/dtd/docAliceSys.dtd"}, 69 70 // The prefer attribute is public, and only the specified public 71 // id has match. The returned URI is the system match. 72 { "-//REMOTE//DTD ALICE DOCALICE XML//EN", 73 "http://remote/dtd/alice/docAliceDummy.dtd", 74 "http://local/base/dtd/docAlicePub.dtd" }, 75 76 // The prefer attribute is system, and both of the specified 77 // system id and public id have matches. But the returned URI is 78 // the system match. 79 { "-//REMOTE//DTD BOB DOCBOB XML//EN", 80 "http://remote/dtd/bob/docBob.dtd", 81 "http://local/base/dtd/docBobSys.dtd" }, 82 83 // The prefer attribute is system, and only system id has match. 84 // The returned URI is the system match. 85 { "-//REMOTE//DTD BOB DOCBOBDUMMY XML//EN", 86 "http://remote/dtd/bob/docBob.dtd", 87 "http://local/base/dtd/docBobSys.dtd" } }; 88 } 89 90 private CatalogResolver createResolver() { 91 return catalogResolver("prefer.xml"); 92 } 93 }