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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

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

import com.meterware.httpunit.WebResponse;

/**
 * <b>Bug description:</b>
 * <p>
 * report cannot be rendered if drill through link contains a parameter with
 * empty value.
 * </p>
 * <b>Steps to reproduce:</b>
 * <ol>
 * <li>use the attached reports
 * <li>preview new_report_1.rptdesign
 * <li>click on link Atelier graphique
 * <li>drill through to new_report2.rptdesign
 * <li>modify new_report_1.rptdesign
 * <li>edit drill through link by adding a parameter with empty value
 * <li>preview new_report_1.rptdesign
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * it simply did not, and an empty report was displayed instead.
 * <p>
 * <b>Expected result:</b>
 * <p>
 * report is rendered
 * </p>
 * <b>Test description:</b>
 * <p>
 * This test maily ensure that the html hyperlink is rendered correctly. We make
 * a request to run a report, server returns the content, make sure the
 * hyperlink defined on label is correct.
 * </p>
 */
public class Regression_141710 extends BaseViewerTestCase
{

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

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

	public void begin_Regression_141710( WebRequest webRequest )
	{
		// viewer "/run" pattern

		webRequest.setURL( null, null, SERVLET_PATH_RUN, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.addParameter( PARAM_LOCALE, "en_US" ); //$NON-NLS-1$
	}

	/**
	 * Process "/run" request
	 */
	public void test_Regression_141710( )
	{
		BirtEngineServlet servlet = new BirtEngineServlet( );
		try
		{
			servlet.init( config );
			servlet.doGet( request, response );
		}
		catch ( Exception e )
		{
			e.printStackTrace( );
			fail( e.toString( ) );
		}
	}

	/**
	 * get "/run" response, and assert contents status and check the hyperlink
	 * of label.
	 * 
	 * @param webResponse
	 * @throws SAXException
	 * @throws UnsupportedEncodingException
	 */

	public void end_Regression_141710( WebResponse webResponse )
			throws SAXException, UnsupportedEncodingException
	{
		assertEquals( 200, webResponse.getResponseCode( ) );
		String hyperlink = webResponse.getLinkWith( "drill through link" ) //$NON-NLS-1$
				.getURLString( );
		assertEquals( CATALINAHOME + "/webapps/" + RUNTIME //$NON-NLS-1$
				+ "/report/regression_141710b.rptdesign", URLDecoder.decode( //$NON-NLS-1$
				getReportParam( hyperlink ), "UTF-8" ) ); //$NON-NLS-1$
		System.out.println( hyperlink );
		assertEquals( "html", getFormatParam( hyperlink ) );//$NON-NLS-1$
		assertEquals( "en_US", getLocaleParam( hyperlink ) );//$NON-NLS-1$
		assertEquals( "true", getMasterpageParam( hyperlink ) );//$NON-NLS-1$
	}

}