8379441: Refactor jaxp/javax catalog tests to use JUnit

Reviewed-by: joehw, dfuchs
This commit is contained in:
David Beaumont 2026-03-09 13:07:10 +00:00 committed by SendaoYan
parent 82430a7666
commit e018cd60a0
28 changed files with 412 additions and 436 deletions

View File

@ -23,18 +23,20 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.CatalogReferCircularityTest
* @run junit/othervm catalog.CatalogReferCircularityTest
* @summary Via nextCatalog entry, the catalog reference chain may be
* a (partial) closed circuit. For instance, a catalog may use itself
* as an additional catalog specified in its own nextCatalog entry.
@ -42,22 +44,19 @@ import org.testng.annotations.Test;
*/
public class CatalogReferCircularityTest {
@Test(dataProvider = "catalogName",
expectedExceptions = CatalogException.class)
@ParameterizedTest
@ValueSource(strings={
// This catalog defines itself as next catalog.
"catalogReferCircle-itself.xml",
// This catalog defines catalogReferCircle-right.xml as its next
// catalog. And catalogReferCircle-right.xml also defines
// catalogReferCircle-left.xml as its next catalog, too.
"catalogReferCircle-left.xml" })
public void testReferCircularity(String catalogFile) {
catalogResolver(catalogFile).resolveEntity(null,
"http://remote/dtd/ghost/docGhost.dtd");
}
@DataProvider(name = "catalogName")
public Object[][] catalogName() {
return new Object[][] {
// This catalog defines itself as next catalog.
{ "catalogReferCircle-itself.xml" },
// This catalog defines catalogReferCircle-right.xml as its next
// catalog. And catalogReferCircle-right.xml also defines
// catalogReferCircle-left.xml as its next catalog, too.
{ "catalogReferCircle-left.xml" } };
CatalogResolver resolver = catalogResolver(catalogFile);
Assertions.assertThrows(
CatalogException.class,
() -> resolver.resolveEntity(null, "http://remote/dtd/ghost/docGhost.dtd"));
}
}

View File

