View Javadoc

1   /* $Id: URLTestCase.java 1127949 2011-05-26 14:57:52Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.commons.digester3;
20  
21  import static org.junit.Assert.*;
22  
23  import java.net.URL;
24  
25  import org.apache.commons.digester3.Digester;
26  import org.junit.After;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  /**
31   * <p>
32   * Unit tests that exercise the new (in 1.8) methods for passing in <code>URL</code> arguments instead of strings.
33   * </p>
34   */
35  public class URLTestCase
36  {
37  
38      // ----------------------------------------------------- Overall Test Methods
39  
40      /**
41       * Set up instance variables required by this test case.
42       */
43      @Before
44      public void setUp()
45      {
46  
47          digester = new Digester();
48  
49      }
50  
51      /**
52       * Tear down instance variables required by this test case.
53       */
54      @After
55      public void tearDown()
56      {
57  
58          digester = null;
59  
60      }
61  
62      // ------------------------------------------------------ Manifest Constants
63  
64      /**
65       * <p>
66       * Public identifier of the Digester Rules DTD.
67       * </p>
68       */
69      private static final String DIGESTER_RULES_PUBLIC_ID = "-//Apache Commons //DTD digester-rules XML V1.0//EN";
70  
71      /**
72       * <p>
73       * System identifier of the Digester Rules DTD.
74       * </p>
75       */
76      private static final String DIGESTER_RULES_SYSTEM_ID = "/org/apache/commons/digester3/xmlrules/digester-rules.dtd";
77  
78      /**
79       * <p>
80       * System identifier for the Digester Rules file that we will parse.
81       * </p>
82       */
83      private static final String TEST_INPUT_SYSTEM_ID =
84          "/org/apache/commons/digester3/xmlrules/test-call-param-rules.xml";
85  
86      // ------------------------------------------------------ Instance Variables
87  
88      /**
89       * <p>
90       * The <code>Digester</code> instance under test.
91       * </p>
92       */
93      private Digester digester = null;
94  
95      // ------------------------------------------------------------ Test Methods
96  
97      // Test a pristine instance
98      @Test
99      public void testPristine()
100     {
101 
102         assertNotNull( digester );
103 
104     }
105 
106     // Test parsing a resource, using a registered DTD, both passed with URLs
107     @Test
108     public void testResource()
109         throws Exception
110     {
111 
112         // Register the Digester Rules DTD
113         URL dtd = URLTestCase.class.getResource( DIGESTER_RULES_SYSTEM_ID );
114         assertNotNull( dtd );
115         digester.register( DIGESTER_RULES_PUBLIC_ID, dtd );
116 
117         // Parse one of the existing test resources twice with
118         // the same Digester instance
119         URL xml = URLTestCase.class.getResource( TEST_INPUT_SYSTEM_ID );
120         assertNotNull( xml );
121         digester.parse( xml );
122         digester.parse( xml );
123 
124     }
125 
126 }