/*******************************************************************************
 * 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 Datasource shows weird results when using wild cards.
 * <p>
 * Description:
 * </p>
 * <p>
 * I'm trying to create a dataset from an XML file. I created my datasource with
 * the xml file attached to this defect. I then tried to create a dataset. My
 * row mapping XML expression is set to:
 * 
 * /testSuites/testsuite/*
 * 
 * I assume that this expression will return all children elements under the
 * /testSuites/testsuite element.
 * 
 * Now I try to set up the column mapping by defining a "VerdictName" column.
 * The xpath expression for this column is "[@verdictName]" I also setup up
 * "VerdictValue" column The xpath expression for this column is
 * "[@verdictValue]" I also setup up "Timestamp" column The xpath expression for
 * this column is "[@timestamp]"
 * 
 * When I go to the "Preview Results" pane it shows some wierd results. Some
 * cells in the table aren't filled. It doesn't show the timestamp information
 * as well. I was expecting all the rows to be filled.
 * 
 * </p>
 * 
 * <p>
 * <b>Test description:</b>
 * </p>
 * <p>
 * Construct a query text with Xpath expressions like "@attributeNameand",
 * import the report.xml from input folder and generate the result and print it.
 * Compare the results with golen file.
 * </p>
 * 
 * 
 */
public class Regression_119999 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/*]#:#{verdictName;String;@verdictName},"
				+ "{verdictValue;String;@verdictValue},"
				+ "{timestamp;String;@timestamp}";
		String filename = getInputFolder( ) + "\\reports.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 testColMapXpathWithWeirdResults( ) 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;
	}

}