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