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

import java.util.ArrayList;

import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.tests.engine.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * Sort alphabetically doesn't work for report parameter
 * <p>
 * <b>Test description</b>
 * <p>
 * This test makes sure that parameter values are sorted
 * 
 */

public class Regression_142412 extends EngineCase
{

	private final static String INPUT = "regression_142412.rptdesign"; //$NON-NLS-1$
	private final static String OUTPUT = "regression_142412.html"; //$NON-NLS-1$
	private String inputPath = getClassFolder( )
			+ System.getProperty( "file.separator" ) + INPUT_FOLDER
			+ System.getProperty( "file.separator" );
	private String outputPath = getClassFolder( )
			+ System.getProperty( "file.separator" ) + OUTPUT_FOLDER
			+ System.getProperty( "file.separator" );

	/**
	 * @throws Exception
	 */
	public void test_Regression_142412( ) throws Exception
	{
		IReportRunnable reportRunnable = engine.openReportDesign( inputPath
				+ INPUT );
		IGetParameterDefinitionTask paramTask = engine
				.createGetParameterDefinitionTask( reportRunnable );
		ArrayList values = (ArrayList) paramTask.getSelectionList( "p1" );
		assertEquals( "Parameter values are incorrect", 3, values.size( ) );
		assertEquals( "Parameter values are not sorted.", String.valueOf( 1 ),
				( (IParameterSelectionChoice) values.get( 0 ) ).getValue( ) );
		assertEquals( "Parameter values are not sorted.", String.valueOf( 2 ),
				( (IParameterSelectionChoice) values.get( 1 ) ).getValue( ) );
		assertEquals( "Parameter values are not sorted.", String.valueOf( 3 ),
				( (IParameterSelectionChoice) values.get( 2 ) ).getValue( ) );

		values = (ArrayList) paramTask.getSelectionList( "p2" );
		assertEquals( "Parameter values are incorrect", 2, values.size( ) );
		assertEquals( "Parameter values are not sorted.", "Boston",
				( (IParameterSelectionChoice) values.get( 0 ) ).getValue( ) );
		assertEquals( "Parameter values are not sorted.", "San Francisco",
				( (IParameterSelectionChoice) values.get( 1 ) ).getValue( ) );
	}
}
