hi remo, ds-test-control uses the same instance for @Before and @Test methods (per default). activating deltaspike.testcontrol.use_test_class_as_cdi_bean is the only known way to get the effect you described. (in that case you get dependent-scoped test-instances, >if< you don't specify a scope for the test-class.)
regards, gerhard 2016-08-17 16:28 GMT+02:00 Remo Meier <[email protected]>: > Hi Gerhard > > Thx. Seems that injection is working fine for normal JAX-RS Resources, but > not for JAX-RS Features. I will investigate this further. > > An other issue I have noticed that test classes get loaded twice by > openejb. The stack traces look like (1.7.1 version): > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner at localhost:52037 > Thread [main] (Suspended (entry into method <init> in BasicTest)) > BasicTest.<init>() line: 17 > NativeConstructorAccessorImpl.newInstance0(Constructor<?>, Object[]) > line: not available [native method] > NativeConstructorAccessorImpl.newInstance(Object[]) line: 62 > DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45 > Constructor<T>.newInstance(Object...) line: 408 > InjectableConstructor<T>.doInjection() line: 72 > InjectionTargetImpl<T>.newInstance(CreationalContextImpl<T>) line: 190 > InjectionTargetImpl<T>.produce(Map<Interceptor<?>,?>, > CreationalContextImpl<T>) line: 173 > InjectionTargetImpl<T>(AbstractProducer<T>).produce(CreationalContext<T>) > line: 172 > ManagedBean<T>(AbstractOwbBean<T>).create(CreationalContext<T>) line: 122 > ManagedBean<T>.create(CreationalContext<T>) line: 67 > DependentContext.getInstance(Contextual<T>, CreationalContext<T>) > line: 68 > DependentContext(AbstractContext).get(Contextual<T>, > CreationalContext<T>) line: 125 > BeanManagerImpl.getReference(Bean<?>, Type, CreationalContext<?>) > line: 789 > InjectableBeanManager.getReference(Bean<?>, Type, > CreationalContext<?>) line: 165 > CdiTestRunner.createTest() line: 203 > BlockJUnit4ClassRunner$1.runReflectiveCall() line: 266 > BlockJUnit4ClassRunner$1(ReflectiveCallable).run() line: 12 > CdiTestRunner(BlockJUnit4ClassRunner).methodBlock(FrameworkMethod) line: > 263 > CdiTestRunner(BlockJUnit4ClassRunner).runChild(FrameworkMethod, > RunNotifier) line: 78 > CdiTestRunner.runChild(FrameworkMethod, RunNotifier) line: 177 > CdiTestRunner.runChild(Object, RunNotifier) line: 76 > ParentRunner$3.run() line: 290 > ParentRunner$1.schedule(Runnable) line: 71 > CdiTestRunner(ParentRunner<T>).runChildren(RunNotifier) line: 288 > ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 58 > ParentRunner$2.evaluate() line: 268 > CdiTestRunner$BeforeClassStatement.evaluate() line: 372 > CdiTestRunner$AfterClassStatement.evaluate() line: 393 > CdiTestRunner(ParentRunner<T>).run(RunNotifier) line: 363 > CdiTestRunner.run(RunNotifier) line: 144 > JUnit4TestReference.run(TestExecution) line: 86 > TestExecution.run(ITestReference[]) line: 38 > RemoteTestRunner.runTests(String[], String, TestExecution) line: > 459 > RemoteTestRunner.runTests(TestExecution) line: 678 > RemoteTestRunner.run() line: 382 > RemoteTestRunner.main(String[]) line: 192 > Thread [ReaderThread] (Running) > Daemon Thread [LogStreamAsync.Thread] (Running) > Daemon Thread [RetryTimer] (Running) > > > and > > > Thread [main] (Suspended (entry into method <init> in BasicTest)) > BasicTest.<init>() line: 17 > NativeConstructorAccessorImpl.newInstance0(Constructor<?>, Object[]) > line: not available [native method] > NativeConstructorAccessorImpl.newInstance(Object[]) line: 62 > DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45 > Constructor<T>.newInstance(Object...) line: 408 > InjectableConstructor<T>.doInjection() line: 72 > InjectionTargetImpl<T>.newInstance(CreationalContextImpl<T>) line: 190 > InjectionTargetImpl<T>.produce(Map<Interceptor<?>,?>, > CreationalContextImpl<T>) line: 173 > InjectionTargetImpl<T>(AbstractProducer<T>).produce(CreationalContext<T>) > line: 172 > ManagedBean<T>(AbstractOwbBean<T>).create(CreationalContext<T>) line: 122 > ManagedBean<T>.create(CreationalContext<T>) line: 67 > DependentContext.getInstance(Contextual<T>, CreationalContext<T>) > line: 68 > DependentContext(AbstractContext).get(Contextual<T>, > CreationalContext<T>) line: 125 > BeanManagerImpl.getReference(Bean<?>, Type, CreationalContext<?>) > line: 789 > InjectableBeanManager.getReference(Bean<?>, Type, > CreationalContext<?>) line: 165 > CdiTestRunner$ContainerAwareMethodInvoker.evaluate() line: 326 > RunBefores.evaluate() line: 26 > RunAfters.evaluate() line: 27 > CdiTestRunner(ParentRunner<T>).runLeaf(Statement, Description, > RunNotifier) line: 325 > CdiTestRunner(BlockJUnit4ClassRunner).runChild(FrameworkMethod, > RunNotifier) line: 78 > CdiTestRunner.runChild(FrameworkMethod, RunNotifier) line: 177 > CdiTestRunner.runChild(Object, RunNotifier) line: 76 > ParentRunner$3.run() line: 290 > ParentRunner$1.schedule(Runnable) line: 71 > CdiTestRunner(ParentRunner<T>).runChildren(RunNotifier) line: 288 > ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 58 > ParentRunner$2.evaluate() line: 268 > CdiTestRunner$BeforeClassStatement.evaluate() line: 372 > CdiTestRunner$AfterClassStatement.evaluate() line: 393 > CdiTestRunner(ParentRunner<T>).run(RunNotifier) line: 363 > CdiTestRunner.run(RunNotifier) line: 144 > JUnit4TestReference.run(TestExecution) line: 86 > TestExecution.run(ITestReference[]) line: 38 > RemoteTestRunner.runTests(String[], String, TestExecution) line: 459 > RemoteTestRunner.runTests(TestExecution) line: 678 > RemoteTestRunner.run() line: 382 > RemoteTestRunner.main(String[]) line: 192 > > For example, @Before and @Test get called on different instances. It works > when I annotate the test class with @Singleton. Not sure about the > Deltaspike internals, but maybe @RunWith should imply @Singleton. I have > only seen this when using with Jersey. Maybe because it uses request > scoping by default and messes something up within deltaspike. > > Regards Remo > > > > Am 16.08.2016 um 15:00 schrieb Gerhard Petracek: > >> hi remo, >> >> if you would like to stick with tomee/openejb as well as with jersey, you >> need a setup which integrates jersey with owb like jersey-weld2-se is >> doing >> it with weld (or jersey with the cdi 1.1+ api) or you need a setup which >> integrates tomee/openejb with jersey. >> >> the last time i looked at jersey, only the out-of-the-box integration with >> weld worked as expected. >> -> if jersey still doesn't provide a better out-of-the-box integration >> (based on the cdi 1.1+ api or with owb directly), you need to contact one >> of the two communities (tomee or jersey) or replace one of the parts. >> >> regards, >> gerhard >> >> >> >> 2016-08-16 10:03 GMT+02:00 Remo Meier <[email protected]>: >> >> Hi >>> >>> I attempt to get get the Jersey integration running together with >>> Deltaspike, OpenEJB and Test Control according to the documentation at >>> the >>> bottom of the page here: >>> >>> https://deltaspike.apache.org/documentation/test-control.html >>> >>> Not working so far is the injection of CDI beans into JAX-RS resources. >>> The resulting exceptions look like like: >>> >>> MultiException stack 1 of 1 >>> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no >>> object >>> available for injection at SystemInjecteeImpl(requiredTyp >>> e=EntityManagerFactory,parent=KatharsisMgmtFeature,qualifier >>> s={},position=-1,optional=false,self=false,unqualified=null,1475912655) >>> at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThir >>> tyResolver.java:75) >>> at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:945) >>> at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLoca >>> torImpl.java:979) >>> at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitializ >>> e(ServiceLocatorImpl.java:1054) >>> at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitializ >>> e(ServiceLocatorImpl.java:1045) >>> at org.glassfish.jersey.model.internal.CommonConfig.configureFe >>> atures(CommonConfig.java:711) >>> at org.glassfish.jersey.model.internal.CommonConfig.configureMe >>> taProviders(CommonConfig.java:648) >>> at org.glassfish.jersey.server.ResourceConfig.configureMetaProv >>> iders(ResourceConfig.java:829) >>> at org.glassfish.jersey.server.ApplicationHandler.initialize(Ap >>> plicationHandler.java:453) >>> at org.glassfish.jersey.server.ApplicationHandler.access$500(Ap >>> plicationHandler.java:184) >>> at org.glassfish.jersey.server.ApplicationHandler$3.call(Applic >>> ationHandler.java:350) >>> at org.glassfish.jersey.server.ApplicationHandler$3.call(Applic >>> ationHandler.java:347) >>> at org.glassfish.jersey.internal.Errors.process(Errors.java:315) >>> at org.glassfish.jersey.internal.Errors.process(Errors.java:297) >>> at org.glassfish.jersey.internal.Errors.processWithException(Er >>> rors.java:255) >>> at org.glassfish.jersey.server.ApplicationHandler.<init>(Applic >>> ationHandler.java:347) >>> at org.glassfish.jersey.server.ApplicationHandler.<init>(Applic >>> ationHandler.java:311) >>> at org.glassfish.jersey.jetty.JettyHttpContainer.<init>(JettyHt >>> tpContainer.java:474) >>> at org.glassfish.jersey.jetty.JettyHttpContainerProvider.create >>> Container(JettyHttpContainerProvider.java:60) >>> at org.glassfish.jersey.server.ContainerFactory.createContainer >>> (ContainerFactory.java:81) >>> at org.glassfish.jersey.jetty.JettyHttpContainerFactory.createS >>> erver(JettyHttpContainerFactory.java:161) >>> at ch.adnovum.jcan.test.deltaspike.jaxrs.internal.DeltaspikeAwa >>> reJettyTestContainer.<init>(DeltaspikeAwareJettyTestContainer.java:41) >>> at ch.adnovum.jcan.test.deltaspike.jaxrs.internal.DeltaspikeAwa >>> reJettyTestContainerFactory.create(DeltaspikeAwareJettyTes >>> tContainerFactory.java:16) >>> at org.glassfish.jersey.test.JerseyTest.createTestContainer(Jer >>> seyTest.java:277) >>> at org.glassfish.jersey.test.JerseyTest.setUp(JerseyTest.java:607) >>> at ch.adnovum.moap.movie.management.web.EntityAccessTest.setUp( >>> EntityAccessTest.java:50) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce >>> ssorImpl.java:62) >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe >>> thodAccessorImpl.java:43) >>> at java.lang.reflect.Method.invoke(Method.java:483) >>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( >>> FrameworkMethod.java:50) >>> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl >>> ectiveCallable.java:12) >>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr >>> ameworkMethod.java:47) >>> at org.junit.internal.runners.statements.RunBefores.evaluate( >>> RunBefores.java:24) >>> at org.junit.internal.runners.statements.RunAfters.evaluate(Run >>> Afters.java:27) >>> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) >>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit >>> 4ClassRunner.java:78) >>> at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner. >>> runChild(CdiTestRunner.java:177) >>> at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner. >>> runChild(CdiTestRunner.java:76) >>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) >>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) >>> at org.junit.runners.ParentRunner.runChildren(ParentRunner. >>> java:288) >>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) >>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) >>> at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$Be >>> foreClassStatement.evaluate(CdiTestRunner.java:372) >>> at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$Af >>> terClassStatement.evaluate(CdiTestRunner.java:393) >>> at org.junit.runners.ParentRunner.run(ParentRunner.java:363) >>> at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner. >>> run(CdiTestRunner.java:144) >>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference. >>> run(JUnit4TestReference.java:86) >>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run( >>> TestExecution.java:38) >>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe >>> sts(RemoteTestRunner.java:459) >>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe >>> sts(RemoteTestRunner.java:678) >>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run( >>> RemoteTestRunner.java:382) >>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( >>> RemoteTestRunner.java:192) >>> >>> KatharsisMgmtFeature is a regular Feature. And their is a Producer that >>> makes the EntityManagerFactory available with @Inject. >>> >>> The application works if I manually register a >>> org.glassfish.hk2.utilities.binding.AbstractBinder bean as singleton to >>> the Application and use it to bind CDI beans to jersey/hk2 with >>> AbstractBinder.bind(x).to(y). But I would rather prefer for Jersey to >>> directly access the CDI beans instead of bridging those with the >>> AbstractBinder. >>> >>> My dependencies for Jersey currently look like: >>> >>> compile 'org.glassfish.jersey.core:jersey-client:2.23.1' >>> compile 'org.glassfish.jersey.core:jersey-common:2.23.1' >>> compile 'org.glassfish.jersey.test-framework:jersey-test-framework- >>> core:2.23.1' >>> compile 'org.glassfish.jersey.test-framework.providers:jersey-test- >>> framework-provider-jetty:2.23.1' >>> compile 'org.glassfish.jersey.containers:jersey-container-jetty- >>> http:2.23.1' >>> compile 'org.glassfish.jersey.bundles. >>> repackaged:jersey-guava:2.23.1' >>> >>> compile 'org.glassfish.jersey.ext.cdi:jersey-cdi1x:2.23.1' >>> compile 'org.glassfish.jersey.ext.cdi: >>> jersey-cdi1x-transaction:2.23.1' >>> compile 'org.glassfish.jersey.ext.cdi:jersey-cdi1x-servlet:2.23.1' >>> >>> The last three are new jersey libraries first having become available >>> last >>> year. Documentation about those is available here: >>> https://jersey.java.net/documentation/latest/cdi.support.html. >>> Potentially that api would open up the possiblity for a small deltaspike >>> library that does all the necessary integration work (request scoping, >>> cdi >>> binding), probably independent of Jetty. >>> >>> Or is there a complete example somewhere? >>> >>> Regards Remo >>> >>> >>> >>> >>> >>> >>> >>> >>>
