Search in sources :

Example 1 with BundleContextBeanQualifier

use of org.apache.aries.cdi.test.interfaces.BundleContextBeanQualifier in project aries by apache.

the class CdiBeanTests method testBundleContextInjection.

public void testBundleContextInjection() throws Exception {
    BeanManager beanManager = cdiContainer.getBeanManager();
    assertNotNull(beanManager);
    @SuppressWarnings("serial") Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<BundleContextBeanQualifier>() {
    });
    Bean<?> bean = beanManager.resolve(beans);
    CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
    Object bcb = beanManager.getReference(bean, Object.class, ctx);
    assertNotNull(bcb);
    @SuppressWarnings("unchecked") BeanService<BundleContext> bti = (BeanService<BundleContext>) bcb;
    assertNotNull(bti.get());
    assertTrue(bti.get() instanceof BundleContext);
}
Also used : BundleContextBeanQualifier(org.apache.aries.cdi.test.interfaces.BundleContextBeanQualifier) BeanManager(javax.enterprise.inject.spi.BeanManager) BeanService(org.apache.aries.cdi.test.interfaces.BeanService) Bean(javax.enterprise.inject.spi.Bean) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 BeanService (org.apache.aries.cdi.test.interfaces.BeanService)1 BundleContextBeanQualifier (org.apache.aries.cdi.test.interfaces.BundleContextBeanQualifier)1 BundleContext (org.osgi.framework.BundleContext)1