Esempio n. 1
0
  /** Runs the tests and collects their result in a TestResult. */
  public void run(TestResult result) {
    // it probably make some sense to call result.run(this),
    // but, to avoid the suite being counted we try/catch ourselves
    try {
      setUp();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }

    for (Enumeration e = tests(); e.hasMoreElements(); ) {
      if (result.shouldStop()) break;
      Test test = (Test) e.nextElement();
      runTest(test, result);
    }

    try {
      tearDown();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }
  }
 /* Run a single test and decide whether the test was
  * successful, meaningless, or a failure.  This is the
  * Template Method pattern abstraction of the inner loop in a
  * JML/JUnit test. */
 public void runTest() throws java.lang.Throwable {
   try {
     // The call being tested!
     doCall();
   } catch (org.jmlspecs.jmlrac.runtime.JMLEntryPreconditionError e) {
     // meaningless test input
     addMeaningless();
   } catch (org.jmlspecs.jmlrac.runtime.JMLAssertionError e) {
     // test failure
     int l = org.jmlspecs.jmlrac.runtime.JMLChecker.getLevel();
     org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(org.jmlspecs.jmlrac.runtime.JMLOption.NONE);
     try {
       java.lang.String failmsg = this.failMessage(e);
       junit.framework.AssertionFailedError err =
           new junit.framework.AssertionFailedError(failmsg);
       err.setStackTrace(new java.lang.StackTraceElement[] {});
       err.initCause(e);
       result.addFailure(this, err);
     } finally {
       org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(l);
     }
   } catch (java.lang.Throwable e) {
     // test success
   }
 }
Esempio n. 3
0
 @SuppressWarnings("unchecked")
 @Override
 public void run(TestResult result) {
   result.startTest(this);
   ScriptRuntime runtime =
       new ScriptRuntime(script, environment, false, new HashMap<String, Object>());
   runtime.setLabelEvaluator(new EnvironmentLabelEvaluator(label));
   runtime.run();
   // map the exception (if any)
   if (runtime.getException() != null) {
     result.addError(this, runtime.getException());
   }
   // check all the validations that occurred
   List<Validation<?>> validations = (List<Validation<?>>) runtime.getContext().get("$validation");
   for (Validation<?> validation : validations) {
     if (validation.getSeverity() == Severity.ERROR
         || validation.getSeverity() == Severity.CRITICAL) {
       result.addFailure(this, new AssertionFailedError(validation.toString()));
       if (!addAllFailures) {
         break;
       }
     }
   }
   result.endTest(this);
 }
 @Override
 public void run(TestResult result) {
   super.run(result);
   if (!result.wasSuccessful()) {
     result.addFailure(this, new AssertionFailedError(mLog.toString()));
   }
 }
 /**
  * Report results as error, failure, or success (ignored), differently if result is null
  *
  * @param description the String description of the result
  * @param isError if true, report as failure
  * @param isFailure if true and not isError, report as failure
  * @param test the Test case
  * @param result the TestResult sink - ignored if null
  * @return 0
  */
 private static int reportResultToJUnit(
     String description, boolean isError, boolean isFailure, Test test, TestResult result) {
   if (null != result) {
     if (isError) {
       result.addError(test, new AssertionFailedError(description));
     } else if (isFailure) {
       result.addFailure(test, new AssertionFailedError(description));
     } // no need to log success
   } else { // have to throw failure
     if (isError) {
       String m = safeTestName(test) + " " + description;
       throw new Error(m);
     } else if (isFailure) {
       //                String m = safeTestName(test) + " " + description;
       throw new AssertionFailedError(description);
     } // no need to log success
   }
   return 0;
 }
Esempio n. 6
0
  @Override
  public void run(TestResult result) {
    result.startTest(this);

    try {
      // define request
      Security security = SecurityFactory.getInstance(delegator);
      MockServletContext servletContext = new MockServletContext();
      request.setAttribute("security", security);
      request.setAttribute("servletContext", servletContext);
      request.setAttribute("delegator", delegator);
      request.setAttribute("dispatcher", dispatcher);
      Map<String, Object> serviceResult =
          SimpleMethod.runSimpleService(
              methodLocation,
              methodName,
              dispatcher.getDispatchContext(),
              UtilMisc.toMap(
                  "test",
                  this,
                  "testResult",
                  result,
                  "locale",
                  Locale.getDefault(),
                  "request",
                  request,
                  "response",
                  response));

      // do something with the errorMessage
      String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
      if (UtilValidate.isNotEmpty(errorMessage)) {
        result.addFailure(this, new AssertionFailedError(errorMessage));
      }

      // do something with the errorMessageList
      List<Object> errorMessageList =
          UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
      if (UtilValidate.isNotEmpty(errorMessageList)) {
        for (Object message : errorMessageList) {
          result.addFailure(this, new AssertionFailedError(message.toString()));
        }
      }

      // do something with the errorMessageMap
      Map<String, Object> errorMessageMap =
          UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
      if (!UtilValidate.isEmpty(errorMessageMap)) {
        for (Map.Entry<String, Object> entry : errorMessageMap.entrySet()) {
          result.addFailure(
              this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
        }
      }

    } catch (MiniLangException e) {
      result.addError(this, e);
    } catch (SecurityConfigurationException e) {
      result.addError(this, e);
    }

    result.endTest(this);
  }