jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java
author joehw
Tue, 12 Apr 2016 14:44:23 -0700
changeset 37382 c7d898d8da12
parent 36984 4d76e25cb8d3
child 37384 04a4a89d81b9
permissions -rw-r--r--
8151162: Public entries not searched when prefer='system' Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     1
/*
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
     2
 * Copyright (c) 2015, 2016, 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
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    25
import java.io.IOException;
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
    26
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
    27
import javax.xml.catalog.CatalogException;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    28
import javax.xml.catalog.CatalogFeatures;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    29
import javax.xml.catalog.CatalogFeatures.Feature;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    30
import javax.xml.catalog.CatalogManager;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    31
import javax.xml.catalog.CatalogResolver;
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
    32
import javax.xml.catalog.CatalogUriResolver;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    33
import javax.xml.parsers.ParserConfigurationException;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    34
import javax.xml.parsers.SAXParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    35
import javax.xml.parsers.SAXParserFactory;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    36
import org.testng.Assert;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    37
import org.testng.annotations.DataProvider;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    38
import org.testng.annotations.Test;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    39
import org.xml.sax.Attributes;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    40
import org.xml.sax.ErrorHandler;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    41
import org.xml.sax.SAXException;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    42
import org.xml.sax.XMLReader;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    43
import org.xml.sax.ext.DefaultHandler2;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    44
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    45
/*
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    46
 * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    47
 * @summary Tests basic Catalog functions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    48
 */
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
    49
public class CatalogTest {
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    50
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    51
     * @bug 8151162
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    52
     * 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
    53
     * results as expected.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    54
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    55
    @Test(dataProvider = "matchWithPrefer")
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    56
    public void matchWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    57
        String catalogFile = getClass().getResource(cfile).getFile();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    58
        Catalog c = CatalogManager.catalog(CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).build(), catalogFile);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    59
        String result;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    60
        if (publicId != null && publicId.length() > 0) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    61
            result = c.matchPublic(publicId);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    62
        } else {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    63
            result = c.matchSystem(systemId);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    64
        }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    65
        Assert.assertEquals(expected, result);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    66
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    67
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    68
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    69
     * @bug 8151162
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    70
     * Verifies that the CatalogResolver resolves specified publicId or systemId
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    71
     * in accordance with the prefer setting.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    72
     * prefer "system": resolves with a system entry.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    73
     *                  Exception: use the public entry when the catalog contains
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    74
     *                  only public entry and only publicId is specified.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    75
     * prefer "public": attempts to resolve with a system entry;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    76
     *                  attempts to resolve with a public entry if no matching
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    77
     *                  system entry is found.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    78
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    79
    @Test(dataProvider = "resolveWithPrefer")
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    80
    public void resolveWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    81
        String catalogFile = getClass().getResource(cfile).getFile();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    82
        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
    83
        CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    84
        String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    85
        Assert.assertEquals(expected, result);
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    86
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
    87
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
    88
    /**
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    89
     * @bug 8150969
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    90
     * 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
    91
     * 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
    92
     * 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
    93
     */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    94
    @Test(dataProvider = "invalidAltCatalogs", expectedExceptions = CatalogException.class)
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    95
    public void testDeferAltCatalogs(String file) {
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    96
        String catalogFile = getClass().getResource(file).getFile();
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    97
        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
    98
        /*
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
    99
          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
   100
          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
   101
          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
   102
        */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   103
        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
   104
    }
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   105
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   106
    /**
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   107
     * @bug 8151154
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   108
     * Verifies that the CatalogFeatures' builder throws IllegalArgumentException
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   109
     * on invalid file inputs.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   110
     * @param file the file path
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   111
     */
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   112
    @Test(dataProvider = "invalidPaths", expectedExceptions = IllegalArgumentException.class)
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   113
    public void testFileInput(String file) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   114
            CatalogFeatures features = CatalogFeatures.builder()
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   115
                .with(CatalogFeatures.Feature.FILES, file)
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   116
                .build();
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   117
    }
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   118
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   119
    /**
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   120
     * @bug 8146237
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   121
     * 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
   122
     */
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   123
    @Test
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   124
    public void testJDK8146237() {
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   125
        String catalogFile = getClass().getResource("JDK8146237_catalog.xml").getFile();
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   126
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   127
        try {
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   128
            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
   129
            Catalog catalog = CatalogManager.catalog(features, catalogFile);
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   130
            CatalogResolver catalogResolver = CatalogManager.catalogResolver(catalog);
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   131
            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
   132
            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
   133
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   134
        } catch (Exception e) {
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   135
            Assert.fail(e.getMessage());
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   136
        }
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   137
    }
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   138
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   139
    /*
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   140
       @bug 8146606
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   141
       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
   142
    */
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   143
    @Test
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   144
    public void testRewriteSystem() {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   145
        String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   146
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   147
        try {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   148
            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   149
            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
   150
            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   151
        } catch (Exception e) {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   152
            Assert.fail(e.getMessage());
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   153
        }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   154
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   155
    }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   156
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   157
    /*
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   158
       @bug 8146606
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   159
       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
   160
    */
