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

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


    * Activate ContainerContext on all Container Events
    *
    */
   public void createContainerContext(@Observes EventContext<ContainerControlEvent> context)
   {
      ContainerContext containerContext = this.containerContext.get();
      ContainerControlEvent event = context.getEvent();

      try
      {
         containerContext.activate(event.getContainerName());
         context.proceed();
      }
      finally
      {
         containerContext.deactivate();
      }
   }
View Full Code Here


      }
   }

   private Object runInContainerContext(TargetDescription targetDescription, ArquillianResource resource, Annotation... qualifiers)
   {
      ContainerContext context = null;
      ContainerRegistry registry = null;
      boolean activateContext = targetDescription != null;
      boolean contextActivated = false;
      try
      {
         if(activateContext)
         {
            context = containerContext.get();
            registry = containerRegistry.get();
            if(registry == null)
            {
               throw new IllegalStateException("No " + ContainerRegistry.class.getSimpleName() + " found. " +
                     "Possible problem is, @" + OperateOnDeployment.class.getSimpleName() + " is currently only supported on the client side.");
            }
            Container container = registry.getContainer(targetDescription);
            if(container == null)
            {
               throw new IllegalArgumentException(
                     "Could not operate on deployment (@" + OperateOnDeployment.class.getSimpleName() + "), " +
                     "no container found with name: " + targetDescription);
            }
            context.activate(container.getName());
            contextActivated = true;
         }
         return doLookup(resource, qualifiers);
      }
      finally
      {
         if(contextActivated)
         {
            context.deactivate();
         }
      }
   }
View Full Code Here

                                                   .setTarget(new TargetDescription("X")));

      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());
            }
         }
         if(containerContext.isActive())
         {
            String activeContext = containerContext.getActiveId();
            if(!"TEST".equalsIgnoreCase(activeContext))
            {
               Assert.fail("Wrong container context active, potential leak in Enricher. Active context was " + activeContext);
            }
         }
View Full Code Here

TOP

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

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.