Search code examples
jsf-2cdijunit4jsf-2.2deltaspike

ContextNotActiveException: WELD-001303: No active contexts for scope type org.apache.deltaspike.core.api.scope.GroupedConversationScoped


I want to use DeltaSpike for CDI-based tests. I use a lot of GroupedConversationScoped Beans for my application and when I'm trying to test them, I always run into this failure:

org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type org.apache.deltaspike.core.api.scope.GroupedConversationScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:708)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
at com.pass.project.generated.context.MainDataContext$Proxy$_$$_WeldClientProxy.setTestAttr(Unknown Source)
at com.pass.project.test.DeltaSpikeTest.main(DeltaSpikeTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:340)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:312)
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:174)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:75)
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:366)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:392)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:141)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

I can't figure why it's not active. That's my test

@RunWith(CdiTestRunner.class)
public class DeltaSpikeTest {

@Inject
private DlgListBoRoleFormBean dlgListBoRoleFormBean;

@Inject
private MainDataContext mainDataContext;

@Test
public void main() {


    TblTestAttrListBeanList tbl = (TblTestAttrListBeanList) dlgListBoRoleFormBean.getTblTestAttr();

    List<ContactpersonValueImpl> li = new ArrayList<>();
    mainDataContext.setTestAttr(li);

    {
        ContactpersonValueImpl person = new ContactpersonValueImpl();
        person.setName("Harald");
        li.add(person);
    }
    {
        ContactpersonValueImpl person = new ContactpersonValueImpl();
        person.setName("Wilhelm");
        li.add(person);
    }

    tbl.update();

    Assert.assertTrue(tbl.getList().size() == 2);
    Assert.assertTrue(tbl.getList().get(0).getName().equals("Harald"));

    System.out.println(tbl.toString());

}

}

Every help is highly appreciated!


Solution

  • You just need to activate a (test-)window, because grouped-conversations are based on the window-context to support different windows. @Inject WindowContext and use the method activateWindow. Provide any value you like.

    See the example provided by OS890: https://github.com/os890/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/PageBeanTest.java

    If you ask such questions on their mailing-list, you get answers petty quickly.

    @John: You don't need to list it via that annotation in this case.