Author: vhalbert(a)redhat.com
Date: 2009-09-22 18:01:35 -0400 (Tue, 22 Sep 2009)
New Revision: 1460
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/framework/AbstractQueryTransactionTest.java
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/DataSourceSetupFactory.java
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/SingleDataSourceSetup.java
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/TwoDataSourceSetup.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/BaseAbstractTransactionTestCase.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/SingleSourceTransactionScenarios.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/TwoSourceTransactionScenarios.java
Log:
Teiid 773 - reorganized how datasources are referenced at all stages of a test
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/framework/AbstractQueryTransactionTest.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/framework/AbstractQueryTransactionTest.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/framework/AbstractQueryTransactionTest.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -5,23 +5,26 @@
package org.teiid.test.framework;
import static org.junit.Assert.assertEquals;
-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.Statement;
+import java.util.Map;
import java.util.Properties;
import javax.sql.XAConnection;
import org.teiid.test.framework.connection.ConnectionStrategy;
import org.teiid.test.framework.connection.ConnectionStrategyFactory;
+import org.teiid.test.framework.connection.ConnectionUtil;
+import org.teiid.test.framework.datasource.DataSource;
import org.teiid.test.framework.datasource.DataSourceSetupFactory;
+import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
import com.metamatrix.jdbc.api.AbstractQueryTest;
-import com.metamatrix.jdbc.api.ExecutionProperties;
/**
@@ -33,10 +36,12 @@
*
*/
public abstract class AbstractQueryTransactionTest extends AbstractQueryTest implements
TransactionQueryTest{
- Properties executionProperties = null;
- String testname = "NA";
+ protected Properties executionProperties = null;
+ protected String testname = "NA";
+ protected Map<String, DataSource> datasources = null;
+
public AbstractQueryTransactionTest() {
super();
}
@@ -50,7 +55,16 @@
return this.testname;
}
+ /**
+ * Called to set the datasources used during this test
+ *
+ * @since
+ */
+ public void setDataSources(Map<String, DataSource> datasources) {
+ this.datasources = datasources;
+ }
+
public void setExecutionProperties(Properties props) {
assertNotNull(props);
this.executionProperties = props;
@@ -85,20 +99,35 @@
return true;
}
- @Override
- public void setupDataSource() {
+
+ /**
+ * Override <code>setupDataSource</code> if there is different mechinism
for
+ * setting up the datasources for the testcase
+ *
+ * @since
+ */
+ @Override
+ public void setupDataSources() {
DataSourceSetup dss = null;
try {
- dss =
DataSourceSetupFactory.createDataSourceSetup(getNumberRequiredDataSources());
+ dss = DataSourceSetupFactory.createDataSourceSetup(this.datasources);
dss.setup();
} catch(Exception e) {
throw new TransactionRuntimeException(e.getMessage());
}
- }
+ }
+
+
+ public Connection getSource(String identifier) throws QueryTestFailedException {
+ return ConnectionUtil.getConnection(identifier, this.datasources);
+ }
+
+ public XAConnection getXASource(String identifier) throws QueryTestFailedException {
+ return ConnectionUtil.getXAConnection(identifier, this.datasources);
+ }
-
/**
* Implement testCase(), it is the entry point to the execution of the test.
* @throws Exception
@@ -137,7 +166,13 @@
public void after() {
}
+
+ @Override
+ public void validateTestCase() throws Exception {
+
+ }
+
/**
* At end of each test, clean up the connection factory so that it can be
* established at the start of the next test.
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/DataSourceSetupFactory.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/DataSourceSetupFactory.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/DataSourceSetupFactory.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -1,24 +1,26 @@
package org.teiid.test.framework.datasource;
+import java.util.Map;
+
import org.teiid.test.framework.DataSourceSetup;
import org.teiid.test.framework.exception.QueryTestFailedException;
public class DataSourceSetupFactory {
- public static DataSourceSetup createDataSourceSetup(int numOfDataSources) throws
QueryTestFailedException {
+ public static DataSourceSetup createDataSourceSetup(Map<String, DataSource>
datasources) throws QueryTestFailedException {
DataSourceSetup dss = null;
- switch (numOfDataSources) {
+ switch (datasources.size()) {
case 1:
- dss = new SingleDataSourceSetup();
+ dss = new SingleDataSourceSetup(datasources);
break;
case 2:
- dss = new TwoDataSourceSetup();
+ dss = new TwoDataSourceSetup(datasources);
break;
default:
- throw new QueryTestFailedException("Number of datasources " +
numOfDataSources + " is not supported");
+ throw new QueryTestFailedException("Number of datasources " +
datasources.size() + " is not supported");
}
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/SingleDataSourceSetup.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/SingleDataSourceSetup.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/SingleDataSourceSetup.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -4,6 +4,8 @@
*/
package org.teiid.test.framework.datasource;
+import java.util.Map;
+
import org.teiid.test.framework.DataSourceSetup;
import org.teiid.test.framework.QueryExecution;
import org.teiid.test.framework.connection.ConnectionUtil;
@@ -16,7 +18,13 @@
* This performs the data setup for SingleSource test cases
*/
public class SingleDataSourceSetup implements DataSourceSetup {
+
+ private Map ds=null;
+ public SingleDataSourceSetup(Map datasources) {
+ this.ds = datasources;
+ }
+
@Override
public void setup() throws Exception {
@@ -28,7 +36,7 @@
// Only one of the models are needed because pm1 and pm2 point to the same
datasource
- AbstractQueryTest test1 = new
QueryExecution(ConnectionUtil.getSource("pm1")); //$NON-NLS-1$
+ AbstractQueryTest test1 = new
QueryExecution(ConnectionUtil.getConnection("pm1", ds) ); //$NON-NLS-1$
test1.execute("delete from g2"); //$NON-NLS-1$
test1.execute("delete from g1"); //$NON-NLS-1$
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/TwoDataSourceSetup.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/TwoDataSourceSetup.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/framework/datasource/TwoDataSourceSetup.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -4,6 +4,8 @@
*/
package org.teiid.test.framework.datasource;
+import java.util.Map;
+
import org.teiid.test.framework.DataSourceSetup;
import org.teiid.test.framework.QueryExecution;
import org.teiid.test.framework.connection.ConnectionUtil;
@@ -16,7 +18,12 @@
* This performs the data setup for SingleSource test cases
*/
public class TwoDataSourceSetup implements DataSourceSetup {
+ private Map ds=null;
+ public TwoDataSourceSetup(Map datasources) {
+ this.ds = datasources;
+ }
+
@Override
public void setup() throws Exception {
@@ -27,7 +34,8 @@
System.out.println("Run TwoSource Setup...");
- AbstractQueryTest test1 = new
QueryExecution(ConnectionUtil.getSource("pm1")); //$NON-NLS-1$
+ AbstractQueryTest test1 = new
QueryExecution(ConnectionUtil.getConnection("pm1", ds));//$NON-NLS-1$
+
test1.execute("delete from g2"); //$NON-NLS-1$
test1.execute("delete from g1"); //$NON-NLS-1$
@@ -55,7 +63,7 @@
test1.execute("select * from g2 ");
test1.assertRowCount(100);
- AbstractQueryTest test2 = new
QueryExecution(ConnectionUtil.getSource("pm2")); //$NON-NLS-1$
+ AbstractQueryTest test2 = new
QueryExecution(ConnectionUtil.getConnection("pm2", ds));//$NON-NLS-1$
test2.execute("delete from g2"); //$NON-NLS-1$
test2.execute("delete from g1"); //$NON-NLS-1$
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/BaseAbstractTransactionTestCase.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/BaseAbstractTransactionTestCase.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/BaseAbstractTransactionTestCase.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -35,12 +35,12 @@
}
- public Connection getSource(String identifier) throws QueryTestFailedException {
- return ConnectionUtil.getSource(identifier);
- }
-
- public XAConnection getXASource(String identifier) throws QueryTestFailedException {
- return ConnectionUtil.getXASource(identifier);
- }
+// public Connection getSource(String identifier) throws QueryTestFailedException {
+// return ConnectionUtil.getSource(identifier);
+// }
+//
+// public XAConnection getXASource(String identifier) throws QueryTestFailedException
{
+// return ConnectionUtil.getXASource(identifier);
+// }
}
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/SingleSourceTransactionScenarios.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/SingleSourceTransactionScenarios.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/SingleSourceTransactionScenarios.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -4,8 +4,11 @@
*/
package org.teiid.test.testcases;
+import java.util.Map;
+
import org.teiid.test.framework.AbstractQueryTransactionTest;
import org.teiid.test.framework.QueryExecution;
+import org.teiid.test.framework.datasource.DataSource;
import com.metamatrix.jdbc.api.AbstractQueryTest;
@@ -37,10 +40,8 @@
execute("select * from pm1.g1 where pm1.g1.e1 < 100");
assertRowCount(100);
}
-
- public void validateTestCase() throws Exception {
-
- }
+
+
};
// run test
@@ -68,6 +69,7 @@
test.closeConnection();
}
+
};
// run test
@@ -151,9 +153,7 @@
execute("select * from pm1.g1 where pm1.g1.e1 < 100 limit
10");
assertRowCount(10);
}
-
- public void validateTestCase() throws Exception {
- }
+
};
// run test
@@ -168,15 +168,7 @@
* result = rollback
*/
- public void testSingleSourceMultipleCommandsExplicitRollback() throws Exception {
- // now it's empty
- AbstractQueryTest test = new QueryExecution(getSource("pm1"));
- //getSource("pm1"));
- test.execute("select * from g1 where e1 >= 200 and e1 < 220");
- test.assertRowCount(0);
- test.execute("select * from g2 where e1 >= 200 and e1 < 220");
- test.assertRowCount(0);
- test.closeConnection();
+ public void testSingleSourceMultipleCommandsExplicitRollback() throws Exception {
AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceMultipleCommandsExplicitRollback")
{
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/TwoSourceTransactionScenarios.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/TwoSourceTransactionScenarios.java 2009-09-22
22:00:58 UTC (rev 1459)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/TwoSourceTransactionScenarios.java 2009-09-22
22:01:35 UTC (rev 1460)
@@ -45,9 +45,7 @@
public int getNumberRequiredDataSources(){
return 2;
}
-
- public void validateTestCase() throws Exception {
- }
+
};
// run test
@@ -70,8 +68,7 @@
public int getNumberRequiredDataSources(){
return 2;
}
- public void validateTestCase() throws Exception {
- }
+
};