/*******************************************************************************
 * 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.BaseTestCase;
import testutil.APITestCase.DataSourceInfo;

/**
 * <b>Bug description:</b>
 * <p>
 * Preview of XML attributes is not working
 * <p>
 * Description:
 * </p>
 * <p>
 * The XML attribute values are not working in the current BIRT XML ODA driver.
 * Only 'text'-type XML elements' values are displayable in Preview.
 * ColumnMapping XPath expressions like "@attributeName" are broken in Preview.
 * I'll attach document showing the problem and sample XML/XSD data
 * </p>
 * 
 * <p>
 * <b>Test description:</b>
 * </p>
 * <p>
 * Construct a query text with Xpath expressions like "@attributeNameand",
 * import the small.xml from input folder and generate the result and print it.
 * </p>
 * 
 * 
 */
public class Regression_120036 extends BaseTestCase
{

	IResultSet rs;
	String queryText;

	protected void setUp( ) throws Exception
	{
		super.setUp( );
		Connection conn = new Connection( );
		Properties prop = new Properties( );
		queryText = "book#-TNAME-#book#:#[//book]#:#{book.category;String;/@category},"
				+ "{book.title;String;title},"
				+ "{book.title.language;String;title/@lang},"
				+ "{book.author.name;String;author/@name},"
				+ "{book.author.country;String;author/@country},"
				+ "{book.date;Date;date},"
				+ "{book.price;Double;price},"
				+ "{book.isn;Int;isn},"
				+ "{book.timestamp;Timestamp;timestamp},"
				+ "{book.time;Time;time}";
		String filename = getInputFolder( ) + "\\small.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 testColMapXpath( ) throws OdaException, IOException
	{
		String outputStr = "";
		assertTrue( rs != null );
		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;
	}
}
