Package org.teiid.test.framework.exception

Examples of org.teiid.test.framework.exception.QueryTestFailedException


  Connection conn = 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;
    }
View Full Code Here


      DataSource source = (DataSource) ctx.lookup(jndi_name);

      if (source == null) {
    String msg = "Unable to find jndi source " + jndi_name;//$NON-NLS-1$

    QueryTestFailedException mme = new QueryTestFailedException(msg);//$NON-NLS-1$
    throw mme;
      }
      Connection conn = source.getConnection();
      return conn;
  } catch (QueryTestFailedException qtfe) {
      throw qtfe;
  } catch (Exception e) {
      throw new QueryTestFailedException(e);
  }
    }
View Full Code Here

  String queryFile = querySetIDToFileMap.get(querySetID);

  try {
      return loadQueries(querySetID, queryFile);
  } catch (IOException e) {
      throw new QueryTestFailedException((new StringBuilder()).append(
        "Failed to load queries from file: ").append(queryFile).append(" error:").append(e.getMessage())
        .toString());
  }

    }
View Full Code Here


    private void loadQuerySets() throws QueryTestFailedException {
  String query_dir_loc = this.props.getProperty(PROP_QUERY_FILES_DIR_LOC);
  if (query_dir_loc == null)
      throw new QueryTestFailedException(
        "queryfiles.loc property was not specified ");

  String query_root_loc = this.props
    .getProperty(PROP_QUERY_FILES_ROOT_DIR);

  String loc = query_dir_loc;

  if (query_root_loc != null) {
      File dir = new File(query_root_loc, query_dir_loc);
      loc = dir.getAbsolutePath();
  }

  TestLogger.log("Loading queries from " + loc);

  File files[] = FileUtils.findAllFilesInDirectoryHavingExtension(loc,
    ".xml");
  if (files == null || files.length == 0)
      throw new QueryTestFailedException((new StringBuilder()).append(
        "No query files found in directory ").append(loc)
        .toString());
  // List<String> queryFiles = new ArrayList<String>(files.length);
  for (int i = 0; i < files.length; i++) {
      String queryfile = files[i].getAbsolutePath();
View Full Code Here

  ResultsHolder actualResults;

  switch (testStatus) {
    case TestResult.RESULT_STATE.TEST_EXCEPTION:
      throw new QueryTestFailedException(
        eMsg
          + "Test resulted in unexpected exception " + actualException.getMessage()); //$NON-NLS-1$

     
    case TestResult.RESULT_STATE.TEST_EXPECTED_EXCEPTION:

                if (!expectedResults.isException()) {
                    // The actual exception was expected, but the expected results was not
                    throw new QueryTestFailedException(eMsg + "The actual result was an exception, but the Expected results wasn't an exception.  Actual exception: '" //$NON-NLS-1$
                                                       + actualException.getMessage() + "'"); //$NON-NLS-1$
                }
                // We got an exception that we expected - convert actual exception to ResultsHolder
                actualResults = new ResultsHolder(TagNames.Elements.EXCEPTION);
                actualResults.setQueryID(expectedResults.getQueryID());

                actualResults = convertException(actualException, actualResults);
               
                compareExceptions(actualResults, expectedResults, eMsg);

                break;
               
      default:
          // DEBUG:
          // debugOut.println("*** Expected Results (holder): " +
          // expectedResults);
          // DEBUG:
          // debugOut.println("*** Actual Results (ResultSet): " +
          // printResultSet(results));

          // Convert results to ResultsHolder
           actualResults = new ResultsHolder(TagNames.Elements.QUERY_RESULTS);
            actualResults.setQueryID(expectedResults.getQueryID());
            convertResults(resultSet, batchSize,   actualResults);

              if (expectedResults.getRows().size() > 0) {
                  compareResults(actualResults, expectedResults, eMsg, isOrdered);
              } else if (actualResults.getRows() != null &&  actualResults.getRows().size() > 0) {
                      throw new QueryTestFailedException(eMsg + "Expected results indicated no results, but actual shows " + actualResults.getRows().size() + " rows."); //$NON-NLS-1$                                 
              }

          // DEBUG:
          // debugOut.println("*** Actual Results (holder): " +
          // actualResults);
View Full Code Here

            for (int col = 1; col <= colCount; col++) {
                columnTypeNames.add(rsMetadata.getColumnName(col));
                columnTypes.add(rsMetadata.getColumnTypeName(col));
            }
        } catch (SQLException qre) {
            throw new QueryTestFailedException("Can't get results metadata: " + qre.getMessage()); //$NON-NLS-1$
        }

        // Get rows
        try {
            // Read all the rows
            for (int row = 0; results.next(); row++) {
                final List currentRecord = new ArrayList(colCount);
                // Read values for this row
                for (int col = 1; col <= colCount; col++) {
                    currentRecord.add(results.getObject(col));
                }
                records.add(currentRecord);
                // If this row is the (fetch size - 1)th row, record first batch response time
                if (row == batchSize) {
                    firstBatchResponseTime = System.currentTimeMillis();
                }
            }
        } catch (SQLException qre) {
            throw new QueryTestFailedException("Can't get results: " + qre.getMessage()); //$NON-NLS-1$
        }

        // Set info on resultsHolder
        resultsHolder.setRows(records);
        resultsHolder.setIdentifiers(columnTypeNames);
View Full Code Here

        .getExceptionClassName();
    final String actualExceptionMsg = actualResults.getExceptionMsg().toLowerCase();

    if (actualExceptionClass == null) {
      // We didn't get an actual exception, we should have
      throw new QueryTestFailedException(eMsg + "Expected exception: " //$NON-NLS-1$
          + expectedExceptionClass + " but got none."); //$NON-NLS-1$
    }
    // Compare exception classes
    if (!expectedExceptionClass.equals(actualExceptionClass)) {
      throw new QueryTestFailedException(eMsg
          + "Got wrong exception, expected \"" //$NON-NLS-1$
          + expectedExceptionClass + "\" but got \"" + //$NON-NLS-1$
          actualExceptionClass + "\""); //$NON-NLS-1$
    }
    // Compare exception messages
    if (!expectedExceptionMsg.equals(actualExceptionMsg)) {
      // Give it another chance by comparing w/o line separators
      if (!compareStrTokens(expectedExceptionMsg, actualExceptionMsg)) {
        throw new QueryTestFailedException(
            eMsg
                + "Got expected exception but with wrong message. Got " + actualExceptionMsg); //$NON-NLS-1$
      }
    }
  }
View Full Code Here

        final int expectedRowCount = expectedResults.size();
        final int actualColumnCount = actualIdentifiers.size();

        // Check for less records than in expected results
        if (actualRowCount < expectedRowCount) {
            throw new QueryTestFailedException(eMsg + "Expected " + expectedRowCount + //$NON-NLS-1$
                                               " records but received only " + actualRowCount); //$NON-NLS-1$
        } else if (actualRowCount > expectedRowCount) {
            // Check also for more records than expected
            throw new QueryTestFailedException(eMsg + "Expected " + expectedRowCount + //$NON-NLS-1$
                                               " records but received " + actualRowCount); //$NON-NLS-1$
        }

        //      DEBUG:
        //       debugOut.println("================== Compariing Rows ===================");
        // Loop through rows
        for (int row = 0; row < actualRowCount; row++) {

            // Get actual record
            final List actualRecord = (List)actualResults.get(row);

            // Get expected record
            final List expectedRecord = (List)expectedResults.get(row);

            //          DEBUG:
            //            debugOut.println("Row: " + (row + 1));
            //            debugOut.println(" expectedRecord: " + expectedRecord);
            //            debugOut.println(" actualRecord: " + actualRecord);
            // Loop through columns
            // Compare actual elements with expected elements column by column in this row
            for (int col = 0; col < actualColumnCount; col++) {
                // Get actual value
                Object actualValue = actualRecord.get(col);
                // Get expected value
                Object expectedValue = expectedRecord.get(col);
                //              DEBUG:
                //                debugOut.println(" Col: " +(col +1) + ": expectedValue:[" + expectedValue + "] actualValue:[" + actualValue +
                // "]");

                // Compare these values
                if ( ( expectedValue == null && actualValue != null) ||
                    (actualValue == null && expectedValue != null) ){
                    // Compare nulls
                        throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
                                                           + " and column " + (col + 1) //$NON-NLS-1$
                                                           + ": expected = [" //$NON-NLS-1$
                                                           + (expectedValue!=null?expectedValue:"null") + "], actual = [" //$NON-NLS-1$
                                                           + (actualValue!=null?actualValue:"null"+ "]"); //$NON-NLS-1$

                }
               
                if (expectedValue == null && actualValue == null) {
                  continue;
                }
                 
                if (actualValue instanceof Blob || actualValue instanceof Clob || actualValue instanceof SQLXML) {
                      
                  if (actualValue instanceof Clob){
                    Clob c = (Clob)actualValue;
                    try {
              actualValue = ObjectConverterUtil.convertToString(c.getAsciiStream());
             
            } catch (Throwable e) {
              // TODO Auto-generated catch block
              throw new QueryTestFailedException(e);
            }
                  } else if (actualValue instanceof Blob){
                        Blob b = (Blob)actualValue;
                        try {
                  actualValue = ObjectConverterUtil.convertToString(b.getBinaryStream());
                 
                } catch (Throwable e) {
                  // TODO Auto-generated catch block
                  throw new QueryTestFailedException(e);
                }
                    } else if (actualValue instanceof SQLXML){
                      SQLXML s = (SQLXML)actualValue;
                    try {
              actualValue = ObjectConverterUtil.convertToString(s.getBinaryStream());
             
            } catch (Throwable e) {
              // TODO Auto-generated catch block
              throw new QueryTestFailedException(e);
            }
                    }

                 
                  if (!(expectedValue instanceof String)) {
                    expectedValue = expectedValue.toString();
                  }
                }
                 
                    // Compare values with equals
                    if (!expectedValue.equals(actualValue)) {
                        // DEBUG:
                        //                        debugOut.println(" ExpectedType: " + expectedValue.getClass() + " ActualType: " +
                        // actualValue.getClass());
                 
                         if (expectedValue instanceof String) {
                            final String expectedString = (String)expectedValue;
//                            if (actualValue instanceof Blob || actualValue instanceof Clob || actualValue instanceof SQLXML) {
//                             
//                              Clob c = (Clob)actualValue;
//                                // LOB types are special case - metadata says they're Object types so
//                                // expected results are of type String. Actual object type is MMBlob, MMClob.
//                                // Must compare w/ String verion of actual!
//                                if (!expectedValue.equals(actualValue.toString())) {
//                                    throw new QueryTestFailedException(eMsg + "LOB Value mismatch at row " + (row + 1) //$NON-NLS-1$
//                                                                       + " and column " + (col + 1) //$NON-NLS-1$
//                                                                       + ": expected = [" //$NON-NLS-1$
//                                                                       + expectedValue + "], actual = [" //$NON-NLS-1$
//                                                                       + actualValue + "]"); //$NON-NLS-1$
//                                }
//                            } else
                            if (!(actualValue instanceof String)) {
                                throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
                                                                   + " and column " + (col + 1) //$NON-NLS-1$
                                                                   + ": expected = [" //$NON-NLS-1$
                                                                   + expectedValue + "], actual = [" //$NON-NLS-1$
                                                                   + actualValue + "]"); //$NON-NLS-1$
                            } else if (expectedString.length() > 0) {
                                // Check for String difference
                                assertStringsMatch(expectedString, (String)actualValue, (row + 1), (col + 1), eMsg);
                            }
                        } else {
                           
                            throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
                                    + " and column " + (col + 1) //$NON-NLS-1$
                                    + ": expected = [" //$NON-NLS-1$
                                    + expectedValue + "], actual = [" //$NON-NLS-1$
                                    + actualValue + "]"); //$NON-NLS-1$
             
View Full Code Here

      List expectedIdentifiers, List actualDataTypes,
      List expectedDatatypes) throws QueryTestFailedException {

    // Check sizes
    if (expectedIdentifiers.size() != actualIdentifiers.size()) {
      throw new QueryTestFailedException(
          "Got incorrect number of columns, expected = " + expectedIdentifiers.size() + ", actual = " //$NON-NLS-1$ //$NON-NLS-2$
              + actualIdentifiers.size());
    }

    // Compare identifier lists only by short name
    for (int i = 0; i < actualIdentifiers.size(); i++) {
      String actualIdent = (String) actualIdentifiers.get(i);
      String expectedIdent = (String) expectedIdentifiers.get(i);
      String actualType = (String) actualDataTypes.get(i);
      String expectedType = (String) expectedDatatypes.get(i);

      // Get short name for each identifier
      String actualShort = getShortName(actualIdent);
      String expectedShort = getShortName(expectedIdent);

      if (!expectedShort.equalsIgnoreCase(actualShort)) {
        throw new QueryTestFailedException(
            "Got incorrect column name at column " + i + ", expected = " + expectedShort + " but got = " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + actualShort);
      }
      if (actualType.equalsIgnoreCase("xml")) {//$NON-NLS-1$
        actualType = "string";//$NON-NLS-1$
      }
      if (actualType.equalsIgnoreCase("clob")) {//$NON-NLS-1$
        actualType = "string";//$NON-NLS-1$
      }
      if (!expectedType.equalsIgnoreCase(actualType)) {
        throw new QueryTestFailedException(
            "Got incorrect column type at column " + i + ", expected = " + expectedType + " but got = " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + actualType);
      }
    }
  }
View Full Code Here

      String message = eMsg + "Value mismatch at row " + row + //$NON-NLS-1$
          " and column " + col + //$NON-NLS-1$
          ". Expected: {0} but was: {1}" + locationText; //$NON-NLS-1$
      message = MessageFormat.format(message, new Object[] {
          expectedPartOfMessage, actualPartOfMessage });
      throw new QueryTestFailedException(message);
    }
  }
View Full Code Here

TOP

Related Classes of org.teiid.test.framework.exception.QueryTestFailedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.