/*******************************************************************************
 * 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.tests.data.engine.regression;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import utility.EngineCase;

/**
 * <b>Bug description</b>
 * <p>
 * HTTP status 500 display when preview xml data set
 * <p>
 * <b>Test description</b>
 * <p>
 * This test test the XML data set can be previewed.
 * 
 */
public class Regression_117437 extends EngineCase {

	private final static String INPUTXML = "Employee.xml";

	private final static String INPUT = "Reg_117437.xml"; //$NON-NLS-1$

	private final static String GOLDEN = "Reg_117437.html"; //$NON-NLS-1$

	private final static String OUTPUT = "Reg_117437.html"; //$NON-NLS-1$

	/**
	 * @throws Exception
	 */

	public void testRegression_117437() throws Exception {
		DataInputStream instr;
		DataOutputStream outstr;

		String outputFileName = "C:\\" + INPUTXML;
		String inputFileName = getClassFolder() + "/" + INPUT_FOLDER + "/"
				+ INPUTXML;

		File inFile = new File(inputFileName);
		File outFile = new File(outputFileName);

		if (outFile.exists()) {
			System.out.println(" already exists");

		}

		if (!inFile.exists()) {
			System.out.println(" does not exist");

		}

		try {
			instr = new DataInputStream(new BufferedInputStream(
					new FileInputStream(inFile)));
			outstr = new DataOutputStream(new BufferedOutputStream(
					new FileOutputStream(outFile)));
			try {
				int data;
				while (true) {
					data = instr.readUnsignedByte();
					outstr.writeByte(data);
				}
			} catch (EOFException eof) {
				outstr.close();
				instr.close();
			}
		} catch (FileNotFoundException nfx) {
			System.out.println("Problem opening files");
		} catch (IOException iox) {
			System.out.println("IO Problems");
		}

		runAndRender_HTML(INPUT, OUTPUT);
		assertTrue(compareHTML(GOLDEN, OUTPUT));
		outFile.delete();
		assertFalse("The temp file hasn't been cleared", outFile.exists());

	}

}
