Exemple #1
0
  /* (non-Javadoc)
   * @see caarray.client.test.suite.SearchByExampleTestSuite#evaluateResults(java.util.List, caarray.client.test.search.ExampleSearch, caarray.client.test.TestResult)
   */
  @Override
  protected void evaluateResults(
      List<? extends AbstractCaArrayEntity> resultsList,
      ExampleSearch search,
      TestResult testResult) {
    FileTypeSearch fileTypeSearch = (FileTypeSearch) search;
    List<FileType> fileResults = (List<FileType>) resultsList;
    int namedResults = 0;
    for (FileType fileType : fileResults) {
      if (fileType.getName() != null && fileType.getId() != null) namedResults++;
    }
    if (fileTypeSearch.getExpectedResults() != null) {

      if (namedResults != fileTypeSearch.getExpectedResults()) {
        String errorMessage =
            "Failed with unexpected number of results, expected: "
                + fileTypeSearch.getExpectedResults()
                + ", actual number of results: "
                + namedResults;
        setTestResultFailure(testResult, fileTypeSearch, errorMessage);
      } else {
        String detail = "Found expected number of results: " + namedResults;
        testResult.addDetail(detail);
      }
    }
    if (fileTypeSearch.getMinResults() != null) {

      if (namedResults < fileTypeSearch.getMinResults()) {
        String errorMessage =
            "Failed with unexpected number of results, expected minimum: "
                + fileTypeSearch.getMinResults()
                + ", actual number of results: "
                + namedResults;
        setTestResultFailure(testResult, fileTypeSearch, errorMessage);
      } else {
        String detail = "Found expected number of results: " + namedResults;
        testResult.addDetail(detail);
      }
    }
    if (testResult.isPassed() && !fileTypeSearch.getExpectedNames().isEmpty()) {

      for (String expectedName : fileTypeSearch.getExpectedNames()) {
        boolean foundName = false;
        for (FileType fileType : fileResults) {
          if (fileType.getName().equalsIgnoreCase(expectedName)) {
            foundName = true;
            break;
          }
        }
        if (!foundName) {
          String errorMessage = "Didn't find expected name: " + expectedName;
          setTestResultFailure(testResult, fileTypeSearch, errorMessage);
        } else {
          String detail = "Found expected name: " + expectedName;
          testResult.addDetail(detail);
        }
      }
    }
    if (testResult.isPassed() && !fileTypeSearch.getExpectedCategories().isEmpty()) {

      for (String expectedCategory : fileTypeSearch.getExpectedCategories()) {
        boolean foundName = false;
        for (FileType fileType : fileResults) {
          // TODO: not sure how this works now
          /*if (fileType.getCategory() != null && fileType.getCategory().getName().equalsIgnoreCase(expectedCategory))
          {
              foundName = true;
              break;
          }*/
        }
        if (!foundName) {
          String errorMessage = "Didn't find expected category: " + expectedCategory;
          setTestResultFailure(testResult, fileTypeSearch, errorMessage);
        } else {
          String detail = "Found expected category: " + expectedCategory;
          testResult.addDetail(detail);
        }
      }
    }
  }
 @Override
 protected void evaluateResults(
     List<? extends AbstractCaArrayEntity> resultsList,
     ExampleSearch search,
     TestResult testResult) {
   ArrayDesignSearch adSearch = (ArrayDesignSearch) search;
   List<ArrayDesign> adResults = (List<ArrayDesign>) resultsList;
   if (adSearch.getExpectedResults() != null || adSearch.getMinResults() != null) {
     int namedResults = 0;
     for (ArrayDesign arrayDesign : adResults) {
       if (arrayDesign.getName() != null) namedResults++;
     }
     if (adSearch.getExpectedResults() != null && namedResults != adSearch.getExpectedResults()) {
       testResult.setPassed(false);
       String detail =
           "Failed with unexpected number of results, ArrayDesign:"
               + adSearch.getArrayDesign().getName()
               + "- expected number of results: "
               + adSearch.getExpectedResults()
               + ", actual number of results: "
               + namedResults;
       testResult.addDetail(detail);
     } else {
       String detail = "Found expected number of results: " + namedResults;
       testResult.addDetail(detail);
     }
     if (adSearch.getMinResults() != null && namedResults < adSearch.getMinResults()) {
       testResult.setPassed(false);
       String detail =
           "Failed with unexpected minimum number of results, ArrayDesign:"
               + adSearch.getArrayDesign().getName()
               + "- expected number of results: "
               + adSearch.getMinResults()
               + ", actual number of results: "
               + namedResults;
       testResult.addDetail(detail);
     }
   }
   if (adSearch.getExample() == null) {
     if (adSearch.getExceptionClass() != null) {
       if (!adSearch.getExceptionClass().equals(InvalidInputException.class.toString())
           && !adSearch.getExceptionClass().equals(InvalidInputFault.class.toString())) {
         testResult.setPassed(false);
         String detail = "Failed with unexpected exception class: " + adSearch.getExceptionClass();
         testResult.addDetail(detail);
       } else {
         testResult.addDetail("Found expected exception " + adSearch.getExceptionClass());
       }
     }
   }
   for (ArrayDesign arrayDesign : adResults) {
     if (adSearch.getExpectedProvider() != null) {
       if (arrayDesign.getArrayProvider() == null
           || !arrayDesign.getArrayProvider().getName().equals(adSearch.getExpectedProvider())) {
         testResult.setPassed(false);
         String detail =
             "Failed with unexpected array provider: "
                 + (arrayDesign.getArrayProvider() == null
                     ? "null"
                     : arrayDesign.getArrayProvider().getName())
                 + ", expected provider: "
                 + adSearch.getExpectedProvider();
         testResult.addDetail(detail);
       } else {
         String detail = "Found expected provider: " + adSearch.getExpectedProvider();
         testResult.addDetail(detail);
       }
     }
     if (adSearch.getExpectedOrganism() != null) {
       if (arrayDesign.getOrganism() == null
           || !arrayDesign
               .getOrganism()
               .getCommonName()
               .equalsIgnoreCase(adSearch.getExpectedOrganism())) {
         testResult.setPassed(false);
         String detail =
             "Failed with unexpected organism common name: "
                 + (arrayDesign.getOrganism() == null
                     ? "null"
                     : arrayDesign.getOrganism().getCommonName())
                 + ", expected name: "
                 + adSearch.getExpectedOrganism();
         testResult.addDetail(detail);
       } else {
         String detail = "Found expected organism: " + adSearch.getExpectedOrganism();
         testResult.addDetail(detail);
       }
     }
   }
 }