/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.model.parser;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.ColumnHint;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.birt.report.model.api.elements.structures.DataSetParameter;
import org.eclipse.birt.report.model.api.elements.structures.FilterCondition;
import org.eclipse.birt.report.model.api.elements.structures.OdaDataSetParameter;
import org.eclipse.birt.report.model.api.elements.structures.OdaDesignerState;
import org.eclipse.birt.report.model.api.elements.structures.OdaResultSetColumn;
import org.eclipse.birt.report.model.api.elements.structures.ParamBinding;
import org.eclipse.birt.report.model.api.elements.structures.ResultSetColumn;
import org.eclipse.birt.report.model.elements.OdaDataSet;
import org.eclipse.birt.report.model.elements.SimpleDataSet;
import org.eclipse.birt.report.model.metadata.PropertyDefn;
import org.eclipse.birt.report.model.metadata.StructureDefn;
import org.eclipse.birt.report.model.util.BaseTestCase;

/**
 * Tests oda data set case. <table border="1" cellpadding="0" cellspacing="0"
 * style="border-collapse: collapse" bordercolor="#111111" width="100%"
 * id="AutoNumber6">
 * 
 * <tr>
 * <td width="33%"><b>Method </b></td>
 * <td width="33%"><b>Test Case </b></td>
 * <td width="34%"><b>Expected Result </b></td>
 * </tr>
 * 
 * <tr>
 * <td width="33%">{@link #testParserDesignFile()}</td>
 * <td width="33%">Test all properties</td>
 * <td width="34%">the correct value returned.</td>
 * </tr>
 * 
 * <tr>
 * <td width="33%">{@link #testWriterDesignFile()}</td>
 * <td width="33%">Set new value to properties and save it.</td>
 * <td width="34%">new value should be save into the output file, and output
 * file is same as golden file.</td>
 * </tr>
 * 
 * <tr>
 * <td>{@link #testQueryConflictCheck()}</td>
 * <td>The query conflict is forbidden.</td>
 * <td>Property value error found</td>
 * </tr>
 * </table>
 * 
 * @see org.eclipse.birt.report.model.elements.OdaDataSource
 * @see org.eclipse.birt.report.model.elements.OdaDataSet
 */

public class OdaDataSetParserTest extends BaseTestCase
{

	String fileName = "OdaDataSetParseTest.xml"; //$NON-NLS-1$

	String outFileName = "OdaDataSetParseTest_out.xml"; //$NON-NLS-1$
	String goldenFileName = "OdaDataSetParseTest_golden.xml"; //$NON-NLS-1$

	String queryTextInputFileName = "OdaDataSetParseTest_1.xml";//$NON-NLS-1$
	String queryTextOutFileName = "OdaDataSetQueryTextParseTest_out.xml";//$NON-NLS-1$
	String queryTextGoldenFileName = "OdaDataSetQueryTextParseTest_golden.xml";//$NON-NLS-1$

	String obsoleteFileName = "OdaDataSetParseTest_obsolete.xml"; //$NON-NLS-1$
	String obsoleteOutFileName = "OdaDataSetParseTest_obsolete_out.xml";//$NON-NLS-1$
	String obsoleteGoldenFileName = "OdaDataSetParseTest_obsolete_golden.xml";//$NON-NLS-1$

	/*
	 * @see BaseTestCase#setUp()
	 */

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

	/**
	 * This test reads the design file, and checks the properties and style
	 * properties of line.
	 * 
	 * @throws Exception
	 */

	public void testParserDesignFile( ) throws Exception
	{
		openDesign( fileName );
		parse( );

		OdaDataSetHandle dataSet = (OdaDataSetHandle) designHandle
				.findDataSet( "MyDataSet" ); //$NON-NLS-1$
		assertNotNull( dataSet );

		assertEquals( "1.1", dataSet.getDesigerStateVersion( ) ); //$NON-NLS-1$
		assertEquals( "content as string", dataSet //$NON-NLS-1$
				.getDesigerStateContentAsString( ) );
		assertEquals( "content as blob", new String( dataSet //$NON-NLS-1$
				.getDesigerStateContentAsBlob( ), OdaDesignerState.CHARSET ) );
	}

