/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

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

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

import com.meterware.httpunit.HTMLElement;
import com.meterware.httpunit.WebResponse;

/**
 * <b>step to reproduce:</b>
 * <p>
 * <ol>
 * <li>Add a data item "new Date( );" in the report
 * <li>Change locale from "English(United State)" to "Dutch" (TopMenu -> Window ->
 * Preference -> Preview)
 * <li>Save and preview
 * </ol>
 * <b>expected behavior:</b>
 * <p>
 * 22-dec-2005 14:49
 * <p>
 * <b>actual behavior:</b>
 * <p>
 * Dec 22, 2005 2:50 PM
 * <p>
 * <b>Test Description:</b>
 * <p>
 * Set report locale to Dutch, make sure the date time is formatted as
 * XX-XXX-XXXX
 */
public class Regression_121841 extends BaseViewerTestCase
{

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

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

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

	/**
	 * Assert the date time is formatted as XX-XXX-XXXX
	 * @param webResponse
	 * @throws Exception
	 */
	public void end_regression_121841( WebResponse webResponse )
			throws Exception
	{
		HTMLElement element = webResponse.getElementWithID( "bookmark" ); //$NON-NLS-1$
		String text = element.getText( );
		assertEquals( "-", text.substring( 2, 3 ) ); //$NON-NLS-1$
		assertEquals( "-", text.substring( 6, 7 ) ); //$NON-NLS-1$
	}
}
