use of org.jboss.weld.proxy.WeldConstruct 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.proxy.WeldConstruct 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.proxy.WeldConstruct 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