Search in sources :

Example 81 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project Payara by payara.

the class ACCJCDIServiceImpl method injectManagedObject.

@Override
public <T> void injectManagedObject(T managedObject, BundleDescriptor bundle) {
    WeldContainer wc = getWeldContainer();
    if (wc != null) {
        BeanManager beanManager = wc.getBeanManager();
        @SuppressWarnings("unchecked") AnnotatedType<T> annotatedType = beanManager.createAnnotatedType((Class<T>) managedObject.getClass());
        InjectionTarget<T> target = beanManager.createInjectionTarget(annotatedType);
        CreationalContext<T> cc = beanManager.createCreationalContext(null);
        target.inject(managedObject, cc);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 82 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project Payara by payara.

the class WeldContextListenerTest method testcontextInitialized.

@Test
public void testcontextInitialized() throws Exception {
    EasyMockSupport mockSupport = new EasyMockSupport();
    ELResolver elResolver = mockSupport.createMock(ELResolver.class);
    ExpressionFactory expressionFactory = mockSupport.createMock(ExpressionFactory.class);
    StandardContext servletContext = new StandardContext();
    servletContext.getServletContext();
    ServletContextEvent servletContextEvent = mockSupport.createMock(ServletContextEvent.class);
    BeanManager beanManager = mockSupport.createMock(BeanManager.class);
    JspApplicationContextImpl jspApplicationContext = new JspApplicationContextImpl(servletContext);
    expect(beanManager.getELResolver()).andReturn(elResolver);
    expect(beanManager.wrapExpressionFactory(isA(ExpressionFactory.class))).andReturn(expressionFactory);
    mockSupport.replayAll();
    WeldContextListener weldContextListener = getWeldContextListener(beanManager, jspApplicationContext);
    weldContextListener.contextInitialized(servletContextEvent);
    assertSame(expressionFactory, jspApplicationContext.getExpressionFactory());
    validateJspApplicationContext(jspApplicationContext, elResolver);
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) ELResolver(javax.el.ELResolver) ExpressionFactory(javax.el.ExpressionFactory) JspApplicationContextImpl(org.apache.jasper.runtime.JspApplicationContextImpl) StandardContext(org.apache.catalina.core.StandardContext) BeanManager(javax.enterprise.inject.spi.BeanManager) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 83 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project Payara by payara.

the class WeldContextListenerTest method testcontextDestroyed.

@Test
public void testcontextDestroyed() throws Exception {
    EasyMockSupport mockSupport = new EasyMockSupport();
    BeanManager beanManager = mockSupport.createMock(BeanManager.class);
    mockSupport.replayAll();
    WeldContextListener weldContextListener = getWeldContextListener(beanManager, null);
    Class<?> clazz = LocalWeldContextListener.class.getSuperclass();
    Field beanManagerField = clazz.getDeclaredField("beanManager");
    beanManagerField.setAccessible(true);
    assertNotNull(beanManagerField.get(weldContextListener));
    weldContextListener.contextDestroyed(null);
    assertNull(beanManagerField.get(weldContextListener));
    mockSupport.verifyAll();
    mockSupport.resetAll();
}
Also used : Field(java.lang.reflect.Field) EasyMockSupport(org.easymock.EasyMockSupport) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.junit.Test)

Aggregations

BeanManager (javax.enterprise.inject.spi.BeanManager)83 Bean (javax.enterprise.inject.spi.Bean)34 Test (org.junit.Test)16 NamingException (javax.naming.NamingException)7 Annotation (java.lang.annotation.Annotation)6 ArrayList (java.util.ArrayList)6 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)6 CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)6 CreationalContext (javax.enterprise.context.spi.CreationalContext)5 InitialContext (javax.naming.InitialContext)5 ValidatorFactory (javax.validation.ValidatorFactory)5 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)5 HashMap (java.util.HashMap)4 Set (java.util.Set)4 TransactionManager (javax.transaction.TransactionManager)4 ContextControl (org.apache.deltaspike.cdise.api.ContextControl)4 Type (java.lang.reflect.Type)3 Map (java.util.Map)3 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)3 Validator (javax.validation.Validator)3