use of org.jboss.weld.bean.WeldBean in project core by weld.
the class WeldInternalConstructsTest method testInterceptedProxiedBean.
@Test
public void testInterceptedProxiedBean() {
InterceptedProxiedBean interceptedBean = holder.getInterceptedProxiedBean();
// trigger interception and assert it works
Assert.assertTrue(interceptedBean.ping());
// should be instance of WeldConstruct and WeldClientProxy
Assert.assertTrue(interceptedBean instanceof WeldConstruct);
Assert.assertTrue(interceptedBean instanceof WeldClientProxy);
// cast to WeldClientProxy and test the methods
WeldClientProxy wcp = (WeldClientProxy) interceptedBean;
WeldClientProxy.Metadata cm = wcp.getMetadata();
Object contextualInstance = cm.getContextualInstance();
// kind of indirect check that this is the actual contextual instance
Assert.assertTrue(contextualInstance instanceof InterceptedProxiedBean);
Assert.assertFalse(contextualInstance instanceof WeldClientProxy);
// NOTE - contextual instance is still a Weld subclass because of interception/decoration
Assert.assertTrue(contextualInstance instanceof WeldConstruct);
Bean<?> bean = cm.getBean();
Set<Bean<?>> beans = bm.getBeans(InterceptedProxiedBean.class);
Assert.assertEquals(1, beans.size());
Assert.assertEquals(((WeldBean) beans.iterator().next()).getIdentifier().asString(), ((WeldBean) bean).getIdentifier().asString());
}
use of org.jboss.weld.bean.WeldBean in project core by weld.
the class AfterBeanDiscoveryImpl method processBeanRegistration.
private <T> void processBeanRegistration(BeanRegistration registration, GlobalEnablementBuilder globalEnablementBuilder) {
Bean<?> bean = registration.initBean();
BeanManagerImpl beanManager = registration.initBeanManager();
if (beanManager == null) {
// Get the bean manager for beans added via ABD#addBean()
beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager();
} else {
// Also validate the bean produced by a builder
ExternalBeanAttributesFactory.validateBeanAttributes(bean, getBeanManager());
validateBean(bean);
}
// Custom beans (alternatives, interceptors, decorators) may also implement javax.enterprise.inject.spi.Prioritized
Integer priority = (bean instanceof Prioritized) ? ((Prioritized) bean).getPriority() : null;
// if added via WeldBeanConfigurator, there might be a priority specified as well
if (priority == null && bean instanceof WeldBean) {
priority = ((WeldBean) bean).getPriority();
}
if (bean instanceof Interceptor<?>) {
beanManager.addInterceptor((Interceptor<?>) bean);
if (priority != null) {
globalEnablementBuilder.addInterceptor(bean.getBeanClass(), priority);
}
} else if (bean instanceof Decorator<?>) {
beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager));
if (priority != null) {
globalEnablementBuilder.addDecorator(bean.getBeanClass(), priority);
}
} else {
beanManager.addBean(bean);
if (priority != null && bean.isAlternative()) {
globalEnablementBuilder.addAlternative(bean.getBeanClass(), priority);
}
}
containerLifecycleEvents.fireProcessBean(beanManager, bean, registration.extension);
}
use of org.jboss.weld.bean.WeldBean in project core by weld.
the class WeldInternalConstructsTest method testClientProxyBean.
@Test
public void testClientProxyBean() {
ClientProxyBean clientProxyBean = holder.getClientProxyBean();
// trigger proxy creation
clientProxyBean.ping();
// injected bean should be instance of WeldConstruct and WeldClientProxy
Assert.assertTrue(clientProxyBean instanceof WeldConstruct);
Assert.assertTrue(clientProxyBean instanceof WeldClientProxy);
// cast to WeldClientProxy and test the methods
WeldClientProxy wcp = (WeldClientProxy) clientProxyBean;
WeldClientProxy.Metadata cm = wcp.getMetadata();
Object contextualInstance = cm.getContextualInstance();
// kind of indirect check that this is the actual contextual instance
Assert.assertTrue(contextualInstance instanceof ClientProxyBean);
Assert.assertFalse(contextualInstance instanceof WeldConstruct);
Bean<?> bean = cm.getBean();
Set<Bean<?>> beans = bm.getBeans(ClientProxyBean.class);
Assert.assertEquals(1, beans.size());
Assert.assertEquals(((WeldBean) beans.iterator().next()).getIdentifier().asString(), ((WeldBean) bean).getIdentifier().asString());
}
use of org.jboss.weld.bean.WeldBean in project core by weld.
the class WeldInternalConstructsTest method testDecoratedProxiedBean.
@Test
public void testDecoratedProxiedBean() {
DecoratedProxiedBean decoratedBean = holder.getDecoratedProxiedBean();
// trigger decoration and assert it works
Assert.assertTrue(decoratedBean.ping());
// should be instance of WeldConstruct and WeldClientProxy
Assert.assertTrue(decoratedBean instanceof WeldConstruct);
Assert.assertTrue(decoratedBean instanceof WeldClientProxy);
// cast to WeldClientProxy and test the methods
WeldClientProxy wcp = (WeldClientProxy) decoratedBean;
WeldClientProxy.Metadata cm = wcp.getMetadata();
Object contextualInstance = cm.getContextualInstance();
// kind of indirect check that this is the actual contextual instance
Assert.assertTrue(contextualInstance instanceof DecoratedProxiedBean);
Assert.assertFalse(contextualInstance instanceof WeldClientProxy);
// NOTE - contextual instance is still a Weld subclass because of interception/decoration
Assert.assertTrue(contextualInstance instanceof WeldConstruct);
Bean<?> bean = cm.getBean();
Set<Bean<?>> beans = bm.getBeans(DecoratedProxiedBean.class);
Assert.assertEquals(1, beans.size());
Assert.assertEquals(((WeldBean) beans.iterator().next()).getIdentifier().asString(), ((WeldBean) bean).getIdentifier().asString());
}
Aggregations