	/**
	 * This test sets properties, writes the design file and compares it with
	 * golden file.
	 * 
	 * @throws Exception
	 */

	public void testWriterDesignFile( ) throws Exception
	{
		openDesign( fileName );
		write( );

		OdaDataSetHandle dataSet = (OdaDataSetHandle) designHandle
				.findDataSet( "MyDataSet" ); //$NON-NLS-1$
		assertNotNull( dataSet );

		dataSet.setDesigerStateVersion( "2.1" ); //$NON-NLS-1$
		dataSet.setDesigerStateContentAsString( "new content as string" ); //$NON-NLS-1$

		String strBlob = "new content as blob"; //$NON-NLS-1$

		dataSet.setDesigerStateContentAsBlob( strBlob
				.getBytes( OdaDesignerState.CHARSET ) );

		saveAs( outFileName );
		assertTrue( compareTextFile( goldenFileName, outFileName ) );
	}

	/**
	 * This test reads the design file, and checks the properties and style
	 * properties of line.
	 * 
	 * @throws Exception
	 */

	public void testReadWriteObsoleteDesignFile( ) throws Exception
	{
		openDesign( obsoleteFileName );
		write( );

		saveAs( obsoleteOutFileName );
		assertTrue( compareTextFile( obsoleteGoldenFileName,
				obsoleteOutFileName ) );
	}

	/**
	 * This test reads the design file, and checks the properties and style
	 * properties of line.
	 * 
	 * @throws Exception
	 */

