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