Package org.jboss.kernel.spi.dependency

Examples of org.jboss.kernel.spi.dependency.KernelControllerContext


   }

   protected KernelControllerContext getControllerContext(final Object name, final ControllerState state)
   {
      Controller controller;
      KernelControllerContext context;
      try
      {
         controller = new TestController((AbstractController)kernel.getController());
         context = (KernelControllerContext)controller.getContext(name, state);
      }
View Full Code Here


            pojo = (POJO) getBean("Intercepted");
            fail("Bean should not be installed until the dependency is");
         }
         catch (IllegalStateException expected)
         {
            KernelControllerContext context = getControllerContext("Intercepted", ControllerState.DESCRIBED);
            assertNotNull(context);
         }
  
         deploy(getFile0());
         try
         {
            validate();
            Dependency dependency = (Dependency) getBean("Dependency");
            assertNotNull(dependency);
            pojo = (POJO) getBean("Intercepted");
            assertNotNull(pojo);
            TestAspectWithDependency.invoked = null;
            TestInterceptor.invoked = false;
            pojo.method(2);
            assertTrue(dependency == TestAspectWithDependency.invoked);
            assertTrue(TestInterceptor.invoked);
         }
         finally
         {
            undeploy(getFile0());
         }
        
         try
         {
            pojo = (POJO) getBean("Intercepted");
            fail("Bean should not be installed after the dependency is undeployed");
         }
         catch (IllegalStateException expected)
         {
            KernelControllerContext context = getControllerContext("Intercepted", ControllerState.DESCRIBED);
            assertNotNull(context);
         }
  
        
         deploy(getFile0());
View Full Code Here

      return suite(CardinalityCallbackTestCase.class);
   }

   public void testCallback() throws Throwable
   {
      KernelControllerContext context = getControllerContext("testObject", ControllerState.NOT_INSTALLED);
      assertNull(context.getTarget());
      assertEquals(ControllerState.NOT_INSTALLED, context.getState());

      // move conetxt to change - triggering callback addition + cardinality dependency
      change(context, ControllerState.CREATE);
      CallbackTestObject injectee = (CallbackTestObject)context.getTarget();
      assertNotNull(injectee);
      assertNull(injectee.getTesterInterfaces());

      // install 1st - cardinality dependency not yet satisfied
      KernelControllerContext tester1 = getControllerContext("tester1", ControllerState.NOT_INSTALLED);
      assertNotNull(tester1);
      change(tester1, ControllerState.INSTALLED);

      assertNull(injectee.getTesterInterfaces());

      // install 1st - cardinality dependency now satisfied
      KernelControllerContext tester2 = getControllerContext("tester2", ControllerState.NOT_INSTALLED);
      assertNotNull(tester2);
      change(tester2, ControllerState.INSTALLED);

      // can be moved to installed
      change(context, ControllerState.INSTALLED);
      assertEquals(ControllerState.INSTALLED, context.getState());

      // collection should be there
      assertNotNull(injectee.getTesterInterfaces());
      assertEquals(2, injectee.getTesterInterfaces().size());

      // add another tester, should be injected as well
      KernelControllerContext tester3 = getControllerContext("tester3", ControllerState.NOT_INSTALLED);
      assertNotNull(tester3);
      change(tester3, ControllerState.INSTALLED);

      assertNotNull(injectee.getTesterInterfaces());
      assertEquals(3, injectee.getTesterInterfaces().size());
View Full Code Here

         bean.setMode(ControllerMode.MANUAL);
         DemandMetaData demand = new AbstractDemandMetaData("foobar");
         ((AbstractDemandMetaData)demand).setWhenRequired(ControllerState.INSTANTIATED);
         bean.setDemands(Collections.singleton(demand));

         KernelControllerContext beanContext = controller.install(bean);
         controller.change(beanContext, ControllerState.NOT_INSTALLED);

         ModifiedLazyMetaData lazy = new ModifiedLazyMetaData("bean", getFactoryClassName());
         lazy.setInterfaces(Collections.singleton(IRare.class.getName()));
         KernelControllerContext lazyContext = controller.install(lazy);

         assertNotNull(lazyContext);
         assertEquals(ControllerState.INSTALLED, lazyContext.getState());

         controller.change(beanContext, ControllerState.DESCRIBED);
         controller.change(lazyContext, ControllerState.INSTALLED);

         IRare lazyRare = (IRare)lazyContext.getTarget();
         assertNotNull(lazyRare);

         try
         {
            lazyRare.getHits();
            throw new RuntimeException("Should not be here.");
         }
         catch(Throwable t)
         {
            assertInstanceOf(t, IllegalArgumentException.class);
         }

         controller.install(new AbstractBeanMetaData("foobar", Object.class.getName()));
         controller.change(beanContext, ControllerState.INSTALLED);

         assertEquals(0, lazyRare.getHits());
         lazyRare.setHits(10);
         assertEquals(5, lazyRare.checkHits(15));

         controller.uninstall(beanContext.getName());
         assertEquals(ControllerState.DESCRIBED, lazyContext.getState());
      }
      finally
      {
         controller.shutdown();
      }
