ResolveFeatureTest.java revision 988:1c6c21d87aa4
1/*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24package catalog;
25
26import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
27import static catalog.CatalogTestUtils.CATALOG_URI;
28import static catalog.CatalogTestUtils.RESOLVE_CONTINUE;
29import static catalog.CatalogTestUtils.RESOLVE_IGNORE;
30import static catalog.CatalogTestUtils.RESOLVE_STRICT;
31import static catalog.CatalogTestUtils.catalogResolver;
32import static catalog.CatalogTestUtils.catalogUriResolver;
33import static catalog.ResolutionChecker.checkSysIdResolution;
34import static catalog.ResolutionChecker.checkUriResolution;
35import static javax.xml.catalog.CatalogFeatures.builder;
36
37import javax.xml.catalog.CatalogException;
38import javax.xml.catalog.CatalogFeatures;
39import javax.xml.catalog.CatalogFeatures.Feature;
40import javax.xml.catalog.CatalogResolver;
41
42import org.testng.annotations.Listeners;
43import org.testng.annotations.Test;
44
45/*
46 * @test
47 * @bug 8077931
48 * @library /javax/xml/jaxp/libs
49 * @run testng/othervm -DrunSecMngr=true catalog.ResolveFeatureTest
50 * @run testng/othervm catalog.ResolveFeatureTest
51 * @summary This case tests how does resolve feature affect the catalog
52 *          resolution.
53 */
54@Listeners({jaxp.library.FilePolicy.class})
55public class ResolveFeatureTest {
56
57    /*
58     * For strict external identifier resolution, if no match is found,
59     * it should throw CatalogException.
60     */
61    @Test(expectedExceptions = CatalogException.class)
62    public void testStrictResolutionOnEntityResolver() {
63        createEntityResolver(RESOLVE_STRICT).resolveEntity(null,
64                "http://remote/dtd/alice/docAliceDummy.dtd");
65    }
66
67    /*
68     * For strict URI reference resolution, if no match is found,
69     * it should throw CatalogException.
70     */
71    @Test(expectedExceptions = CatalogException.class)
72    public void testStrictResolutionOnUriResolver() {
73        createUriResolver(RESOLVE_STRICT).resolve(
74                "http://remote/dtd/alice/docAliceDummy.dtd", null);
75    }
76
77    /*
78     * For continue external identifier resolution, if no match is found,
79     * it should continue the process.
80     */
81    @Test
82    public void testContinueResolutionOnEntityResolver() {
83        CatalogResolver resolver = createEntityResolver(RESOLVE_CONTINUE);
84        resolver.resolveEntity(null, "http://remote/dtd/bob/docBobDummy.dtd");
85        checkSysIdResolution(resolver, "http://remote/dtd/bob/docBob.dtd",
86                "http://local/base/dtd/docBobSys.dtd");
87    }
88
89    /*
90     * For continue URI reference resolution, if no match is found,
91     * it should continue the process.
92     */
93    @Test
94    public void testContinueResolutionOnUriResolver() {
95        CatalogResolver resolver = createUriResolver(RESOLVE_CONTINUE);
96        resolver.resolve("http://remote/dtd/bob/docBobDummy.dtd", null);
97        checkUriResolution(resolver, "http://remote/dtd/bob/docBob.dtd",
98                "http://local/base/dtd/docBobURI.dtd");
99    }
100
101    /*
102     * For ignore external identifier resolution, if no match is found,
103     * it should break the process and return null.
104     */
105    @Test
106    public void testIgnoreResolutionOnEntityResolver() {
107        checkSysIdResolution(createEntityResolver(RESOLVE_IGNORE),
108                "http://remote/dtd/carl/docCarlDummy.dtd", null);
109    }
110
111    /*
112     * For ignore URI reference resolution, if no match is found,
113     * it should break the process and return null.
114     */
115    @Test
116    public void testIgnoreResolutionOnUriResolver() {
117        checkUriResolution(createUriResolver(RESOLVE_IGNORE),
118                "http://remote/dtd/carl/docCarlDummy.dtd", null);
119    }
120
121    private CatalogResolver createEntityResolver(String resolve) {
122        return catalogResolver(createFeature(resolve), CATALOG_SYSTEM);
123    }
124
125    private CatalogResolver createUriResolver(String resolve) {
126        return catalogUriResolver(createFeature(resolve), CATALOG_URI);
127    }
128
129    private CatalogFeatures createFeature(String resolve) {
130        return builder().with(Feature.RESOLVE, resolve).build();
131    }
132}
133