/*
 *************************************************************************
 * Copyright (c) 2005 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *  
 *************************************************************************
 */

package org.eclipse.birt.data.engine.odaconsumer;

import java.util.Properties;

import junit.framework.TestCase;

import org.eclipse.birt.core.framework.Platform;

/**
 * Testing of backward compatibility of BIRT ODA runtime plug-in.
 * Ensures that an BIRT ODA driver gets loaded via the
 * org.eclipse.birt.data.oda.adapter.dtp plug-in.
 */
public class BirtOdaAdapterTest extends TestCase
{
    private final String TEST_DRIVER_ID = 
        "org.eclipse.birt.data.engine.odaconsumer.testbirtdriver";

	private ConnectionManager sm_connManager;
    private Properties sm_connProps;
    
    private final String MAX_QUERIES_KEY = "MaxQueries";
    private final Integer MAX_QUERIES_VALUE = new Integer( 100 );
    
    static
    {
		if ( System.getProperty( "BIRT_HOME" ) == null )
			System.setProperty( "BIRT_HOME", "./test" );
		System.setProperty( "PROPERTY_RUN_UNDER_ECLIPSE", "false" );
		Platform.initialize( null );
    }
    
    /* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();
	    if( sm_connManager == null )
	        sm_connManager = ConnectionManager.getInstance();
	    if( sm_connProps == null )
	    {
	        sm_connProps = new Properties();
	        sm_connProps.put( MAX_QUERIES_KEY, MAX_QUERIES_VALUE );
	    }
    }
    
    /* (non-Javadoc)
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception
    {
        super.tearDown();
    }
    
    public void testBirtOdaAdapter()
    {
        Connection hostConn = null;
        
        try
        {
            hostConn = sm_connManager.openConnection( TEST_DRIVER_ID, sm_connProps );
            assertTrue( hostConn != null );
            
            assertEquals( TEST_DRIVER_ID, hostConn.getDataSourceId() );
            assertEquals( MAX_QUERIES_VALUE.intValue(), hostConn.getMaxQueries() );
        }
        catch( Exception e1 )
        {
            fail( "testBirtOdaAdapter failed: " + e1.toString() );
        }
    } 

}
