/*******************************************************************************
 * Copyright (c) 2004, 2005 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.xml;

import java.io.IOException;
import java.util.Properties;

import org.eclipse.birt.report.data.oda.xml.Constants;
import org.eclipse.birt.report.data.oda.xml.impl.Connection;
import org.eclipse.datatools.connectivity.oda.IQuery;
import org.eclipse.datatools.connectivity.oda.IResultSet;
import org.eclipse.datatools.connectivity.oda.OdaException;

import testutil.APITestCase;

/**
 * <b>Bug description:</b>
 * <p>
 * XML data source does not accept long values for timestamp
 * <p>
 * Description:
 * </p>
 * <p>
 * When creating a XML data source I cannot create a column mapping with a
 * timestamp type and set the value to a long value. The xml data source expects
 * the timestamp to be in canonical form specified in the XML schema spec.
 * However I believe there are various usecases in the industry where the time
 * stamp may be a long millisecond value. As a result, the xml data source
 * should accept long values for timestamps.
 * 
 * 
 * </p>
 * 
 * <p>
 * <b>Test description:</b>
 * </p>
 * <p>
 * Construct a query text with Xpath expressions like "@attributeNameand",
 * import the timeStampWithLongValue.xml from input folder, which has long value in time stamp and generate the result and print it.
 * Compare the results with golen file.
 * </p>
 * 
 * 
 */
public class Regression_123157 extends APITestCase
{

	IResultSet rs;
	String queryText;

	protected void setUp( ) throws Exception
	{
		super.setUp( );
		Connection conn = new Connection( );
		Properties prop = new Properties( );
		queryText = "testSuites#-TNAME-#testSuites#:#[/testSuites/testsuite/*]#:#{timestamp;String;@timestamp}";
		String filename = getInputFolder( ) + "\\timeStampWithLongValue.xml";

		prop.put( Constants.CONST_PROP_FILELIST, filename );
		// System.out.println(filename);
		conn.open( prop );
		IQuery query = conn.newQuery( null );
		query.prepare( queryText );
		rs = query.executeQuery( );
	}

	public void testTimeStampWithLongValue( ) throws OdaException, IOException
	{
		assertTrue( rs != null );
		String outputStr = "";
		while ( rs.next( ) )
		{
			int columnCount = rs.getMetaData( ).getColumnCount( );
			for ( int i = 1; i <= columnCount; i++ )
			{
				outputStr += "Column" + i + ":" + rs.getString( i ) + "  ";
			}
			outputStr += "\n";
		}
		testPrint( outputStr );
		this.checkOutputFile( );
	}

	protected void tearDown( ) throws Exception
	{
		super.tearDown( );
	}

	protected DataSourceInfo getDataSourceInfo( )
	{
		return null;
	}

}