Thanks, yes that makes sense. If I comment the @RunWith (going to pure JerseyTest), the dependency injection doesn’t happen at all, so I was thinking Jersey recognize the test container in some way, but I can see now there are 2 different BeanManangers in application and tests. Any idea how to solve that issue ? Doing the same thing in Spring is 2 lines of code so I hope there’s way to do the same with CDI.
JC On Feb 3, 2015, at 3:13 PM, Gerhard Petracek <[email protected]> wrote: > hi jc, > > it doesn't work because jetty uses an own thread to answer the request and > therefore the cdi-container needs to be integrated properly > (the request-context needs to be active for every request answered by > jetty). > > just fyi: > CdiTestRunner just manages the current (test-)thread. > > regards, > gerhard > > http://www.irian.at > > Your JavaEE powerhouse - > JavaEE Consulting, Development and > Courses in English and German > > Professional Support for Apache > MyFaces, DeltaSpike and OpenWebBeans > > > > 2015-02-03 19:54 GMT+01:00 Gerhard Petracek <[email protected]>: > >> hi jc, >> >> ok - i'll have a look at it soon. >> >> regards, >> gerhard >> >> http://www.irian.at >> >> Your JavaEE powerhouse - >> JavaEE Consulting, Development and >> Courses in English and German >> >> Professional Support for Apache >> MyFaces, DeltaSpike and OpenWebBeans >> >> >> >> 2015-02-03 19:27 GMT+01:00 Jean-Christophe Counio < >> [email protected]>: >> >>> Hi, >>> >>> Here’s the link : >>> https://github.com/couniojc/jerseytest-cdi >>> >>> If you set >>> "deltaspike.testcontrol.mock-support.allow_mocked_beans=false”, you can run >>> PingResourceSimpleTest (no mocks in this one) >>> As soon as you set it to true, it throws the exception. >>> >>> Thanks >>> >>> JC >>> >>> >>> On Feb 3, 2015, at 12:29 AM, Gerhard Petracek <[email protected]> >>> wrote: >>> >>>> hi jc, >>>> >>>> please provide a link to a demo which illustrates the issue. >>>> >>>> regards, >>>> gerhard >>>> >>>> http://www.irian.at >>>> >>>> Your JavaEE powerhouse - >>>> JavaEE Consulting, Development and >>>> Courses in English and German >>>> >>>> Professional Support for Apache >>>> MyFaces, DeltaSpike and OpenWebBeans >>>> >>>> >>>> >>>> 2015-02-03 2:18 GMT+01:00 Jean-Christophe Counio < >>>> [email protected]>: >>>> >>>>> 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 >>>>> >>>>> >>> >>> >>
