/*******************************************************************************
 * 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>Bug Description:</b>
 * <p>
 * Background setting in predefined style doesn't take effect in table header
 * and table details.
 * <p>
 * <b>Steps to reproduce:</b>
 * <p>
 * <ol>
 * <li>Add a predefined style "table-header".
 * <li> Set background color as "silver".
 * <li>Add a table and fill it with some data.
 * <li>Preview.
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * background color setting doesn't work in predefined style. <b>Test
 * Description</b>
 * <p>
 * Background color is in the "style" content, and element "class" refer to the
 * style
 */
public class Regression_110284 extends BaseViewerTestCase
{

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

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

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

	/**
	 * @param webResponse
	 * @throws Exception
	 */
	public void end_regression_110284( WebResponse webResponse )
			throws Exception
	{
		HTMLElement element = webResponse.getElementWithID( "tableheader" ); //$NON-NLS-1$
		String style = element.getAttribute( "class" ); //$NON-NLS-1$
		assertNotNull( style );
		assertEquals( "style_1", style ); //$NON-NLS-1$
		String content = webResponse.getText( );
		String color = content
				.substring(
						content.indexOf( ".style_1" ) + 29, content.indexOf( ".style_1" ) + 47 ); //$NON-NLS-1$ //$NON-NLS-2$
		assertEquals( "rgb(192, 192, 192)", color ); //$NON-NLS-1$
	}
}