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

import org.eclipse.birt.data.engine.api.querydefn.OdaDataSetDesign;
import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition;
import org.eclipse.birt.data.engine.api.querydefn.ScriptExpression;

import testutil.APITestCase;
import testutil.ConfigText;

/**
 * <b>Regression test case description:</b>
 * <p>
 * The JS expression of the BirtStr.toLower() dosen't work
 * </p>
 * <b>Test description:</b>
 * <p>
 * New a dataset with column COUNTRY, and set another column with the expression
 * "BirtStr.toLower(dataSetRow.COUNTRY)". Compare it with golden file.
 * </p>
 */

public class Regression_142122 extends APITestCase
{

	String callsTableName;

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

		prepareDataSet( new DataSourceInfo( ConfigText
				.getString( "Api.TestData0.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 testBirtStr( ) throws Exception
	{
		String testSQL = "select " + callsTableName + ".COUNTRY " + "from "
				+ callsTableName;

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

		String[] bindingNameRow = new String[2];
		bindingNameRow[0] = "ROW_COUNTRY";
		bindingNameRow[1] = "ROW_LOWER";

		ScriptExpression[] bindingExprRow = new ScriptExpression[]{

		new ScriptExpression( "dataSetRow.COUNTRY" ),
				new ScriptExpression( "BirtStr.toLower(dataSetRow.COUNTRY)" )};

		String[] columnStr = new String[]{"Origin", "toLower"};

		QueryDefinition qd = this.createQuery( null, null, null, null, null,
				null, null, null, null, bindingNameRow, bindingExprRow );
		// Generate a group
		String outputStr = getOutputStrForGroupTest( 30, qd, 0, bindingNameRow,
				columnStr );
		// use DtE output framework
		testPrint( outputStr );
		// golden file compare
		this.checkOutputFile( );
	}
}