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.CatalogTestUtils.catalogUriResolver;
  28 import static catalog.ResolutionChecker.checkPubIdResolution;
  29 import static catalog.ResolutionChecker.checkSysIdResolution;
  30 import static catalog.ResolutionChecker.checkUriResolution;
  31 
  32 import javax.xml.catalog.CatalogResolver;
  33 import javax.xml.catalog.CatalogUriResolver;
  34 
  35 import org.testng.annotations.DataProvider;
  36 import org.testng.annotations.Test;
  37 
  38 /*
  39  * @test
  40  * @bug 8077931
  41  * @summary Get matched URIs from system, public and uri entries respectively,
  42  *          but some of the entries are defined in none-current catalog files.
  43  * @compile ../../libs/catalog/CatalogTestUtils.java
  44  * @compile ../../libs/catalog/ResolutionChecker.java
  45  */
  46 public class NextCatalogTest {
  47 
  48     private static final String CATALOG_NEXTCATALOGLEFT
  49             = "nextCatalog-left.xml";
  50     private static final String CATALOG_NEXTCATALOGRIGHT
  51             = "nextCatalog-right.xml";
  52 
  53     @Test(dataProvider = "systemId-matchedUri")
  54     public void testNextCatalogOnSysId(String sytemId, String matchedUri) {
  55         checkSysIdResolution(createEntityResolver(), sytemId, matchedUri);
  56     }
  57 
  58     @DataProvider(name = "systemId-matchedUri")
  59     private Object[][] dataOnSysId() {
  60         return new Object[][] {
  61                 // This matched URI of the specified system id is defined in a
  62                 // next catalog file.
  63                 { "http://remote/dtd/sys/docAlice.dtd",
  64                         "http://local/base/dtd/docAliceNextLeftSys.dtd" },
  65 
  66                 // There are two matches of the specified system id. One is in
  67                 // the current catalog file, and the other is in a next catalog
  68                 // file. But finally, the returned matched URI is the one in the
  69                 // current catalog file.
  70                 { "http://remote/dtd/sys/docBob.dtd",
  71                         "http://local/base/dtd/docBobLeftSys.dtd" },
  72 
  73                 // The matched URI of the specified system id is defined in a
  74                 // two-level next catalog file.
  75                 { "http://remote/dtd/sys/docCarl.dtd",
  76                         "http://local/base/dtd/docCarlSys.dtd" },
  77 
  78                 // Multiple catalog files, which are defined as next catalog,
  79                 // have the matched system entries of the specified system id.
  80                 // But finally, the returned matched URI is the first found.
  81                 { "http://remote/dtd/sys/docDuplicate.dtd",
  82                         "http://local/base/dtd/docDuplicateLeftSys.dtd" } };
  83     }
  84 
  85     @Test(dataProvider = "publicId-matchedUri")
  86     public void testNextCatalogOnPubId(String publicId, String matchedUri) {
  87         checkPubIdResolution(createEntityResolver(), publicId, matchedUri);
  88     }
  89 
  90     @DataProvider(name = "publicId-matchedUri")
  91     private Object[][] dataOnPubId() {
  92         return new Object[][] {
  93                 // This matched URI of the specified public id is defined in a
  94                 // next catalog file.
  95                 { "-//REMOTE//DTD ALICE DOCALICE XML//EN",
  96                         "http://local/base/dtd/docAliceNextLeftPub.dtd" },
  97 
  98                 // There are two matches of the specified public id. One is in
  99                 // the current catalog file, and the other is in a next catalog
 100                 // file. But finally, the returned matched URI is the one in the
 101                 // current catalog file.
 102                 { "-//REMOTE//DTD BOB DOCBOB XML//EN",
 103                         "http://local/base/dtd/docBobLeftPub.dtd" },
 104 
 105                 // The matched URI of the specified public id is defined in a
 106                 // two-level next catalog file.
 107                 { "-//REMOTE//DTD CARL DOCCARL XML//EN",
 108                         "http://local/base/dtd/docCarlPub.dtd" },
 109 
 110                 // Multiple catalog files, which are defined as next catalog,
 111                 // have the matched public entries of the specified public id.
 112                 // But finally, the returned matched URI is the first found.
 113                 { "-//REMOTE//DTD DUPLICATE DOCDUPLICATE XML//EN",
 114                         "http://local/base/dtd/docDuplicateLeftPub.dtd" } };
 115     }
 116 
 117     @Test(dataProvider = "uri-matchedUri")
 118     public void testNextCatalogOnUri(String uri, String matchedUri) {
 119         checkUriResolution(createUriResolver(), uri, matchedUri);
 120     }
 121 
 122     @DataProvider(name = "uri-matchedUri")
 123     private Object[][] dataOnUri() {
 124         return new Object[][] {
 125                 // This matched URI of the specified URI reference is defined in
 126                 // a next catalog file.
 127                 { "http://remote/dtd/uri/docAlice.dtd",
 128                         "http://local/base/dtd/docAliceNextLeftURI.dtd" },
 129 
 130                 // There are two matches of the specified URI reference. One is
 131                 // in the current catalog file, and the other is in a next
 132                 // catalog file. But finally, the returned matched URI is the
 133                 // one in the current catalog file.
 134                 { "http://remote/dtd/uri/docBob.dtd",
 135                         "http://local/base/dtd/docBobLeftURI.dtd" },
 136 
 137                 // The matched URI of the specified URI reference is defined in
 138                 // a two-level next catalog file.
 139                 { "http://remote/dtd/uri/docCarl.dtd",
 140                         "http://local/base/dtd/docCarlURI.dtd" },
 141 
 142                 // Multiple catalog files, which are defined as next catalog,
 143                 // have the matched uri entries of the specified URI reference.
 144                 // But finally, the returned matched URI is the first found.
 145                 { "http://remote/dtd/uri/docDuplicate.dtd",
 146                         "http://local/base/dtd/docDuplicateLeftURI.dtd" } };
 147     }
 148 
 149     private CatalogResolver createEntityResolver() {
 150         return catalogResolver(CATALOG_NEXTCATALOGLEFT,
 151                 CATALOG_NEXTCATALOGRIGHT);
 152     }
 153 
 154     private CatalogUriResolver createUriResolver() {
 155         return catalogUriResolver(CATALOG_NEXTCATALOGLEFT,
 156                 CATALOG_NEXTCATALOGRIGHT);
 157     }
 158 }