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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import utility.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * Description:
 * <p>
 * Use the store procedure "counterInt1(?)" will cause an expection
 * <ol>
 * Step to reproduce:
 * <li>new a report
 * <li>new a datasource:
 * <P>
 * net.sourceforge.jtds.jdbc.Driver
 * <P>
 * jdbc:jtds:sqlserver://spmdb:1433/gui sa/sa
 * <li>new a data set with the dataset type ¡°SQL Stored Procedure Query¡±
 * <li>input ¡°{call dbo.counterInT1(?)}¡± in the query
 * <li>click finish
 * </ol>
 * <P>
 * Actual result: Cause an exception
 * <P>
 * <b>Test description</b>
 * <p>
 * <li>Create a report include the store procedure
 * <li>Run&Render the report to generate a html file
 * <li>Check the result
 * 
 */

public class Regression_144179 extends EngineCase
{

	private final static String INPUT = "Regression_144179.xml"; //$NON-NLS-1$
	private final static String OUTPUT = "Regression_144179.html"; //$NON-NLS-1$

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

	public void testRegression_144179( ) throws Exception
	{
		runAndRender_HTML( INPUT, OUTPUT );
		testCompare( OUTPUT );
	}

	protected void testCompare( String fileHTMLName ) throws IOException
	{
		String fileHTMLFile = getClassFolder( ) + "/" + OUTPUT_FOLDER + "/"
				+ OUTPUT;
		BufferedReader reader = new BufferedReader( new FileReader( new File(
				fileHTMLFile ) ) );
		String line = null;
		String sResult = null;
		int startNumber = 0;
		int endNumber = 0;

		while ( ( line = reader.readLine( ) ) != null )
		{
			if ( line.indexOf( "text-align:left;\">3</div>" ) > 0 )
			{
				startNumber = line.trim( ).indexOf( "text-align:left;\">" ) + 18;
				endNumber = startNumber + 1;
				sResult = line.trim( ).substring( startNumber, endNumber );
				break;
			}
		}
		assertNotNull( "No result!", sResult );
		assertEquals( sResult + " is incorrect result!", "3", sResult );
	}
}
