Package org.teiid.test.framework.exception

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


        XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();
        final ResultsHolder expectedResult;
        try {
            expectedResult = jstrat.parseXMLResultsFile(resultsFile);
        } catch (IOException e) {
            throw new QueryTestFailedException("Unable to load expected results: " + e.getMessage()); //$NON-NLS-1$
        } catch (JDOMException e) {
            throw new QueryTestFailedException("Unable to load expected results: " + e.getMessage()); //$NON-NLS-1$
        }
        return expectedResult;
    }
View Full Code Here


    private File findExpectedResultsFile(String queryIdentifier,
      String querySetIdentifier) throws QueryTestFailedException {
    String resultFileName = queryIdentifier + ".xml"; //$NON-NLS-1$
    File file = new File(results_dir_loc + "/" + querySetIdentifier, resultFileName);
    if (!file.exists() && this.isExpectedResultsNeeded()) {
      throw new QueryTestFailedException("Query results file " + file.getAbsolutePath() + " cannot be found");
    }
   
    return file;

  }
View Full Code Here

  long firstBatchResponseTime = 0;
  final String eMsg = "CompareResults Error: "; //$NON-NLS-1$
 
         switch (testStatus) {
    case TestResult.RESULT_STATE.TEST_EXCEPTION:
                  throw new QueryTestFailedException(eMsg + "TestResult indicates test exception occured, the process should not have passed it in for comparison."); //$NON-NLS-1$
     
     
//      break;
     
    case TestResult.RESULT_STATE.TEST_EXPECTED_EXCEPTION:
    //    String actualExceptionClass = actualException.getClass().getName();

                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);

                return firstBatchResponseTime;
       
//          break;
       
         }
        


//  if (results == null) {
//      // The result is an exception - compare exceptions
//
//      String actualExceptionClass = null;
//      if (actualException != null) {
//    actualExceptionClass = actualException.getClass().getName();
//      } else {
//    // We didn't get results but there was no exception either
//    throw new QueryTestFailedException(eMsg
//      + "Didn't get results or exception '"); //$NON-NLS-1$
//      }
//
//      if (!expectedResults.isException()) {
//    // We didn't get results but there was no expected exception
//    // either
//    throw new QueryTestFailedException(
//      eMsg
//        + "Expected results but didn't get results or exception '" //$NON-NLS-1$
//        + actualExceptionClass + "'"); //$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);
//
//  } else {
      // The result is a ResultSet - compare actual results with expected

      if (expectedResults.isException()) {
    throw new QueryTestFailedException(
      eMsg
        + "Expected exception " + expectedResults.getExceptionMsg() //$NON-NLS-1$
        + " but got results"); //$NON-NLS-1$
      }
      // DEBUG:
