jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java
author joehw
Wed, 11 Jan 2017 13:06:04 -0800
changeset 43121 e73af7b6ce47
parent 41847 e444f2f9dc8a
child 44380 0197177795e9
permissions -rw-r--r--
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar Reviewed-by: rriggs, dfuchs, lancea, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     1
/*
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     4
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     8
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    13
 * accompanied this code).
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    14
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    18
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    21
 * questions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    22
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    23
package catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    24
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    25
import java.io.File;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    26
import java.io.FileInputStream;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    27
import java.io.IOException;
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    28
import java.io.InputStream;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    29
import java.io.StringReader;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    30
import java.io.StringWriter;
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
    31
import java.net.URI;
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    32
import java.nio.file.Paths;
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    33
import javax.xml.XMLConstants;
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
    34
import javax.xml.catalog.Catalog;
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    35
import javax.xml.catalog.CatalogException;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    36
import javax.xml.catalog.CatalogFeatures;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    37
import javax.xml.catalog.CatalogFeatures.Feature;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    38
import javax.xml.catalog.CatalogManager;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    39
import javax.xml.catalog.CatalogResolver;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    40
import javax.xml.parsers.ParserConfigurationException;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    41
import javax.xml.parsers.SAXParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    42
import javax.xml.parsers.SAXParserFactory;
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    43
import javax.xml.stream.XMLInputFactory;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    44
import javax.xml.stream.XMLStreamConstants;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    45
import javax.xml.stream.XMLStreamReader;
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
    46
import javax.xml.transform.Source;
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    47
import javax.xml.transform.Transformer;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    48
import javax.xml.transform.TransformerFactory;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    49
import javax.xml.transform.sax.SAXSource;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    50
import javax.xml.transform.stream.StreamResult;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    51
import javax.xml.transform.stream.StreamSource;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    52
import javax.xml.validation.Schema;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    53
import javax.xml.validation.SchemaFactory;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    54
import javax.xml.validation.Validator;
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
    55
import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
    56
import static jaxp.library.JAXPTestUtilities.setSystemProperty;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    57
import org.testng.Assert;
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    58
import org.testng.annotations.BeforeClass;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    59
import org.testng.annotations.DataProvider;
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    60
import org.testng.annotations.Listeners;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    61
import org.testng.annotations.Test;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    62
import org.xml.sax.Attributes;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    63
import org.xml.sax.ErrorHandler;
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
    64
import org.xml.sax.InputSource;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    65
import org.xml.sax.SAXException;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    66
import org.xml.sax.XMLReader;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    67
import org.xml.sax.ext.DefaultHandler2;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    68
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    69
/*
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    70
 * @test
41847
e444f2f9dc8a 8168968: Two jaxp tests failing after JDK-8167646
fyuan
parents: 40753
diff changeset
    71
 * @bug 8081248 8144966 8146606 8146237 8150969 8151162 8152527 8154220 8163232
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    72
 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    73
 * @run testng/othervm -DrunSecMngr=true catalog.CatalogTest
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    74
 * @run testng/othervm catalog.CatalogTest
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    75
 * @summary Tests basic Catalog functions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    76
 */
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
    77
