
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 utility.StringUtil;

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

/**
 * <b>Description:</b>
 * <p>
 * HCG_BIDI: Preview tab is not mirrored
 * <p>
 * <b>Steps to reproduce:</b>
 * <p>
 * <ol>
 * <li>Start eclipse with "-dir rtl" option
 * <li>Create any report and use Template Image option to put any image to the
 * report Result: The image appear in the right corner of the report on the
 * Layout page. (Notice the when you run Eclipse in the usual mode the image
 * would appear in the left corner of the report). This is expected behavior
 * <li>Switch to Preview tab Result: The image appear in the left most corner
 * as if Eclipse was ran in regular mode (not with "-dir rtl")
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * The image appear in the left most corner as if Eclipse was ran in regular
 * mode (not with "-dir rtl")
 * <p>
 * <b>Expected result:</b>
 * <p>
 * The image should appear in the rightmost corner as on the Layout tab.
 * </p>
 * <b>Test description:</b>
 * <p>
 * Specify __rtl=true, make sure that viewer support right-to-left parameters,
 * ensure that text direction is changed correctly.
 * </p>
 */

public class Regression_129788 extends BaseViewerTestCase
{

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

	/**
	 * Set request url, add parameter __rtl=true to request right-to-left text
	 * direction.
	 * 
	 * @param webRequest
	 */

	public void begin_regression_129788( 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$
		webRequest.addParameter( "__rtl", "true" ); //$NON-NLS-1$//$NON-NLS-2$
	}

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

	/**
	 * get response, and assert make sure style is right-aligned.
	 * 
	 * @param webResponse
	 * @throws SAXException
	 * @throws IOException
	 */

	public void end_regression_129788( WebResponse webResponse ) throws SAXException,
			IOException
	{
		HTMLElement element = webResponse.getElementWithID( "rtl bookmark" ); //$NON-NLS-1$
		String style = StringUtil.trimString( element.getAttribute( "style" ) ); //$NON-NLS-1$
		assertEquals( "RTL right-to-left direction", element.getText( ) ); //$NON-NLS-1$

		// make sure style is right-aligned.
		
		assertEquals( "text-align:right;", style ); //$NON-NLS-1$
	}
}