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