Пример #1
0
 public TestResult matchMessage(String actual, String expected) {
   if (actual == null) return TestResult.fail("NULL");
   if (actual.equals(replaceSymbols(expected)))
     return TestResult.pass(replaceSymbolsWithFullExpansion(expected));
   Comparator c = new Comparator(actual, expected);
   return c.evaluate();
 }
Пример #2
0
 protected void scanRowForMatch(int tableRow, QueryResults queryResults) {
   int matchedRow = queryResults.findBestMatch(tableRow);
   if (matchedRow == -1) {
     replaceAllvariablesInRow(tableRow);
     TestResult testResult = TestResult.fail(null, table.getCellContents(0, tableRow), "missing");
     table.updateContent(0, tableRow, testResult);
     getTestContext().increment(testResult.getExecutionResult());
   } else {
     markFieldsInMatchedRow(tableRow, matchedRow, queryResults);
   }
 }
Пример #3
0
 private void markMissingFields(List<String> surplusRow, int newTableRow) {
   for (int col = 0; col < surplusRow.size(); col++) {
     String surplusField = surplusRow.get(col);
     if (surplusField == null) {
       String fieldName = fieldNames.get(col);
       TestResult testResult = TestResult.fail(String.format("field %s not present", fieldName));
       table.updateContent(col, newTableRow, testResult);
       getTestContext().increment(testResult.getExecutionResult());
     }
   }
 }
Пример #4
0
 @Override
 public TestResult evaluateExpectation(Object queryReturn) {
   TestResult testResult;
   if (queryId == null || queryReturn == null) {
     testResult = TestResult.error("query method did not return a list");
     table.updateContent(0, 0, testResult);
   } else if (queryReturn instanceof List) {
     testResult = new TestResult(scanRowsForMatches((List<Object>) queryReturn));
   } else {
     testResult = TestResult.error(String.format("The query method returned: %s", queryReturn));
     table.updateContent(0, 0, testResult);
   }
   return testResult;
 }
Пример #5
0
 protected TestResult markField(int tableRow, int matchedRow, int col, QueryResults queryResults) {
   if (col >= fieldNames.size()) return null; // ignore strange table geometry.
   String fieldName = fieldNames.get(col);
   String actualValue = queryResults.getCell(fieldName, matchedRow);
   String expectedValue = table.getCellContents(col, tableRow);
   TestResult testResult;
   if (actualValue == null)
     testResult = TestResult.fail(String.format("field %s not present", fieldName), expectedValue);
   else if (expectedValue == null || expectedValue.length() == 0)
     testResult = TestResult.ignore(actualValue);
   else {
     testResult = matchMessage(actualValue, expectedValue);
     //      if (testResult != null)
     //        table.substitute(col, tableRow, replaceSymbolsWithFullExpansion(message));
     //      else
     //        table.substitute(col, tableRow, replaceSymbolsWithFullExpansion(expectedValue));
     //      else
     if (testResult == null)
       testResult = TestResult.fail(actualValue, replaceSymbolsWithFullExpansion(expectedValue));
     else if (testResult.getExecutionResult() == ExecutionResult.PASS)
       testResult = markMatch(tableRow, matchedRow, col, testResult.getMessage());
   }
   table.updateContent(col, tableRow, testResult);
   getTestContext().increment(testResult.getExecutionResult());
   return testResult;
 }
Пример #6
0
 private ExecutionResult markSurplusRows(final QueryResults queryResults) {
   List<Integer> unmatchedRows = queryResults.getUnmatchedRows();
   ExecutionResult result = ExecutionResult.PASS;
   for (int unmatchedRow : unmatchedRows) {
     List<String> surplusRow = queryResults.getList(fieldNames, unmatchedRow);
     int newTableRow = table.addRow(surplusRow);
     TestResult testResult = TestResult.fail(surplusRow.get(0), null, "surplus");
     table.updateContent(0, newTableRow, testResult);
     getTestContext().increment(result);
     markMissingFields(surplusRow, newTableRow);
     result = ExecutionResult.FAIL;
   }
   return result;
 }
Пример #7
0
 protected TestResult markMatch(int tableRow, int matchedRow, int col, String message) {
   return TestResult.pass(message);
 }
Пример #8
0
 public String formatTestResult() {
   if (testResult.getExecutionResult() == null) {
     return testResult.getMessage() != null
         ? Utils.escapeHTML(testResult.getMessage())
         : originalContent;
   }
   final String escapedMessage =
       testResult.hasMessage() ? Utils.escapeHTML(testResult.getMessage()) : originalContent;
   switch (testResult.getExecutionResult()) {
     case PASS:
       return String.format("<span class=\"pass\">%s</span>", escapedMessage);
     case FAIL:
       if (testResult.hasActual() && testResult.hasExpected()) {
         return String.format(
             "[%s] <span class=\"fail\">expected [%s]</span>",
             Utils.escapeHTML(testResult.getActual()),
             Utils.escapeHTML(testResult.getExpected()));
       } else if ((testResult.hasActual() || testResult.hasExpected())
           && testResult.hasMessage()) {
         return String.format(
             "[%s] <span class=\"fail\">%s</span>",
             Utils.escapeHTML(
                 testResult.hasActual() ? testResult.getActual() : testResult.getExpected()),
             Utils.escapeHTML(testResult.getMessage()));
       }
       return String.format("<span class=\"fail\">%s</span>", escapedMessage);
     case IGNORE:
       return String.format(
           "%s <span class=\"ignore\">%s</span>", originalContent, escapedMessage);
     case ERROR:
       return String.format(
           "%s <span class=\"error\">%s</span>", originalContent, escapedMessage);
   }
   return "Should not be here";
 }
Пример #9
0
 public String getTestResult() {
   return testResult != null ? testResult.toString(originalContent) : getContent();
 }
Пример #10
0
 @Override
 public void updateContent(int rowIndex, TestResult testResult) {
   rows.get(rowIndex).setExecutionResult(testResult.getExecutionResult());
 }