View Full Code Here

  OutputStream outputStream;
  try {
      FileOutputStream fos = new FileOutputStream(resultsFile);
      outputStream = new BufferedOutputStream(fos);
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to open new results file: " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  }

  try {
      XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();

      // Create root JDOM element
      Element rootElement = new Element(TagNames.Elements.ROOT_ELEMENT);

      // Create Query element
      Element queryElement = new Element(TagNames.Elements.QUERY);
      queryElement.addContent(new CDATA(query));
      rootElement.addContent(queryElement);

      // create a result attribute for the queryID
      Attribute resultsIDAttribute = new Attribute(
        TagNames.Attributes.NAME, queryID);

      if (result != null) {
    // produce a JDOM element from the results object
    Element resultsElement = jstrat.produceResults(result);
    // set the resultsIDAttribute on the results element
    resultsElement.setAttribute(resultsIDAttribute);
    // add the results elements to the root element
    rootElement.addContent(resultsElement);
    // debug:
    // System.out.println("\n Result: " + printResultSet(result));
      } else {
    // create a JDOM element from the exception object with the
    // results tag
    Element exceptionElement = new Element(
      TagNames.Elements.QUERY_RESULTS);
    // produce xml for the actualException and this to the
    // exceptionElement
    if (ex != null) {
        exceptionElement.addContent(jstrat.produceMsg(ex, null));
    }
    // set the resultsIDAttribute on the exception element
    exceptionElement.setAttribute(resultsIDAttribute);
    // add the results elements to the root element
    rootElement.addContent(exceptionElement);

      }

      // Output xml
      XMLOutputter outputter = new XMLOutputter(JdomHelper.getFormat(
        "  ", true)); //$NON-NLS-1$
      outputter.output(new Document(rootElement), outputStream);

  } catch (SQLException e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (JDOMException e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to output new results to " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  } catch (Throwable e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + StringUtil.getStackTrace(e)); //$NON-NLS-1$
  } finally {
      try {
    outputStream.close();
      } catch (IOException e) {
View Full Code Here

       
        filePrintStream.flush();

    } catch (Exception e) {
          e.printStackTrace();
          throw new QueryTestFailedException(e);
    } finally {
          if (actualOut != null) {
        try {
            actualOut.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      }
    }
    return errorFileName;

      }

      // rewind resultset

      resultSet.beforeFirst();

      generateErrorResults(querySetID, queryID, sql, errorFile,
        resultSet, (File) results);

  } catch (Throwable e) {
      throw new QueryTestFailedException(e.getMessage());
      //           CombinedTestClient.logError("Error writing error file \"" + outputDir + "\"/" + errorFileName + ": " + e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  return errorFileName;
    }
View Full Code Here

      TestResultSetUtil.printResultSet(actualResult, sql, MAX_COL_WIDTH, true, filePrintStream);
         

  } catch (Exception e) {
      e.printStackTrace();
      throw new QueryTestFailedException(e);
  } finally {
      if (actualOut != null) {
    try {
        actualOut.close();
    } catch (IOException e) {
View Full Code Here

      }
      generateErrorResults(querySetID, queryID, sql, errorFile,
        resultSet, (File) expectedResultsFile, queryError);

  } catch (Throwable e) {
      throw new QueryTestFailedException(e.getMessage());
      //           CombinedTestClient.logError("Error writing error file \"" + outputDir + "\"/" + errorFileName + ": " + e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  return errorFileName;
    }
View Full Code Here

  OutputStream outputStream;
  try {
      FileOutputStream fos = new FileOutputStream(resultsFile);
      outputStream = new BufferedOutputStream(fos);
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to open error results file: " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  }

  try {
      XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();

      // Create root JDOM element
      Element rootElement = new Element(TagNames.Elements.ROOT_ELEMENT);

      // create a JDOM element for the results
      Element resultElement = new Element(TagNames.Elements.QUERY_RESULTS);
      // set the queryIDAttr on the exception element
      resultElement.setAttribute(new Attribute(TagNames.Attributes.NAME,
        queryID));
      // set the querySQLAttr on the exception element
      resultElement.setAttribute(new Attribute(TagNames.Attributes.VALUE,
        sql));

      // ---------------------
      // Actual Exception
      // ---------------------
      // create a JDOM element from the actual exception object
      // produce xml for the actualException and this to the
      // exceptionElement
      if (ex != null) {
    Element actualExceptionElement = new Element(
      TagNames.Elements.ACTUAL_EXCEPTION);

    actualExceptionElement = XMLQueryVisitationStrategy
      .jdomException(ex, actualExceptionElement);
    resultElement.addContent(actualExceptionElement);
      }

      if (actualResult != null) {
    // ------------------------------
    // Got a ResultSet from server
    // error was in comparing results
    // ------------------------------

    // --------------------------
    // Actual Result - ResultSet
    // --------------------------
    // produce a JDOM element from the actual results object
    Element actualResultsElement = new Element(
      TagNames.Elements.ACTUAL_QUERY_RESULTS);
    actualResultsElement = jstrat.produceMsg(actualResult,
      actualResultsElement);

    // add the results elements to the root element
    resultElement.addContent(actualResultsElement);

    // ---------------------
    // Expected Results - ...
    // ---------------------
    // produce xml for the expected results
    // Get expected results
    Element expectedResult = new Element("bogus"); //$NON-NLS-1$
    expectedResult = jstrat.parseXMLResultsFile(expectedResultFile,
      expectedResult);
    if (expectedResult.getChild(TagNames.Elements.SELECT) != null) {
        //----------------------------------------------------------
        // -
        // Expected result was a ResultSet set element name to
        // reflect
        //----------------------------------------------------------
        // -
        expectedResult
          .setName(TagNames.Elements.EXPECTED_QUERY_RESULTS);
    } else {
        //----------------------------------------------------------
        // --
        // Expected result was an exception set element name to
        // reflect
        //----------------------------------------------------------
        // --
        expectedResult
          .setName(TagNames.Elements.EXPECTED_EXCEPTION);
    }
    resultElement.addContent(expectedResult);
      } else {

    // ---------------------
    // Expected Results - ...
    // ---------------------
    // produce xml for the expected results
    // Get expected results
    Element expectedResult = new Element("bogus"); //$NON-NLS-1$
    expectedResult = jstrat.parseXMLResultsFile(expectedResultFile,
      expectedResult);
    if (expectedResult.getChild(TagNames.Elements.SELECT) != null) {
        //----------------------------------------------------------
        // -
        // Expected result was a ResultSet set element name to
        // reflect
        //----------------------------------------------------------
        // -
        expectedResult
          .setName(TagNames.Elements.EXPECTED_QUERY_RESULTS);
    } else {
        //----------------------------------------------------------
        // --
        // Expected result was an exception set element name to
        // reflect
        //----------------------------------------------------------
        // --
        expectedResult
          .setName(TagNames.Elements.EXPECTED_EXCEPTION);
    }
    resultElement.addContent(expectedResult);
      }

      // ------------------------------
      // Got an exeption from the server
      // error was in comparing exceptions
      // ------------------------------

      // add the results elements to the root element
      rootElement.addContent(resultElement);

      // Output xml
      XMLOutputter outputter = new XMLOutputter(JdomHelper.getFormat(
        "  ", true)); //$NON-NLS-1$
      outputter.output(new Document(rootElement), outputStream);

  } catch (SQLException e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (JDOMException e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to output error results to " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  } catch (Throwable e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + StringUtil.getStackTrace(e)); //$NON-NLS-1$
  } finally {
      try {
    outputStream.close();
      } catch (IOException e) {
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.