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

import java.io.IOException;

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.HTMLElement;
import com.meterware.httpunit.WebResponse;

/**
 * <b>Steps to reproduce:</b>
 * <ol>
 * <li>Create a report
 * <li>Add a label and edit its hyperlink
 * <li>Let it link to another report's bookmark
 * <li>Preview in HTML and click on the label
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * HTTP 500 Error
 * <p>
 * <b>Expected result:</b>
 * <p>
 * Target report can be linked properly
 * </p>
 * <b>Test description:</b>
 * <p>
 * This test maily ensure that the html hyperlink tag 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_141937 extends BaseViewerTestCase
{

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

	/**
	 * @param webRequest
	 * @throws Exception
	 */
	public void begin_regression_141937( WebRequest webRequest )
	{
		webRequest.setURL( null, null, SERVLET_PATH_RUN, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.addParameter( PARAM_LOCALE, "en_US" ); //$NON-NLS-1$
	}

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

	/**
	 * @param webResponse
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws Exception 
	 */
	public void end_regression_141937( WebResponse webResponse ) throws IOException, SAXException
	{
		String text = webResponse.getText( );
		System.out.println( webResponse.getResponseMessage( ) );
		System.out.println( text );
	
		HTMLElement[] bk1 = webResponse.getElementsWithAttribute( "id", "bk1" ); //$NON-NLS-1$ //$NON-NLS-2$
		assertNotNull( bk1 );
		assertTrue( bk1.length > 0 );
		
		// get the data time text(locale:en_US) 
		
		assertEquals( "May 5, 2006 2:41 PM", bk1[0].getText( ) ); //$NON-NLS-1$
	}

}