deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Christophe Counio <jean-christophe.cou...@oracle.com>
Subject JerseyTest mock support
Date Tue, 03 Feb 2015 01:18:42 GMT
Hi,

Anyone successfully integrated JerseyTest with mocks using deltaspike ?
When I activate deltaspike.testcontrol.mock-support.allow_mocked_beans=true, I have the following
error :

org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope
type javax.enterprise.context.RequestScoped
	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:687)
	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:79)
	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99)
	at org.jboss.weld.proxies.DynamicMockManager$1777947725$Proxy$_$$_WeldClientProxy.getMock(Unknown
Source)
	at org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:149)
	at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:98)
	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:78)
	at com.test.simplerest.PingResource$Proxy$_$$_WeldClientProxy.ping(Unknown Source)

The test is like this :
@RunWith(CdiTestRunner.class)
public class PingResourceTest extends JerseyTest {
    
    @Inject
    ApplicationMockManager applicationMockManager;
    
    MyInj injMock = EasyMock.createMock(MockType.NICE, MyInj.class);
    
    @Override
    protected Application configure() {
        return new MyApp();
    }
    
    @Test
    public void testPing() {
        applicationMockManager.addMock(injMock); //no behavior set so it should return null
        String resp = target("/ping").request().get(String.class);
        Assert.assertEquals("Ping", “null", resp);
    }    
}

I tried to play with @TestControl but there’s no changes.

Thanks

JC


Mime
View raw message