use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class OpenEJbContainerControlConfigurationTest method basicInjection.
@Test
public // useless because of tcks but nice to have when working on this specific container
void basicInjection() {
final CdiContainer container = CdiContainerLoader.getCdiContainer();
container.boot();
try {
final BeanManager beanManager = container.getBeanManager();
assertEquals("foo", Foo.class.cast(beanManager.getReference(beanManager.resolve(beanManager.getBeans(Foo.class)), Foo.class, null)).name());
} finally {
container.shutdown();
}
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class OpenWebBeansContainerControl method getContextControl.
@Override
public synchronized ContextControl getContextControl() {
if (ctxCtrl == null) {
BeanManager beanManager = getBeanManager();
if (beanManager == null) {
LOG.warning("If the CDI-container was started by the environment, you can't use this helper." + "Instead you can resolve ContextControl manually " + "(e.g. via BeanProvider.getContextualReference(ContextControl.class) ). " + "If the container wasn't started already, you have to use CdiContainer#boot before.");
return null;
}
Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
ctxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
ctxCtrlCreationalContext = getBeanManager().createCreationalContext(ctxCtrlBean);
ctxCtrl = (ContextControl) getBeanManager().getReference(ctxCtrlBean, ContextControl.class, ctxCtrlCreationalContext);
}
return ctxCtrl;
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class DynamicMBeanWrapper method instance.
private synchronized Object instance() {
final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classloader);
try {
if (instance != null) {
return instance;
}
if (normalScope) {
instance = BeanProvider.getContextualReference(clazz, qualifiers);
} else {
final BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
final Set<Bean<?>> beans = bm.getBeans(clazz, qualifiers);
if (beans == null || beans.isEmpty()) {
throw new IllegalStateException("Could not find beans for Type=" + clazz + " and qualifiers:" + Arrays.toString(qualifiers));
}
final Bean<?> resolvedBean = bm.resolve(beans);
final CreationalContext<?> creationalContext = bm.createCreationalContext(resolvedBean);
instance = bm.getReference(resolvedBean, clazz, creationalContext);
creationalContext.release();
}
return instance;
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class CdiTestRunner method createTest.
@Override
protected Object createTest() throws Exception {
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
Class<?> type = getTestClass().getJavaClass();
Set<Bean<?>> beans = beanManager.getBeans(type);
Object result;
if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty()) {
result = super.createTest();
//fallback to simple injection
BeanProvider.injectFields(result);
} else {
Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans);
CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);
result = beanManager.getReference(bean, type, creationalContext);
}
return result;
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class BeanManagerProviderTest method testBeanManagerProvider.
@Test
public void testBeanManagerProvider() throws Exception {
BeanManagerProvider bmp = BeanManagerProvider.getInstance();
Assert.assertNotNull(bmp);
BeanManager bm = bmp.getBeanManager();
Assert.assertNotNull(bm);
}
Aggregations