use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class InterceptorLookup method resolveInterceptors.
protected List<Interceptor<?>> resolveInterceptors(Object instance, Method method) {
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
Annotation[] interceptorBindings = extractInterceptorBindings(beanManager, instance, method);
if (interceptorBindings.length > 0) {
return beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, interceptorBindings);
}
return new ArrayList<Interceptor<?>>();
}
use of javax.enterprise.inject.spi.BeanManager in project aries by apache.
the class OSGiBeanDescriptorTests method testReferences.
@SuppressWarnings("serial")
public void testReferences() throws Exception {
Bundle tb1Bundle = installBundle("tb1.jar");
Bundle tb2Bundle = installBundle("tb2.jar");
CdiContainer cdiContainer = waitForCdiContainer(tb1Bundle.getBundleId());
try {
BeanManager beanManager = cdiContainer.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans("beanimpl");
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
BeanService<?> beanService = (BeanService<?>) beanManager.getReference(bean, new TypeLiteral<BeanService<?>>() {
}.getType(), ctx);
assertNotNull(beanService);
assertEquals("POJO-IMPLBEAN-IMPL", beanService.doSomething());
} finally {
tb2Bundle.uninstall();
tb1Bundle.uninstall();
}
}
use of javax.enterprise.inject.spi.BeanManager in project aries by apache.
the class ConfigurationTests method testNamedConfiguration.
@SuppressWarnings({ "unchecked", "serial" })
public void testNamedConfiguration() throws Exception {
Bundle tb3Bundle = installBundle("tb3.jar");
Configuration configurationA = null, configurationB = null;
try {
configurationA = configurationAdmin.getConfiguration("configA", "?");
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("ports", new int[] { 12, 4567 });
configurationA.update(properties);
configurationB = configurationAdmin.getConfiguration("configB", "?");
properties = new Hashtable<>();
properties.put("color", "green");
properties.put("ports", new int[] { 80 });
configurationB.update(properties);
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=CREATED))");
ServiceTracker<CdiContainer, CdiContainer> st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
CdiContainer container = st.waitForService(timeout);
assertNotNull(container);
int t = st.getTrackingCount();
BeanManager beanManager = container.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans("configB");
assertNotNull(beans);
Bean<? extends Object> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Map<String, Object> config = (Map<String, Object>) beanManager.getReference(bean, new TypeLiteral<Map<String, Object>>() {
}.getType(), ctx);
assertNotNull(config);
assertEquals("green", config.get("color"));
assertArrayEquals(new int[] { 80 }, (int[]) config.get("ports"));
configurationA.delete();
while (t == st.getTrackingCount()) {
Thread.sleep(10);
}
assertTrue(st.isEmpty());
st.close();
filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=" + CdiEvent.Type.WAITING_FOR_CONFIGURATIONS + "))");
st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
assertFalse(st.isEmpty());
} finally {
if (configurationB != null) {
try {
configurationB.delete();
} catch (Exception e) {
// ignore
}
}
tb3Bundle.uninstall();
}
}
use of javax.enterprise.inject.spi.BeanManager in project aries by apache.
the class EventsTests method testEventsGetSent.
public void testEventsGetSent() throws Exception {
BeanManager beanManager = cdiContainer.getBeanManager();
assertNotNull(beanManager);
@SuppressWarnings("serial") Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<CdiEventObserverQualifier>() {
});
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Object bcb = beanManager.getReference(bean, Object.class, ctx);
assertNotNull(bcb);
@SuppressWarnings("unchecked") BeanService<List<CdiEvent>> bti = (BeanService<List<CdiEvent>>) bcb;
List<CdiEvent> list = bti.get();
assertNotNull(list);
assertEquals(3, list.size());
}
use of javax.enterprise.inject.spi.BeanManager in project aries by apache.
the class JndiExtensionTests method testGetBeanManagerThroughJNDI.
public void testGetBeanManagerThroughJNDI() throws Exception {
Hashtable<String, Object> env = new Hashtable<>();
env.put(JNDIConstants.BUNDLE_CONTEXT, cdiBundle.getBundleContext());
InitialContext context = new InitialContext(env);
BeanManager beanManager = (BeanManager) context.lookup("java:comp/BeanManager");
assertNotNull(beanManager);
assertPojoExists(beanManager);
}
Aggregations