[teiid-commits] teiid SVN: r1556 - in trunk/test-integration/db/src/main/java/org/teiid/test/framework: transaction and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Nov 16 15:58:17 EST 2009


Author: vhalbert at redhat.com
Date: 2009-11-16 15:58:17 -0500 (Mon, 16 Nov 2009)
New Revision: 1556

Modified:
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/JNDITransaction.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java
Log:
Teiid 773 - cleanup and refactoring so that the assumption is there will be 2 datasources required in order to run the test.    

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java	2009-11-16 20:57:50 UTC (rev 1555)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java	2009-11-16 20:58:17 UTC (rev 1556)
@@ -4,15 +4,9 @@
  */
 package org.teiid.test.framework.query;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.BufferedReader;
-import java.io.IOException;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
@@ -21,219 +15,240 @@
 import org.teiid.test.framework.TransactionQueryTest;
 import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
 import org.teiid.test.framework.connection.ConnectionStrategy;
-import org.teiid.test.framework.connection.ConnectionUtil;
-import org.teiid.test.framework.datasource.DataSource;
-import org.teiid.test.framework.datasource.DataSourceSetup;
-import org.teiid.test.framework.datasource.DataSourceSetupFactory;
+import org.teiid.test.framework.datasource.DataStore;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 
-import com.metamatrix.jdbc.api.AbstractQueryTest;
 
 
-/** 
- * The AbstractQueryTransactionTest is the class that should be extended when
- * a testcase is being created to validate certain behavior
+/**
+ * The AbstractQueryTransactionTest is the base implementation for the
+ * {@link TransactionQueryTest}. This provides the default logic for perform a testcase.
+ * The only method to implement in order to perform a basic, single datasource, test
+ * is the {@link #testCase()} method.
  * 
- * @see QueryExecution for use when direct queries to the source are used
- * to validate the results of the testcase.
+ * AbstractQueryTransactionTest is the class that should be extended when a
+ * testcase is being created to validate certain behavior
  * 
+ * <br>
+ * The following methods are useful when writing validation logic because they provide
+ * a direct connection to the datasource that was used by the VDB.  This enables data
+ * validation of expected behavior of Teiid.
+ * <li>{@link #getSource(String)}. </li>
+ * <li>{@link #getXASource(String)} </li>
+ * 
+ * <br>
+ * 
+ * @see QueryExecution for use when direct queries to the source are used to
+ *      validate the results of the testcase.
+ * 
  */
