示例#1
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);
 }
示例#2
0
 private void addErrorMessage(TestResult testResult, String message) {
   String processedTestsMessage =
       myRunTests <= 0 ? "None of tests was run" : myRunTests + " tests processed";
   try {
     testResult.startTest(this);
     testResult.addError(this, new Throwable(processedTestsMessage + " before: " + message));
     testResult.endTest(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#3
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);
  }