
package org.eclipse.birt.tests.data.engine.regression;

import java.util.Collection;
import java.util.Iterator;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.impl.GetParameterDefinitionTask;

import utility.EngineCase;

/**
 * <b>Regression test case description:</b>
 * <p>
 * Description: When set an alias on a column, the column can not be used in the
 * cascading parameter
 * <p>
 * Steps to reproduce:
 * <ol>
 * <li>new a datasource and a dataset
 * <li>set an alias on a column
 * <li>new a cascading parameter, set the column with an alias as the values
 * column
 * </ol>
 * Actual result: the column can not be used in the cascading parameter
 * <p>
 * <b>Test description:</b>
 * <p>
 * Create a design file with dataset which have a column with alias name and set
 * a cascading parameter with it.
 * <P>
 * The cascading parameter should be displayed correctly.
 * 
 */

public class Regression_136966 extends EngineCase
{

	protected void setUp( ) throws Exception
	{
		super.setUp( );
	}

	public void testRefernceParameterfromAlias( ) throws Exception
	{
		EngineConfig config = new EngineConfig( );

		Platform.startup( config );

		IReportEngineFactory factory = (IReportEngineFactory) Platform
				.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );

		IReportEngine engine = factory.createReportEngine( config );

		// create task
		IReportRunnable runnable = engine.openReportDesign( getClassFolder( )
				+ "/" + INPUT_FOLDER + "/" + "ParamOnAlias.rptdesign" );

		GetParameterDefinitionTask paraTask = (GetParameterDefinitionTask) engine
				.createGetParameterDefinitionTask( runnable );

		Collection c = paraTask.getSelectionListForCascadingGroup(
				"NewCascadingParameterGroup", new Object[]{"181"} );
		assertEquals( 1, c.size( ) );
		Iterator it = c.iterator( );
		if ( it.hasNext( ) )
		{
			Object o = it.next( );
			assertTrue( o instanceof IParameterSelectionChoice );
			Object value = ( (IParameterSelectionChoice) o ).getValue( );
			assertEquals( "Vitachrome Inc.", value );
		}
		assertNotNull( paraTask.getParameters( ).iterator( ) );
	}
}