package org.apache.maven.hibernate;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

import junit.framework.TestCase;

/**
 * Test cases for the {@link HibernateEntityResolver}.  Based heavily
 * on J2EEEntityResolver.
 *
 * @author <a href="mailto:epugh@opnesourceconnections.com">Eric Pugh</a>
 * @version $Id$
 */
public class HibernateEntityResolverTest extends TestCase
{

    /** instance for unit testing */
    private HibernateEntityResolver instance;
    /**
     * Creates a new instance of J2EEEntityResolverTest
     * @param testName the name of the test
     */
    public HibernateEntityResolverTest(String testName)
    {
        super(testName);
    }

    /**
     * Initialize per test data
     * @throws Exception when there is an unexpected problem
     */
    public void setUp() throws Exception
    {
        instance = new HibernateEntityResolver();
    }

    /**
     * Test that all public ids are available and being found
     */
    public void testAllAvailable()
    {
        assertNotNull("id to resource map not available", instance.getIdToResource());
        int numDTDs = HibernateEntityResolver.HIBERNATE_DTDS.length;
        assertEquals("wrong number of entries", numDTDs, instance.getIdToResource().size());
        for (int i = 0; i < numDTDs; i++)
        {
            assertNotNull("Can't find resource for publicId",
                instance.getIdToResource().get(HibernateEntityResolver.HIBERNATE_DTDS[i]));
        }
    }

    /**
     * Test that the resolver is getting resources locally
     */
    public void testResolvingLocally() throws Exception
    {
        int numDTDs = HibernateEntityResolver.HIBERNATE_DTDS.length;
        for (int i = 0; i < numDTDs; i++)
        {
            String publicId = HibernateEntityResolver.HIBERNATE_DTDS[i];
            assertNotNull("Can't find resource for publicId " + publicId,
                instance.resolveEntity(publicId, null));
        }
    }
}