	private void parse( ) throws Exception
	{
		openDesign( fileName );

		OdaDataSourceHandle dataSource = (OdaDataSourceHandle) designHandle
				.findDataSource( "extendedDataSource" ); //$NON-NLS-1$
		assertNotNull( dataSource );

		OdaDataSetHandle dataSet = (OdaDataSetHandle) designHandle
				.findDataSet( "MyDataSet" ); //$NON-NLS-1$
		assertNotNull( dataSet );
		assertEquals( "select * from user", dataSet.getQueryText( ) ); //$NON-NLS-1$
		assertEquals( "userid", dataSet.getResultSetName( ) ); //$NON-NLS-1$
		assertEquals( dataSource, dataSet.getDataSource( ) );

		// Test "input-parameters" on DataSet

		List parameters = (List) dataSet
				.getProperty( OdaDataSet.PARAMETERS_PROP );
		assertEquals( 5, parameters.size( ) );

		int i = 0;
		OdaDataSetParameter parameter = (OdaDataSetParameter) parameters
				.get( i++ );
		assertEquals( 1, parameter.getPosition( ).intValue( ) );
		assertEquals( "name", parameter.getName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_STRING, parameter
				.getDataType( ) );
		assertTrue( parameter.isOptional( ) );
		assertEquals( "default value 1", parameter.getDefaultValue( ) ); //$NON-NLS-1$
		assertEquals( true, parameter.allowNull( ) );
		assertEquals( -100, parameter.getNativeDataType( ).intValue( ) );

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		assertEquals( 2, parameter.getPosition( ).intValue( ) );
		assertEquals( "date", parameter.getName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_DATETIME, parameter
				.getDataType( ) );
		assertFalse( parameter.isOptional( ) );

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		assertEquals( 3, parameter.getPosition( ).intValue( ) );
		assertEquals( "id", parameter.getName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER, parameter
				.getDataType( ) );
		assertTrue( parameter.isOptional( ) );

		// Test "output-parameters" on DataSet

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		assertEquals( "birth", parameter.getName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_DATETIME, parameter
				.getDataType( ) );

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		assertEquals( "title", parameter.getName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_STRING, parameter
				.getDataType( ) );

		// Test "param-bindings" on DataSet

		List bindings = (List) dataSet
				.getProperty( SimpleDataSet.PARAM_BINDINGS_PROP );
		assertEquals( 2, bindings.size( ) );

		i = 0;
		ParamBinding binding = (ParamBinding) bindings.get( i++ );
		assertEquals( "param1", binding.getParamName( ) ); //$NON-NLS-1$
		assertEquals( "value1", binding.getExpression( ) ); //$NON-NLS-1$

		binding = (ParamBinding) bindings.get( i++ );
		assertEquals( "param2", binding.getParamName( ) ); //$NON-NLS-1$
		assertEquals( "value2", binding.getExpression( ) ); //$NON-NLS-1$

		// Test "result-set" on DataSet

		List columns = (List) dataSet
				.getProperty( SimpleDataSet.RESULT_SET_PROP );
		assertEquals( 3, columns.size( ) );

		i = 0;
		OdaResultSetColumn column = (OdaResultSetColumn) columns.get( i++ );
		assertEquals( 1, column.getPosition( ).intValue( ) );
		assertEquals( "name", column.getColumnName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_STRING, column
				.getDataType( ) );
		assertEquals( 10, column.getNativeDataType( ).intValue( ) );

		column = (OdaResultSetColumn) columns.get( i++ );
		assertEquals( 2, column.getPosition( ).intValue( ) );
		assertEquals( "date", column.getColumnName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_DATETIME, column
				.getDataType( ) );

		column = (OdaResultSetColumn) columns.get( i++ );
		assertEquals( 3, column.getPosition( ).intValue( ) );
		assertEquals( "id", column.getColumnName( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER, column
				.getDataType( ) );

		// Test "computed-columns" on DataSet

		columns = (List) dataSet
				.getProperty( SimpleDataSet.COMPUTED_COLUMNS_PROP );
		assertEquals( 3, columns.size( ) );

		i = 0;
		ComputedColumn computedColumn = (ComputedColumn) columns.get( i++ );
		assertEquals( "column1", computedColumn.getName( ) ); //$NON-NLS-1$
		assertEquals( "expression1", computedColumn.getExpression( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER,
				computedColumn.getDataType( ) );

		computedColumn = (ComputedColumn) columns.get( i++ );
		assertEquals( "column2", computedColumn.getName( ) ); //$NON-NLS-1$
		assertEquals( "expression2", computedColumn.getExpression( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_DATETIME,
				computedColumn.getDataType( ) );

		computedColumn = (ComputedColumn) columns.get( i++ );
		assertEquals( "column3", computedColumn.getName( ) ); //$NON-NLS-1$
		assertEquals( "expression3", computedColumn.getExpression( ) ); //$NON-NLS-1$
		assertEquals( DesignChoiceConstants.COLUMN_DATA_TYPE_ANY,
				computedColumn.getDataType( ) );

		// Test "column-hints" on DataSet

		List columnHints = (List) dataSet
				.getProperty( SimpleDataSet.COLUMN_HINTS_PROP );
		assertEquals( 1, columnHints.size( ) );

		i = 0;
		ColumnHint columnHint = (ColumnHint) columnHints.get( i++ );
		PropertyDefn member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.COLUMN_NAME_MEMBER );
		assertEquals( "username", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.ALIAS_MEMBER );
		assertEquals( "userid", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.SEARCHING_MEMBER );
		assertEquals( DesignChoiceConstants.SEARCH_TYPE_NONE, columnHint
				.getProperty( design, member ) );
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.EXPORT_MEMBER );
		assertEquals( DesignChoiceConstants.EXPORT_TYPE_ALWAYS, columnHint
				.getProperty( design, member ) );
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.ANALYSIS_MEMBER );
		assertEquals( DesignChoiceConstants.ANALYSIS_TYPE_DIMENSION, columnHint
				.getProperty( design, member ) );
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.PARENT_LEVEL_MEMBER );
		assertEquals( "4", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.FORMAT_MEMBER );
		assertEquals( "##.###", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.DISPLAY_NAME_ID_MEMBER );
		assertEquals(
				"message.column-hint.username", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.DISPLAY_NAME_MEMBER );
		assertEquals( "User Name", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.HELP_TEXT_ID_MEMBER );
		assertEquals(
				"message.column-hint.help", columnHint.getProperty( design, member ) ); //$NON-NLS-1$
		member = (PropertyDefn) columnHint.getDefn( ).getMember(
				ColumnHint.HELP_TEXT_MEMBER );
		assertEquals( "Help me!", columnHint.getProperty( design, member ) ); //$NON-NLS-1$