36029
a847c5a7e22d 8146237: PREFER from Features API taking precedence over catalog file
joehw
parents: 34985
diff changeset
   161
    @Test
34985
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   162
    public void testRewriteUri() {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   163
        String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   164
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   165
        try {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   166
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   167
            CatalogUriResolver resolver = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalog);
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   168
            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
   169
            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   170
        } catch (Exception e) {
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   171
            Assert.fail(e.getMessage());
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   172
        }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   173
    }
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   174
512ebcf54647 8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents: 34984
diff changeset
   175
    /*
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   176
       @bug 8144966
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   177
       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
   178
    */
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   179
    @Test(expectedExceptions = NullPointerException.class)
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   180
    public void testFeatureNull() {
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   181
        CatalogResolver resolver = CatalogManager.catalogResolver(null, "");
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   182
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   183
    }
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   184
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   185
    /*
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   186
       @bug 8144966
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   187
       Verifies that passing null as the path will result in a NPE.
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   188
    */
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   189
    @Test(expectedExceptions = NullPointerException.class)
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   190
    public void testPathNull() {
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   191
        String path = null;
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   192
        CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), path);
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   193
    }
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   194
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   195
    /*
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   196
       Tests basic catalog feature by using a CatalogResolver instance to
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   197
    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
   198
    is successful, the Handler shall return the value of the entity reference
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   199
    that matches the expected value.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   200
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   201
    @Test(dataProvider = "catalog")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   202
    public void testCatalogResolver(String test, String expected, String catalogFile, String xml, SAXParser saxParser) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   203
        String catalog = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   204
        if (catalogFile != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   205
            catalog = getClass().getResource(catalogFile).getFile();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   206
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   207
        String url = getClass().getResource(xml).getFile();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   208
        try {
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   209
            CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   210
            XMLReader reader = saxParser.getXMLReader();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   211
            reader.setEntityResolver(cr);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   212
            MyHandler handler = new MyHandler(saxParser);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   213
            reader.setContentHandler(handler);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   214
            reader.parse(url);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   215
            System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   216
            Assert.assertEquals(handler.getResult(), expected);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   217
        } catch (SAXException | IOException e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   218
            Assert.fail(e.getMessage());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   219
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   220
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   221
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   222
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   223
       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
   224
    catalog is provided, the resolver will throw an exception by default.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   225
    */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   226
    @Test
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   227
    public void testInvalidCatalog() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   228
        String catalog = getClass().getResource("catalog_invalid.xml").getFile();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   229
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   230
        String test = "testInvalidCatalog";
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   231
        try {
34984
48a409c654e9 8144966: Catalog API: Null handling and reference to Reader
joehw
parents: 33542
diff changeset
   232
            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   233
            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
   234
        } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   235
            String msg = e.getMessage();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   236
            if (msg != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   237
                if (msg.contains("No match found for publicId")) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   238
                    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
   239
                    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
   240
                    System.out.println("actual [" + msg + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   241
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   242
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   243
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   244
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   245
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   246
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   247
       Verifies that if resolve is "ignore", an empty InputSource will be returned
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   248
    when there's no match. The systemId is then null.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   249
    */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   250
    @Test
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   251
    public void testIgnoreInvalidCatalog() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   252
        String catalog = getClass().getResource("catalog_invalid.xml").getFile();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   253
        CatalogFeatures f = CatalogFeatures.builder()
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   254
                .with(Feature.FILES, catalog)
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   255
                .with(Feature.PREFER, "public")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   256
                .with(Feature.DEFER, "true")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   257
                .with(Feature.RESOLVE, "ignore")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   258
                .build();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   259
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   260
        String test = "testInvalidCatalog";
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   261
        try {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   262
            CatalogResolver resolver = CatalogManager.catalogResolver(f, "");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   263
            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
   264
            System.out.println("testIgnoreInvalidCatalog: expected [null]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   265
            System.out.println("testIgnoreInvalidCatalog: expected [null]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   266
            System.out.println("actual [" + actualSystemId + "]");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   267
            Assert.assertEquals(actualSystemId, null);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   268
        } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   269
            Assert.fail(e.getMessage());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   270
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   271
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   272
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   273
    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
   274
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   275
       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
   276
        Catalog's matching operation.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   277
        Data columns:
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   278
        prefer, catalog, publicId, systemId, expected result
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   279
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   280
    @DataProvider(name = "matchWithPrefer")
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   281
    Object[][] getDataForMatch() {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   282
        return new Object[][]{
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   283
            {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   284
            {"public", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   285
            {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   286
            {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   287
            {"system", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   288
            {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   289
            {"public", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   290
            {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   291
            {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   292
            {"system", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   293
            {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   294
            {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   295
        };
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   296
    }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   297
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   298
    /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   299
       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
   300
        CatalogResolver's resolution operation.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   301
        Data columns:
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   302
        prefer, catalog, publicId, systemId, expected result
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   303
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   304
    @DataProvider(name = "resolveWithPrefer")
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   305
    Object[][] getDataForResolve() {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   306
        return new Object[][]{
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   307
            {"system", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   308
            {"system", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   309
            {"system", "pubOnly.xml", id, id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   310
            {"public", "pubOnly.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   311
            {"public", "pubOnly.xml", "", id, null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   312
            {"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
   313
            {"system", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   314
            {"system", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   315
            {"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
   316
            {"public", "sysOnly.xml", id, "", null},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   317
            {"public", "sysOnly.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   318
            {"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
   319
            {"system", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   320
            {"system", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   321
            {"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
   322
            {"public", "sysAndPub.xml", id, "", "http://local/base/dtd/public.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   323
            {"public", "sysAndPub.xml", "", id, "http://local/base/dtd/system.dtd"},
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   324
            {"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
   325
        };
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36984
diff changeset
   326
    }
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   327
    /*
36984
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   328
       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
   329
                     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
   330
     */
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   331
    @DataProvider(name = "invalidAltCatalogs")
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   332
    Object[][] getCatalogs() {
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   333
        return new Object[][]{
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   334
            {"defer_false_2.xml"},
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   335
            {"defer_del_false.xml"}
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   336
        };
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   337
    }
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   338
4d76e25cb8d3 8150969: DEFER from Features API is taking precedence over defer preference in catalog file
joehw
parents: 36700
diff changeset
   339
    /*
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   340
       DataProvider: for testing the verification of file paths by
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   341
                     the CatalogFeatures builder
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   342
     */
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   343
    @DataProvider(name = "invalidPaths")
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   344
    Object[][] getFiles() {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   345
        return new Object[][]{
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   346
            {null},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   347
            {""},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   348
            {"file:a/b\\c"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   349
            {"file:/../../.."},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   350
            {"c:/te:t"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   351
            {"c:/te?t"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   352
            {"c/te*t"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   353
            {"in|valid.txt"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   354
            {"shema:invalid.txt"},
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   355
        };
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 36029
diff changeset
   356
    }
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   357
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   358
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   359
       DataProvider: provides test name, expected string, the catalog, and XML
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   360
       document.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   361
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   362
    @DataProvider(name = "catalog")
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   363
    Object[][] getCatalog() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   364
        return new Object[][]{
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   365
            {"testSystem", "Test system entry", "catalog.xml", "system.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   366
            {"testRewriteSystem", "Test rewritesystem entry", "catalog.xml", "rewritesystem.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   367
            {"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   368
            {"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   369
            {"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   370
            {"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   371
            {"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()},
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   372
        };
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   373
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   374
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   375
    SAXParser getParser() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   376
        SAXParser saxParser = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   377
        try {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   378
            SAXParserFactory factory = SAXParserFactory.newInstance();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   379
            factory.setNamespaceAware(true);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   380
            saxParser = factory.newSAXParser();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   381
        } catch (ParserConfigurationException | SAXException e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   382
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   383
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   384
        return saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   385
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   386
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   387
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   388
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   389
     * SAX handler
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   390
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   391
    public class MyHandler extends DefaultHandler2 implements ErrorHandler {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   392
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   393
        StringBuilder textContent = new StringBuilder();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   394
        SAXParser saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   395
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   396
        MyHandler(SAXParser saxParser) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   397
            textContent.setLength(0);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   398
            this.saxParser = saxParser;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   399
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   400
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   401
        String getResult() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   402
            return textContent.toString();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   403
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   404
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   405
        @Override
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   406
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   407
            textContent.delete(0, textContent.length());
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   408
            try {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   409
                System.out.println("Element: " + uri + ":" + localName + " " + qName);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   410
            } catch (Exception e) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   411
                throw new SAXException(e);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   412
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   413
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   414
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   415
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   416
        @Override
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   417
        public void characters(char ch[], int start, int length) throws SAXException {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   418
            textContent.append(ch, start, length);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   419
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   420
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   421
}