Search in sources :

Example 1 with WeldClientProxy

use of org.jboss.weld.proxy.WeldClientProxy 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());
}
Also used : WeldBean(org.jboss.weld.bean.WeldBean) WeldClientProxy(org.jboss.weld.proxy.WeldClientProxy) WeldConstruct(org.jboss.weld.proxy.WeldConstruct) WeldBean(org.jboss.weld.bean.WeldBean) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 2 with WeldClientProxy

use of org.jboss.weld.proxy.WeldClientProxy 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());
}
Also used : WeldBean(org.jboss.weld.bean.WeldBean) WeldClientProxy(org.jboss.weld.proxy.WeldClientProxy) WeldConstruct(org.jboss.weld.proxy.WeldConstruct) WeldBean(org.jboss.weld.bean.WeldBean) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 3 with WeldClientProxy

use of org.jboss.weld.proxy.WeldClientProxy 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());
}
Also used : WeldBean(org.jboss.weld.bean.WeldBean) WeldClientProxy(org.jboss.weld.proxy.WeldClientProxy) WeldConstruct(org.jboss.weld.proxy.WeldConstruct) WeldBean(org.jboss.weld.bean.WeldBean) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Aggregations

Bean (javax.enterprise.inject.spi.Bean)3 WeldBean (org.jboss.weld.bean.WeldBean)3 WeldClientProxy (org.jboss.weld.proxy.WeldClientProxy)3 WeldConstruct (org.jboss.weld.proxy.WeldConstruct)3 Test (org.junit.Test)3