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

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

import com.meterware.httpunit.WebResponse;

/**
 * <b>Description:</b>
 * <p>
 * Prompt text on cascading parameter group can't be preview <b>Test
 * description:</b>
 * <p>
 * Preview a report contains a cascading parameter, in the response, locate
 * first match of: <FONT TITLE=""><B>Test&#32;prompt&#32;text</B></FONT>,
 * ensure that the Prompt text on cascading parameter group can be preview.
 * <p>
 */

public class Regression_141227 extends BaseViewerTestCase
{

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

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

	public void begin_regression_141227( 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_141227( )
	{
		ViewerServlet servlet = new ViewerServlet( );

		try
		{
			servlet.init( config );
			servlet.doPost( 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_141227( WebResponse webResponse )
			throws SAXException, IOException
	{
		String text = webResponse.getText( );

		Pattern pattern = Pattern
				.compile( "<FONT .*Test&#32;prompt&#32;text.*</FONT>" ); //$NON-NLS-1$
		Matcher matcher = pattern.matcher( text );

		// locate first match of: <FONT
		// TITLE=""><B>Test&#32;prompt&#32;text</B></FONT>

		boolean find = matcher.find( );
		if ( !find )
			fail( text );
	}

}