View Full Code Here

      KernelController controller = kernel.getController();
      try
      {
         AbstractBeanMetaData bean = new AbstractBeanMetaData("bean", RareBean.class.getName());
         bean.setMode(ControllerMode.ON_DEMAND);
         KernelControllerContext beanContext = controller.install(bean);

         ModifiedLazyMetaData lazy = new ModifiedLazyMetaData("bean", getFactoryClassName());
         lazy.setInterfaces(Collections.singleton(IRare.class.getName()));
         KernelControllerContext lazyContext = controller.install(lazy);
         assertNotNull(lazyContext);
         assertEquals(ControllerState.INSTALLED, lazyContext.getState());

         IRare lazyRare = (IRare)lazyContext.getTarget();
         assertNotNull(lazyRare);

         // should not be fully installed yet
         assertEquals(ControllerState.DESCRIBED, beanContext.getState());
         assertEquals(0, lazyRare.getHits());
         // the hit should install it
         assertEquals(ControllerState.INSTALLED, beanContext.getState());

         lazyRare.setHits(10);
         assertEquals(5, lazyRare.checkHits(15));

         controller.uninstall(beanContext.getName());
         assertEquals(ControllerState.DESCRIBED, lazyContext.getState());
      }
      finally
      {
         controller.shutdown();
      }
View Full Code Here

      return suite(BadCardinalityCallbackTestCase.class);
   }

   public void testCallback() throws Throwable
   {
      KernelControllerContext context = getControllerContext("testObject", ControllerState.NOT_INSTALLED);
      assertNull(context.getTarget());
      assertEquals(ControllerState.NOT_INSTALLED, context.getState());

      change(context, ControllerState.CREATE);
      CallbackTestObject injectee = (CallbackTestObject)context.getTarget();
      assertNotNull(injectee);
      assertNull(injectee.getTesterInterfaces());

      KernelControllerContext tester1 = getControllerContext("tester1", ControllerState.NOT_INSTALLED);
      assertNotNull(tester1);
      change(tester1, ControllerState.INSTALLED);

      assertEquals(ControllerState.CONFIGURED, context.getState());
      assertNull(injectee.getTesterInterfaces());

      KernelControllerContext tester2 = getControllerContext("tester2", ControllerState.NOT_INSTALLED);
      assertNotNull(tester2);
      change(tester2, ControllerState.INSTALLED);

      change(context, ControllerState.INSTALLED);
      assertNull(injectee.getTesterInterfaces());
View Full Code Here

            pojo = (POJO) getBean("Intercepted");
            fail("Bean should not be installed until the dependency is");
         }
         catch (IllegalStateException expected)
         {
            KernelControllerContext context = getControllerContext("Intercepted", ControllerState.DESCRIBED);
            assertNotNull(context);
         }
  
         deploy(getFile0());
         try
         {
            validate();
            Dependency dependency = (Dependency) getBean("Dependency");
            assertNotNull(dependency);
            pojo = (POJO) getBean("Intercepted");
            assertNotNull(pojo);
            pojo.method(2);
            assertTrue(dependency == TestInterceptorWithDependency.invoked);
         }
         finally
         {
            undeploy(getFile0());
         }
        
         try
         {
            pojo = (POJO) getBean("Intercepted");
            fail("Bean should not be installed after the dependency is undeployed");
         }
         catch (IllegalStateException expected)
         {
            KernelControllerContext context = getControllerContext("Intercepted", ControllerState.DESCRIBED);
            assertNotNull(context);
         }
  
        
         deploy(getFile0());
