示例#1
0
  private TestResult executeRemote(
      Test event, DeploymentDescription deployment, Container container) throws Exception {
    ProtocolRegistry protoReg = protocolRegistry.get();

    // if no default marked or specific protocol defined in the registry, use the
    // DeployableContainers defaultProtocol.
    ProtocolDefinition protocol = protoReg.getProtocol(deployment.getProtocol());
    if (protocol == null) {
      protocol = protoReg.getProtocol(container.getDeployableContainer().getDefaultProtocol());
    }

    ProtocolConfiguration protocolConfiguration;

    if (container.hasProtocolConfiguration(protocol.getProtocolDescription())) {
      protocolConfiguration =
          protocol.createProtocolConfiguration(
              container
                  .getProtocolConfiguration(protocol.getProtocolDescription())
                  .getProtocolProperties());
    } else {
      protocolConfiguration = protocol.createProtocolConfiguration();
    }
    // TODO: cast to raw type to get away from generic issue..
    ContainerMethodExecutor executor =
        ((Protocol) protocol.getProtocol())
            .getExecutor(protocolConfiguration, protocolMetadata.get());
    return executor.invoke(event.getTestMethodExecutor());
  }
示例#2
0
  public void execute(@Observes Test event) throws Exception {
    ContainerContext containerContext = containerContextProvider.get();
    DeploymentContext deploymentContext = deploymentContextProvider.get();

    // TODO : move as a abstract/SPI on TestMethodExecutor
    DeploymentTargetDescription target = null;
    if (event.getTestMethod().isAnnotationPresent(DeploymentTarget.class)) {
      target =
          new DeploymentTargetDescription(
              event.getTestMethod().getAnnotation(DeploymentTarget.class).value());
    } else {
      target = DeploymentTargetDescription.DEFAULT;
    }

    DeploymentScenario scenario = deploymentScenario.get();

    try {
      DeploymentDescription deployment = scenario.getDeployment(target);

      Container container = containerRegistry.get().getContainer(deployment.getTarget());
      containerContext.activate(container.getName());

      try {
        // TODO: split up local vs remote execution in two handlers, fire a new set of events
        // LocalExecute RemoteExecute
        deploymentContext.activate(deployment);
        if (scenario.getRunMode()
            == RunModeType
                .AS_CLIENT) // TODO: DeploymentScenario should not depend on RunModeType API
        {
          testResult.set(executeLocal(event));
        } else {
          testResult.set(executeRemote(event, deployment, container));
        }
      } finally {
        deploymentContext.deactivate();
      }
    } finally {
      containerContext.deactivate();
    }
  }
 public void verifyExpectedExceptionDuringDeploy(@Observes EventContext<DeployDeployment> context)
     throws Exception {
   DeploymentDescription deployment = context.getEvent().getDeployment();
   boolean deploymentExceptionThrown = true;
   try {
     context.proceed();
     if (deployment.getExpectedException() != null) {
       deploymentExceptionThrown = false;
       throw new RuntimeException(
           "Expected exception of type "
               + deployment.getExpectedException().getName()
               + " during deployment of "
               + deployment.getName()
               + ", but no exception was thrown.");
     }
   } catch (Exception e) {
     // if exception is not thrown from the deployment, rethrow it (we threw it).
     if (!deploymentExceptionThrown) {
       throw e;
     }
     if (deployment.getExpectedException() != null) {
       if (!containsType(transform(e), deployment.getExpectedException())) {
         throw e;
       }
     } else {
       throw e;
     }
   }
 }