[teiid-commits] teiid SVN: r1805 - in trunk/test-integration/db/src/main/java/org/teiid/test: client/impl and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Feb 9 11:27:21 EST 2010


Author: vhalbert at redhat.com
Date: 2010-02-09 11:27:21 -0500 (Tue, 09 Feb 2010)
New Revision: 1805

Added:
   trunk/test-integration/db/src/main/java/org/teiid/test/util/TestResultSetUtil.java
Modified:
   trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.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/client/results/TestResultStat.java
Log:
Teiid-773 -  Added TestResultSetUtil so that when writing out a generated file for an exception, changed so that the line terminator was not being appended to the file.  This was causing, in comparison mode, the expected exceptions to fail

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java	2010-02-08 19:45:46 UTC (rev 1804)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestResult.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -142,7 +142,20 @@
     
     Throwable getException();
     
+    /**
+     * Set the exception that indicates the reason why there is a problem
+     * with the results.   Call {@link #setExceptionMessage(String)} to display
+     * a different message in the summary file.
+     * @param error
+     */
     void setException(Throwable error);
+    
+    /**
+     * Set the error message relating to the reason why there is a problem
+     * with the results.
+     * @param errorMsg
+     */
+    void setExceptionMessage(String errorMsg);
 
     /**
      * Return the time (in a long value) that this query started.

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-02-08 19:45:46 UTC (rev 1804)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -33,7 +33,7 @@
 import org.teiid.test.client.ctc.ResultsHolder;
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
-import org.teiid.test.framework.exception.TransactionRuntimeException;
+import org.teiid.test.util.TestResultSetUtil;
 
 import com.metamatrix.common.util.SqlUtil;
 import com.metamatrix.jdbc.util.ResultSetUtil;
@@ -116,13 +116,12 @@
 
 	List<?> results = null;
 	if (actualException != null) {
-
 	    try {
-		results = ResultSetUtil.writeAndCompareThrowable(
-			actualException, null, expectedResultsFile, false);
+		results = TestResultSetUtil.compareThrowable(
+			actualException, expectedResultsFile, false);
 
 	    } catch (Throwable e) {
-		TransactionRuntimeException t = new TransactionRuntimeException(
+		QueryTestFailedException t = new QueryTestFailedException(
 			e.getMessage());
 		t.initCause(e);
 		throw t;
@@ -177,7 +176,7 @@
 	    } catch (QueryTestFailedException qe) {
 		throw qe;
 	    } catch (Throwable e) {
-		TransactionRuntimeException t = new TransactionRuntimeException(
+		QueryTestFailedException t = new QueryTestFailedException(
 			e.getMessage());
 		t.initCause(e);
 		throw t;

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-02-08 19:45:46 UTC (rev 1804)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/QueryScenarioImpl.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -55,18 +55,19 @@
 	if (getResultsMode().equalsIgnoreCase(
 		TestProperties.RESULT_MODES.COMPARE)) {
 	    
-		Object error_results = null;
+		Object results = null;
 		try {
-		    error_results = this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(), 
+		    results = this.getExpectedResults(tr.getQuerySetID()).compareResults(tr.getQueryID(), 
 			    sql, 
 			    resultSet, 
 			    resultException, 
 			    tr.getStatus(), isOrdered(sql), updateCnt, resultFromQuery);
 		    
-		    if (error_results == null) {
+		    if (results == null) {
 			tr.setStatus(TestResult.RESULT_STATE.TEST_SUCCESS);
 		    } else {
 			tr.setStatus(TestResult.RESULT_STATE.TEST_EXCEPTION);
+			tr.setExceptionMessage("Results did not compare to expected results");
 		    }
 		    
 		    
@@ -82,7 +83,7 @@
 		    try {
     		    	this.getResultsGenerator().generateErrorFile(tr.getQuerySetID(),
     			    tr.getQueryID(), sql, resultSet, resultException,
-    			    error_results );	
+    			    results );	
     		    	
 		    } 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-02-08 19:45:46 UTC (rev 1804)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -37,7 +37,7 @@
 import org.teiid.test.client.ResultsGenerator;
 import org.teiid.test.client.TestProperties;
 import org.teiid.test.framework.exception.QueryTestFailedException;
-import org.teiid.test.framework.exception.TransactionRuntimeException;
+import org.teiid.test.util.TestResultSetUtil;
 
 import com.metamatrix.core.util.FileUtils;
 import com.metamatrix.jdbc.util.ResultSetUtil;
@@ -128,7 +128,7 @@
 	    PrintStream filePrintStream = new PrintStream(actualOut);
 	    
 	    if (ex != null) {
-		ResultSetUtil.printThrowable(ex, filePrintStream);
+		TestResultSetUtil.printThrowable(ex, filePrintStream);
 	    } else if (result != null ){
 		result.beforeFirst();
 		ResultSetUtil.printResultSet(result, MAX_COL_WIDTH, true, filePrintStream);
@@ -136,7 +136,7 @@
 
 	} catch (Exception e) {
 	    e.printStackTrace();
-	    throw new TransactionRuntimeException(e);
+	    throw new QueryTestFailedException(e);
 	} finally {
 	    if (actualOut != null) {
 		try {
@@ -172,11 +172,13 @@
 		    PrintStream filePrintStream = new PrintStream(actualOut);
 		    
 
-		    ResultSetUtil.printThrowable(queryError, filePrintStream);
+		    TestResultSetUtil.printThrowable(queryError, filePrintStream);
+		    
+		    filePrintStream.flush();
 
 		} catch (Exception e) {
 			    e.printStackTrace();
-			    throw new TransactionRuntimeException(e);
+			    throw new QueryTestFailedException(e);
 		} finally {
 		    	if (actualOut != null) {
 				try {
@@ -265,7 +267,7 @@
 
 	} catch (Exception e) {
 	    e.printStackTrace();
-	    throw new TransactionRuntimeException(e);
+	    throw new QueryTestFailedException(e);
 	} finally {
 	    if (actualOut != null) {
 		try {

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java	2010-02-08 19:45:46 UTC (rev 1804)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/results/TestResultStat.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -114,13 +114,18 @@
     }
 
     public String getExceptionMsg() {
-        return (error != null ? error.getMessage() : "");
+        return (this.errorMsg != null ? this.errorMsg : ( error != null ? error.getMessage() : ""));
     }
     
     public void setException(Throwable error){
 	this.error = error;
     }
     
+    public  void setExceptionMessage(String errorMsg) {
+	this.errorMsg = errorMsg;
+	
+    }
+    
     public Throwable getException() {
 	return this.error;
     }

Added: trunk/test-integration/db/src/main/java/org/teiid/test/util/TestResultSetUtil.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/util/TestResultSetUtil.java	                        (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/util/TestResultSetUtil.java	2010-02-09 16:27:21 UTC (rev 1805)
@@ -0,0 +1,67 @@
+/*
+ * 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.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.sql.SQLException;
+import java.util.List;
+
+import com.metamatrix.jdbc.util.ResultSetUtil;
+
+
+/** 
+ * TestResultSetUtil was built in order to override the {@link #printThrowable(Throwable, PrintStream)} method
+ * in order to call  out.print  instead of out.println
+ * This is because the println adds a line terminator, and when the result file is in turn used for 
+ * comparison it fails because of the line terminator.
+ * 
+ * @since
+ */
+public class TestResultSetUtil {
+
+    public static final int DEFAULT_MAX_COL_WIDTH = ResultSetUtil.DEFAULT_MAX_COL_WIDTH;
+    
+    public static List compareThrowable(Throwable t, File expectedResultsFile, boolean printToConsole) throws IOException, SQLException  {
+        BufferedReader expectedResultsReader = null;
+        if (expectedResultsFile != null && expectedResultsFile.exists() && expectedResultsFile.canRead()) {
+            expectedResultsReader = new BufferedReader(new FileReader(expectedResultsFile));
+        }
+        
+        PrintStream out =  ResultSetUtil.getPrintStream(null,expectedResultsReader, printToConsole ? System.out : null);
+             
+         printThrowable(t, out);
+        return ResultSetUtil.getUnequalLines(out);
+     }
+    
+    
+    public static void printThrowable(Throwable t, PrintStream out) {
+        
+      out.print(t.getClass().getName() + " : " + t.getMessage()); //$NON-NLS-1$
+        	
+    }
+    
+}


Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/util/TestResultSetUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the teiid-commits mailing list