Ejemplo n.º 1
0
 private Machine createMachine(MachineConfiguration machineConfiguration) {
   Collection<Context> contexts = createContexts(machineConfiguration);
   Machine machine = new SimpleMachine(contexts);
   for (Context context : machine.getContexts()) {
     if (context instanceof Observer) {
       machine.addObserver((Observer) context);
     }
   }
   return machine;
 }
Ejemplo n.º 2
0
 private void updateResult(Result result, Machine machine) {
   int completed = 0, failed = 0, notExecuted = 0, incomplete = 0;
   for (Context context : machine.getContexts()) {
     switch (context.getExecutionStatus()) {
       case COMPLETED:
         {
           completed++;
         }
         break;
       case FAILED:
         {
           failed++;
         }
         break;
       case NOT_EXECUTED:
         {
           notExecuted++;
         }
         break;
       case EXECUTING:
         {
           incomplete++;
         }
     }
   }
   result.setCompletedCount(completed);
   result.setFailedCount(failed);
   result.setNotExecutedCount(notExecuted);
   result.setIncompleteCount(incomplete);
   for (MachineException exception : getFailures()) {
     result.addError(getStackTrace(exception.getCause()));
   }
 }
Ejemplo n.º 3
0
 @Override
 public Result execute(boolean ignoreErrors) {
   result = new Result(machine.getContexts().size());
   executeAnnotation(BeforeExecution.class, machine);
   try {
     Context context = null;
     while (machine.hasNextStep()) {
       if (null != context) {
         executeAnnotation(BeforeElement.class, context);
       }
       context = machine.getNextStep();
       executeAnnotation(AfterElement.class, context);
     }
   } catch (MachineException e) {
     failures.put(e.getContext(), e);
   }
   executeAnnotation(AfterExecution.class, machine);
   updateResult(result, machine);
   if (!ignoreErrors && !failures.isEmpty()) {
     throw new TestExecutionException("Test execution contains failures");
   }
   return result;
 }
Ejemplo n.º 4
0
 private void executeAnnotation(Class<? extends Annotation> annotation, Machine machine) {
   for (Context context : machine.getContexts()) {
     executeAnnotation(annotation, context);
   }
 }