/*******************************************************************************
 * 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 org.xml.sax.SAXException;

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

/**
 * <b>Bug Description:</b>
 * <p>
 * Insert a .gif or .bmp image from URI, and preview the report with HTML/PDF
 * viewer, error message shows:
 * <p>
 * There are errors on the report page: Error1:Failed to evaluate
 * file:///E:/WINDOWS/pchealth/helpctr/System/images/48x48/desktop_icon_01.bmp
 * Unexpected end of file (#1)
 * <p>
 * <b>Test Description:</b>
 * <p>
 * The test report include a URI image, make sure it can be rendered correctly
 * 
 */

public class Regression_99498 extends BaseViewerTestCase
{

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

	/**
	 * Set request url for Regression_99498.rptdesign
	 * 
	 * @param webRequest
	 */

	public void begin_regression_99498( 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$
		webRequest.addParameter( PARAM_FORMAT, "html" ); //$NON-NLS-1$
	}

	/**
	 * Process request
	 */

	public void test_regression_99498( )
	{
		BirtEngineServlet servlet = new BirtEngineServlet( );

		try
		{
			servlet.init( config );
			servlet.doGet( request, response );

		}
		catch ( Exception e )
		{
			e.printStackTrace( );
			fail( e.toString( ) );
		}
	}

	/**
	 * get response, make sure the image is rendered correctly
	 * 
	 * @param webResponse
	 * @throws SAXException
	 */

	public void end_regression_99498( WebResponse webResponse )
			throws SAXException
	{
		HTMLElement element = webResponse.getElementWithID( "image" ); //$NON-NLS-1$
		assertNotNull( element );
		assertEquals(
				"http://www.google.com/intl/zh-CN_ALL/images/logo.gif", element.getAttribute( "src" ) ); //$NON-NLS-1$//$NON-NLS-2$
	}

}