View Full Code Here

   public void testAfterInstantiationBeanInfo() throws Throwable
   {
      KernelController controller = getController();
      // other
      KernelControllerContext occ = controller.install(new AbstractBeanMetaData("other", OtherVerifier.class.getName()));
      assertNotNull(occ);
      Object tcc = occ.getTarget();
      assertNotNull(tcc);

      // tester
      AbstractBeanMetaData abmd = new AbstractBeanMetaData();
      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(abmd);
      builder.setName("tester");
      builder.setAccessMode(BeanAccessMode.ALL);
      builder.setFactoryClass(AfterInstantiateTester.class.getName());
      builder.setFactoryMethod("getTester");

      KernelControllerContext kcc = controller.install(builder.getBeanMetaData());
      try
      {
         assertNotNull(kcc);
         BeanMetaData beanMetaData = kcc.getBeanMetaData();
         // test aliases
         assertNotNull(controller.getContext("qwert", null));
         // propertys
         Set<PropertyMetaData> properties = beanMetaData.getProperties();
         assertNotNull(properties);
         assertEquals(2, properties.size());
         // lifecycle
         LifecycleMetaData create = beanMetaData.getCreate();
         assertNotNull(create);
         assertEquals("createMe", create.getMethodName());
         LifecycleMetaData start = beanMetaData.getStart();
         assertNotNull(start);
         assertEquals("startMe", start.getMethodName());
         LifecycleMetaData stop = beanMetaData.getStop();
         assertNotNull(stop);
         assertEquals("stopMe", stop.getMethodName());
         LifecycleMetaData destroy = beanMetaData.getDestroy();
         assertNotNull(destroy);
         assertEquals("destroyMe", destroy.getMethodName());
         // callbacks
         List<CallbackMetaData> incallbacks = beanMetaData.getInstallCallbacks();
         assertNotNull(incallbacks);
         assertEquals(2, incallbacks.size());
         List<CallbackMetaData> uncallbacks = beanMetaData.getUninstallCallbacks();
         assertNotNull(uncallbacks);
         assertEquals(2, uncallbacks.size());
         // installs
         List<InstallMetaData> installs = beanMetaData.getInstalls();
         assertNotNull(installs);
         assertEquals(2, installs.size());
         List<InstallMetaData> uninstalls = beanMetaData.getUninstalls();
         assertNotNull(uninstalls);
         assertEquals(2, uninstalls.size());

         Object tkcc = kcc.getTarget();
         assertNotNull(tkcc);
         AfterInstantiateTester tester = assertInstanceOf(tkcc, AfterInstantiateTester.class);
         assertTrue(tester.time != 0);
      }
      finally
      {
         controller.uninstall(kcc.getName());
      }
   }
View Full Code Here

      String name = target != null ? target.toString() : (className + System.currentTimeMillis());
      AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, className);
      beanMetaData.setAccessMode(mode);
      try
      {
         KernelControllerContext context = controller.install(beanMetaData, target);
         checkContextState(clazz, context);
         if (target == null)
            target = clazz.cast(context.getTarget());
         doTestAfterInstall(clazz, target);
      }
      finally
      {
         controller.uninstall(name);
View Full Code Here

   protected SimpleAnnotation instantiateAnnotation(boolean replace) throws Throwable
   {
      XMLUtil util = bootstrapXML(true);
      KernelController controller = util.getKernel().getController();
      KernelControllerContext context = (KernelControllerContext)controller.getInstalledContext("MyBean" + (replace ? "Replace" : "Ignore"));
      BeanMetaData beanMetaData = context.getBeanMetaData();
      Set<AnnotationMetaData> annotations = beanMetaData.getAnnotations();
      assertNotNull(annotations);
      assertFalse(annotations.isEmpty());
      assertEquals(1, annotations.size());
      return (SimpleAnnotation)annotations.iterator().next().getAnnotationInstance();
View Full Code Here

TOP

Related Classes of org.jboss.kernel.spi.dependency.KernelControllerContext

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.