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

import java.util.HashMap;
import java.util.Locale;

import org.eclipse.birt.core.archive.FileArchiveWriter;
import org.eclipse.birt.core.archive.IDocArchiveWriter;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.tests.engine.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * NPE is thrown when using engine API to run attached report
 * <p>
 * <b>Test description</b>
 * <p>
 * This test makes sure that report document can be created without NPE.
 * 
 */
public class Regression_138300 extends EngineCase
{

	private final static String INPUT = "regression_138300.rptdesign"; //$NON-NLS-1$
	private final static String OUTPUT = "regression_138300.rptdocument"; //$NON-NLS-1$

	/**
	 * @throws Exception
	 */

	public void test_Regression_138300( )
	{

		String outputFile = this.getClassFolder( ) + "/" + OUTPUT_FOLDER //$NON-NLS-1$
				+ "/" + OUTPUT; //$NON-NLS-1$
		String inputFile = this.getClassFolder( )
				+ "/" + INPUT_FOLDER + "/" + INPUT; //$NON-NLS-1$ //$NON-NLS-2$

		try
		{
			IReportRunnable runnable = engine.openReportDesign( inputFile );
			IRunTask task = engine.createRunTask( runnable );
			task.setAppContext( new HashMap( ) );
			task.setLocale( Locale.ENGLISH );
			IDocArchiveWriter archive = null;
			archive = new FileArchiveWriter( outputFile );
			task.run( archive );
			assertTrue( "Exception when create report document.", task
					.getErrors( ).size( ) <= 0 );
			task.close( );
		}
		catch ( Exception e )
		{
			e.printStackTrace( );
		}
	}
}
