コード例 #1
0
 @Override
 public final SampleResult runTest(JavaSamplerContext context) {
   if (setupError != null) {
     SampleResult errorResult = new SampleResult();
     errorResult.setSuccessful(false);
     errorResult.setResponseMessage(setupError);
     errorResult.setStopTest(true);
     return errorResult;
   } else {
     try {
       SampleResult result = doRunTest(context);
       if (result != null && !result.isSuccessful() && stopOnError) {
         result.setStopTest(true);
       }
       return result;
     } catch (Throwable t) {
       SampleResult errorResult = new SampleResult();
       errorResult.setSuccessful(false);
       errorResult.setStopTest(stopOnError);
       String message =
           "Unexpected exception during test execution: "
               + t
               + " (sampler "
               + getClass().getSimpleName()
               + ")";
       errorResult.setResponseMessage(message);
       logError(message, t);
       return errorResult;
     }
   }
 }
コード例 #2
0
 /**
  * ********************************************************** !ToDoo (Method description)
  *
  * @param response !ToDo (Parameter description)
  * @return !ToDo (Return description) *********************************************************
  */
 public AssertionResult getResult(SampleResult response) {
   AssertionResult result;
   if (!response.isSuccessful()) {
     result = new AssertionResult();
     result.setError(true);
     result.setFailureMessage(new String((byte[]) response.getResponseData()));
     return result;
   }
   result = evaluateResponse(response);
   return result;
 }
コード例 #3
0
ファイル: BeanShellAssertion.java プロジェクト: zioda/Lab7ORW
  /** {@inheritDoc} */
  @Override
  public AssertionResult getResult(SampleResult response) {
    AssertionResult result = new AssertionResult(getName());

    final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
    if (bshInterpreter == null) {
      result.setFailure(true);
      result.setError(true);
      result.setFailureMessage("BeanShell Interpreter not found");
      return result;
    }
    try {

      // Add SamplerData for consistency with BeanShell Sampler
      bshInterpreter.set("SampleResult", response); // $NON-NLS-1$
      bshInterpreter.set("Response", response); // $NON-NLS-1$
      bshInterpreter.set("ResponseData", response.getResponseData()); // $NON-NLS-1$
      bshInterpreter.set("ResponseCode", response.getResponseCode()); // $NON-NLS-1$
      bshInterpreter.set("ResponseMessage", response.getResponseMessage()); // $NON-NLS-1$
      bshInterpreter.set("ResponseHeaders", response.getResponseHeaders()); // $NON-NLS-1$
      bshInterpreter.set("RequestHeaders", response.getRequestHeaders()); // $NON-NLS-1$
      bshInterpreter.set("SampleLabel", response.getSampleLabel()); // $NON-NLS-1$
      bshInterpreter.set("SamplerData", response.getSamplerData()); // $NON-NLS-1$
      bshInterpreter.set("Successful", response.isSuccessful()); // $NON-NLS-1$

      // The following are used to set the Result details on return from
      // the script:
      bshInterpreter.set("FailureMessage", ""); // $NON-NLS-1$ //$NON-NLS-2$
      bshInterpreter.set("Failure", false); // $NON-NLS-1$

      processFileOrScript(bshInterpreter);

      result.setFailureMessage(bshInterpreter.get("FailureMessage").toString()); // $NON-NLS-1$
      result.setFailure(
          Boolean.parseBoolean(
              bshInterpreter
                  .get("Failure") // $NON-NLS-1$
                  .toString()));
      result.setError(false);
    }
    /*
     * To avoid class loading problems when the BSH jar is missing, we don't
     * try to catch this error separately catch (bsh.EvalError ex) {
     * log.debug("",ex); result.setError(true);
     * result.setFailureMessage(ex.toString()); }
     */
    // but we do trap this error to make tests work better
    catch (NoClassDefFoundError ex) {
      log.error("BeanShell Jar missing? " + ex.toString());
      result.setError(true);
      result.setFailureMessage("BeanShell Jar missing? " + ex.toString());
      response.setStopThread(true); // No point continuing
    } catch (Exception ex) // Mainly for bsh.EvalError
    {
      result.setError(true);
      result.setFailureMessage(ex.toString());
      log.warn(ex.toString());
    }

    return result;
  }