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

/*******************************************************************************************
 * Regression test case description:            
 * Create a data set, Edit the data set, select "Output Columns", set alias name to a column
 * View in Data Explorer. Alias name can not listed in the data set tree
 *
 * 
 * Test description:
 * Caused when merging resultSetHints with columnHints, thus add columnHints to the resultSetHints
 * Can Get the alias name from IResultIterator.
 * 
 **********************************************************************************/
import org.eclipse.birt.data.engine.api.IResultIterator;
import org.eclipse.birt.data.engine.api.querydefn.ColumnDefinition;
import org.eclipse.birt.data.engine.api.querydefn.OdaDataSetDesign;
import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition;

import testutil.APITestCase;
import testutil.ConfigText;

public class Reg_145508 extends APITestCase
{

	String callsTableName;

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

		prepareDataSet( new DataSourceInfo( ConfigText
				.getString( "Api.TestData.TableName" ), ConfigText
				.getString( "Api.TestData.TableSQL" ), ConfigText
				.getString( "Api.TestData.TestDataFileName" ) ) );

		callsTableName = ConfigText.getString( "Api.TestData.TableName" );
	}

	/*
	 * @see org.eclipse.birt.data.engine.api.APITestCase#getDataSourceInfo()
	 */
	protected DataSourceInfo getDataSourceInfo( )
	{
		return new DataSourceInfo( ConfigText
				.getString( "Api.TestData.TableName" ), ConfigText
				.getString( "Api.TestData.TableSQL" ), ConfigText
				.getString( "Api.TestData.TestDataFileName" ) );
	}

	public void testAlias( ) throws Exception
	{
		String testSQL = "select " + callsTableName + ".CITY " + "from "
				+ callsTableName;

		( (OdaDataSetDesign) this.dataSet ).setQueryText( testSQL );

		ColumnDefinition colDef = new ColumnDefinition( "CITY" );
		colDef.setAlias( "a" );
		colDef.setColumnPosition( 1 );
		colDef.setDataType( 0 );

		this.dataSet.addResultSetHint( colDef );

		QueryDefinition queryDefn = newReportQuery( );

		IResultIterator resultIter = this.executeQuery( queryDefn );
		assertTrue( "a".equals( resultIter.getResultMetaData( ).getColumnAlias(
				1 ) ) );
	}

}