Package javax.enterprise.inject.spi

Examples of javax.enterprise.inject.spi.Bean


    }

   @Test
   public void testSimpleInterceptor()
   {
      Bean bean = beanManager.getBeans(SimpleBeanImpl.class).iterator().next();
      CreationalContext creationalContext = beanManager.createCreationalContext(bean);
      SimpleBeanImpl simpleBean = (SimpleBeanImpl) bean.create(creationalContext);
      String result = simpleBean.doSomething();
      assert "decorated-Hello!-decorated".equals(result);
      bean.destroy(simpleBean, creationalContext);
      assert SimpleInterceptor.aroundInvokeCalled;
      assert !SimpleInterceptor.postConstructCalled;
      assert !SimpleInterceptor.preDestroyCalled;
      assert TwoBindingsInterceptor.aroundInvokeCalled;
      assert SimpleBeanImpl.postConstructCalled;
View Full Code Here


   }

   @Test
   public void testSimpleInterceptorWithStereotype()
   {
      Bean bean = beanManager.getBeans(SimpleBeanWithStereotype.class).iterator().next();
      CreationalContext creationalContext = beanManager.createCreationalContext(bean);
      SimpleBeanWithStereotype simpleBean = (SimpleBeanWithStereotype) bean.create(creationalContext);
      String result = simpleBean.doSomething();
      assert "Hello!".equals(result);
      bean.destroy(simpleBean, creationalContext);
      assert SimpleInterceptor.aroundInvokeCalled;
      assert SimpleInterceptor.postConstructCalled;
      assert SimpleInterceptor.preDestroyCalled;
      assert TwoBindingsInterceptor.aroundInvokeCalled;
      assert SimpleBeanWithStereotype.postConstructCalled;
View Full Code Here

    }

    @Test
    @SuppressWarnings("unchecked")
    public void testLifecycleInterceptor() {
        Bean bean = beanManager.getBeans(Marathon.class).iterator().next();
        CreationalContext creationalContext = beanManager.createCreationalContext(bean);
        Marathon m = (Marathon) bean.create(creationalContext);

        Assert.assertTrue(LifecycleInterceptor.isPostConstructCalled());
        Assert.assertEquals(42, m.getLength());
        bean.destroy(m, creationalContext);
        Assert.assertTrue(LifecycleInterceptor.isPreDestroyCalled());
    }
View Full Code Here

    private BeanManager beanManager;

    @Test
    @Ignore // requires Module CL resolution
    public void testPassivationAndActivation() throws Exception {
        Bean bean = beanManager.getBeans(Ball.class).iterator().next();
        CreationalContext creationalContext = beanManager.createCreationalContext(bean);

        PassivationActivationInterceptor.initialMessage = "Goal!";

        Ball ball = (Ball) bean.create(creationalContext);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        new ObjectOutputStream(byteArrayOutputStream).writeObject(ball);

        PassivationActivationInterceptor oldInterceptor = PassivationActivationInterceptor.instance;
View Full Code Here

    private BeanManager beanManager;

    @Test
    public void testSimpleInterceptor() {
        reset();
        Bean bean = beanManager.getBeans(Ball.class).iterator().next();
        CreationalContext creationalContext = beanManager.createCreationalContext(bean);
        Ball ball = (Ball) bean.create(creationalContext);
        ball.shoot();
        assert Defender.defended;
        assert Ball.played;
        assert !Goalkeeper.caught;
        assert Ball.aroundInvoke;
View Full Code Here


    @Test
    public void testSimpleInterceptor2() {
        reset();
        Bean bean = beanManager.getBeans(Ball.class).iterator().next();
        CreationalContext creationalContext = beanManager.createCreationalContext(bean);
        Ball ball = (Ball) bean.create(creationalContext);
        ball.pass();
        assert Defender.defended;
        assert Ball.played;
        assert Goalkeeper.caught;
        assert Ball.aroundInvoke;
View Full Code Here

    }

    @Test
    public void testSimpleInterceptor3() {
        reset();
        Bean bean = beanManager.getBeans(Ball.class).iterator().next();
        CreationalContext creationalContext = beanManager.createCreationalContext(bean);
        Ball ball = (Ball) bean.create(creationalContext);
        ball.lob();
        assert !Defender.defended;
        assert Ball.played;
        assert Goalkeeper.caught;
        assert Ball.aroundInvoke;
View Full Code Here

        final String name;

        if (contextual instanceof Bean)
        {
            Bean bean = (Bean) contextual;
            name = bean.getBeanClass().getSimpleName();
        }
        else
        {
            name = "unknown";
        }
View Full Code Here

        final String name;

        if (contextual instanceof Bean)
        {
            Bean bean = (Bean) contextual;
            name = bean.getBeanClass().getSimpleName();
        }
        else
        {
            name = "unknown";
        }
View Full Code Here


    public static <T> T getBeanByType(Class<T> type) {

        BeanManager bm = getBeanManager();
        Bean bean = bm.getBeans(type).iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean); // could be inlined below
        T o = (T) bm.getReference(bean, type, ctx); // could be inlined with return
        return o;
    }
View Full Code Here

TOP

Related Classes of javax.enterprise.inject.spi.Bean

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.