You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Reinhard Sandtner (JIRA)" <ji...@apache.org> on 2017/01/18 07:14:27 UTC

[jira] [Created] (DELTASPIKE-1230) use of ContextControl in CdiTestRunner blows up with NullPointerException

Reinhard Sandtner created DELTASPIKE-1230:
---------------------------------------------

             Summary: use of ContextControl in CdiTestRunner blows up with NullPointerException
                 Key: DELTASPIKE-1230
                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1230
             Project: DeltaSpike
          Issue Type: Bug
          Components: TestControl
    Affects Versions: 1.7.2, 1.7.1, 1.7.0
            Reporter: Reinhard Sandtner


i'm trying to implement a base test class with the annotation {{@RunWith(CdiTestRunner.class)}} and provide some utility methods for tests.

to start a new request in a test method i'm using {{ContextControl}} to stop and start {{RequestContext}} and {{SessionContext}}.

here are my cdi-ctrl dependencies
{code}
<dependency>
  <groupId>org.apache.deltaspike.cdictrl</groupId>
  <artifactId>deltaspike-cdictrl-openejb</artifactId>
  <version>${deltaspike.version}</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>openejb-core</artifactId>
  <version>7.0.2</version>
  <scope>test</scope>
</dependency>
{code}

with one test everything works fine but as soon as i've more the call to {{contextControl.stopContext(RequestScoped.class)}} (or any other scope) blows up with an NPE

{noformat}
java.lang.NullPointerException
	at java.util.Collections$UnmodifiableCollection.<init>(Collections.java:1026)
	at java.util.Collections$UnmodifiableList.<init>(Collections.java:1302)
	at java.util.Collections.unmodifiableList(Collections.java:1287)
	at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.getActiveExternalContainers(CdiTestRunner.java:838)
	at org.apache.deltaspike.testcontrol.impl.request.ContextControlDecorator.stopContext(ContextControlDecorator.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.webbeans.intercept.DecoratorHandler.invoke(DecoratorHandler.java:96)
	at org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl$$OwbInterceptProxy0.stopContext(org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.webbeans.intercept.AbstractInvocationContext.directProceed(AbstractInvocationContext.java:113)
	at org.apache.webbeans.intercept.AbstractInvocationContext.proceed(AbstractInvocationContext.java:106)
	at org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:67)
	at org.apache.webbeans.intercept.DefaultInterceptorHandler.invoke(DefaultInterceptorHandler.java:139)
	at org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl$$OwbInterceptProxy0.stopContext(org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java)
	at at.rsandtner.sample.deltaspike.test.ContainerTest.cleanInstances(ContainerTest.java:40)
	at at.rsandtner.sample.deltaspike.test.TestTwo.testSomething(TestTwo.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:346)
	at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:318)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.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$BeforeClassStatement.evaluate(CdiTestRunner.java:372)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:144)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
{noformat}

i've configured {{deltaspike.testcontrol.stop_container = false}} in {{src/test/resources/META-INF/apache-deltaspike.properties}}

when booting the container for each test class it works but my goal is to start the container only once for all test in my module since this takes some time for bigger modules ;)

don't know if the fix is as trivial as it looks but adding
{code}
if (cdiTestRunner == null || *cdiTestRunner.testContext.externalContainers == null*)

{
    
    return Collections.emptyList();

}
{code}
fixes at least the NPE. 

or is there anything else i’m doing wrong?

will upload a small sample but i'm currently on train and connection is really bad :/ so this can take some time



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)