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

import java.io.IOException;

import org.eclipse.birt.data.engine.api.IBaseExpression;
import org.eclipse.birt.data.engine.api.IResultIterator;
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>Bug description</b>
 * <p>
 * An error in data JS-Expression will affect another data which in the same
 * table
 * <p>
 * Setp:
 * </p>
 * <ol>
 * <li>New a sample datasource and dataset
 * <li>Insert a table and inclued two data: "Total.countDistinct(row["FIRST"])"
 * in and "Total.max(row["First"])"
 * <li>Preview
 * </ol>
 * <p>
 * Actual results:
 * </p>
 * <p>
 * In dataset, row FIRST is error and row First is right. When preview, two data
 * is pop up an error message.
 * </p>
 * <p>
 * Expection results:
 * </p>
 * <p>
 * Right data WITH JS can preview, in other words, an error can't affect to the
 * right data.
 * </p>
 * <p>
 * <b>Test description</b>
 * </p>
 * <p>
 * Name two bindingNameRows, one is correct, the other is incorrect, try the
 * uncorrect statement and catch it
 * </p>
 * 
 */
public class Regression_124593 extends APITestCase
{

	// Use database in test framework
	protected DataSourceInfo getDataSourceInfo( )
	{
		return new DataSourceInfo( ConfigText
				.getString( "Api.TestDataforGroup.TableName" ), ConfigText
				.getString( "Api.TestDataforGroup.TableSQL" ), ConfigText
				.getString( "Api.TestDataforGroup.TestDataFileName" ) );
	}

	/**
	 * Test feature of group on Number Decimal type
	 * 
	 * @throws Exception
	 */

	public void test2LevelGroupResult( ) throws Exception, IOException
	{

		// column binding
		String[] bindingNameRow = new String[2];
		bindingNameRow[0] = "ROW_CITY";
		bindingNameRow[1] = "ROW_city";

		IBaseExpression[] bindingExprRow = new IBaseExpression[3];
		bindingExprRow[0] = new ScriptExpression(
				"Total.countDistinct(dataSetRow.CITY)" );
		bindingExprRow[1] = new ScriptExpression( "Total.max(dataSetRow.city)" );

		QueryDefinition queryDefn = this.createQuery( null, null, null, null,
				null, null, null, null, null, bindingNameRow, bindingExprRow );

		IResultIterator resultIter = this.executeQuery( queryDefn );

		assertEquals( new Integer( 5 ), resultIter.getValue( "ROW_CITY" ) );
		try
		{
			resultIter.getValue( "ROW_city" );
			fail( "Should not arrive here" );
		}
		catch ( Exception e )
		{
		}

		// resultIter.getValue( "ROW_city" ));

	}
}