		// Test "filter" on DataSet

		ArrayList filters = (ArrayList) dataSet
				.getProperty( SimpleDataSet.FILTER_PROP );

		assertEquals( 1, filters.size( ) );
		assertEquals(
				"lt", ( (FilterCondition) filters.get( 0 ) ).getOperator( ) ); //$NON-NLS-1$
		assertEquals(
				"filter expression", ( (FilterCondition) filters.get( 0 ) ).getExpr( ) ); //$NON-NLS-1$
		assertEquals(
				"value1 expression", ( (FilterCondition) filters.get( 0 ) ).getValue1( ) ); //$NON-NLS-1$
		assertEquals(
				"value2 expression", ( (FilterCondition) filters.get( 0 ) ).getValue2( ) ); //$NON-NLS-1$

		dataSet = (OdaDataSetHandle) designHandle.findDataSet( "SecondDataSet" ); //$NON-NLS-1$
		assertNotNull( dataSet );
		assertEquals( null, dataSet.getQueryScript( ) );

	}

	/**
	 * This test sets properties, writes the design file and compares it with
	 * golden file.
	 * 
	 * @throws Exception
	 */

	private void write( ) throws Exception
	{
		OdaDataSourceHandle dataSource = (OdaDataSourceHandle) designHandle
				.findDataSource( "extendedDataSource" ); //$NON-NLS-1$
		assertNotNull( dataSource );

		OdaDataSetHandle dataSet = (OdaDataSetHandle) designHandle
				.findDataSet( "MyDataSet" ); //$NON-NLS-1$
		assertNotNull( dataSet );
		dataSet.setQueryText( "new text" ); //$NON-NLS-1$
		dataSet.setResultSetName( "new result set" ); //$NON-NLS-1$

		dataSet.setCachedRowCount( 20 );
		assertEquals( 20, dataSet.getCachedRowCount( ) );

		// Change "input-parameters" on DataSet

		List parameters = (List) dataSet
				.getProperty( OdaDataSet.PARAMETERS_PROP );
		assertEquals( 5, parameters.size( ) );

		PropertyDefn posDefn = (PropertyDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.PARAMETERS_PROP )
				.getStructDefn( ).getMember( DataSetParameter.POSITION_MEMBER );
		PropertyDefn nameDefn = (PropertyDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.PARAMETERS_PROP )
				.getStructDefn( ).getMember( DataSetParameter.NAME_MEMBER );
		PropertyDefn dataTypeDefn = (PropertyDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.PARAMETERS_PROP )
				.getStructDefn( ).getMember( DataSetParameter.DATA_TYPE_MEMBER );

		int i = 0;
		OdaDataSetParameter parameter = (OdaDataSetParameter) parameters
				.get( i++ );
		parameter.setProperty( posDefn, Integer.valueOf( "91" ) ); //$NON-NLS-1$
		parameter.setProperty( nameDefn, "new name" ); //$NON-NLS-1$
		parameter.setProperty( dataTypeDefn,
				DesignChoiceConstants.PARAM_TYPE_FLOAT );
		parameter.setIsOptional( false );
		parameter.setDefaultValue( "new default value 1" ); //$NON-NLS-1$
		parameter.setAllowNull( true );
		parameter.setNativeDataType( Integer.valueOf( "22" ) ); //$NON-NLS-1$

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		parameter.setProperty( posDefn, Integer.valueOf( "92" ) ); //$NON-NLS-1$
		parameter.setProperty( nameDefn, "new date" ); //$NON-NLS-1$
		parameter.setIsOptional( false );
		parameter.setAllowNull( true );

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		parameter.setProperty( posDefn, Integer.valueOf( "93" ) ); //$NON-NLS-1$
		parameter.setProperty( nameDefn, "new id" ); //$NON-NLS-1$
		parameter.setProperty( dataTypeDefn,
				DesignChoiceConstants.PARAM_TYPE_DECIMAL );
		parameter.setIsOptional( false );

		// Change "output-parameters" on DataSet

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		parameter.setProperty( nameDefn, "new name" ); //$NON-NLS-1$
		parameter.setProperty( dataTypeDefn,
				DesignChoiceConstants.PARAM_TYPE_FLOAT );

		parameter = (OdaDataSetParameter) parameters.get( i++ );
		parameter.setProperty( nameDefn, "new date" ); //$NON-NLS-1$

		parameter = new OdaDataSetParameter( );
		parameter.setProperty( nameDefn, "new id" ); //$NON-NLS-1$
		parameter.setProperty( dataTypeDefn,
				DesignChoiceConstants.PARAM_TYPE_DECIMAL );
		parameter.setIsOutput( true );
		parameters.add( parameter );

		// Change "param-binding" on DataSet

		nameDefn = (PropertyDefn) dataSet.getElement( ).getPropertyDefn(
				SimpleDataSet.PARAM_BINDINGS_PROP ).getStructDefn( ).getMember(
				ParamBinding.PARAM_NAME_MEMBER );
		PropertyDefn valueDefn = (PropertyDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.PARAM_BINDINGS_PROP )
				.getStructDefn( ).getMember( ParamBinding.EXPRESSION_MEMBER );

		List bindings = (List) dataSet
				.getProperty( SimpleDataSet.PARAM_BINDINGS_PROP );
		assertEquals( 2, bindings.size( ) );

		i = 0;
		ParamBinding binding = (ParamBinding) bindings.get( i++ );
		binding.setProperty( nameDefn, "new param1" ); //$NON-NLS-1$
		binding.setProperty( valueDefn, "new value1" ); //$NON-NLS-1$

		binding = (ParamBinding) bindings.get( i++ );
		binding.setProperty( nameDefn, "new param2" ); //$NON-NLS-1$
		binding.setProperty( valueDefn, "new value2" ); //$NON-NLS-1$

		// Change "result-set" on DataSet

		posDefn = (PropertyDefn) dataSet.getElement( ).getPropertyDefn(
				SimpleDataSet.RESULT_SET_PROP ).getStructDefn( ).getMember(
				ResultSetColumn.POSITION_MEMBER );
		nameDefn = (PropertyDefn) dataSet.getElement( ).getPropertyDefn(
				SimpleDataSet.RESULT_SET_PROP ).getStructDefn( ).getMember(
				ResultSetColumn.NAME_MEMBER );
		dataTypeDefn = (PropertyDefn) dataSet.getElement( ).getPropertyDefn(
				SimpleDataSet.RESULT_SET_PROP ).getStructDefn( ).getMember(
				ResultSetColumn.DATA_TYPE_MEMBER );

		List columns = (List) dataSet.getElement( ).getProperty( design,
				SimpleDataSet.RESULT_SET_PROP );
		assertEquals( 3, columns.size( ) );

		i = 0;
		OdaResultSetColumn column = (OdaResultSetColumn) columns.get( i++ );
		column.setProperty( posDefn, Integer.valueOf( "81" ) ); //$NON-NLS-1$
		column.setProperty( nameDefn, "new name" ); //$NON-NLS-1$
		column.setProperty( dataTypeDefn,
				DesignChoiceConstants.COLUMN_DATA_TYPE_FLOAT );
		column.setNativeDataType( Integer.valueOf( "2" ) ); //$NON-NLS-1$

		column = (OdaResultSetColumn) columns.get( i++ );
		column.setProperty( posDefn, Integer.valueOf( "82" ) ); //$NON-NLS-1$
		column.setProperty( nameDefn, "new date" ); //$NON-NLS-1$

		column = (OdaResultSetColumn) columns.get( i++ );
		column.setProperty( posDefn, Integer.valueOf( "83" ) ); //$NON-NLS-1$
		column.setProperty( nameDefn, "new id" ); //$NON-NLS-1$
		column.setProperty( dataTypeDefn,
				DesignChoiceConstants.COLUMN_DATA_TYPE_DECIMAL );

		// Change "computed-columns" in DataSet

		nameDefn = (PropertyDefn) dataSet.getElement( ).getPropertyDefn(
				SimpleDataSet.COMPUTED_COLUMNS_PROP ).getStructDefn( )
				.getMember( ComputedColumn.NAME_MEMBER );
		PropertyDefn expressionDefn = (PropertyDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.COMPUTED_COLUMNS_PROP )
				.getStructDefn( ).getMember( ComputedColumn.EXPRESSION_MEMBER );

		columns = (List) dataSet.getElement( ).getProperty( design,
				SimpleDataSet.COMPUTED_COLUMNS_PROP );
		assertEquals( 3, columns.size( ) );

		i = 0;
		ComputedColumn computedColumn = (ComputedColumn) columns.get( i++ );
		computedColumn.setProperty( nameDefn, "new column1" ); //$NON-NLS-1$
		computedColumn.setProperty( expressionDefn, "new expression 1" ); //$NON-NLS-1$
		computedColumn
				.setDataType( DesignChoiceConstants.COLUMN_DATA_TYPE_DECIMAL );

		computedColumn = (ComputedColumn) columns.get( i++ );
		computedColumn.setProperty( nameDefn, "new column2" ); //$NON-NLS-1$
		computedColumn.setProperty( expressionDefn, "new expression 2" ); //$NON-NLS-1$
		computedColumn.setDataType( null );

		computedColumn = (ComputedColumn) columns.get( i++ );
		computedColumn.setProperty( nameDefn, "new column3" ); //$NON-NLS-1$
		computedColumn.setProperty( expressionDefn, "new expression 3" ); //$NON-NLS-1$

		// Change "column-hints" on DataSet

		List columnHints = (List) dataSet
				.getProperty( SimpleDataSet.COLUMN_HINTS_PROP );
		assertEquals( 1, columnHints.size( ) );

		i = 0;
		ColumnHint columnHint = (ColumnHint) columnHints.get( i++ );
		StructureDefn structureDefn = (StructureDefn) dataSet.getElement( )
				.getPropertyDefn( SimpleDataSet.COLUMN_HINTS_PROP )
				.getStructDefn( );
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.COLUMN_NAME_MEMBER ), "new username" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.ALIAS_MEMBER ), "new userid" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.SEARCHING_MEMBER ),
				DesignChoiceConstants.SEARCH_TYPE_INDEXED );
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.EXPORT_MEMBER ),
				DesignChoiceConstants.EXPORT_TYPE_IF_REALIZED );
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.ANALYSIS_MEMBER ),
				DesignChoiceConstants.ANALYSIS_TYPE_DETAIL );
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.PARENT_LEVEL_MEMBER ), "new level" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.FORMAT_MEMBER ), "new format" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.DISPLAY_NAME_ID_MEMBER ),
				"new display name id" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.DISPLAY_NAME_MEMBER ),
				"new display name" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.HELP_TEXT_ID_MEMBER ),
				"new help text id" ); //$NON-NLS-1$
		columnHint.setProperty( (PropertyDefn) structureDefn
				.getMember( ColumnHint.HELP_TEXT_MEMBER ), "new help text" ); //$NON-NLS-1$
	}

	/**
	 * Tests to write empty string of queryText to the design file.
	 * 
	 * @throws Exception
	 */

	public void testWriteEmptyQueryText( ) throws Exception
	{
		openDesign( queryTextInputFileName );

		// Test if it can parser and write querytext when the type of it is
		// changed to literalstringproperty type

		OdaDataSetHandle odaHandle = (OdaDataSetHandle) designHandle
				.findDataSet( "myDataSet2" ); //$NON-NLS-1$
		assertEquals( "", odaHandle.getQueryText( ) ); //$NON-NLS-1$

		odaHandle = (OdaDataSetHandle) designHandle.findDataSet( "myDataSet3" ); //$NON-NLS-1$
		assertEquals( "  ", odaHandle.getQueryText( ) ); //$NON-NLS-1$

		saveAs( queryTextOutFileName );
		assertTrue( compareTextFile( queryTextGoldenFileName,
				queryTextOutFileName ) );
	}
}