001: /* $Id: URLTestCase.java 479257 2006-11-26 01:54:32Z craigmcc $
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package org.apache.commons.digester;
020:
021: import java.net.URL;
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: /**
027: * <p>Unit tests that exercise the new (in 1.8) methods for passing in
028: * <code>URL</code> arguments instead of strings.</p>
029: */
030: public class URLTestCase extends TestCase {
031:
032: // ------------------------------------------------------------ Constructors
033:
034: /**
035: * Construct a new instance of this test case.
036: *
037: * @param name Name of the test case
038: */
039: public URLTestCase(String name) {
040:
041: super (name);
042:
043: }
044:
045: // ----------------------------------------------------- Overall Test Methods
046:
047: /**
048: * Set up instance variables required by this test case.
049: */
050: public void setUp() {
051:
052: digester = new Digester();
053:
054: }
055:
056: /**
057: * Return the tests included in this test suite.
058: */
059: public static Test suite() {
060:
061: return (new TestSuite(URLTestCase.class));
062:
063: }
064:
065: /**
066: * Tear down instance variables required by this test case.
067: */
068: public void tearDown() {
069:
070: digester = null;
071:
072: }
073:
074: // ------------------------------------------------------ Manifest Constants
075:
076: /**
077: * <p>Public identifier of the Digester Rules DTD.</p>
078: */
079: private static final String DIGESTER_RULES_PUBLIC_ID = "-//Jakarta Apache //DTD digester-rules XML V1.0//EN";
080:
081: /**
082: * <p>System identifier of the Digester Rules DTD.</p>
083: */
084: private static final String DIGESTER_RULES_SYSTEM_ID = "/org/apache/commons/digester/xmlrules/digester-rules.dtd";
085:
086: /**
087: * <p>System identifier for the Digester Rules file that we will parse.</p>
088: */
089: private static final String TEST_INPUT_SYSTEM_ID = "/org/apache/commons/digester/xmlrules/test-call-param-rules.xml";
090:
091: // ------------------------------------------------------ Instance Variables
092:
093: /**
094: * <p>The <code>Digester</code> instance under test.</p>
095: */
096: private Digester digester = null;
097:
098: // ------------------------------------------------------------ Test Methods
099:
100: // Test a pristine instance
101: public void testPristine() {
102:
103: assertNotNull(digester);
104:
105: }
106:
107: // Test parsing a resource, using a registered DTD, both passed with URLs
108: public void testResource() throws Exception {
109:
110: Object root = null;
111:
112: // Register the Digester Rules DTD
113: URL dtd = URLTestCase.class
114: .getResource(DIGESTER_RULES_SYSTEM_ID);
115: assertNotNull(dtd);
116: digester.register(DIGESTER_RULES_PUBLIC_ID, dtd);
117:
118: // Parse one of the existing test resources twice with
119: // the same Digester instance
120: URL xml = URLTestCase.class.getResource(TEST_INPUT_SYSTEM_ID);
121: assertNotNull(xml);
122: root = digester.parse(xml);
123: root = digester.parse(xml);
124:
125: }
126:
127: }
|