
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>Description:</b>
 * <p>
 * Truncation of time part in datetime parameter to 00:00 i.e. midnight 12:00
 * <p>
 * It looks like in a datetime parameter the time part is always truncted to
 * 00:00 i.e. midnight 12:00 To a datetime parameter, I am passing this string
 * as parameter value "05/17/2006 10:25 AM" in MM/DD/YYYY hh:mm:ss a" format
 * which is also shown on edit parameter page.
 * <p>
 * BIRT engine would parse this datetime as "05/17/2006 12:00 AM"
 * <p>
 * <b>Test description:</b>
 * <p>
 * Run a report with a datetime parameter, pass the parameter through URL,
 * verify the text is correct in the response.
 * <p>
 */
public class Regression_142540 extends BaseViewerTestCase
{

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

	/**
	 * @param webRequest
	 * @throws Exception
	 */
	public void begin_regression_142540( WebRequest webRequest )
	{
		webRequest.setURL( null, null, SERVLET_PATH_RUN, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.addParameter( "datetime", "05/17/2006 10:25 AM" ); //$NON-NLS-1$//$NON-NLS-2$
		webRequest.addParameter( PARAM_LOCALE, "en_US" ); //$NON-NLS-1$
	}

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

	/**
	 * @param webResponse
	 * @throws IOException
	 * @throws SAXException
	 * @throws Exception
	 */
	public void end_regression_142540( WebResponse webResponse )
			throws IOException, SAXException
	{
		System.out.println( webResponse.toString( ) );
		String text = webResponse.getText( );
		System.out.println( text );
		HTMLElement[] elements = webResponse.getElementsWithAttribute( "id", //$NON-NLS-1$
				"bk1" ); //$NON-NLS-1$
		assertNotNull( elements );
		assertTrue( elements.length > 0 );

		assertEquals( "May 17, 2006 10:25 AM", elements[0].getText( ) ); //$NON-NLS-1$
	}

}