Esempio n. 1
0
  @Override
  public void doExecute(TestContext context) {
    boolean success = true;

    testSuiteListener.onFinish();

    log.info("Executing " + actions.size() + " actions after suite");
    log.info("");

    for (TestAction action : actions) {
      try {
        /* Executing test action and validate its success */
        action.execute(context);
      } catch (Exception e) {
        log.error("After suite action failed " + action.getName() + "Nested exception is: ", e);
        log.error("Continue after suite actions");
        success = false;
      }
    }

    if (success) {
      testSuiteListener.onFinishSuccess();
    } else {
      testSuiteListener.onFinishFailure(new CitrusRuntimeException("Error in after suite"));
      throw new CitrusRuntimeException("Error in after suite");
    }
  }
 public void run() {
   if (afterSuite != null) {
     try {
       afterSuite.execute(context);
     } catch (Exception e) {
       throw new CitrusRuntimeException("After suite failed with errors", e);
     }
   } else {
     testSuiteListener.onFinish();
     testSuiteListener.onFinishSuccess();
   }
 }
  /**
   * @see
   *     org.springframework.test.context.support.AbstractTestExecutionListener#prepareTestInstance(org.springframework.test.context.TestContext)
   */
  @Override
  public void prepareTestInstance(TestContext testContext) throws Exception {
    synchronized (doneMonitor) {
      if (done) {
        return;
      } else {
        TestSuiteAwareExecutionListener.preparationDone();
      }

      ApplicationContext ctx = testContext.getApplicationContext();

      SequenceBeforeSuite beforeSuite = null;
      if (ctx.getBeansOfType(SequenceBeforeSuite.class).size() == 1) {
        beforeSuite = ctx.getBean(SequenceBeforeSuite.class);
      }

      SequenceAfterSuite afterSuite = null;
      if (ctx.getBeansOfType(SequenceAfterSuite.class).size() == 1) {
        afterSuite = ctx.getBean(SequenceAfterSuite.class);
      }

      com.consol.citrus.context.TestContext context =
          ctx.getBean(com.consol.citrus.context.TestContext.class);
      TestSuiteListeners testSuiteListener = ctx.getBean(TestSuiteListeners.class);

      if (beforeSuite != null) {
        try {
          beforeSuite.execute(context);
        } catch (Exception e) {
          throw new CitrusRuntimeException("Before suite failed with errors", e);
        }
      } else {
        testSuiteListener.onStart();
        testSuiteListener.onStartSuccess();
      }

      Runtime.getRuntime()
          .addShutdownHook(
              new Thread(new AfterSuiteShutdownHook(afterSuite, context, testSuiteListener)));
    }
  }