@ -23,42 +23,30 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.DefaultFeaturesTest
* @run junit/othervm catalog.DefaultFeaturesTest
* @summary This case tests if the default feature values are expected.
*/
public class DefaultFeaturesTest {
private CatalogFeatures defaultFeature;
@BeforeClass
public void init() {
defaultFeature = CatalogFeatures.defaults();
}
@Test(dataProvider="feature-value")
@ParameterizedTest
@MethodSource("defaultFeaturesData")
public void testDefaultFeatures(Feature feature, String expected) {
String featureValue = defaultFeature.get(feature);
if (expected != null) {
Assert.assertEquals(featureValue, expected);
} else {
Assert.assertNull(featureValue);
}
CatalogFeatures defaultFeature = CatalogFeatures.defaults();
assertEquals(expected, defaultFeature.get(feature));
}
@DataProvider(name = "feature-value")
public Object[][] data() {
public static Object[][] defaultFeaturesData() {
return new Object[][] {
{ Feature.FILES, null },
{ Feature.PREFER, CatalogTestUtils.PREFER_PUBLIC },

View File

@ -23,42 +23,43 @@
package catalog;
import static catalog.CatalogTestUtils.DEFER_FALSE;
import static catalog.CatalogTestUtils.DEFER_TRUE;
import static catalog.CatalogTestUtils.getCatalogPath;
import static javax.xml.catalog.CatalogFeatures.Feature.DEFER;
import java.lang.reflect.Method;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.Catalog;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import java.lang.reflect.Method;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.DEFER_FALSE;
import static catalog.CatalogTestUtils.DEFER_TRUE;
import static catalog.CatalogTestUtils.getCatalogPath;
import static javax.xml.catalog.CatalogFeatures.Feature.DEFER;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* @test
* @bug 8077931 8176405
* @library /javax/xml/jaxp/libs
* @modules java.xml/javax.xml.catalog:open
* @run testng/othervm catalog.DeferFeatureTest
* @run junit/othervm catalog.DeferFeatureTest
* @summary This case tests whether the catalogs specified in delegateSystem,
* delegatePublic, delegateURI and nextCatalog entries are used lazily
* in resolution via defer feature.
*/
public class DeferFeatureTest {
@Test(dataProvider = "catalog-countOfLoadedCatalogFile")
@ParameterizedTest
@MethodSource("deferData")
public void testDeferFeature(Catalog catalog, int catalogCount)
throws Exception {
Assert.assertEquals(loadedCatalogCount(catalog), catalogCount);
assertEquals(catalogCount, loadedCatalogCount(catalog));
}
@Test(dataProvider = "testDeferFeatureByResolve")
@ParameterizedTest
@MethodSource("deferByResolveData")
public void testDeferFeatureByResolve(Catalog catalog, int catalogCount)
throws Exception {
CatalogResolver cr = createResolver(catalog);
@ -67,41 +68,39 @@ public class DeferFeatureTest {
cr.resolveEntity("-//REMOTE//DTD ALICE DOCALICE", "http://remote/dtd/alice/");
} catch (CatalogException ce) {}
Assert.assertEquals(loadedCatalogCount(catalog), catalogCount);
assertEquals(catalogCount, loadedCatalogCount(catalog));
}
@DataProvider(name = "catalog-countOfLoadedCatalogFile")
public Object[][] data() {
return new Object[][]{
// By default, alternative catalogs are not loaded.
{createCatalog(CatalogFeatures.defaults()), 1},
// Alternative catalogs are not loaded when DEFER is set to true.
{createCatalog(createDeferFeature(DEFER_TRUE)), 1},
// The 3 alternative catalogs are pre-loaded along with the parent
//when DEFER is set to false.
{createCatalog(createDeferFeature(DEFER_FALSE)), 4}};
public static Object[][] deferData() {
return new Object[][] {
// By default, alternative catalogs are not loaded.
{ createCatalog(CatalogFeatures.defaults()), 1 },
// Alternative catalogs are not loaded when DEFER is set to true.
{ createCatalog(createDeferFeature(DEFER_TRUE)), 1 },
// The 3 alternative catalogs are pre-loaded along with the parent
//when DEFER is set to false.
{ createCatalog(createDeferFeature(DEFER_FALSE)), 4 } };
}
@DataProvider(name = "testDeferFeatureByResolve")
public Object[][] getData() {
return new Object[][]{
{createCatalog(createDeferFeature(DEFER_TRUE)), 4}
public static Object[][] deferByResolveData() {
return new Object[][] {
{ createCatalog(createDeferFeature(DEFER_TRUE)), 4 }
};
}
private CatalogFeatures createDeferFeature(String defer) {
private static CatalogFeatures createDeferFeature(String defer) {
return CatalogFeatures.builder().with(DEFER, defer).build();
}
private Catalog createCatalog(CatalogFeatures feature) {
private static Catalog createCatalog(CatalogFeatures feature) {
return CatalogManager.catalog(feature, getCatalogPath("deferFeature.xml"));
}
private CatalogResolver createResolver(Catalog catalog) {
private static CatalogResolver createResolver(Catalog catalog) {
return CatalogManager.catalogResolver(catalog);
}
private int loadedCatalogCount(Catalog catalog) throws Exception {
private static int loadedCatalogCount(Catalog catalog) throws Exception {
Method method = catalog.getClass().getDeclaredMethod("loadedCatalogCount");
method.setAccessible(true);
return (int) method.invoke(catalog);

View File

@ -23,32 +23,32 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static catalog.ResolutionChecker.expectExceptionOnPubId;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static catalog.ResolutionChecker.expectExceptionOnPubId;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.DelegatePublicTest
* @run junit/othervm catalog.DelegatePublicTest
* @summary Get matched URIs from DelegatePublic entries.
*/
public class DelegatePublicTest {
@Test(dataProvider = "publicId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String publicId, String matchedUri) {
checkPubIdResolution(createResolver(), publicId, matchedUri);
}
@DataProvider(name = "publicId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified public id is defined in
// a delegate catalog file of the current catalog file.
@ -71,15 +71,15 @@ public class DelegatePublicTest {
"http://local/base/dtd/carl/docCarlPub.dtd" } };
}
@Test(dataProvider = "publicId-expectedExceptionClass")
@ParameterizedTest
@MethodSource("dataOnException")
public void testException(String publicId,
Class<? extends Throwable> expectedExceptionClass) {
expectExceptionOnPubId(createResolver(), publicId,
expectedExceptionClass);
}
@DataProvider(name = "publicId-expectedExceptionClass")
public Object[][] dataOnException() {
public static Object[][] dataOnException() {
return new Object[][] {
// The matched delegatePublic entry of the specified public id
// defines a non-existing delegate catalog file. That should
@ -93,7 +93,7 @@ public class DelegatePublicTest {
CatalogException.class } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("delegatePublic.xml");
}
}

View File

@ -23,32 +23,32 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.expectExceptionOnSysId;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.expectExceptionOnSysId;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.DelegateSystemTest
* @run junit/othervm catalog.DelegateSystemTest
* @summary Get matched URIs from delegateSystem entries.
*/
public class DelegateSystemTest {
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkSysIdResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified system id is defined in
// a delegate catalog file of the current catalog file.
@ -71,15 +71,15 @@ public class DelegateSystemTest {
"http://local/base/dtd/carl/docCarlDS.dtd"} };
}
@Test(dataProvider = "systemId-expectedExceptionClass")
@ParameterizedTest
@MethodSource("dataOnException")
public void testException(String systemId,
Class<? extends Throwable> expectedExceptionClass) {
expectExceptionOnSysId(createResolver(), systemId,
expectedExceptionClass);
}
@DataProvider(name = "systemId-expectedExceptionClass")
public Object[][] dataOnException() {
public static Object[][] dataOnException() {
return new Object[][] {
// The matched delegateSystem entry of the specified system id
// defines a non-existing delegate catalog file. That should
@ -93,7 +93,7 @@ public class DelegateSystemTest {
CatalogException.class } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("delegateSystem.xml");
}
}

View File

@ -23,32 +23,32 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkUriResolution;
import static catalog.ResolutionChecker.expectExceptionOnUri;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.DelegateUriTest
* @run junit/othervm catalog.DelegateUriTest
* @summary Get matched URIs from delegateURI entries.
*/
public class DelegateUriTest {
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String uri, String matchedUri) {
checkUriResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] data() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified URI reference is defined in
// a delegate catalog file of the current catalog file.
@ -71,14 +71,14 @@ public class DelegateUriTest {
"http://local/base/dtd/carl/docCarlDU.dtd"} };
}
@Test(dataProvider = "uri-expectedExceptionClass")
@ParameterizedTest
@MethodSource("dataOnException")
public void testException(String uri,
Class<? extends Throwable> expectedExceptionClass) {
expectExceptionOnUri(createResolver(), uri, expectedExceptionClass);
}
@DataProvider(name = "uri-expectedExceptionClass")
public Object[][] dataOnException() {
public static Object[][] dataOnException() {
return new Object[][] {
// The matched delegateURI entry of the specified URI reference
// defines a non-existing delegate catalog file. That should
@ -92,7 +92,7 @@ public class DelegateUriTest {
CatalogException.class } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogUriResolver("delegateUri.xml");
}
}

View File

@ -23,22 +23,22 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.GroupTest
* @run junit/othervm catalog.GroupTest
* @summary Get matched URIs from system, public and uri entries respectively,
* and some of the entries are enclosed by group entries.
*/
@ -46,13 +46,13 @@ public class GroupTest {
private static final String CATALOG_GROUP = "group.xml";
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataMatchSysId")
public void testMatchOnSysId(String uri, String matchedUri) {
checkSysIdResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnSysId() {
public static Object[][] dataMatchSysId() {
return new Object[][] {
// The matched URI of the specified system id is enclosed by a
// group entry.
@ -72,13 +72,13 @@ public class GroupTest {
"http://local/base/dtd/docCarlSys1.dtd" } };
}
@Test(dataProvider = "publicId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatchPubId")
public void testMatchOnPubId(String uri, String matchedUri) {
checkPubIdResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "publicId-matchedUri")
public Object[][] dataOnPubId() {
public static Object[][] dataOnMatchPubId() {
return new Object[][] {
// The matched URI of the specified public id is enclosed by a
// group entry.
@ -98,13 +98,13 @@ public class GroupTest {
"http://local/base/dtd/docCarlPub1.dtd" } };
}
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatchUri")
public void testMatchOnUri(String uri, String matchedUri) {
checkUriResolution(catalogUriResolver(CATALOG_GROUP), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnUri() {
public static Object[][] dataOnMatchUri() {
return new Object[][] {
// The matched URI of the specified URI reference is enclosed by
// a group entry.
@ -124,7 +124,7 @@ public class GroupTest {
"http://local/base/dtd/docAliceURI.dtd" } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver(CATALOG_GROUP);
}
}

View File

@ -23,6 +23,12 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.CATALOG_PUBLIC;
import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
import static catalog.CatalogTestUtils.CATALOG_URI;
@ -30,18 +36,13 @@ import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.LoadCatalogTest
* @run junit/othervm catalog.LoadCatalogTest
* @summary When catalog resolver loads catalog files, the current catalog file
* and the catalog files specified by the nextCatalog entries may not
* accessible. This case tests how does the resolver handle this issue.
@ -55,14 +56,14 @@ public class LoadCatalogTest {
private static final String ID_ALICE_URI = "http://remote/dtd/uri/alice/docAlice.dtd";
private static final String ID_DUMMY = "http://remote/dtd/doc.dtd";
@Test(dataProvider = "entityResolver")
@ParameterizedTest
@MethodSource("entityResolver")
public void testMatchOnEntityResolver(CatalogResolver resolver) {
checkSysIdResolution(resolver, ID_ALICE,
"http://local/dtd/docAliceSys.dtd");
}
@DataProvider(name = "entityResolver")
public Object[][] entityResolver() {
public static Object[][] entityResolver() {
return new Object[][] {
// This EntityResolver loads multiple catalog files one by one.
// All of the files are available.
@ -75,14 +76,14 @@ public class LoadCatalogTest {
CATALOG_SYSTEM) } };
}
@Test(dataProvider = "uriResolver")
@ParameterizedTest
@MethodSource("uriResolver")
public void testMatchOnUriResolver(CatalogResolver resolver) {
checkUriResolution(resolver, ID_ALICE_URI,
"http://local/dtd/docAliceURI.dtd");
}
@DataProvider(name = "uriResolver")
public Object[][] uriResolver() {
public static Object[][] uriResolver() {
return new Object[][] {
// This URIResolver loads multiple catalog files one by one.
// All of the files are available.
@ -95,20 +96,21 @@ public class LoadCatalogTest {
CATALOG_URI) } };
}
@Test(dataProvider = "catalogName",
expectedExceptions = CatalogException.class)
public void testExceptionOnEntityResolver(String[] catalogName) {
catalogResolver(catalogName).resolveEntity(null, ID_DUMMY);
@ParameterizedTest
@MethodSource("catalogName")
public void testException(String[] catalogName) {
CatalogResolver resolver = catalogResolver(catalogName);
assertThrows(CatalogException.class, () -> resolver.resolveEntity(null, ID_DUMMY));
}
@Test(dataProvider = "catalogName",
expectedExceptions = CatalogException.class)
@ParameterizedTest
@MethodSource("catalogName")
public void testExceptionOnUriResolver(String[] catalogName) {
catalogUriResolver(catalogName).resolve(ID_DUMMY, null);
CatalogResolver resolver = catalogUriResolver(catalogName);
assertThrows(CatalogException.class, () -> resolver.resolve(ID_DUMMY, null));
}
@DataProvider(name = "catalogName")
public Object[][] catalogName() {
public static Object[][] catalogName() {
return new Object[][] {
// This catalog file set includes null catalog files.
{ (String[]) null },

View File

@ -23,22 +23,22 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.NextCatalogTest
* @run junit/othervm catalog.NextCatalogTest
* @summary Get matched URIs from system, public and uri entries respectively,
* but some of the entries are defined in none-current catalog files.
*/
@ -49,13 +49,13 @@ public class NextCatalogTest {
private static final String CATALOG_NEXTCATALOGRIGHT
= "nextCatalog-right.xml";
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnSysId")
public void testNextCatalogOnSysId(String sytemId, String matchedUri) {
checkSysIdResolution(createEntityResolver(), sytemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnSysId() {
public static Object[][] dataOnSysId() {
return new Object[][] {
// This matched URI of the specified system id is defined in a
// next catalog file.
@ -81,13 +81,13 @@ public class NextCatalogTest {
"http://local/base/dtd/docDuplicateLeftSys.dtd" } };
}
@Test(dataProvider = "publicId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnPubId")
public void testNextCatalogOnPubId(String publicId, String matchedUri) {
checkPubIdResolution(createEntityResolver(), publicId, matchedUri);
}
@DataProvider(name = "publicId-matchedUri")
public Object[][] dataOnPubId() {
public static Object[][] dataOnPubId() {
return new Object[][] {
// This matched URI of the specified public id is defined in a
// next catalog file.
@ -113,13 +113,13 @@ public class NextCatalogTest {
"http://local/base/dtd/docDuplicateLeftPub.dtd" } };
}
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnUri")
public void testNextCatalogOnUri(String uri, String matchedUri) {
checkUriResolution(createUriResolver(), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnUri() {
public static Object[][] dataOnUri() {
return new Object[][] {
// This matched URI of the specified URI reference is defined in
// a next catalog file.
@ -145,12 +145,12 @@ public class NextCatalogTest {
"http://local/base/dtd/docDuplicateLeftURI.dtd" } };
}
private CatalogResolver createEntityResolver() {
private static CatalogResolver createEntityResolver() {
return catalogResolver(CATALOG_NEXTCATALOGLEFT,
CATALOG_NEXTCATALOGRIGHT);
}
private CatalogResolver createUriResolver() {
private static CatalogResolver createUriResolver() {
return catalogUriResolver(CATALOG_NEXTCATALOGLEFT,
CATALOG_NEXTCATALOGRIGHT);
}

View File

@ -23,22 +23,22 @@
package catalog;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.NormalizationTest
* @run junit/othervm catalog.NormalizationTest
* @summary Before matching identifiers and URI references, it has to normalize
* the passed identifiers and URI references. And then the catalog
* resolver uses the normalized stuff to search the counterparts in
@ -48,23 +48,25 @@ public class NormalizationTest {
private static final String CATALOG_NORMALIZATION = "normalization.xml";
@Test(dataProvider = "systemId_uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnSysIdAndUri")
public void testNormalizationOnSysId(String sytemId, String matchedUri) {
checkSysIdResolution(createEntityResolver(), sytemId, matchedUri);
}
@Test(dataProvider = "publicId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnPubId")
public void testNormalizationOnPubId(String publicId, String matchedUri) {
checkPubIdResolution(createEntityResolver(), publicId, matchedUri);
}
@Test(dataProvider = "systemId_uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnSysIdAndUri")
public void testNormalizationOnUri(String uri, String matchedUri) {
checkUriResolution(createUriResolver(), uri, matchedUri);
}
@DataProvider(name = "systemId_uri-matchedUri")
public Object[][] dataOnSysIdAndUri() {
public static Object[][] dataOnSysIdAndUri() {
return new Object[][] {
// The specified system id/URI reference contains spaces. And
// the counterparts in system/uri entries also contain spaces.
@ -85,8 +87,7 @@ public class NormalizationTest {
"http://local/base/dtd/docBobSys.dtd" } };
}
@DataProvider(name = "publicId-matchedUri")
public Object[][] dataOnPubId() {
public static Object[][] dataOnPubId() {
return new Object[][] {
// The specified public id contains spaces. And the counterparts
// in public entry also contains spaces.
@ -103,11 +104,11 @@ public class NormalizationTest {
"http://local/base/dtd/docBobPub.dtd" } };
}
private CatalogResolver createEntityResolver() {
private static CatalogResolver createEntityResolver() {
return catalogResolver(CATALOG_NORMALIZATION);
}
private CatalogResolver createUriResolver() {
private static CatalogResolver createUriResolver() {
return catalogUriResolver(CATALOG_NORMALIZATION);
}
}

View File

@ -23,38 +23,38 @@
package catalog;
import static catalog.CatalogTestUtils.PREFER_PUBLIC;
import static catalog.CatalogTestUtils.PREFER_SYSTEM;
import static catalog.CatalogTestUtils.catalogResolver;
import static javax.xml.catalog.CatalogFeatures.Feature.PREFER;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.PREFER_PUBLIC;
import static catalog.CatalogTestUtils.PREFER_SYSTEM;
import static catalog.CatalogTestUtils.catalogResolver;
import static javax.xml.catalog.CatalogFeatures.Feature.PREFER;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.PreferFeatureTest
* @run junit/othervm catalog.PreferFeatureTest
* @summary This case tests how does the feature affect the catalog resolution,
* and tests the priority between this feature and attribute prefer
* in catalog file.
*/
public class PreferFeatureTest {
@Test(dataProvider = "prefer-publicId-systemId",
expectedExceptions = CatalogException.class)
public void testPreferFeature(String prefer, String systemId,
String publicId) {
createResolver(prefer).resolveEntity(systemId, publicId);
@ParameterizedTest
@MethodSource("data")
public void testPreferFeature(String prefer, String systemId, String publicId) {
CatalogResolver resolver = createResolver(prefer);
assertThrows(CatalogException.class, () -> resolver.resolveEntity(systemId, publicId));
}
@DataProvider(name = "prefer-publicId-systemId")
public Object[][] data() {
public static Object[][] data() {
return new Object[][] {
// The feature prefer is system. There's a match for the
// specified public id, and no match for the specified system id.
@ -72,7 +72,7 @@ public class PreferFeatureTest {
"http://remote/dtd/bob/docBobDummy.dtd"} };
}
private CatalogResolver createResolver(String prefer) {
private static CatalogResolver createResolver(String prefer) {
return catalogResolver(
CatalogFeatures.builder().with(PREFER, prefer).build(),
"preferFeature.xml");

View File

@ -23,19 +23,19 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkExtIdResolution;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkExtIdResolution;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.PreferTest
* @run junit/othervm catalog.PreferTest
* @summary Get matched URIs from system and public family entries, which
* specify the prefer attribute. It tests how does the prefer attribute
* affect the resolution procedure. The test rule is based on OASIS
@ -43,14 +43,14 @@ import org.testng.annotations.Test;
*/
public class PreferTest {
@Test(dataProvider = "publicId-systemId-matchedUri")
@ParameterizedTest
@MethodSource("data")
public void testPrefer(String publicId, String systemId,
String expected) {
checkExtIdResolution(createResolver(), publicId, systemId, expected);
}
@DataProvider(name = "publicId-systemId-matchedUri")
public Object[][] data() {
public static Object[][] data() {
return new Object[][] {
// The prefer attribute is public. Both of the specified public
// id and system id have matches in the catalog file. But
@ -85,7 +85,7 @@ public class PreferTest {
"http://local/base/dtd/docBobSys.dtd" } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("prefer.xml");
}
}

View File

@ -23,20 +23,21 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkPubIdResolution;
import org.junit.jupiter.api.Test;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.PublicFamilyTest
* @run junit/othervm catalog.PublicFamilyTest
* @summary Get matched URIs from public and delegatePublic entries.
* It tests the resolution priorities among the public family entries.
* The test rule is based on OASIS Standard V1.1 section 7.1.2.
@ -58,12 +59,12 @@ public class PublicFamilyTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
public void testNoMatched() {
checkNoMatch(createResolver());
@Test
public void testNoMatch() {
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("publicFamily.xml");
}
}

View File

@ -23,33 +23,35 @@
package catalog;
import static catalog.CatalogTestUtils.CATALOG_PUBLIC;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkPubIdResolution;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.CATALOG_PUBLIC;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkPubIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.PublicTest
* @run junit/othervm catalog.PublicTest
* @summary Get matched URIs from public entries.
*/
public class PublicTest {
@Test(dataProvider = "publicId-matchedUri")
@ParameterizedTest
@MethodSource("data")
public void testPublic(String publicId, String matchedUri) {
checkPubIdResolution(createResolver(), publicId, matchedUri);
}
@DataProvider(name = "publicId-matchedUri")
public Object[][] data() {
public static Object[][] data() {
return new Object[][] {
// The matched URI of the specified public id is defined in a
// public entry. The match is an absolute path.
@ -80,12 +82,12 @@ public class PublicTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver(CATALOG_PUBLIC);
}
}

View File

@ -23,6 +23,13 @@
package catalog;
import org.junit.jupiter.api.Test;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
import static catalog.CatalogTestUtils.CATALOG_URI;
import static catalog.CatalogTestUtils.RESOLVE_CONTINUE;
@ -33,19 +40,13 @@ import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import static javax.xml.catalog.CatalogFeatures.builder;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.ResolveFeatureTest
* @run junit/othervm catalog.ResolveFeatureTest
* @summary This case tests how does resolve feature affect the catalog
* resolution.
*/
@ -55,20 +56,24 @@ public class ResolveFeatureTest {
* For strict external identifier resolution, if no match is found,
* it should throw CatalogException.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testStrictResolutionOnEntityResolver() {
createEntityResolver(RESOLVE_STRICT).resolveEntity(null,
"http://remote/dtd/alice/docAliceDummy.dtd");
CatalogResolver resolver = createEntityResolver(RESOLVE_STRICT);
assertThrows(
CatalogException.class,
() -> resolver.resolveEntity(null, "http://remote/dtd/alice/docAliceDummy.dtd"));
}
/*
* For strict URI reference resolution, if no match is found,
* it should throw CatalogException.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testStrictResolutionOnUriResolver() {
createUriResolver(RESOLVE_STRICT).resolve(
"http://remote/dtd/alice/docAliceDummy.dtd", null);
CatalogResolver resolver = createUriResolver(RESOLVE_STRICT);
assertThrows(
CatalogException.class,
() -> resolver.resolve("http://remote/dtd/alice/docAliceDummy.dtd", null));
}
/*
@ -115,15 +120,15 @@ public class ResolveFeatureTest {
"http://remote/dtd/carl/docCarlDummy.dtd", null);
}
private CatalogResolver createEntityResolver(String resolve) {
private static CatalogResolver createEntityResolver(String resolve) {
return catalogResolver(createFeature(resolve), CATALOG_SYSTEM);
}
private CatalogResolver createUriResolver(String resolve) {
private static CatalogResolver createUriResolver(String resolve) {
return catalogUriResolver(createFeature(resolve), CATALOG_URI);
}
private CatalogFeatures createFeature(String resolve) {
private static CatalogFeatures createFeature(String resolve) {
return builder().with(Feature.RESOLVE, resolve).build();
}
}

View File

@ -23,32 +23,34 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.RewriteSystemTest
* @run junit/othervm catalog.RewriteSystemTest
* @summary Get matched URIs from rewriteSystem entries.
*/
public class RewriteSystemTest {
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkSysIdResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified system id is defined in a
// rewriteSystem entry. The match is an absolute path.
@ -83,12 +85,12 @@ public class RewriteSystemTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("rewriteSystem.xml");
}
}

View File

@ -23,32 +23,34 @@
package catalog;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkNoUriMatch;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.RewriteUriTest
* @run junit/othervm catalog.RewriteUriTest
* @summary Get matched URIs from rewriteURI entries.
*/
public class RewriteUriTest {
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String uri, String matchedUri) {
checkUriResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified URI reference is defined in
// a rewriteURI entry. The match is an absolute path.
@ -83,12 +85,12 @@ public class RewriteUriTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoUriMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoUriMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogUriResolver("rewriteUri.xml");
}
}

View File

@ -23,7 +23,10 @@
package catalog;
import static jaxp.library.JAXPTestUtilities.setSystemProperty;
import org.junit.jupiter.api.Test;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.FEATURE_FILES;
import static catalog.CatalogTestUtils.catalogResolver;
@ -31,19 +34,14 @@ import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.CatalogTestUtils.getCatalogPath;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import static javax.xml.catalog.CatalogFeatures.builder;
import static javax.xml.catalog.CatalogFeatures.Feature.FILES;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.Test;
import static javax.xml.catalog.CatalogFeatures.builder;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.SpecifyCatalogTest
* @run junit/othervm catalog.SpecifyCatalogTest
* @summary This case tests how to specify the catalog files.
*/
public class SpecifyCatalogTest {
@ -77,7 +75,7 @@ public class SpecifyCatalogTest {
*/
@Test
public void specifyCatalogViaSysProps() {
setSystemProperty(FEATURE_FILES,
System.setProperty(FEATURE_FILES,
getCatalogPath("specifyCatalog-sysProps.xml").toASCIIString());
checkResolutionOnEntityResolver(catalogResolver((String[]) null),
@ -93,13 +91,13 @@ public class SpecifyCatalogTest {
"http://local/base/dtd/docAPIURI.dtd");
}
private void checkResolutionOnEntityResolver(CatalogResolver resolver,
String matchedUri) {
private static void checkResolutionOnEntityResolver(CatalogResolver resolver,
String matchedUri) {
checkSysIdResolution(resolver, ID_SYS, matchedUri);
}
private void checkResolutionOnUriResolver(CatalogResolver resolver,
String matchedUri) {
private static void checkResolutionOnUriResolver(CatalogResolver resolver,
String matchedUri) {
checkUriResolution(resolver, ID_URI, matchedUri);
}

View File

@ -23,21 +23,23 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.SystemFamilyTest
* @run junit/othervm catalog.SystemFamilyTest
* @summary Get matched URIs from system, rewriteSystem, systemSuffix and
* delegateSystem entries. It tests the resolution priorities among
* the system family entries. The test rule is based on OASIS
@ -45,13 +47,13 @@ import org.testng.annotations.Test;
*/
public class SystemFamilyTest {
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkSysIdResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified system id is defined in a
// system entry.
@ -72,12 +74,12 @@ public class SystemFamilyTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("systemFamily.xml");
}
}

View File

@ -23,32 +23,34 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.SystemSuffixTest
* @run junit/othervm catalog.SystemSuffixTest
* @summary Get matched URIs from systemSuffix entries.
*/
public class SystemSuffixTest {
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkSysIdResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified system id is defined in a
// systemIdSuffix entry. The match is an absolute path.
@ -83,12 +85,12 @@ public class SystemSuffixTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("systemSuffix.xml");
}
}

View File

@ -23,33 +23,35 @@
package catalog;
import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkNoMatch;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.SystemTest
* @run junit/othervm catalog.SystemTest
* @summary Get matched URIs from system entries.
*/
public class SystemTest {
@Test(dataProvider = "systemId-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkSysIdResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "systemId-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified system id is defined in a
// system entry. The match is an absolute path.
@ -80,12 +82,12 @@ public class SystemTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver(CATALOG_SYSTEM);
}
}

View File

@ -23,21 +23,23 @@
package catalog;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkNoUriMatch;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.UriFamilyTest
* @run junit/othervm catalog.UriFamilyTest
* @summary Get matched URIs from uri, rewriteURI, uriSuffix and delegateURI
* entries. It tests the resolution priorities among the uri family
* entries. The test rule is based on OASIS Standard V1.1 section
@ -45,13 +47,13 @@ import org.testng.annotations.Test;
*/
public class UriFamilyTest {
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String systemId, String matchedUri) {
checkUriResolution(createResolver(), systemId, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified URI reference is defined in
// a uri entry.
@ -72,12 +74,12 @@ public class UriFamilyTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoUriMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoUriMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogUriResolver("uriFamily.xml");
}
}

View File

@ -23,32 +23,34 @@
package catalog;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkNoUriMatch;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.UriSuffixTest
* @run junit/othervm catalog.UriSuffixTest
* @summary Get matched URIs from rewriteURI entries.
*/
public class UriSuffixTest {
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String uri, String matchedUri) {
checkUriResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified URI reference is defined in
// a uriSuffix entry. The match is an absolute path.
@ -83,12 +85,12 @@ public class UriSuffixTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoUriMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoUriMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogUriResolver("uriSuffix.xml");
}
}

View File

@ -23,35 +23,37 @@
package catalog;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogResolver;
import static catalog.CatalogTestUtils.CATALOG_URI;
import static catalog.CatalogTestUtils.RESOLVE_CONTINUE;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkNoUriMatch;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogResolver;
import javax.xml.catalog.CatalogException;
import javax.xml.catalog.CatalogFeatures;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.UriTest
* @run junit/othervm catalog.UriTest
* @summary Get matched URIs from uri entries.
*/
public class UriTest {
@Test(dataProvider = "uri-matchedUri")
@ParameterizedTest
@MethodSource("dataOnMatch")
public void testMatch(String uri, String matchedUri) {
checkUriResolution(createResolver(), uri, matchedUri);
}
@DataProvider(name = "uri-matchedUri")
public Object[][] dataOnMatch() {
public static Object[][] dataOnMatch() {
return new Object[][] {
// The matched URI of the specified URI reference is defined in
// a uri entry. The match is an absolute path.
@ -92,12 +94,12 @@ public class UriTest {
/*
* If no match is found, a CatalogException should be thrown.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void testNoMatch() {
checkNoUriMatch(createResolver());
assertThrows(CatalogException.class, () -> checkNoUriMatch(createResolver()));
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogUriResolver(CATALOG_URI);
}
}

View File

@ -23,32 +23,32 @@
package catalog;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.catalog.CatalogResolver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.ResolutionChecker.checkPubIdResolution;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.UrnUnwrappingTest
* @run junit/othervm catalog.UrnUnwrappingTest
* @summary If the passed public identifier is started with "urn:publicid:",
* it has to be regarded as URN and normalized. And then the catalog
* resolver uses the normalized stuff to do matching.
*/
public class UrnUnwrappingTest {
@Test(dataProvider = "urn-matchedUri")
@ParameterizedTest
@MethodSource("data")
public void testUnwrapping(String urn, String matchedUri) {
checkPubIdResolution(createResolver(), urn, matchedUri);
}
@DataProvider(name = "urn-matchedUri")
public Object[][] data() {
public static Object[][] data() {
return new Object[][] {
// The specified public id is URN format.
{ "urn:publicid:-:REMOTE:DTD+ALICE+DOCALICE+XML:EN",
@ -60,7 +60,7 @@ public class UrnUnwrappingTest {
"http://local/base/dtd/docBobPub.dtd" } };
}
private CatalogResolver createResolver() {
private static CatalogResolver createResolver() {
return catalogResolver("urnUnwrapping.xml");
}
}

View File

@ -23,22 +23,23 @@
package catalog;
import org.junit.jupiter.api.Test;
import javax.xml.catalog.CatalogException;
import static catalog.CatalogTestUtils.CATALOG_SYSTEM;
import static catalog.CatalogTestUtils.CATALOG_URI;
import static catalog.CatalogTestUtils.catalogResolver;
import static catalog.CatalogTestUtils.catalogUriResolver;
import static catalog.ResolutionChecker.checkSysIdResolution;
import static catalog.ResolutionChecker.checkUriResolution;
import javax.xml.catalog.CatalogException;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* @test
* @bug 8077931
* @library /javax/xml/jaxp/libs
* @run testng/othervm catalog.ValidateCatalogTest
* @run junit/othervm catalog.ValidateCatalogTest
* @summary A legal catalog file must be well-formed XML, the root element
* must be catalog, and the naming space of the root element must be
* urn:oasis:names:tc:entity:xmlns:xml:catalog.
@ -52,36 +53,36 @@ public class ValidateCatalogTest {
* EntityResolver tries to load catalog with wrong root,
* it should throw CatalogException.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void validateWrongRootCatalogOnEntityResolver() {
catalogResolver(CATALOG_WRONGROOT);
assertThrows(CatalogException.class, () -> catalogResolver(CATALOG_WRONGROOT));
}
/*
* URIResolver tries to load catalog with wrong root,
* it should throw CatalogException.
*/
@Test(expectedExceptions = CatalogException.class)
@Test
public void validateWrongRootCatalogOnUriResolver() {
catalogUriResolver(CATALOG_WRONGROOT);
assertThrows(CatalogException.class, () -> catalogUriResolver(CATALOG_WRONGROOT));
}
/*
* EntityResolver tries to load malformed catalog,
* it should throw RuntimeException.
*/
@Test(expectedExceptions = RuntimeException.class)
@Test
public void validateMalformedCatalogOnEntityResolver() {
catalogResolver(CATALOG_MALFORMED);
assertThrows(RuntimeException.class, () -> catalogResolver(CATALOG_MALFORMED));
}
/*
* UriResolver tries to load malformed catalog,
* it should throw RuntimeException.
*/
@Test(expectedExceptions = RuntimeException.class)
@Test
public void validateMalformedCatalogOnUriResolver() {
catalogUriResolver(CATALOG_MALFORMED);
assertThrows(RuntimeException.class, () -> catalogUriResolver(CATALOG_MALFORMED));
}
/*

View File

@ -30,12 +30,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import jaxp.library.JAXPTestUtilities;
/*
* Utilities for testing XML Catalog API.
@ -69,6 +67,9 @@ final class CatalogTestUtils {
private static final String JAXP_PROPS = "jaxp.properties";
private static final String JAXP_PROPS_BAK = JAXP_PROPS + ".bak";
private static final Path CATALOG_DIR =
Path.of(System.getProperty("test.src")).resolve("catalogFiles").normalize().toAbsolutePath();
private CatalogTestUtils() { }
/* ********** create resolver ********** */
@ -109,19 +110,12 @@ final class CatalogTestUtils {
// Gets the paths of the specified catalogs.
private static URI[] getCatalogPaths(String... catalogNames) {
return catalogNames == null
? null
: Stream.of(catalogNames).map(
catalogName -> getCatalogPath(catalogName)).collect(
Collectors.toList()).toArray(new URI[0]);
return Stream.of(catalogNames).map(CatalogTestUtils::getCatalogPath).toList().toArray(new URI[0]);
}
// Gets the paths of the specified catalogs.
static URI getCatalogPath(String catalogName) {
return catalogName == null
? null
: Paths.get(JAXPTestUtilities.getPathByClassName(CatalogTestUtils.class, "catalogFiles")
+ catalogName).toUri();
return CATALOG_DIR.resolve(catalogName).toUri();
}
/* ********** jaxp.properties ********** */

View File

@ -25,12 +25,13 @@ package catalog;
import javax.xml.catalog.CatalogResolver;
import org.testng.Assert;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/*
* Utilities for checking catalog resolution.
*/
class ResolutionChecker {
final class ResolutionChecker {
/* ********** Checks normal resolution ********** */
@ -38,8 +39,8 @@ class ResolutionChecker {
* Checks the resolution result for specified external identifier.
*/
static void checkExtIdResolution(CatalogResolver resolver,
String publicId, String systemId, String matchedUri) {
Assert.assertEquals(
String publicId, String systemId, String matchedUri) {
assertEquals(
resolver.resolveEntity(publicId, getNotSpecified(systemId)).getSystemId(),
matchedUri);
}
@ -65,8 +66,8 @@ class ResolutionChecker {
* with the specified base location.
*/
static void checkUriResolution(CatalogResolver resolver,
String href, String base, String matchedUri) {
Assert.assertEquals(resolver.resolve(href, base).getSystemId(),
String href, String base, String matchedUri) {
assertEquals(resolver.resolve(href, base).getSystemId(),
matchedUri);
}
@ -106,9 +107,9 @@ class ResolutionChecker {
static <T extends Throwable> void expectExceptionOnExtId(
CatalogResolver resolver, String publicId, String systemId,
Class<T> expectedExceptionClass) {
expectThrows(expectedExceptionClass, () -> {
resolver.resolveEntity(publicId, getNotSpecified(systemId));
});
assertThrows(
expectedExceptionClass,
() -> resolver.resolveEntity(publicId, getNotSpecified(systemId)));
}
/*
@ -140,9 +141,7 @@ class ResolutionChecker {
static <T extends Throwable> void expectExceptionOnUri(
CatalogResolver resolver, String href, String base,
Class<T> expectedExceptionClass) {
expectThrows(expectedExceptionClass, () -> {
resolver.resolve(href, base);
});
assertThrows(expectedExceptionClass, () -> resolver.resolve(href, base));
}
/*
@ -155,31 +154,6 @@ class ResolutionChecker {
expectExceptionOnUri(resolver, href, null, expectedExceptionClass);
}
// The TestNG distribution in current JTREG build doesn't support
// method Assert.expectThrows().
private static <T extends Throwable> T expectThrows(Class<T> throwableClass,
ThrowingRunnable runnable) {
try {
runnable.run();
} catch (Throwable t) {
if (throwableClass.isInstance(t)) {
return throwableClass.cast(t);
} else {
String mismatchMessage = String.format(
"Expected %s to be thrown, but %s was thrown",
throwableClass.getSimpleName(),
t.getClass().getSimpleName());
throw new AssertionError(mismatchMessage, t);
}
}
String message = String.format(
"Expected %s to be thrown, but nothing was thrown",
throwableClass.getSimpleName());
throw new AssertionError(message);
}
/*
* SystemId can never be null in XML. For publicId tests, if systemId is null,
* it will be considered as not-specified instead. A non-existent systemId
@ -191,8 +165,4 @@ class ResolutionChecker {
}
return systemId;
}
private interface ThrowingRunnable {
void run() throws Throwable;
}
}