LoadCatalogTest.java revision 968:874082a9b565
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_PUBLIC;
27import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
28import static catalog.CatalogTestUtils.CATALOG_URI;
29import static catalog.CatalogTestUtils.catalogResolver;
30import static catalog.CatalogTestUtils.catalogUriResolver;
31import static catalog.ResolutionChecker.checkSysIdResolution;
32import static catalog.ResolutionChecker.checkUriResolution;
33
34import javax.xml.catalog.CatalogException;
35import javax.xml.catalog.CatalogResolver;
36import javax.xml.catalog.CatalogUriResolver;
37
38import org.testng.annotations.DataProvider;
39import org.testng.annotations.Listeners;
40import org.testng.annotations.Test;
41
42/*
43 * @test
44 * @bug 8077931
45 * @library /javax/xml/jaxp/libs
46 * @run testng/othervm -DrunSecMngr=true catalog.LoadCatalogTest
47 * @run testng/othervm catalog.LoadCatalogTest
48 * @summary When catalog resolver loads catalog files, the current catalog file
49 *          and the catalog files specified by the nextCatalog entries may not
50 *          accessible. This case tests how does the resolver handle this issue.
51 */
52@Listeners({jaxp.library.FilePolicy.class})
53public class LoadCatalogTest {
54
55    private static final String CATALOG_LOADCATALOGFILES = "loadCatalogFiles.xml";
56    private static final String CATALOG_DUMMY = "dummy.xml";
57
58    private static final String ID_ALICE = "http://remote/dtd/alice/docAlice.dtd";
59    private static final String ID_DUMMY = "http://remote/dtd/doc.dtd";
60
61    @Test(dataProvider = "entityResolver")
62    public void testMatchOnEntityResolver(CatalogResolver resolver) {
63        checkSysIdResolution(resolver, ID_ALICE,
64                "http://local/dtd/docAliceSys.dtd");
65    }
66
67    @DataProvider(name = "entityResolver")
68    public Object[][] entityResolver() {
69        return new Object[][] {
70                // This EntityResolver loads multiple catalog files one by one.
71                // All of the files are available.
72                { catalogResolver(CATALOG_PUBLIC, CATALOG_URI,
73                        CATALOG_SYSTEM) },
74
75                // This EntityResolver loads multiple catalog files one by one,
76                // but the middle one isn't existing.
77                { catalogResolver(CATALOG_PUBLIC, CATALOG_DUMMY,
78                        CATALOG_SYSTEM) } };
79    }
80
81    @Test(dataProvider = "uriResolver")
82    public void testMatchOnUriResolver(CatalogUriResolver resolver) {
83        checkUriResolution(resolver, ID_ALICE,
84                "http://local/dtd/docAliceURI.dtd");
85    }
86
87    @DataProvider(name = "uriResolver")
88    public Object[][] uriResolver() {
89        return new Object[][] {
90                // This URIResolver loads multiple catalog files one by one.
91                // All of the files are available.
92                { catalogUriResolver(CATALOG_PUBLIC, CATALOG_SYSTEM,
93                        CATALOG_URI) },
94
95                // This URIResolver loads multiple catalog files one by one,
96                // but the middle one isn't existing.
97                { catalogUriResolver(CATALOG_PUBLIC, CATALOG_DUMMY,
98                        CATALOG_URI) } };
99    }
100
101    @Test(dataProvider = "catalogName",
102            expectedExceptions = CatalogException.class)
103    public void testExceptionOnEntityResolver(String[] catalogName) {
104        catalogResolver(catalogName).resolveEntity(null, ID_DUMMY);
105    }
106
107    @Test(dataProvider = "catalogName",
108            expectedExceptions = CatalogException.class)
109    public void testExceptionOnUriResolver(String[] catalogName) {
110        catalogUriResolver(catalogName).resolve(ID_DUMMY, null);
111    }
112
113    @DataProvider(name = "catalogName")
114    public Object[][] catalogName() {
115        return new Object[][] {
116                // This catalog file set includes null catalog files.
117                { (String[]) null },
118
119                // This catalog file set includes one catalog file, but this
120                // catalog defines a non-existing next catalog.
121                { new String[] { CATALOG_LOADCATALOGFILES } } };
122    }
123}
124
125