@Listeners({jaxp.library.FilePolicy.class})
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    78
public class CatalogTest extends CatalogSupportBase {
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    79
    static final String KEY_FILES = "javax.xml.catalog.files";
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    80
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    81
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    82
    /*
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    83
     * Initializing fields
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    84
     */
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    85
    @BeforeClass
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
    86
    public void setUpClass() throws Exception {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    87
        super.setUp();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    88
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
    89
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    90
    /*
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    91
     * @bug 8162431
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    92
     * Verifies that circular references are caught and
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    93
     * CatalogException is thrown.
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    94
     */
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    95
    @Test(dataProvider = "getFeatures", expectedExceptions = CatalogException.class)
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
    96
    public void testCircularRef(CatalogFeatures cf, String xml) throws Exception {
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    97
        CatalogResolver catalogResolver = CatalogManager.catalogResolver(
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
    98
                cf,
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
    99
                getClass().getResource(xml).toURI());
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   100
        catalogResolver.resolve("anyuri", "");
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   101
    }
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   102
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   103
    /*
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   104
       DataProvider: used to verify circular reference
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   105
        Data columns: CatalogFeatures, catalog
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   106
     */
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   107
    @DataProvider(name = "getFeatures")
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   108
    public Object[][] getFeatures() {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   109
        String self = "catalogReferCircle-itself.xml";
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   110
        String left = "catalogReferCircle-left.xml";
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   111
        return new Object[][]{
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   112
            {CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "false").build(), self},
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   113
            {CatalogFeatures.defaults(), self},
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   114
            {CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "false").build(), left},
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   115
            {CatalogFeatures.defaults(), left}
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   116
        };
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 40582
diff changeset
   117
    }
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   118
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   119
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   120
     * @bug 8163232
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   121
     * Verifies that the CatalogResolver supports the following XML Resolvers:
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   122
          javax.xml.stream.XMLResolver
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   123
          javax.xml.transform.URIResolver
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   124
          org.w3c.dom.ls.LSResourceResolver
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   125
          org.xml.sax.EntityResolver
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   126
     *
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   127
     * Plus, system and uri entries can equally be used.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   128
     */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   129
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   130
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   131
     * Verifies the support for org.xml.sax.EntityResolver.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   132
     * Expected: the parser returns the expected string.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   133
    */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   134
    @Test(dataProvider = "supportXMLResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   135
    public void supportEntityResolver(URI catalogFile, String xml, String expected) throws Exception {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   136
        String xmlSource = getClass().getResource(xml).getFile();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   137
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   138
        CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   139
        MyCatalogHandler handler = new MyCatalogHandler(cr, elementInSystem);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   140
        SAXParser parser = getSAXParser(false, true, null);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   141
        parser.parse(xmlSource, handler);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   142
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   143
        Assert.assertEquals(handler.getResult().trim(), expected);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   144
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   145
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   146
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   147
     * Verifies the support for javax.xml.stream.XMLResolver.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   148
     * Expected: the parser returns the expected string.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   149
    */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   150
    @Test(dataProvider = "supportXMLResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   151
    public void supportXMLResolver(URI catalogFile, String xml, String expected) throws Exception {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   152
        String xmlSource = getClass().getResource(xml).getFile();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   153
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   154
        CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   155
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   156
        XMLInputFactory xifactory = XMLInputFactory.newInstance();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   157
        xifactory.setProperty(XMLInputFactory.IS_COALESCING, true);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   158
        xifactory.setProperty(XMLInputFactory.RESOLVER, cr);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   159
        File file = new File(xmlSource);
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   160
        String systemId = file.toURI().toASCIIString();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   161
        InputStream entityxml = new FileInputStream(file);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   162
        XMLStreamReader streamReader = xifactory.createXMLStreamReader(systemId, entityxml);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   163
        String result = null;
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   164
        while (streamReader.hasNext()) {
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   165
            int eventType = streamReader.next();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   166
            if (eventType == XMLStreamConstants.START_ELEMENT) {
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   167
                eventType = streamReader.next();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   168
                if (eventType == XMLStreamConstants.CHARACTERS) {
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   169
                    result = streamReader.getText();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   170
                }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   171
            }
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   172
        }
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   173
        System.out.println(": expected [" + expected + "] <> actual [" + result.trim() + "]");
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   174
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   175
        Assert.assertEquals(result.trim(), expected);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   176
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   177
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   178
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   179
     * Verifies the support for org.w3c.dom.ls.LSResourceResolver by ShemaFactory.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   180
     * Success: parsing goes through with no error
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   181
     * Fail: throws Exception if references are not resolved (by the CatalogResolver)
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   182
    */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   183
    @Test(dataProvider = "supportLSResourceResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   184
    public void supportLSResourceResolver(URI catalogFile, Source schemaSource) throws SAXException {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   185
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   186
        CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   187
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   188
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   189
        factory.setResourceResolver(cr);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   190
        Schema schema = factory.newSchema(schemaSource);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   191
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   192
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   193
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   194
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   195
     * Verifies the support for org.w3c.dom.ls.LSResourceResolver by Validator.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   196
     * Success: parsing goes through with no error
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   197
     * Fail: throws Exception if references are not resolved (by the CatalogResolver)
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   198
    */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   199
    @Test(dataProvider = "supportLSResourceResolver1")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   200
    public void supportLSResourceResolver1(URI catalogFile, Source source) throws Exception {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   201
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   202
        CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   203
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   204
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   205
        Validator validator = factory.newSchema().newValidator();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   206
        validator.setResourceResolver(cr);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   207
        validator.validate(source);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   208
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   209
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   210
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   211
     * Verifies the support for javax.xml.transform.URIResolver.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   212
     * Success: parsing goes through with no error
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   213
     * Fail: throws Exception if references are not resolved (by the CatalogResolver)
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   214
    */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   215
    @Test(dataProvider = "supportURIResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   216
    public void supportURIResolver(URI catalogFile, Source xsl, Source xml, String expected) throws Exception {
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   217
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   218
        CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   219
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   220
            TransformerFactory factory = TransformerFactory.newInstance();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   221
            factory.setURIResolver(cr);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   222
            Transformer transformer = factory.newTransformer(xsl);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   223
            StringWriter out = new StringWriter();
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   224
            transformer.transform(xml, new StreamResult(out));
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   225
            if (expected != null) {
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   226
                Assert.assertTrue(out.toString().contains(expected), "supportURIResolver");
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   227
            }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   228
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   229
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   230
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   231
       DataProvider: used to verify the support of XML Resolvers.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   232
        Data columns:
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   233
        catalog filepath, xml source file, expected result
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   234
     */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   235
    @DataProvider(name = "supportXMLResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   236
    public Object[][] supportXMLResolver() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   237
        URI catalogFile = getClass().getResource("catalog.xml").toURI();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   238
        URI catalogFileUri = getClass().getResource("catalog_uri.xml").toURI();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   239
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   240
        return new Object[][]{
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   241
            {catalogFile, "system.xml", "Test system entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   242
            {catalogFile, "rewritesystem.xml", "Test rewritesystem entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   243
            {catalogFile, "rewritesystem1.xml", "Test rewritesystem entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   244
            {catalogFile, "systemsuffix.xml", "Test systemsuffix entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   245
            {catalogFile, "delegatesystem.xml", "Test delegatesystem entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   246
            {catalogFile, "public.xml", "Test public entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   247
            {catalogFile, "delegatepublic.xml", "Test delegatepublic entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   248
            // using uri entries
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   249
            {catalogFileUri, "system.xml", "Test system entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   250
            {catalogFileUri, "rewritesystem.xml", "Test rewritesystem entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   251
            {catalogFileUri, "rewritesystem1.xml", "Test rewritesystem entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   252
            {catalogFileUri, "systemsuffix.xml", "Test systemsuffix entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   253
            {catalogFileUri, "delegateuri.xml", "Test delegateuri entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   254
            {catalogFileUri, "public.xml", "Test public entry"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   255
         };
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   256
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   257
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   258
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   259
       DataProvider: used to verify the support of LSResourceResolver by SchemaFactory.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   260
        Data columns:
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   261
        catalog filepath, schema source file
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   262
     */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   263
    @DataProvider(name = "supportLSResourceResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   264
    public Object[][] supportLSResourceResolver() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   265
        URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   266
        URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   267
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   268
        /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   269
         * XMLSchema.xsd has a reference to XMLSchema.dtd which in turn refers to
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   270
         * datatypes.dtd
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   271
        */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   272
        return new Object[][]{
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   273
            {catalogFile, new StreamSource(new StringReader(xsd_xmlSchema))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   274
            {catalogFile, new StreamSource(new StringReader(xsd_xmlSchema_import))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   275
            {catalogFile, new StreamSource(new StringReader(xsd_include_company))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   276
            {catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   277
            {catalogFileUri, new StreamSource(new StringReader(xsd_xmlSchema_import))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   278
            {catalogFileUri, new StreamSource(new StringReader(xsd_include_company))},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   279
         };
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   280
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   281
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   282
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   283
       DataProvider: used to verify the support of LSResourceResolver by Validator.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   284
        Data columns:
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   285
        catalog filepath, source file
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   286
     */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   287
    @DataProvider(name = "supportLSResourceResolver1")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   288
    public Object[][] supportLSResourceResolver1() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   289
        URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   290
        URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   291
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   292
        /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   293
         * val_test.xml has a reference to system.dtd and val_test.xsd
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   294
        */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   295
        SAXSource ss = new SAXSource(new InputSource(xml_val_test));
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   296
        ss.setSystemId(xml_val_test_id);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   297
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   298
        return new Object[][]{
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   299
            {catalogFile, ss},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   300
            {catalogFileUri, ss},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   301
         };
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   302
    }
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   303
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   304
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   305
    /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   306
       DataProvider: used to verify the support of LSResourceResolver by Validator.
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   307
        Data columns:
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   308
        catalog filepath, xsl source, xml source file
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   309
     */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   310
    @DataProvider(name = "supportURIResolver")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   311
    public Object[][] supportURIResolver() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   312
        URI catalogFile = getClass().getResource("CatalogSupport.xml").toURI();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   313
        URI catalogFileUri = getClass().getResource("CatalogSupport_uri.xml").toURI();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   314
        SAXSource xslSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString()));
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   315
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   316
        /*
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   317
         * val_test.xml has a reference to system.dtd and val_test.xsd
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   318
        */
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   319
        SAXSource ss = new SAXSource(new InputSource(xml_val_test));
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   320
        ss.setSystemId(xml_val_test_id);
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   321
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   322
        return new Object[][]{
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   323
            {catalogFile, new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())),
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   324
                new StreamSource(new File(xml_doc)), "Resolved by a catalog"},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   325
            {catalogFileUri, new SAXSource(new InputSource(new StringReader(xsl_include))),
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   326
                new StreamSource(new StringReader(xml_xsl)), null},
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   327
         };
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   328
    }
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   329
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   330
    /*
38818
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   331
     * @bug 8150187
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   332
     * NPE is expected if the systemId is null. The specification for systemId
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   333
     * is as follows:
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   334
     * A system identifier is required on all external entities. XML
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   335
     * requires a system identifier on all external entities, so this value is
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   336
     * always specified.
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   337
     */
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   338
    @Test(expectedExceptions = NullPointerException.class)
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   339
    public void sysIdCantBeNull() {
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   340
        CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   341
        InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null);
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   342
    }
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   343
57f451f8c235 8150187: NPE expected if the system identifier is null for CatalogResolver
joehw
parents: 38497
diff changeset
   344
    /*
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   345
     * @bug 8156845
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   346
     * Verifies that an URI reference with a urn:publicid is correctly resolved
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   347
     * with an uri entry with a publicId.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   348
     *
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   349
     * @param expectedFile is not used in this test, it's kept since we're
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   350
     * copying the JCK test and its dataProvider. This test may be reused for
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   351
     * other cases in that test.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   352
     */
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   353
    @Test(dataProvider = "resolveUri")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   354
    public void testMatch1(String cFile, String href, String expectedFile,
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   355
            String expectedUri, String msg) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   356
        URI catalogFile = getClass().getResource(cFile).toURI();
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   357
        CatalogResolver cur = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   358
        Source source = cur.resolve(href, null);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   359
        Assert.assertNotNull(source, "Source returned is null");
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   360
        Assert.assertEquals(expectedUri, source.getSystemId(), msg);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   361
    }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   362
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   363
    /*
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   364
     * @bug 8154220
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   365
     * Verifies that the file input is validated properly. Valid input includes
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   366
     * multiple file paths separated by semicolon.
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   367
     */
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   368
    @Test(dataProvider = "hierarchyOfCatFilesData")
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   369
    public void hierarchyOfCatFiles2(String systemId, String expectedUri) {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   370
        String file1 = getClass().getResource("first_cat.xml").toExternalForm();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   371
        String file2 = getClass().getResource("second_cat.xml").toExternalForm();
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   372
        String files = file1 + ";" + file2;
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   373
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   374
        try {
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   375
            setSystemProperty(KEY_FILES, files);
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   376
            CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults());
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   377
            String sysId = catalogResolver.resolveEntity(null, systemId).getSystemId();
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   378
            Assert.assertEquals(sysId, Paths.get(filepath + expectedUri).toUri().toString().replace("///", "/"),
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   379
                    "System ID match not right");
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   380
        } finally {
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   381
            clearSystemProperty(KEY_FILES);
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   382
        }
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   383
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   384
    }
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   385
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   386
    /*
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   387
     * @bug 8152527
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   388
     * This test is the same as the JDK test ResolveEntityTests:testMatch1.
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   389
     * Verifies that the CatalogResolver resolves a publicId and/or systemId as
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   390
     * expected.
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   391
     */
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   392
    @Test(dataProvider = "resolveEntity")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   393
    public void testMatch1(String cfile, String prefer, String sysId, String pubId,
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   394
            String expectedUri, String expectedFile, String msg) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   395
        URI catalogFile = getClass().getResource(cfile).toURI();
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   396
        CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build();
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   397
        CatalogResolver catalogResolver = CatalogManager.catalogResolver(features, catalogFile);
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   398
        InputSource is = catalogResolver.resolveEntity(pubId, sysId);
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   399
        Assert.assertNotNull(is, msg);
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   400
        String expected = (expectedUri == null) ? expectedFile : expectedUri;
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   401
        Assert.assertEquals(expected, is.getSystemId(), msg);
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   402
    }
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   403
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   404
    /*
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   405
     * @bug 8151162
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   406
     * Verifies that the Catalog matches specified publicId or systemId and returns
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   407
     * results as expected.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   408
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   409
    @Test(dataProvider = "matchWithPrefer")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   410
    public void matchWithPrefer(String prefer, String cfile, String publicId,
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   411
            String systemId, String expected) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   412
        URI catalogFile = getClass().getResource(cfile).toURI();
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   413
        Catalog c = CatalogManager.catalog(
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   414
                CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(),
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   415
                catalogFile);
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   416
        String result;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   417
        if (publicId != null && publicId.length() > 0) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   418
            result = c.matchPublic(publicId);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   419
        } else {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   420
            result = c.matchSystem(systemId);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   421
        }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   422
        Assert.assertEquals(expected, result);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   423
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   424
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   425
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   426
     * @bug 8151162
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   427
     * Verifies that the CatalogResolver resolves specified publicId or systemId
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   428
     * in accordance with the prefer setting.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   429
     * prefer "system": resolves with a system entry.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   430
     *                  Exception: use the public entry when the catalog contains
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   431
     *                  only public entry and only publicId is specified.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   432
     * prefer "public": attempts to resolve with a system entry;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   433
     *                  attempts to resolve with a public entry if no matching
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   434
     *                  system entry is found.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   435
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   436
    @Test(dataProvider = "resolveWithPrefer")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   437
    public void resolveWithPrefer(String prefer, String cfile, String publicId,
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   438
            String systemId, String expected) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   439
        URI catalogFile = getClass().getResource(cfile).toURI();
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   440
        CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).with(CatalogFeatures.Feature.RESOLVE, "ignore").build();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   441
        CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   442
        String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   443
        Assert.assertEquals(expected, result);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   444
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   445
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   446
    /**
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   447
     * @bug 8150969
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   448
     * Verifies that the defer attribute set in the catalog file takes precedence
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   449
     * over other settings, in which case, whether next and delegate Catalogs will
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   450
     * be loaded is determined by the defer attribute.
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   451
     */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   452
    @Test(dataProvider = "invalidAltCatalogs", expectedExceptions = CatalogException.class)
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   453
    public void testDeferAltCatalogs(String file) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   454
        URI catalogFile = getClass().getResource(file).toURI();
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   455
        CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "true").build();
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   456
        /*
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   457
          Since the defer attribute is set to false in the specified catalog file,
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   458
          the parent catalog will try to load the alt catalog, which will fail
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   459
          since it points to an invalid catalog.
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   460
        */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   461
        Catalog catalog = CatalogManager.catalog(features, catalogFile);
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   462
    }
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   463
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   464
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   465
    /**
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   466
     * @bug 8146237
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   467
     * PREFER from Features API taking precedence over catalog file
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   468
     */
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   469
    @Test
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   470
    public void testJDK8146237() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   471
        URI catalogFile = getClass().getResource("JDK8146237_catalog.xml").toURI();
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   472
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   473
        try {
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   474
            CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, "system").build();
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   475
            Catalog catalog = CatalogManager.catalog(features, catalogFile);
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   476
            CatalogResolver catalogResolver = CatalogManager.catalogResolver(catalog);
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   477
            String actualSystemId = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", "http://www.oracle.com/alt1sys.dtd").getSystemId();
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   478
            Assert.assertTrue(actualSystemId.contains("dummy.dtd"), "Resulting id should contain dummy.dtd, indicating a match by publicId");
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   479
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   480
        } catch (Exception e) {
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   481
            Assert.fail(e.getMessage());
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   482
        }
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   483
    }
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   484
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   485
    /*
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   486
       @bug 8146606
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   487
       Verifies that the resulting systemId does not contain duplicate slashes
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   488
    */
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   489
    @Test
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   490
    public void testRewriteSystem() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   491
        URI catalog = getClass().getResource("rewriteCatalog.xml").toURI();
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   492
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   493
        try {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   494
            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   495
            String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId();
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   496
            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   497
        } catch (Exception e) {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   498
            Assert.fail(e.getMessage());
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   499
        }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   500
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   501
    }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   502
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   503
    /*
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   504
       @bug 8146606
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   505
       Verifies that the resulting systemId does not contain duplicate slashes
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   506
    */
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   507
    @Test
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   508
    public void testRewriteUri() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   509
        URI catalog = getClass().getResource("rewriteCatalog.xml").toURI();
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   510
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   511
        try {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   512
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   513
            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   514
            String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId();
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   515
            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   516
        } catch (Exception e) {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   517
            Assert.fail(e.getMessage());
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   518
        }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   519
    }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   520
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   521
    /*
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   522
       @bug 8144966
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   523
       Verifies that passing null as CatalogFeatures will result in a NPE.
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   524
    */
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   525
    @Test(expectedExceptions = NullPointerException.class)
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   526
    public void testFeatureNull() {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   527
        CatalogResolver resolver = CatalogManager.catalogResolver(null, null);
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   528
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   529
    }
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   530
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   531
    /*
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   532
       @bug 8144966
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   533
       Verifies that passing null as the URI will result in a NPE.
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   534
    */
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   535
    @Test(expectedExceptions = NullPointerException.class)
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   536
    public void testPathNull() {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   537
        URI uri = null;
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   538
        CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), uri);
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   539
    }
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   540
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   541
    /*
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   542
       Tests basic catalog feature by using a CatalogResolver instance to
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   543
    resolve a DTD reference to a locally specified DTD file. If the resolution
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   544
    is successful, the Handler shall return the value of the entity reference
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   545
    that matches the expected value.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   546
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   547
    @Test(dataProvider = "catalog")
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   548
    public void testCatalogResolver(String test, String expected, String catalogFile,
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   549
            String xml, SAXParser saxParser) throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   550
        URI catalog = null;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   551
        if (catalogFile != null) {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   552
            catalog = getClass().getResource(catalogFile).toURI();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   553
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   554
        String url = getClass().getResource(xml).getFile();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   555
        try {
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   556
            CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   557
            XMLReader reader = saxParser.getXMLReader();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   558
            reader.setEntityResolver(cr);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   559
            MyHandler handler = new MyHandler(saxParser);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   560
            reader.setContentHandler(handler);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   561
            reader.parse(url);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   562
            System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   563
            Assert.assertEquals(handler.getResult(), expected);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   564
        } catch (SAXException | IOException e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   565
            Assert.fail(e.getMessage());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   566
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   567
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   568
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   569
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   570
       Verifies that when there's no match, in this case only an invalid
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   571
    catalog is provided, the resolver will throw an exception by default.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   572
    */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   573
    @Test
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   574
    public void testInvalidCatalog() throws Exception {
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   575
        URI catalog = getClass().getResource("catalog_invalid.xml").toURI();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   576
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   577
        String test = "testInvalidCatalog";
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   578
        try {
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   579
            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   580
            String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   581
        } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   582
            String msg = e.getMessage();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   583
            if (msg != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   584
                if (msg.contains("No match found for publicId")) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   585
                    Assert.assertEquals(msg, "No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'.");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   586
                    System.out.println(test + ": expected [No match found for publicId 'null' and systemId 'http://remote/xml/dtd/sys/alice/docAlice.dtd'.]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   587
                    System.out.println("actual [" + msg + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   588
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   589
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   590
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   591
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   592
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   593
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   594
       Verifies that if resolve is "ignore", an empty InputSource will be returned
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   595
    when there's no match. The systemId is then null.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   596
    */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   597
    @Test
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   598
    public void testIgnoreInvalidCatalog() {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   599
        String catalog = getClass().getResource("catalog_invalid.xml").toExternalForm();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   600
        CatalogFeatures f = CatalogFeatures.builder()
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   601
                .with(Feature.FILES, catalog)
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   602
                .with(Feature.PREFER, "public")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   603
                .with(Feature.DEFER, "true")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   604
                .with(Feature.RESOLVE, "ignore")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   605
                .build();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   606
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   607
        String test = "testInvalidCatalog";
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   608
        try {
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 41847
diff changeset
   609
            CatalogResolver resolver = CatalogManager.catalogResolver(f);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   610
            String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   611
            System.out.println("testIgnoreInvalidCatalog: expected [null]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   612
            System.out.println("testIgnoreInvalidCatalog: expected [null]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   613
            System.out.println("actual [" + actualSystemId + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   614
            Assert.assertEquals(actualSystemId, null);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   615
        } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   616
            Assert.fail(e.getMessage());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   617
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   618
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   619
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   620
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   621
    /*
40582
1dddef49982c 8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents: 40223
diff changeset
   622
        DataProvider: used to verify CatalogResolver's resolve function.
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   623
        Data columns:
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   624
        catalog, uri or publicId, expectedFile, expectedUri, msg
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   625
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   626
        This DataProvider is copied from JCK ResolveTests' dataMatch1
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   627
     */
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   628
    @DataProvider(name = "resolveUri")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   629
    public Object[][] getDataForUriResolver() {
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   630
        return new Object[][]{
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   631
            {"uri.xml", "urn:publicid:-:Acme,+Inc.:DTD+Book+Version+1.0", null, "http://local/base/dtd/book.dtd", "Uri in publicId namespace is incorrectly unwrapped"},
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   632
        };
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   633
    }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37737
diff changeset
   634
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   635
    /*
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   636
        DataProvider: used to verify hierarchical catalogs. Refer to JCK test
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   637
    hierarchyOfCatFiles2.
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   638
     */
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   639
    @DataProvider(name = "hierarchyOfCatFilesData")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   640
    public Object[][] getHierarchyOfCatFilesData() {
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   641
        return new Object[][]{
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   642
            {"http://www.oracle.com/sequence.dtd", "first.dtd"},
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   643
            {"http://www.oracle.com/sequence_next.dtd", "next.dtd"},
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   644
            {"http://www.oracle.com/sequence_second.dtd", "second.dtd"}
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   645
        };
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   646
    }
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   647
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   648
    /*
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   649
        DataProvider: used to verify CatalogResolver's resolveEntity function.
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   650
        Data columns:
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   651
        catalog, prefer, systemId, publicId, expectedUri, expectedFile, msg
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   652
     */
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   653
    @DataProvider(name = "resolveEntity")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   654
    public Object[][] getDataForMatchingBothIds() {
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   655
        String expected = "http://www.groupxmlbase.com/dtds/rewrite.dtd";
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   656
        return new Object[][]{
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   657
            {"rewriteSystem_id.xml", "system", "http://www.sys00test.com/rewrite.dtd", "PUB-404", expected, expected, "Relative rewriteSystem with xml:base at group level failed"},
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   658
        };
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   659
    }
37737
5b1ec476d3e7 8154220: Semi-colon delimited list of catalog files in System property is throwing IllegalArgumentException
joehw
parents: 37384
diff changeset
   660
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   661
    static String id = "http://openjdk.java.net/xml/catalog/dtd/system.dtd";
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   662
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   663
       DataProvider: used to verify how prefer settings affect the result of the
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   664
        Catalog's matching operation.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   665
        Data columns:
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   666
        prefer, catalog, publicId, systemId, expected result
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   667
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   668
    @DataProvider(name = "matchWithPrefer")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   669
    public Object[][] getDataForMatch() {
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   670
        return new Object[][]{
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   671
            {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   672
            {"public", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   673
            {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   674
            {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   675
            {"system", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   676
            {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   677
            {"public", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   678
            {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   679
            {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   680
            {"system", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   681
            {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   682
            {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   683
        };
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   684
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   685
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   686
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   687
       DataProvider: used to verify how prefer settings affect the result of the
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   688
        CatalogResolver's resolution operation.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   689
        Data columns:
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   690
        prefer, catalog, publicId, systemId, expected result
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   691
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   692
    @DataProvider(name = "resolveWithPrefer")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   693
    public Object[][] getDataForResolve() {
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   694
        return new Object[][]{
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   695
            {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   696
            {"system", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   697
            {"system", "pubOnly.xml", id, id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   698
            {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   699
            {"public", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   700
            {"public", "pubOnly.xml", id, id, "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   701
            {"system", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   702
            {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   703
            {"system", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   704
            {"public", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   705
            {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   706
            {"public", "sysOnly.xml", id, id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   707
            {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   708
            {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   709
            {"system", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   710
            {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   711
            {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   712
            {"public", "sysAndPub.xml", id, id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   713
        };
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   714
    }
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   715
    /*
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   716
       DataProvider: catalogs that contain invalid next or delegate catalogs.
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   717
                     The defer attribute is set to false.
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   718
     */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   719
    @DataProvider(name = "invalidAltCatalogs")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   720
    public Object[][] getCatalogs() {
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   721
        return new Object[][]{
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   722
            {"defer_false_2.xml"},
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   723
            {"defer_del_false.xml"}
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   724
        };
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   725
    }
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   726
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   727
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   728
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   729
       DataProvider: provides test name, expected string, the catalog, and XML
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   730
       document.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   731
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   732
    @DataProvider(name = "catalog")
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   733
    public Object[][] getCatalog() {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   734
        return new Object[][]{
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   735
            {"testSystem", "Test system entry", "catalog.xml", "system.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   736
            {"testRewriteSystem", "Test rewritesystem entry", "catalog.xml", "rewritesystem.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   737
            {"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   738
            {"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   739
            {"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   740
            {"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   741
            {"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   742
        };
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   743
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   744
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   745
    SAXParser getParser() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   746
        SAXParser saxParser = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   747
        try {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   748
            SAXParserFactory factory = SAXParserFactory.newInstance();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   749
            factory.setNamespaceAware(true);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   750
            saxParser = factory.newSAXParser();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   751
        } catch (ParserConfigurationException | SAXException e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   752
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   753
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   754
        return saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   755
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   756
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   757
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   758
     * SAX handler
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   759
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   760
    public class MyHandler extends DefaultHandler2 implements ErrorHandler {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   761
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   762
        StringBuilder textContent = new StringBuilder();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   763
        SAXParser saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   764
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   765
        MyHandler(SAXParser saxParser) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   766
            textContent.setLength(0);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   767
            this.saxParser = saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   768
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   769
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   770
        String getResult() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   771
            return textContent.toString();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   772
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   773
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   774
        @Override
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   775
        public void startElement(String uri, String localName, String qName, Attributes attributes)
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 38818
diff changeset
   776
                throws SAXException {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   777
            textContent.delete(0, textContent.length());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   778
            try {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   779
                System.out.println("Element: " + uri + ":" + localName + " " + qName);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   780
            } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   781
                throw new SAXException(e);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   782
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   783
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   784
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   785
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   786
        @Override
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   787
        public void characters(char ch[], int start, int length) throws SAXException {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   788
            textContent.append(ch, start, length);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   789
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   790
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   791
}