Author: vhalbert(a)redhat.com
Date: 2010-01-19 15:26:55 -0500 (Tue, 19 Jan 2010)
New Revision: 1753
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/client/QuerySQL.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryTest.java
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ExpectedResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryReader.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ResultsGenerator.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/TagNames.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java
Log:
Teiid-773 - add the following features to client testing:
a. generating results will no longer be in xml format by default
b. added support for muliple sql executions in a single testcase
c. added client tests queries/expected results for simple examples for transaction
testing
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Properties;
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.exception.TransactionRuntimeException;
@@ -46,8 +45,7 @@
* The default scenario class to use when {@link #QUERY_SCENARIO_CLASSNAME} is not
defined.
*/
- // public static final String QUERY_SCENARIO_DEFAULT_CLASSNAME =
"org.teiid.test.client.impl.QueryScenarioImpl"; //$NON-NLS-1$
- public static final String QUERY_SCENARIO_DEFAULT_CLASSNAME =
"org.teiid.test.client.ctc.CTCQueryScenario"; //$NON-NLS-1$
+ public static final String QUERY_SCENARIO_DEFAULT_CLASSNAME =
"org.teiid.test.client.impl.QueryScenarioImpl"; //$NON-NLS-1$
/**
@@ -97,7 +95,7 @@
public static QueryScenario createQueryScenario(String scenarioName) {
String clzzname =
ConfigPropertyLoader.getInstance().getProperty(QUERY_SCENARIO_CLASSNAME);
- if (clzzname == null) {
+ if (clzzname == null || clzzname.startsWith("${")) {
clzzname = QUERY_SCENARIO_DEFAULT_CLASSNAME;
}
@@ -105,12 +103,12 @@
args.add(scenarioName);
args.add(ConfigPropertyLoader.getInstance().getProperties());
-
QueryScenario scenario;
try {
scenario = (QueryScenario) ReflectionHelper.create(clzzname, args, null);
} catch (Exception e) {
- throw new TransactionRuntimeException(e.getMessage());
+ e.printStackTrace();
+ throw new TransactionRuntimeException(e);
}
return scenario;
}
@@ -125,7 +123,8 @@
try {
reader = (QueryReader) ReflectionHelper.create(clzzname, args, null);
} catch (Exception e) {
- throw new TransactionRuntimeException(e.getMessage());
+ e.printStackTrace();
+ throw new TransactionRuntimeException(e);
}
return reader;
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ExpectedResults.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ExpectedResults.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ExpectedResults.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -88,22 +88,25 @@
/**
- * Called to compare the <code>ResultSet</code> from the executed query to
the expected results.
+ * Called to compare the <code>ResultSet</code> from the executed query to
the expected results
+ * and return the errors.
* @param queryIdentifier
* @param sql
* @param resultSet
* @param actualException
* @param testStatus
* @param isOrdered
- * @param batchSize
+ * @param updateCnt
+ * @return Object identifying the errors in the comparison
* @throws QueryTestFailedException
*/
- void compareResults(final String queryIdentifier,
+ Object compareResults(final String queryIdentifier,
final String sql,
final ResultSet resultSet,
final Throwable actualException,
final int testStatus,
final boolean isOrdered,
- final int batchSize) throws QueryTestFailedException;
+ final int updateCnt,
+ final boolean resultFromQuery) throws QueryTestFailedException;
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryReader.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryReader.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryReader.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -23,7 +23,7 @@
package org.teiid.test.client;
import java.util.Collection;
-import java.util.Map;
+import java.util.List;
import org.teiid.test.framework.exception.QueryTestFailedException;
@@ -70,18 +70,15 @@
Collection<String> getQuerySetIDs();
/**
- * Return a <code>Map</code> containing the query identifier as the key,
and
- * the value is the query. In most simple cases, the query will be a
<code>String</code>
- * However, complex types (i.e., to execute prepared statements or other arguments),
it maybe
- * some other type.
+ * Return a <code>List</code> containing {@link QueryTest}
*
- * @return Map
+ * @return List
* @throws QueryTestFailedException
*
* @since
*/
- Map<String, Object> getQueries(String querySetID)
- throws QueryTestFailedException; // key=queryIdentifier
+ List<QueryTest> getQueries(String querySetID)
+ throws QueryTestFailedException;
// Map<String, String> - key = queryIdentifier
}
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/QuerySQL.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/QuerySQL.java
(rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/QuerySQL.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.test.client;
+
+/**
+ * The QuerySQL represents a single sql statement to be executed for a given {@link
QueryTest Test}.
+ * The {@link #rowCnt} and {@link #updateCnt}, when set, provide validation checks after
the
+ * execution of the query.
+ * @author vanhalbert
+ *
+ */
+public class QuerySQL {
+
+ private String sql = null;
+ private Object[] parms;
+ private int updateCnt=-1;
+ private int rowCnt=-1;
+
+ public int getRowCnt() {
+ return rowCnt;
+ }
+
+ public void setRowCnt(int rowCnt) {
+ this.rowCnt = rowCnt;
+ }
+
+ public int getUpdateCnt() {
+ return updateCnt;
+ }
+
+ public void setUpdateCnt(int updateCnt) {
+ this.updateCnt = updateCnt;
+ }
+
+ public QuerySQL(String sql, Object[] parms) {
+ this.sql = sql;
+ this.parms = parms;
+ }
+
+ public String getSql() {
+ return sql;
+ }
+
+ public Object[] getParms() {
+ return parms;
+ }
+
+
+}
Property changes on:
trunk/test-integration/db/src/main/java/org/teiid/test/client/QuerySQL.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -26,7 +26,7 @@
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
+import java.util.List;
import java.util.Properties;
import org.teiid.test.client.TestProperties.RESULT_MODES;
@@ -120,7 +120,8 @@
for (int i = 0; i < vdbfiles.length; i++) {
vdbdef.append(vdbfiles[i].getAbsolutePath() + ";");
}
-
+ TestLogger.log("===== Connect to VDBs: " + vdbdef.toString());
+
deployProperties.setProperty("vdb.definition", vdbdef.toString());
PropertiesUtils.print(deployPropLoc, deployProperties,"Updated for
vdb.definition");
@@ -186,7 +187,7 @@
* @return Map<String, Object>
*/
- public Map<String, Object> getQueries(String querySetID) {
+ public List<QueryTest> getQueries(String querySetID) {
try {
return reader.getQueries(querySetID);
} catch (QueryTestFailedException e) {
@@ -254,7 +255,7 @@
}
- public abstract void handleTestResult(TestResult tr, ResultSet resultSet, String
sql);
+ public abstract void handleTestResult(TestResult tr, ResultSet resultSet, int
updateCnt, boolean resultFromQuery, String sql);
}
Added: trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryTest.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryTest.java
(rev 0)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryTest.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.test.client;
+
+/**
+ * The QueryTest represents a test to be executed. This test can consist of
+ * one or more {@link QuerySQL SQL} queries required to perform the test.
+ *
+ * @author vanhalbert
+ *
+ */
+public class QueryTest {
+
+ private QuerySQL[] queries;
+ private String querySetID;
+ private String queryID;
+ private boolean isException=false;
+
+ public QueryTest(String queryID, String querySetID, QuerySQL[] queries, boolean
isException) {
+ this.queryID = queryID;
+ this.queries = queries;
+ this.isException = isException;
+ this.querySetID = querySetID;
+ }
+
+ public QuerySQL[] getQueries() {
+ return queries;
+ }
+
+ public String getQueryID() {
+ return queryID;
+ }
+
+ public boolean isException() {
+ return this.isException;
+ }
+
+ public String geQuerySetID() {
+ return this.querySetID;
+ }
+
+}
Property changes on:
trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ResultsGenerator.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ResultsGenerator.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ResultsGenerator.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -22,7 +22,6 @@
package org.teiid.test.client;
-import java.io.File;
import java.sql.ResultSet;
import org.teiid.test.framework.exception.QueryTestFailedException;
@@ -63,13 +62,39 @@
*/
String getGenerateDir();
+ /**
+ * Call to generate the results file from an executed query.
+ * If an exception occurred, it is considered the result from
+ * the query. The file created based on the result should
+ * be able to be used as the expected result when query
+ * tests are run with in the resultmode of "compare".
+ * @param querySetID
+ * @param queryIdentfier
+ * @param query
+ * @param result
+ * @param queryError
+ * @param testStatus
+ * @throws QueryTestFailedException
+ */
void generateQueryResultFile(String querySetID, String queryIdentfier,
String query, ResultSet result, Throwable queryError, int testStatus)
throws QueryTestFailedException;
+ /**
+ * Call to generate an error file as the result of incompatibilities in the
+ * comparison of the expected results to the actual results.
+ * @param querySetID
+ * @param queryIdentifier
+ * @param sql
+ * @param resultSet
+ * @param queryError
+ * @param results
+ * @return
+ * @throws QueryTestFailedException
+ */
String generateErrorFile(final String querySetID,
final String queryIdentifier, final String sql,
final ResultSet resultSet, final Throwable queryError,
- final File expectedResultsFile) throws QueryTestFailedException;
+ final Object results) throws QueryTestFailedException;
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -24,7 +24,7 @@
import java.text.SimpleDateFormat;
import java.util.Iterator;
-import java.util.Map;
+import java.util.List;
import java.util.Properties;
import org.junit.Assert;
@@ -67,9 +67,12 @@
static {
if (System.getProperty(ConfigPropertyNames.CONFIG_FILE ) == null) {
- System.setProperty(ConfigPropertyNames.CONFIG_FILE,"qe-test.properties");
+ System.setProperty(ConfigPropertyNames.CONFIG_FILE,"./ctc_tests/ctc-test.properties");
+ } else {
+ System.out.println("Config File Set: " +
System.getProperty(ConfigPropertyNames.CONFIG_FILE ));
}
+ // the project.loc is used
if (System.getProperty("project.loc" ) == null) {
System.setProperty("project.loc",".");
}
@@ -156,7 +159,7 @@
private void runTestCase(QueryScenario queryset, TransactionContainer tc) throws
Exception {
String querySetID = null;
- Map<String, Object> queryTests = null;
+ List<QueryTest> queryTests = null;
TestClientTransaction userTxn = new TestClientTransaction(queryset);
@@ -174,8 +177,8 @@
queryTests = queryset.getQueries(querySetID);
// the iterator to process the query tests
- Iterator<String> queryTestIt = null;
- queryTestIt = queryTests.keySet().iterator();
+ Iterator<QueryTest> queryTestIt = null;
+ queryTestIt = queryTests.iterator();
ExpectedResults expectedResults = queryset.getExpectedResults(querySetID);
@@ -186,13 +189,10 @@
long endTS = 0;
while (queryTestIt.hasNext()) {
-
- String queryidentifier = queryTestIt.next();
-
- Object sqlObject = queryTests.get(queryidentifier);
-
- userTxn.init(summary, expectedResults, querySetID, queryidentifier,
sqlObject);
-
+ QueryTest q = queryTestIt.next();
+
+ userTxn.init(summary, expectedResults, q);
+
// run test
tc.runTransaction(userTxn);
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClientTransaction.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -42,12 +42,8 @@
private QueryScenario querySet = null;
private ExpectedResults expectedResults = null;
+ private QueryTest query = null;
- // the current querySet info
- private String querySetID = null;
- private String queryIdentifier = null;
- private Object queryObject = null;
-
private long endTS = 0;
private long beginTS = 0;
@@ -56,6 +52,7 @@
private boolean errorExpected = false;
private String sql = null;
+ private boolean resultFromQuery = false;
private TestResultsSummary testResultsSummary;
@@ -64,11 +61,12 @@
this.querySet = querySet;
}
+
+
+
- public void init(TestResultsSummary testResultsSummary, ExpectedResults
expectedResults, String querySetID, String queryIdentifier, Object query) {
- this.querySetID = querySetID;
- this.queryIdentifier = queryIdentifier;
- this.queryObject = query;
+ public void init(TestResultsSummary testResultsSummary, ExpectedResults
expectedResults, QueryTest query) {
+ this.query = query;
this.testResultsSummary = testResultsSummary;
this.expectedResults = expectedResults;
@@ -77,13 +75,13 @@
testStatus = TestResult.RESULT_STATE.TEST_SUCCESS;
-
errorExpected = false;
+ resultFromQuery = false;
}
public String getTestName() {
- return querySetID + ":" +
(this.queryIdentifier!=null?this.queryIdentifier:"NA");
+ return query.geQuerySetID() + ":" +
(query.getQueryID()!=null?query.getQueryID():"NA");
}
@@ -95,7 +93,7 @@
try {
this.errorExpected = expectedResults
- .isExceptionExpected(this.queryIdentifier);
+ .isExceptionExpected(query.getQueryID());
} catch (QueryTestFailedException e) {
// TODO Auto-generated catch block
throw new TransactionRuntimeException("ProgramError: "
@@ -104,32 +102,35 @@
}
+
@Override
public void testCase() throws Exception {
- if (this.queryObject instanceof String) {
- this.sql = (String) this.queryObject;
- executeTest(this.querySetID, this.queryIdentifier, sql);
- }
-
- // TODO: support object types for queries (i.e., arguments for prepared statements,
etc)
-
- }
-
- protected void executeTest(String querySetID, String queryidentifier,
- String sql) throws Exception {
-
+ TestLogger.logDebug("expected error: " + this.errorExpected);
+ TestLogger.logDebug("ID: " + query.geQuerySetID() + "-" +
query.getQueryID());
- TestLogger.logDebug("ID: " + querySetID + "-" + queryidentifier +
" execute: " + sql);
+ QuerySQL[] queries = query.getQueries();
+ int l = queries.length;
- TestLogger.logDebug("expected error: " + this.errorExpected);
-
try {
// need to set this so the underlying query execution handles an
// error properly.
beginTS = System.currentTimeMillis();
- execute(sql);
+
+ for (int i= 0; i < l; i++) {
+ QuerySQL qsql = queries[i];
+ this.sql = qsql.getSql();
+ resultFromQuery = execute(sql, qsql.getParms());
+ if (!resultFromQuery) {
+ this.assertUpdateCount(qsql.getUpdateCnt());
+ } else if (qsql.getRowCnt() >= 0) {
+ this.assertRowCount(qsql.getRowCnt());
+
+ }
+
+ }
+
} catch (Throwable t) {
this.setApplicationException(t);
@@ -159,15 +160,16 @@
testStatus = TestResult.RESULT_STATE.TEST_EXCEPTION;
}
-}
+ }
- rs = new TestResultStat(querySetID, this.queryIdentifier, sql,
+ rs = new TestResultStat(query.geQuerySetID(), query.getQueryID(), sql,
testStatus, beginTS, endTS, resultException, null);
- this.querySet.handleTestResult(rs, this.internalResultSet, sql);
+
+ this.querySet.handleTestResult(rs, this.internalResultSet, this.updateCount,
resultFromQuery, sql);
- this.testResultsSummary.addTestResult(this.querySetID, rs);
+ this.testResultsSummary.addTestResult(query.geQuerySetID(), rs);
}
@@ -182,7 +184,6 @@
// exceptions depends on this
@Override
public boolean exceptionExpected() {
- // TODO Auto-generated method stub
return this.errorExpected;
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -98,7 +98,7 @@
throw new TransactionRuntimeException("Invalid property value of " +
type + " for " + TRANSACTION_TYPE );
}
- TestLogger.log("==== TransactionContainer: " +
transacton.getClass().getName());
+ TestLogger.log("==== TransactionContainer: " +
transacton.getClass().getName() + " option:" + type);
return transacton;
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/CTCQueryScenario.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -20,27 +20,17 @@
*/
package org.teiid.test.client.ctc;
-import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Properties;
-import org.teiid.test.client.ClassFactory;
import org.teiid.test.client.ExpectedResults;
-import org.teiid.test.client.QueryReader;
import org.teiid.test.client.QueryScenario;
-import org.teiid.test.client.ResultsGenerator;
import org.teiid.test.client.TestProperties;
import org.teiid.test.client.TestResult;
-import org.teiid.test.client.TestProperties.RESULT_MODES;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.util.FileUtils;
-
/**
* The CTCQueryScenario represents the tests that were created using the old xml file
formats.
*
@@ -81,7 +71,7 @@
}
-
+ @Override
public ExpectedResults getExpectedResults(String querySetID) {
return new XMLExpectedResults( querySetID, this.getProperties());
}
@@ -92,7 +82,7 @@
* @see
org.teiid.test.client.QueryScenario#handleTestResult(org.teiid.test.client.TestResult,
java.lang.String)
*/
@Override
- public void handleTestResult(TestResult tr, ResultSet resultSet, String sql) {
+ public void handleTestResult(TestResult tr, ResultSet resultSet, int updatecnt,
boolean resultFromQuery, String sql) {
Throwable resultException = tr.getException();
if (getResultsMode().equalsIgnoreCase(
@@ -103,7 +93,7 @@
sql,
resultSet,
resultException,
- tr.getStatus(), isOrdered(sql), -1);
+ tr.getStatus(), isOrdered(sql), -1, resultFromQuery);
} catch (QueryTestFailedException qtf) {
resultException = (resultException != null ? resultException
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -39,6 +39,7 @@
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+
/**
* This class encapsulates results associated with a query.
* <p>
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/TagNames.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/TagNames.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/TagNames.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -109,6 +109,8 @@
public static final String QUERY = "query"; //$NON-NLS-1$
public static final String SELECT = "select"; //$NON-NLS-1$
public static final String ROOT_ELEMENT = "root"; //$NON-NLS-1$
+ public static final String SQL = "sql"; //$NON-NLS-1$
+ public static final String PARM = "parm"; //$NON-NLS-1$
}
/**
@@ -123,6 +125,7 @@
public static final String VALUE = "value"; //$NON-NLS-1$
public static final String DISTINCT = "distinct"; //$NON-NLS-1$
public static final String STAR = "star"; //$NON-NLS-1$
+ public static final String UPDATE_CNT = "updatecnt"; //$NON-NLS-1$
}
/**
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -42,6 +42,7 @@
import org.jdom.JDOMException;
import org.teiid.test.client.ClassFactory;
import org.teiid.test.client.ExpectedResults;
+import org.teiid.test.client.QueryTest;
import org.teiid.test.client.QueryScenario;
import org.teiid.test.client.ResultsGenerator;
import org.teiid.test.client.TestResult;
@@ -137,13 +138,14 @@
* @throws QueryTestFailedException
* If comparison fails.
*/
- public void compareResults( final String queryIdentifier,
+ public Object compareResults( final String queryIdentifier,
final String sql,
final ResultSet resultSet,
final Throwable actualException,
final int testStatus,
final boolean isOrdered,
- final int batchSize) throws
QueryTestFailedException {
+ final int batchSize,
+ final boolean resultFromQuery) throws
QueryTestFailedException {
final String eMsg = "CompareResults Error: "; //$NON-NLS-1$
@@ -201,6 +203,8 @@
break;
}
+
+ return null;
}
@@ -713,7 +717,7 @@
while (it.hasNext()) {
String querySetID = it.next();
- Map queries = set.getQueries(querySetID);
+ List<QueryTest> queries = set.getQueries(querySetID);
if (queries.size() == 0l) {
System.out.println("Failed, didn't load any queries " );
}
@@ -725,16 +729,17 @@
ResultsGenerator gr = set.getResultsGenerator();
//new XMLGenerateResults(_instance.getProperties(), "testname",
set.getOutputDirectory());
- Iterator qIt = queries.keySet().iterator();
+ Iterator<QueryTest> qIt = queries.iterator();
while(qIt.hasNext()) {
- String qId = (String) qIt.next();
- String sql = (String) queries.get(qId);
+ QueryTest q = qIt.next();
+ // String qId = (String) qIt.next();
+ // String sql = (String) queries.get(qId);
// System.out.println("SetID #: " + cnt + " Qid: " + qId +
" sql: " + sql);
- File resultsFile = er.getResultsFile(qId);
+ File resultsFile = er.getResultsFile(q.getQueryID());
if (resultsFile == null) {
- System.out.println("Failed to get results file for queryID " + qId);
+ System.out.println("Failed to get results file for queryID " +
q.getQueryID());
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -196,7 +196,7 @@
public String generateErrorFile(final String querySetID,
final String queryID, final String sql, final ResultSet resultSet,
- final Throwable queryError, final File expectedResultsFile)
+ final Throwable queryError, final Object expectedResultsFile)
throws QueryTestFailedException {
String errorFileName = null;
@@ -212,7 +212,7 @@
resultSet.beforeFirst();
}
generateErrorResults(querySetID, queryID, sql, errorFile,
- resultSet, expectedResultsFile, queryError);
+ resultSet, (File) expectedResultsFile, queryError);
} catch (Throwable e) {
throw new QueryTestFailedException(e.getMessage());
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Properties;
+import org.teiid.test.client.QueryTest;
import org.teiid.test.client.QueryReader;
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.ConfigPropertyNames;
@@ -55,7 +56,7 @@
}
@Override
- public Map<String, Object> getQueries(String querySetID)
+ public List<QueryTest> getQueries(String querySetID)
throws QueryTestFailedException {
String queryFile = querySetIDToFileMap.get(querySetID);
@@ -110,10 +111,11 @@
}
- private Map<String, Object> loadQueries(String querySetID, String
queryFileName)
+ private List <QueryTest> loadQueries(String querySetID, String queryFileName)
throws IOException {
- Map<String, Object> queries = new HashMap<String, Object>();
+ List<QueryTest> queries = null;
+// Map<String, Object> queries = new HashMap<String, Object>();
File queryFile = new File(queryFileName);
if (!queryFile.exists() || !queryFile.canRead()) {
String msg = "Query file doesn't exist or cannot be read: " +
queryFileName + ", ignoring and continuing";
@@ -125,23 +127,23 @@
XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();
try {
- Map queryMap = jstrat.parseXMLQueryFile(queryFile);
- Iterator iter = queryMap.keySet().iterator();
- while (iter.hasNext()) {
- String queryID = (String) iter.next();
- String query = (String) queryMap.get(queryID);
+ return jstrat.parseXMLQueryFile(queryFile, querySetID);
+// Iterator iter = queryMap.keySet().iterator();
+// while (iter.hasNext()) {
+// String queryID = (String) iter.next();
+// String query = (String) queryMap.get(queryID);
+//
+// String uniqueID = querySetID + "_" + queryID;
+// queries.put(uniqueID, query);
+// }
- String uniqueID = querySetID + "_" + queryID;
- queries.put(uniqueID, query);
- }
-
} catch (Exception e) {
String msg = "Error reading query file: " + queryFileName + ", " +
e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
TestLogger.log(msg);
throw new IOException(msg); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- return queries;
+// return queries;
}
private static String getQuerySetName(String queryFileName) {
@@ -174,7 +176,7 @@
while (it.hasNext()) {
String querySetID = it.next();
- Map queries = reader.getQueries(querySetID);
+ List<QueryTest> queries = reader.getQueries(querySetID);
if (queries.size() == 0l) {
System.out.println("Failed, didn't load any queries ");
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -33,17 +33,20 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
+import org.teiid.test.client.QuerySQL;
+import org.teiid.test.client.QueryTest;
import org.teiid.test.client.ctc.QueryResults.ColumnInfo;
+import org.teiid.test.framework.TestLogger;
+import org.teiid.test.framework.exception.TransactionRuntimeException;
import org.teiid.test.util.StringUtil;
import com.metamatrix.common.types.DataTypeManager;
@@ -51,6 +54,7 @@
import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.symbol.ElementSymbol;
+
/**
* <P> This program helps in parsing XML Query and Results files into
* map objects containing individual queries/ResultSets</P>
@@ -76,12 +80,13 @@
* queryNames/IDs as Keys.
* <br>
* @param queryFile the XML file object that is to be parsed
- * @return the Map containig query strings.
+ * @return the List containing quers.
* @exception JDOMException if there is an error consuming the message.
*/
- public Map parseXMLQueryFile(File queryFile) throws IOException, JDOMException {
+ public List parseXMLQueryFile(File queryFile, String querySetID) throws IOException,
JDOMException {
- HashMap queryMap = new HashMap();
+ List<QueryTest> queries = new LinkedList();
+// HashMap queryMap = new HashMap();
SAXBuilder builder = SAXBuilderHelper.createSAXBuilder(false);
Document queryDocument = builder.build(queryFile);
List queryElements =
queryDocument.getRootElement().getChildren(TagNames.Elements.QUERY);
@@ -90,17 +95,140 @@
Element queryElement = (Element) iter.next();
String queryName = queryElement.getAttributeValue(TagNames.Attributes.NAME);
if ( queryElement.getChild(TagNames.Elements.EXCEPTION) == null ) {
- String query = queryElement.getTextTrim();
- queryMap.put(queryName, query);
+ String uniqueID = querySetID + "_" + queryName;
+
+ List<Element> parmChildren = queryElement.getChildren(TagNames.Elements.SQL);
+
+ if (parmChildren == null || parmChildren.isEmpty()) {
+ TestLogger.logDebug("======= Single QueryTest ");
+ QuerySQL sql = createQuerySQL(queryElement);
+
+ QueryTest q = new QueryTest(uniqueID, querySetID, new QuerySQL[] {sql},
false);
+ queries.add(q);
+ } else {
+ TestLogger.logDebug("======= QueryTest has multiple sql
statements");
+ QuerySQL[] querysql = new QuerySQL[parmChildren.size()];
+ int c = 0;
+
+ final Iterator<Element> sqliter = parmChildren.iterator();
+ while ( sqliter.hasNext() ) {
+ final Element sqlElement = (Element) sqliter.next();
+ QuerySQL sql = createQuerySQL(sqlElement);
+ querysql[c] = sql;
+ c++;
+ }
+ QueryTest q = new QueryTest(uniqueID, querySetID, querysql, false);
+ queries.add(q);
+
+
+
+ }
+ // queryMap.put(queryName, query);
} else {
Element exceptionElement =
queryElement.getChild(TagNames.Elements.EXCEPTION);
String exceptionType =
exceptionElement.getChild(TagNames.Elements.CLASS).getTextTrim();
- queryMap.put(queryName, exceptionType);
+
+ String uniqueID = querySetID + "_" + queryName;
+ QuerySQL sql = new QuerySQL(exceptionType, null);
+
+ QueryTest q = new QueryTest(uniqueID, querySetID, new QuerySQL[] {sql},
true);
+ queries.add(q);
+
+
+ // queryMap.put(queryName, exceptionType);
}
}
- return queryMap;
+ return queries;
}
+
+ private QuerySQL createQuerySQL(Element queryElement) {
+ String query = queryElement.getTextTrim();
+
+ Object[] parms = getParms(queryElement);
+
+ QuerySQL sql = new QuerySQL(query, parms);
+
+ String updateCnt = queryElement.getAttributeValue(TagNames.Attributes.UPDATE_CNT);
+ if (updateCnt != null && updateCnt.trim().length() > 0) {
+ int cnt = Integer.parseInt(updateCnt);
+ sql.setUpdateCnt(cnt);
+ }
+
+ String rowCnt =
queryElement.getAttributeValue(TagNames.Attributes.TABLE_ROW_COUNT);
+ if (rowCnt != null && rowCnt.trim().length() > 0) {
+ int cnt = Integer.parseInt(rowCnt);
+ sql.setRowCnt(cnt);
+ }
+
+ return sql;
+ }
+
+ private Object[] getParms(Element parent) {
+ List<Element> parmChildren = parent.getChildren(TagNames.Elements.PARM);
+ if (parmChildren == null) {
+ return null;
+ }
+
+ Object[] parms = new Object[parmChildren.size()];
+ int i = 0;
+ final Iterator<Element> iter = parmChildren.iterator();
+ while ( iter.hasNext() ) {
+ final Element parmElement = (Element) iter.next();
+ try {
+ Object parm = createParmType(parmElement);
+ parms[i] = parm;
+ i++;
+ } catch (JDOMException e) {
+ throw new TransactionRuntimeException(e);
+ }
+ }
+
+
+
+ return parms;
+ }
+
+ private Object createParmType(Element cellElement) throws JDOMException {
+ Object cellObject = null;
+
+ final String typeName = cellElement.getAttributeValue(TagNames.Attributes.TYPE);
+
+ if ( typeName.equalsIgnoreCase(TagNames.Elements.BOOLEAN) ) {
+ cellObject = consumeMsg((Boolean) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.STRING) ) {
+ cellObject = consumeMsg((String) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.CHAR) ) {
+ cellObject = consumeMsg((Character) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.BYTE) ) {
+ cellObject = consumeMsg((Byte) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.DOUBLE) ) {
+ cellObject = consumeMsg((Double) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.DATE) ) {
+ cellObject = consumeMsg((java.sql.Date) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.TIME) ) {
+ cellObject = consumeMsg((Time) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.TIMESTAMP) ) {
+ cellObject = consumeMsg((Timestamp) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.FLOAT) ) {
+ cellObject = consumeMsg((Float) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.BIGDECIMAL) ) {
+ cellObject = consumeMsg((BigDecimal) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.BIGINTEGER) ) {
+ cellObject = consumeMsg((BigInteger) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.INTEGER) ) {
+ cellObject = consumeMsg((Integer) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.LONG) ) {
+ cellObject = consumeMsg((Long) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.SHORT) ) {
+ cellObject = consumeMsg((Short) cellObject, cellElement);
+ } else if ( typeName.equalsIgnoreCase(TagNames.Elements.OBJECT) ) {
+ cellObject = consumeMsg((String) cellObject, cellElement);
+ }
+
+ return cellObject;
+ }
+
/**
* Consume an XML results File and produce a Map containing query results
* as List objects, with resultNames/IDs as Keys.
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -35,29 +35,28 @@
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
+import com.metamatrix.common.util.SqlUtil;
import com.metamatrix.jdbc.util.ResultSetUtil;
public class ExpectedResultsImpl implements ExpectedResults {
-
+
private static final int MAX_COL_WIDTH = 65;
-
protected Properties props;
protected int resultMode = -1;
protected String generateDir = null;
protected String querySetIdentifier = null;
protected String results_dir_loc = null;
-
+
protected Map<String, ResultsHolder> loadedResults = new HashMap<String,
ResultsHolder>();
-
-
+
public ExpectedResultsImpl(String querySetIdentifier, Properties properties) {
- this.props = properties;
- this.querySetIdentifier = querySetIdentifier;
-
- this.results_dir_loc = props.getProperty(
- PROP_EXPECTED_RESULTS_DIR_LOC, "");
-
+ this.props = properties;
+ this.querySetIdentifier = querySetIdentifier;
+
+ this.results_dir_loc = props.getProperty(PROP_EXPECTED_RESULTS_DIR_LOC,
+ "");
+
String expected_root_loc = this.props
.getProperty(PROP_EXPECTED_RESULTS_ROOT_DIR);
@@ -66,110 +65,155 @@
this.results_dir_loc = dir.getAbsolutePath();
}
-
- TestLogger.logInfo("Expected results loc: " + this.results_dir_loc);
+ TestLogger.logInfo("Expected results loc: " + this.results_dir_loc);
}
+ @Override
+ public boolean isExceptionExpected(String queryidentifier)
+ throws QueryTestFailedException {
+ return false;
+ }
- @Override
- public boolean isExceptionExpected(String queryidentifier) throws
QueryTestFailedException {
- return false;
- }
+ @Override
+ public String getQuerySetID() {
+ return this.querySetIdentifier;
+ }
+ @Override
+ public synchronized File getResultsFile(String queryidentifier)
+ throws QueryTestFailedException {
+ return findExpectedResultsFile(queryidentifier, this.querySetIdentifier);
+ }
- @Override
- public String getQuerySetID() {
- return this.querySetIdentifier;
- }
-
-
-
- @Override
- public synchronized File getResultsFile(String queryidentifier) throws
QueryTestFailedException {
- return findExpectedResultsFile(queryidentifier, this.querySetIdentifier);
-
- }
-
-
- /**
+ /**
* Compare the results of a query with those that were expected.
*
* @param expectedResults
* The expected results.
* @param results
- * The actual results - may be null if
<code>actualException</code>.
+ * The actual results - may be null if
+ * <code>actualException</code>.
* @param actualException
- * The actual exception recieved durring query execution - may be null if
<code>results</code>.
+ * The actual exception recieved durring query execution - may be
+ * null if <code>results</code>.
* @param isOrdered
* Are the actual results ordered?
* @param batchSize
- * Size of the batch(es) used in determining when the first batch of
results were read.
- * @return The response time for comparing the first batch (sizes) of resutls.
+ * Size of the batch(es) used in determining when the first batch
+ * of results were read.
+ * @return The response time for comparing the first batch (sizes) of
+ * resutls.
* @throws QueryTestFailedException
* If comparison fails.
*/
- public void compareResults( final String queryIdentifier,
- final String sql,
- final ResultSet resultSet,
- final Throwable actualException,
- final int testStatus,
- final boolean isOrdered,
- final int batchSize) throws
QueryTestFailedException {
+ public Object compareResults(final String queryIdentifier, final String sql,
+ final ResultSet resultSet, final Throwable actualException,
+ final int testStatus, final boolean isOrdered, final int updateCnt,
+ final boolean resultFromQuery) throws QueryTestFailedException {
File expectedResultsFile = getResultsFile(queryIdentifier);
-
-// File temp = new File("ERROR_" + queryIdentifier + ".txt");
-// temp.deleteOnExit();
-
+
List<?> results = null;
if (actualException != null) {
-
+
try {
- results = ResultSetUtil.writeAndCompareThrowable(actualException, null,
expectedResultsFile, false);
+ results = ResultSetUtil.writeAndCompareThrowable(
+ actualException, null, expectedResultsFile, false);
- } catch (Exception e1) {
- throw new TransactionRuntimeException(e1);
+ } catch (Throwable e) {
+ TransactionRuntimeException t = new TransactionRuntimeException(
+ e.getMessage());
+ t.initCause(e);
+ throw t;
}
- if (results != null && results.size() >0) {
- throw new QueryTestFailedException("Comparison resulted in unequal
lines");
+ if (results != null && results.size() > 0) {
+ return results;
+ }
+
+ return null;
+
+ }
+
+ // update sql or procedure(with no results) has no results set
+ if (!resultFromQuery) {
+
+ if (SqlUtil.isUpdateSql(sql)) {
+ if (updateCnt == 0 && expectedResultsFile.length() > 0) {
+ throw new QueryTestFailedException("Update cnt was zero: " +
expectedResultsFile.getName());
}
+ if (updateCnt > 0 && expectedResultsFile.length() == 0) {
+ throw new QueryTestFailedException(
+ "Update cnt was greater than zero, but didnt expected any updates");
+ }
+
+ } else {
+ if (expectedResultsFile.length() > 0) {
+ throw new QueryTestFailedException("No results from query, but expected
results");
+ }
+ }
+
+
} else {
-
+
try {
- results = ResultSetUtil.writeAndCompareResultSet(resultSet, MAX_COL_WIDTH, false, null,
expectedResultsFile, false);
+ if (expectedResultsFile.length() == 0) {
+ // if the expectedResult file is empty
+ // and the result doesnt have a first row-meaning its empty
+ // then this is good
+ if (!resultSet.first()) {
+ throw new QueryTestFailedException(
+ "Expected results is empty, but query produced results");
+ }
+ return results;
+ }
+
+ resultSet.beforeFirst();
- } catch (Exception e) {
- throw new TransactionRuntimeException(e);
- }
+ results = ResultSetUtil.writeAndCompareResultSet(resultSet,
+ MAX_COL_WIDTH, false, null, expectedResultsFile, false);
+
+ } catch (QueryTestFailedException qe) {
+ throw qe;
+ } catch (Throwable e) {
+ TransactionRuntimeException t = new TransactionRuntimeException(
+ e.getMessage());
+ t.initCause(e);
+ throw t;
+ }
+
- if (results != null && results.size() >0) {
- throw new QueryTestFailedException("Comparison resulted in unequal
lines");
- }
+ if (results != null && results.size() > 0) {
+ return results;
+ }
+
+ return null;
+
}
+
+ return results;
-
}
- @Override
- public Object getMetaData(String queryidentifier) {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Object getMetaData(String queryidentifier) {
+ // TODO Auto-generated method stub
+ return null;
+ }
-
private File findExpectedResultsFile(String queryIdentifier,
- String querySetIdentifier) throws QueryTestFailedException {
- String resultFileName = queryIdentifier + ".txt"; //$NON-NLS-1$
- File file = new File(results_dir_loc + "/" + querySetIdentifier,
resultFileName);
- if (!file.exists()) {
- throw new QueryTestFailedException("Query results file " +
file.getAbsolutePath() + " cannot be found");
- }
-
- return file;
+ String querySetIdentifier) throws QueryTestFailedException {
+ String resultFileName = queryIdentifier + ".txt"; //$NON-NLS-1$
+ File file = new File(results_dir_loc + "/" + querySetIdentifier,
+ resultFileName);
+ if (!file.exists()) {
+ throw new QueryTestFailedException("Query results file "
+ + file.getAbsolutePath() + " cannot be found");
+ }
- }
-
-
+ return file;
+
+ }
+
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -38,30 +38,29 @@
*/
public class QueryScenarioImpl extends QueryScenario {
-
public QueryScenarioImpl(String scenarioName, Properties queryProperties) {
super(scenarioName, queryProperties);
}
-
/* (non-Javadoc)
* @see
org.teiid.test.client.QueryScenario#handleTestResult(org.teiid.test.client.TestResult,
java.lang.String)
*/
@Override
- public void handleTestResult(TestResult tr, ResultSet resultSet, String sql) {
+ public void handleTestResult(TestResult tr, ResultSet resultSet, int updateCnt,
boolean resultFromQuery, String sql) {
Throwable resultException = tr.getException();
if (getResultsMode().equalsIgnoreCase(
TestProperties.RESULT_MODES.COMPARE)) {
+ Object results = null;
try {
- this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(),
+ results =
this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(),
sql,
resultSet,
resultException,
- tr.getStatus(), isOrdered(sql), -1);
+ tr.getStatus(), isOrdered(sql), updateCnt, resultFromQuery);
tr.setStatus(TestResult.RESULT_STATE.TEST_SUCCESS);
@@ -70,14 +69,18 @@
: qtf);
tr.setException(resultException);
tr.setStatus(TestResult.RESULT_STATE.TEST_EXCEPTION);
+
+
+ }
+
+ if (results != null || tr.getStatus() == TestResult.RESULT_STATE.TEST_EXCEPTION) {
try {
this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
tr.getQueryID(), sql, resultSet, resultException,
- this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID())
);
+ results );
} catch (QueryTestFailedException qtfe) {
throw new TransactionRuntimeException(qtfe.getMessage());
}
-
}
@@ -98,8 +101,7 @@
if (tr.getException() != null) {
try {
this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
- tr.getQueryID(), sql, resultSet, resultException,
- this.getExpectedResults(tr.getQuerySetID()).getResultsFile(tr.getQueryID()) );
+ tr.getQueryID(), sql, resultSet, resultException, null);
} catch (QueryTestFailedException qtfe) {
throw new TransactionRuntimeException(qtfe.getMessage());
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -29,6 +29,8 @@
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
import org.junit.Assert;
@@ -128,7 +130,7 @@
if (ex != null) {
ResultSetUtil.printThrowable(ex, filePrintStream);
} else if (result != null ){
-
+ result.beforeFirst();
ResultSetUtil.printResultSet(result, MAX_COL_WIDTH, true, filePrintStream);
}
@@ -150,7 +152,7 @@
public String generateErrorFile(final String querySetID,
final String queryID, final String sql, final ResultSet resultSet,
- final Throwable queryError, final File expectedResultsFile)
+ final Throwable queryError, final Object results)
throws QueryTestFailedException {
String errorFileName = null;
@@ -194,7 +196,7 @@
resultSet.beforeFirst();
generateErrorResults(querySetID, queryID, sql, errorFile,
- resultSet, expectedResultsFile, queryError);
+ resultSet, (results != null ? (List) results : null));
} catch (Throwable e) {
throw new QueryTestFailedException(e.getMessage());
@@ -241,15 +243,24 @@
*/
private void generateErrorResults(String querySetID, String queryID,
String sql, File resultsFile, ResultSet actualResult,
- File expectedResultFile, Throwable ex)
+ List<String> results)
throws QueryTestFailedException {
FileOutputStream actualOut = null;
try {
actualOut = new FileOutputStream(resultsFile);
PrintStream filePrintStream = new PrintStream(actualOut);
+
- ResultSetUtil.printResultSet(actualResult, MAX_COL_WIDTH, true, filePrintStream);
+ if (results != null) {
+ for (Iterator<String> it=results.iterator(); it.hasNext();) {
+ String line = it.next();
+ filePrintStream.print(line);
+ }
+ } else {
+
+ ResultSetUtil.printResultSet(actualResult, MAX_COL_WIDTH, true, filePrintStream);
+ }
} catch (Exception e) {
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2010-01-19
20:21:16 UTC (rev 1752)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -6,10 +6,11 @@
import org.teiid.test.framework.datasource.DataSourceFactory;
import org.teiid.test.framework.datasource.DataStore;
-import org.teiid.test.framework.exception.TransactionRuntimeException;
import org.teiid.test.util.PropUtils;
+import com.metamatrix.common.util.PropertiesUtils;
+
/**
* The ConfigProperteryLoader will load the configuration properties to be used by a
test.
* Unless a different configuraton file is specified, subsequent loading of the
configuration
@@ -112,7 +113,7 @@
private void initialize() {
- props = PropUtils.loadProperties("/" + LAST_CONFIG_FILE, null);
+ props = PropUtils.loadProperties(LAST_CONFIG_FILE, null);
dsfactory = new DataSourceFactory(this);
}
@@ -143,9 +144,9 @@
}
public Properties getProperties() {
+
- Properties p = new Properties();
- p.putAll(System.getProperties());
+ Properties p = PropertiesUtils.clone(System.getProperties(), false);
if (props != null) {
p.putAll(props);
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java 2010-01-19
20:21:16 UTC (rev 1752)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java 2010-01-19
20:26:55 UTC (rev 1753)
@@ -1,5 +1,6 @@
package org.teiid.test.util;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@@ -7,6 +8,8 @@
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.exception.TransactionRuntimeException;
+import com.metamatrix.common.util.PropertiesUtils;
+
public class PropUtils {
@@ -18,7 +21,15 @@
props.putAll(defaults);
}
try {
- in = ConfigPropertyLoader.class.getResourceAsStream(filename);
+
+ File f = new File(filename);
+ if (f.exists()) {
+ return PropertiesUtils.load(filename);
+
+ }
+
+
+ in = ConfigPropertyLoader.class.getResourceAsStream("/" + filename);
if (in != null) {
Properties lprops = new Properties();
lprops.load(in);