1   package org.apache.maven.hibernate;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   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  
20  import junit.framework.TestCase;
21  
22  /**
23   * Test cases for the {@link HibernateEntityResolver}.  Based heavily
24   * on J2EEEntityResolver.
25   *
26   * @author <a href="mailto:epugh@opnesourceconnections.com">Eric Pugh</a>
27   * @version $Id: HibernateEntityResolverTest.java 170200 2005-05-15 06:24:19Z brett $
28   */
29  public class HibernateEntityResolverTest extends TestCase
30  {
31  
32      /** instance for unit testing */
33      private HibernateEntityResolver instance;
34      /**
35       * Creates a new instance of J2EEEntityResolverTest
36       * @param testName the name of the test
37       */
38      public HibernateEntityResolverTest(String testName)
39      {
40          super(testName);
41      }
42  
43      /**
44       * Initialize per test data
45       * @throws Exception when there is an unexpected problem
46       */
47      public void setUp() throws Exception
48      {
49          instance = new HibernateEntityResolver();
50      }
51  
52      /**
53       * Test that all public ids are available and being found
54       */
55      public void testAllAvailable()
56      {
57          assertNotNull("id to resource map not available", instance.getIdToResource());
58          int numDTDs = HibernateEntityResolver.HIBERNATE_DTDS.length;
59          assertEquals("wrong number of entries", numDTDs, instance.getIdToResource().size());
60          for (int i = 0; i < numDTDs; i++)
61          {
62              assertNotNull("Can't find resource for publicId",
63                  instance.getIdToResource().get(HibernateEntityResolver.HIBERNATE_DTDS[i]));
64          }
65      }
66  
67      /**
68       * Test that the resolver is getting resources locally
69       */
70      public void testResolvingLocally() throws Exception
71      {
72          int numDTDs = HibernateEntityResolver.HIBERNATE_DTDS.length;
73          for (int i = 0; i < numDTDs; i++)
74          {
75              String publicId = HibernateEntityResolver.HIBERNATE_DTDS[i];
76              assertNotNull("Can't find resource for publicId " + publicId,
77                  instance.resolveEntity(publicId, null));
78          }
79      }
80  }