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

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.apache.cactus.WebRequest;
import org.eclipse.birt.report.servlet.ViewerServlet;
import org.eclipse.birt.report.tests.viewer.BaseViewerTestCase;

import utility.HTMLDecoder;

import com.meterware.httpunit.WebResponse;

/**
 * <b>Bug description</b>
 * <p>
 * report viewer doesnt show help text for parameters. 
 * <b>Steps to reproduce:</b>
 * <p>
 * The help text set for a parameter is not displayed in the parameter dialog
 * when the report is run in web-viewer. Though the parameter help text is shown
 * when the report is previewed inside the Eclipse, and the "Show parameter"
 * button is clicked in preview pane.
 * 
 * This is causing problems for us, as we have 2 different databases running
 * which accept dates in different formats. the parameter help text not showing
 * up is causing confusion for the user as they dont/can't remember the desired
 * input format of the date.
 * </p>
 * <b>Test description:</b>
 * <p>
 * This test maily ensure that help text is written into viewer source.
 * </p>
 */
public class Regression_135786 extends BaseViewerTestCase
{

	private final static String REPORT = "report/regression_135786.rptdesign"; //$NON-NLS-1$

	/**
	 * @param webRequest
	 * @throws Exception
	 */
	public void begin_Regression_135786( WebRequest webRequest )
			throws Exception
	{
		webRequest.setURL( null, null, SERVLET_PATH_FRAMESET, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.setContentType( "text/xml; charset=utf-8" ); //$NON-NLS-1$
		webRequest.addParameter( PARAM_LOCALE, "en_US" );
	}

	/**
	 * 
	 */
	public void test_Regression_135786( )
	{
		ViewerServlet servlet = new ViewerServlet( );
		try
		{
			servlet.init( config );
			servlet.doPost( request, response );
		}
		catch ( Exception e )
		{
			e.printStackTrace( );
			fail( e.toString( ) );
		}
	}

	/**
	 * @param webResponse
	 */
	public void end_Regression_135786( WebResponse webResponse )
			throws Exception
	{
		assertEquals( 200, webResponse.getResponseCode( ) );
		String content=HTMLDecoder.decode( webResponse.getText( ));
		content=content.substring( content.indexOf( "CLASS=\"BirtViewer_parameter_dialog_Input\""));
		content=content.substring( 0,content.indexOf( ">" ) );
		System.out.println(content );
		assertTrue(HTMLDecoder.decode( webResponse.getText( )).indexOf( "TITLE=\"help text for p1\"" )!=-1);
	}

}