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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

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

import com.meterware.httpunit.WebResponse;

/**
 * <b>Bug description:</b>
 * <p>
 * [compatibility] an old report cannot be previewed in report viewer
 * <p>
 * <b>Steps to reproduce:</b>
 * <ol>
 * <li>there are errors thrown out when previewing the attached report design
 * in report viewer. note that it can be previewed in HTML.
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * Errors are thrown out.
 * <p>
 * <b>Expected result:</b>
 * <p>
 * No errors.
 * </p>
 * <b>Test description:</b>
 * <p>
 * The test makes sure that no exception is thrown out when parse the old report
 * in Web Viewer.
 * </p>
 */
public class Regression_136573 extends BaseViewerTestCase
{

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

	/**
	 * @param webRequest
	 * @throws Exception
	 */

	public void begin_Regression_136573( WebRequest webRequest ) throws Exception
	{
		webRequest.setURL( null, null, SERVLET_PATH_FRAMESET, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
		webRequest.addHeader( "request-type", "SOAP" );//$NON-NLS-1$//$NON-NLS-2$
		webRequest.setContentType( "text/xml; charset=utf-8" ); //$NON-NLS-1$
		webRequest.addHeader( "SOAPAction", "''" ); //$NON-NLS-1$//$NON-NLS-2$
		webRequest.setUserData( getSoapStream( ) );
	}

	/**
	 * 
	 */

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

	/**
	 * @param webResponse
	 * @throws IOException
	 */
	public void end_Regression_136573( WebResponse webResponse ) throws Exception
	{
		assertEquals( 200, webResponse.getResponseCode( ) );
		System.out.println( webResponse.getText( ));
	}

	/* utility methods */

	private InputStream getSoapStream( )
	{
		String soapMessage = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Body><GetUpdatedObjects xmlns=\"http://schemas.eclipse.org/birt\"><Operation><Target><Id>Document</Id><Type>Document</Type></Target><Operator>GetPage</Operator><Oprand><Name>page</Name><Value>1</Value></Oprand><Oprand><Name>svg</Name><Value>false</Value></Oprand></Operation></GetUpdatedObjects></Body></Envelope>"; //$NON-NLS-1$
		return new ByteArrayInputStream( soapMessage.getBytes( ) );
	}

}