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);
}
}
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();
}
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();
}
Aggregations