Package org.jboss.arquillian.container.spi.context

Examples of org.jboss.arquillian.container.spi.context.DeploymentContext


    *
    * Activate DeploymentContext on all Deployment Events
    */
   public void createDeploymentContext(@Observes EventContext<DeploymentEvent> context)
   {
      DeploymentContext deploymentContext = this.deploymentContext.get();
      try
      {
         DeploymentEvent event = context.getEvent();
         deploymentContext.activate(event.getDeployment());

         context.proceed();
      }
      finally
      {
         deploymentContext.deactivate();
      }
   }
View Full Code Here


      return runInDeploymentContext(resource, qualifiers);
   }

   private Object runInDeploymentContext(ArquillianResource resource, Annotation... qualifiers)
   {
      DeploymentContext context = null;
      DeploymentScenario scenario = null;
      boolean activateContext = containsOperatesOnDeployment(qualifiers);
      boolean contextActivated = false;
      try
      {
         Deployment deployment = null;
         if(activateContext)
         {
            context = deploymentContext.get();
            scenario = deploymentScenario.get();
            if(scenario == null)
            {
               throw new IllegalStateException("No " + DeploymentScenario.class.getSimpleName() + " found. " +
                     "Possible cause, @" + OperateOnDeployment.class.getSimpleName() + " is currently only supported on the client side. (@" + RunAsClient.class.getSimpleName() + ")");
            }
            OperateOnDeployment operatesOn = getOperatesOnDeployment(qualifiers);
            deployment = scenario.deployment(new DeploymentTargetDescription(operatesOn.value()));
            if(deployment == null)
            {
               throw new IllegalArgumentException(
                     "Could not operate on deployment (@" + OperateOnDeployment.class.getSimpleName() + "), " +
                     "no deployment found with name: " + operatesOn.value());
            }
            context.activate(deployment);
            contextActivated = true;
         }
         return runInContainerContext(deployment == null ? null:deployment.getDescription().getTarget(), resource, qualifiers);
      }
      finally
      {
         if(contextActivated)
         {
            context.deactivate();
         }
      }
   }
View Full Code Here

      Mockito.when(scenario.deployment(new DeploymentTargetDescription("Z"))).thenReturn(deploymentZ);
      Mockito.when(scenario.deployment(new DeploymentTargetDescription("X"))).thenReturn(deploymentX);

      ContainerContext containerContext = getManager().getContext(ContainerContext.class);
      DeploymentContext deploymentContext = getManager().getContext(DeploymentContext.class);
      try
      {
         deploymentContext.activate(deploymentX);
         deploymentContext.getObjectStore().add(contextualType, innerType);
         deploymentContext.deactivate();

         /*
          *  deploymentZ is left active and should be handled as 'current'.
          *  The test is to see if the Enricher with Qualifier can activate/deactive and read from X
          */
         deploymentContext.activate(deploymentZ);
         deploymentContext.getObjectStore().add(contextualType, outerType);

         containerContext.activate("TEST");

         TestEnricher enricher = new ArquillianResourceTestEnricher();
         injector.get().inject(enricher);

         X test = enrichType.cast(enrichType.newInstance());
         enricher.enrich(test);

         return test;
      }
      catch (RuntimeException e)
      {
         throw (Exception)e.getCause();
      }
      finally
      {
         if(deploymentContext.isActive())
         {
            Deployment activeContext = deploymentContext.getActiveId();
            if(!"Z".equals(activeContext.getDescription().getName()))
            {
               Assert.fail("Wrong deployment context active, potential leak in Enricher. Active context was " + activeContext.getDescription().getName());
            }
         }
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.container.spi.context.DeploymentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.