From 166c71a317b7d0e8fe358f6d3887c8ea36c0c7cb Mon Sep 17 00:00:00 2001 From: ndw Date: Wed, 13 Apr 2005 13:29:02 +0000 Subject: [PATCH] Basic JUnit tests git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226198 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/tests/BasicResolverTests.java | 125 ++++++++++++++++++ .../org/apache/xml/resolver/tests/catalog.xml | 32 +++++ .../xml/resolver/tests/delegate-system.xml | 7 + .../org/apache/xml/resolver/tests/tr9401.xml | 9 ++ 4 files changed, 173 insertions(+) create mode 100644 java/src/org/apache/xml/resolver/tests/BasicResolverTests.java create mode 100644 java/src/org/apache/xml/resolver/tests/catalog.xml create mode 100644 java/src/org/apache/xml/resolver/tests/delegate-system.xml create mode 100644 java/src/org/apache/xml/resolver/tests/tr9401.xml diff --git a/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java b/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java new file mode 100644 index 0000000..1d8d0b7 --- /dev/null +++ b/java/src/org/apache/xml/resolver/tests/BasicResolverTests.java @@ -0,0 +1,125 @@ +package org.apache.xml.resolver.tests; + +import junit.framework.TestCase; + +import java.net.URL; + +import org.apache.xml.resolver.Catalog; +import org.apache.xml.resolver.CatalogManager; +import org.apache.xml.resolver.tools.CatalogResolver; + +public class BasicResolverTests extends TestCase { + protected Catalog catalog; + + public static void main(String args[]) { + junit.textui.TestRunner.run(BasicResolverTests.class); + } + + protected void setUp() throws Exception { + super.setUp(); + + CatalogManager manager = new CatalogManager(); + + // Just do this to make sure that the debug level gets set. + // I could set the value explicitly, but I know that the + // ant build file is going to set the system property, so just + // make sure that that gets used. + int verbosity = manager.getVerbosity(); + + catalog = new Catalog(manager); + catalog.setupReaders(); + catalog.loadSystemCatalogs(); + } + + public void testResolveSystem() { + String resolved = null; + String local = "file:/local/system-resolver.dtd"; + + try { + resolved = catalog.resolveSystem("http://example.org/resolver.dtd"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testResolvePublic() { + String resolved = null; + String local = "file:/local/public-resolver.dtd"; + + try { + resolved = catalog.resolvePublic("-//Apache//DTD Resolver Test//EN", + "some-broken-system-identifier"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testRewriteSystem() { + String resolved = null; + String local = "file:/longest/path"; + + try { + resolved = catalog.resolveSystem("http://rewrite.example.org/longest/path"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testResolveURI() { + String resolved = null; + String local = "file:/local/uri"; + + try { + resolved = catalog.resolveURI("http://example.org/someURI"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testGroup() { + String resolved = null; + String local = "file:/local/other/uri"; + + try { + resolved = catalog.resolveURI("http://example.org/someOtherURI"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testDelegateSystem() { + String resolved = null; + String local = "file:/local/delegated/system-resolver.dtd"; + + try { + resolved = catalog.resolveSystem("http://delegate.example.org/resolver.dtd"); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } + + public void testDocument() { + String resolved = null; + String local = "file:/default-document"; + + try { + resolved = catalog.resolveDocument(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(local.equals(resolved)); + } +} diff --git a/java/src/org/apache/xml/resolver/tests/catalog.xml b/java/src/org/apache/xml/resolver/tests/catalog.xml new file mode 100644 index 0000000..ac07027 --- /dev/null +++ b/java/src/org/apache/xml/resolver/tests/catalog.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/src/org/apache/xml/resolver/tests/delegate-system.xml b/java/src/org/apache/xml/resolver/tests/delegate-system.xml new file mode 100644 index 0000000..2da1f75 --- /dev/null +++ b/java/src/org/apache/xml/resolver/tests/delegate-system.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/java/src/org/apache/xml/resolver/tests/tr9401.xml b/java/src/org/apache/xml/resolver/tests/tr9401.xml new file mode 100644 index 0000000..273e5a3 --- /dev/null +++ b/java/src/org/apache/xml/resolver/tests/tr9401.xml @@ -0,0 +1,9 @@ + + + + + + +