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

import java.io.IOException;

import org.apache.cactus.WebRequest;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.servlet.BirtEngineServlet;
import org.eclipse.birt.report.tests.viewer.BaseViewerTestCase;
import org.xml.sax.SAXException;

import com.ibm.icu.util.ULocale;
import com.meterware.httpunit.WebResponse;

/**
 * <b>Description:</b>
 * <p>
 * The Title of the report cann't be refresh
 * <p>
 * <b>Steps:</b>
 * <p>
 * <ol>
 * <li>The Title property should appear as the HTML browser title when viewing
 * a report.
 * <li>set 'Birt Report' in the Title property, preview and it's ok
 * <li>rename the title to 'Report' and save
 * </ol>
 * <p>
 * <b>Actual result:</b>
 * <p>
 * The title is still 'Birt Report'
 * <p>
 * <b>Expected result:</b>
 * <p>
 * The title should be 'Report'
 * <p>
 * <b>Test description:</b>
 * <p>
 * View the report the first time, assert the title and then change the report,
 * modify its title, view the report the second time, make sure the title is
 * refreshed.
 * <p>
 */

public class Regression_135444 extends BaseViewerTestCase
{

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

	/**
	 * Set request url for Regression_120058.rptdesign
	 * 
	 * @param webRequest
	 */

	public void begin_regression_135444( WebRequest webRequest )
	{
		webRequest.setURL( null, null, SERVLET_PATH_FRAMESET, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.addParameter( PARAM_LOCALE, "en_US" ); //$NON-NLS-1$
	}

	/**
	 * Process request
	 */

	public void test_regression_135444( )
	{
		BirtEngineServlet servlet = new BirtEngineServlet( );

		try
		{
			servlet.init( config );
			servlet.doGet( request, response );

			IDesignEngine designEngine = new DesignEngine( new DesignConfig( ) );
			SessionHandle session = designEngine
					.newSessionHandle( ULocale.ENGLISH );
			String report = CATALINAHOME + "/webapps/" + RUNTIME + "/" + REPORT; //$NON-NLS-1$//$NON-NLS-2$

			// rename the title to 'Report' and save

			ReportDesignHandle designHandle = session.openDesign( report );
			designHandle.setProperty( ReportDesignHandle.TITLE_PROP, "Report" ); //$NON-NLS-1$
			designHandle.saveAs( report );

			// view the report again.

			servlet.doGet( request, response );

		}
		catch ( Exception e )
		{
			e.printStackTrace( );
			fail( e.toString( ) );
		}
	}

	/**
	 * get response, make sure the title is refreshed to new value.
	 * 
	 * @param webResponse
	 * @throws SAXException
	 * @throws IOException
	 */

	public void end_regression_135444( WebResponse webResponse )
			throws SAXException, IOException
	{
		// make sure the title is refreshed.

		assertEquals( "Report", webResponse.getTitle( ) ); //$NON-NLS-1$
	}

}