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

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

import com.meterware.httpunit.WebResponse;

/**
 * <b>Steps to reproduce:</b>
 * <ol>
 * <li>Create a report without title
 * <li>Add a label and enter Actuate
 * <li>Preview in Web Viewer
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * Titles shown in browser and in content are different
 * <p>
 * <b>Expected result:</b>
 * <p>
 * Titles are same
 * </p>
 * <b>Test description:</b>
 * <p>
 * Verify that BIRT Report Viewer is used in both places
 * </p>
 */
public class Regression_122345 extends BaseViewerTestCase
{

	private final static String REPORT = "report/regression_122345.rptdesign";

	/**
	 * @param webRequest
	 * @throws Exception
	 */
	public void begin_regression_122345( WebRequest webRequest )
			throws Exception
	{
		webRequest.setURL( null, null, SERVLET_PATH_FRAMESET, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
	}

	/**
	 * test_regression_122345
	 */
	public void test_regression_122345( )
	{
		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_122345( WebResponse webResponse )
			throws Exception
	{
		String title = "BIRT Report Viewer";
		assertEquals( title, webResponse.getTitle( ) );
		String content = webResponse.getText( );
		// use 1st <B> to locate expected title
		int sIndex = content.indexOf( "<B>" ) + 3;
		int eIndex = sIndex + title.length( );
		assertEquals( title, content.substring( sIndex, eIndex ) );
	}

}