-public abstract class AbstractQueryTransactionTest  extends AbstractQueryTest implements TransactionQueryTest{
-	protected Properties executionProperties = null;
-	protected String testname = "NA";
-	protected int fetchSize = -1;
-	protected int queryTimeout = -1;
-	
-	protected Map<String, DataSource> datasources = null;
-	
-	protected ConnectionStrategy connStrategy;
-	
-	
-	public AbstractQueryTransactionTest() {
-		super();
-	}
-	
-	public AbstractQueryTransactionTest(String testname) {
-		super();
-		this.testname = testname;
-	}
-	
-	public String getTestName() {
-		return this.testname;
-	}
-		
-	
-    @Override
-	public void setConnectionStrategy(ConnectionStrategy connStrategy) {
-		this.connStrategy = connStrategy;
-		
-		this.datasources = this.connStrategy.getDataSources();
-		
-	}
+public abstract class AbstractQueryTransactionTest extends  com.metamatrix.jdbc.api.AbstractQueryTest
+	implements TransactionQueryTest {
+    
+    private static boolean initialized = false;
 
-	public void setExecutionProperties(Properties props) {
-       	assertNotNull(props);
-        this.executionProperties = props;  
-        
-        String fetchSizeStr = executionProperties.getProperty(CONNECTION_STRATEGY_PROPS.FETCH_SIZE);
-        if ( fetchSizeStr != null ) {
-            try {
-                fetchSize = Integer.parseInt(fetchSizeStr);
-            } catch ( NumberFormatException e ) {
-            	fetchSize = -1;
-            	this.print("Invalid fetch size value: " + fetchSizeStr + ", ignoring");
-            }
-        }
+    protected String testname = "NA";
+    protected int fetchSize = -1;
+    protected int queryTimeout = -1;
+
+    protected ConnectionStrategy connStrategy;
+
+    public AbstractQueryTransactionTest() {
+	super();
     }
-    @Override
-    protected void compareResults(BufferedReader resultReader, BufferedReader expectedReader) throws IOException {
-    	assertEquals(read(expectedReader, compareResultsCaseSensitive()) , read(resultReader, compareResultsCaseSensitive()));
+
+    public AbstractQueryTransactionTest(String testname) {
+	super();
+	this.testname = testname;
     }
+
+    public String getTestName() {
+	return this.testname;
+	
+    }
     
-    @Override protected void assignExecutionProperties(Statement stmt) {
-        if (stmt instanceof com.metamatrix.jdbc.api.Statement) {
-            com.metamatrix.jdbc.api.Statement statement = (com.metamatrix.jdbc.api.Statement)stmt;
 
-	        if (this.executionProperties != null) {  
-                String txnautowrap = this.executionProperties.getProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP);
-                if (txnautowrap != null) {
-                     statement.setExecutionProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP, txnautowrap);
-                }
-                
-	        }
-        
-	        if (this.fetchSize > 0) {
-	        	try {
-					statement.setFetchSize(this.fetchSize);
-				} catch (SQLException e) {
-					this.print(e);
-				}
-	        }
-	        
-	        if (this.queryTimeout > 0) {
-	        	try {
-					statement.setQueryTimeout(this.queryTimeout);
-				} catch (SQLException e) {
-					this.print(e);
-				}
-	        }
-    	}
+    @Override
+    public void setConnectionStrategy(ConnectionStrategy connStrategy) throws QueryTestFailedException {
+	this.connStrategy = connStrategy;
+	
+	this.setConnection(connStrategy.getConnection());
 
-                
     }
-    
-    public boolean hasRequiredDataSources() {
-    	boolean rtn = true;
-    	
-    	if (getNumberRequiredDataSources() == 0 || getNumberRequiredDataSources() > this.connStrategy.getNumberAvailableDataSources()) {
-    		this.print(getTestName() + " will not be run, it requires " + getNumberRequiredDataSources() + 
-    				" datasources, but only available is " + this.connStrategy.getNumberAvailableDataSources());
-    		return false;
 
-    	}
+//    @Override
+//    protected void compareResults(BufferedReader resultReader,
+//	    BufferedReader expectedReader) throws IOException {
+//	assertEquals(read(expectedReader, compareResultsCaseSensitive()), read(
+//		resultReader, compareResultsCaseSensitive()));
+//    }
 
-    
-    	
-    	
-    	return rtn;
+    @Override
+    protected void assignExecutionProperties(Statement stmt) {
+	if (stmt instanceof com.metamatrix.jdbc.api.Statement) {
+	    com.metamatrix.jdbc.api.Statement statement = (com.metamatrix.jdbc.api.Statement) stmt;
+
+	    Properties executionProperties = this.connStrategy.getEnvironment();
+	    if (executionProperties != null) {
+		String txnautowrap = executionProperties
+			.getProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP);
+		if (txnautowrap != null) {
+		    statement.setExecutionProperty(
+			    CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP,
+			    txnautowrap);
+		    
+		    this.print("TransactionAutoWrap = " + txnautowrap);
+		}
+		
+		String fetchSizeStr = executionProperties
+		    .getProperty(CONNECTION_STRATEGY_PROPS.FETCH_SIZE);
+		if (fetchSizeStr != null) {
+		    try {
+			fetchSize = Integer.parseInt(fetchSizeStr);
+			
+			this.print("FetchSize = " + fetchSize);
+		    } catch (NumberFormatException e) {
+			fetchSize = -1;
+		    // this.print("Invalid fetch size value: " + fetchSizeStr
+		    // + ", ignoring");
+		    }
+		}
+
+	    }
+	    
+
+
+	    if (this.fetchSize > 0) {
+		try {
+		    statement.setFetchSize(this.fetchSize);
+		} catch (SQLException e) {
+//		    this.print(e);
+		}
+	    }
+
+	    if (this.queryTimeout > 0) {
+		try {
+		    statement.setQueryTimeout(this.queryTimeout);
+		} catch (SQLException e) {
+//		    this.print(e);
+		}
+	    }
+	}
+
     }
-    
-    public int getNumberRequiredDataSources() {
-    	return 1;
-    }
-    
+
     public boolean compareResultsCaseSensitive() {
-    	return true;
+	return true;
     }
 
-
     /**
-     * Override <code>setupDataSource</code> if there is different mechinism for
+     * Override <code>setupDataSource</code> if there is different mechanism for
      * setting up the datasources for the testcase
-     * @throws QueryTestFailedException 
-     * @throws QueryTestFailedException 
      * 
+     * @throws QueryTestFailedException
+     * @throws QueryTestFailedException
+     * 
      * @since
      */
     @Override
-    public void setupDataSource() throws QueryTestFailedException {
-    	
-    	DataSourceSetup dss = DataSourceSetupFactory.createDataSourceSetup(this.getNumberRequiredDataSources());
-    	dss.setup(datasources, connStrategy);
+    public void setup() throws QueryTestFailedException {
 
-    }	
+	if (!initialized) {
+	    initialized = true;
+	    DataStore.initialize(connStrategy);
+	    
+	}
+	
+	DataStore.setup(connStrategy);
+	
+    }
 
+    /**
+     * The source connection must be asked from the connection strategy because only here
+     * is it known which model was mapped to which datasource.
+     * This is because each test could potentially use an include/exclude datasource option
+     * that could change the mappings between tests.
+     * @param identifier
+     * @return
+     * @throws QueryTestFailedException
+     */
+    public Connection getSource(String identifier)
+	    throws QueryTestFailedException {
+	
+	Connection conn = this.connStrategy.createDriverConnection(identifier);
+	// force autocommit back to true, just in case the last user didnt
+	try {
+		conn.setAutoCommit(true);
+	} catch (Exception sqle) {
+		throw new QueryTestFailedException(sqle);
+	}
+	
+	return conn;
 
-	public Connection getSource(String identifier) throws QueryTestFailedException {
-    	return ConnectionUtil.getConnection(identifier, this.datasources, this.connStrategy);
-    }    
-    
-    public XAConnection getXASource(String identifier) throws QueryTestFailedException {
-       	return ConnectionUtil.getXAConnection(identifier, this.datasources, this.connStrategy);
-     }   
-	
-    
-	/**
-	 * Implement testCase(), it is the entry point to the execution of the test.
-	 * @throws Exception
-	 *
-	 * @since
-	 */
+    }
+
+    public XAConnection getXASource(String identifier)
+	    throws QueryTestFailedException {
+
+	return this.connStrategy.createDataSourceConnection(identifier);
+
+    }
+
+    /**
+     * Implement testCase(), it is the entry point to the execution of the test.
+     * 
+     * @throws Exception
+     * 
+     * @since
+     */
     public abstract void testCase() throws Exception;
-        
+
     /**
-     * Indicates what should be done when a failure occurs in {@link #testCase()}
+     * Indicates what should be done when a failure occurs in
+     * {@link #testCase()}
+     * 
      * @return
-     *
+     * 
      * @since
      */
     public boolean rollbackAllways() {
-        return false;
+	return false;
     }
-    
+
     /**
-     * Override <code>before</code> if there is behavior that needs to be performed
-     * prior to {@link #testCase()} being called.
+     * Override <code>before</code> if there is behavior that needs to be
+     * performed prior to {@link #testCase()} being called.
      * 
-     *
+     * 
      * @since
      */
     public void before() {
     }
-    
+
     /**
-     * Override <code>after</code> if there is behavior that needs to be performed
-     * after {@link #testCase()} being called.
+     * Override <code>after</code> if there is behavior that needs to be
+     * performed after {@link #testCase()} being called.
      * 
-     *
+     * 
      * @since
      */
     public void after() {
     }
-    
 
-	@Override
-	public void validateTestCase() throws Exception {
-		
-	}
-    
-    
     /**
-     * At end of each test, perfoom any cleanup that your test requires.
-     * Note:  Do not cleanup any connections.   That is performed by
-     * the {@link TransactionContainer#runTransaction(TransactionQueryTest)} at the end of the test.
+     * At end of each test, perform any cleanup that your test requires. Note:
+     * Do not cleanup any connections by calling {@link ConnectionStrategy#shutdown()}. 
+     * That is performed by the
+     * {@link TransactionContainer#runTransaction(TransactionQueryTest)} at the
+     * end of the test.
      */
     public void cleanup() {
- 
+
     }
-    
-	@Override
-	public XAConnection getXAConnection() {
-		// TODO Auto-generated method stub
-		return null;
-	}
 
+    @Override
+    public XAConnection getXAConnection() {
+	return null;
+    }
 
-    
-    
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/JNDITransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/JNDITransaction.java	2009-11-16 20:57:50 UTC (rev 1555)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/JNDITransaction.java	2009-11-16 20:58:17 UTC (rev 1556)
@@ -19,9 +19,9 @@
 public class JNDITransaction extends TransactionContainer {
     UserTransaction userTxn = null;
     
-    public JNDITransaction(ConfigPropertyLoader config) {
-        super(config);
-    }
+//    public JNDITransaction(ConfigPropertyLoader config) {
+//        super(config);
+//    }
     
     protected void before(TransactionQueryTest test) {
         if (this.props.getProperty(CONNECTION_STRATEGY_PROPS.JNDINAME_USERTXN) == null) {

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java	2009-11-16 20:57:50 UTC (rev 1555)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java	2009-11-16 20:58:17 UTC (rev 1556)
@@ -10,22 +10,22 @@
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.TransactionContainer;
 import org.teiid.test.framework.TransactionQueryTest;
+import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
+import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
 
-
-
 /** 
  * A transaction which is user controlled. 
  */
 public class LocalTransaction extends TransactionContainer {
 
-    public LocalTransaction(ConfigPropertyLoader config) {
-        super(config);
-        
+    public LocalTransaction() {
+	super();
     }
-    
     protected void before(TransactionQueryTest test) {
+	this.setEnvironmentProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP, TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_OFF);
+	
         try {
         	debug("Autocommit: " + this.connStrategy.getAutocommit());
             test.getConnection().setAutoCommit(this.connStrategy.getAutocommit());

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java	2009-11-16 20:57:50 UTC (rev 1555)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TransactionFactory.java	2009-11-16 20:58:17 UTC (rev 1556)
@@ -22,26 +22,26 @@
     public static TransactionContainer create(ConfigPropertyLoader config) throws QueryTestFailedException {
     	TransactionContainer transacton = null;
     	    	
-        String type = config.getProperty(ConfigPropertyNames.TRANSACTION_TYPE);
-        if (type == null) {
-        	type = ConfigPropertyNames.TRANSACTION_TYPES.LOCAL_TRANSACTION;
-        }
-        
-        System.out.println("Create TransactionContainer: " + type);
-        
-        if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.LOCAL_TRANSACTION)) {
-        	transacton = new LocalTransaction(config);
-        }
-        else if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.XATRANSACTION)) {
-        	transacton = new XATransaction(config);
-        }
-        else if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.JNDI_TRANSACTION)) {
-        	transacton = new JNDITransaction(config);
+//        String type = config.getProperty(ConfigPropertyNames.TRANSACTION_TYPE);
+//        if (type == null) {
+//        	type = ConfigPropertyNames.TRANSACTION_TYPES.LOCAL_TRANSACTION;
+//        }
+//        
+//        System.out.println("Create TransactionContainer: " + type);
+//        
+//        if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.LOCAL_TRANSACTION)) {
+//        	transacton = new LocalTransaction(config);
+//        }
+//        else if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.XATRANSACTION)) {
+//        	transacton = new XATransaction(config);
+//        }
+//        else if (type.equalsIgnoreCase(ConfigPropertyNames.TRANSACTION_TYPES.JNDI_TRANSACTION)) {
+//        	transacton = new JNDITransaction(config);
+//
+//        } else {
+//        	throw new TransactionRuntimeException("Invalid property value of " + type + " for " + ConfigPropertyNames.TRANSACTION_TYPE );
+//        }
 
-        } else {
-        	throw new TransactionRuntimeException("Invalid property value of " + type + " for " + ConfigPropertyNames.TRANSACTION_TYPE );
-        }
-
         return transacton;
     }
     

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java	2009-11-16 20:57:50 UTC (rev 1555)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/XATransaction.java	2009-11-16 20:58:17 UTC (rev 1556)
@@ -21,9 +21,9 @@
 	private static Random RANDOM = new Random();
 	private MMXid xid;
 	
-    public XATransaction(ConfigPropertyLoader config) {
-        super(config);
-    }
+	public XATransaction() {
+		super();
+	}
         
     protected void before(TransactionQueryTest test) {
         try {          



More information about the teiid-commits mailing list