Custom Scopes

198 views
Skip to first unread message

heriber...@googlemail.com

unread,
Mar 13, 2013, 6:14:11 AM3/13/13
to cdi-...@googlegroups.com
Hi!

I'm using cdi-unit and i'm very happy with it because i like its simplicity so much. (Why isn't it used by more people?)

But i run into a problem with custom scopes. I use Vaadin for a web based gui and a addon called cdiutils (https://github.com/tomivirkki/cdiutils). It defines a custom scope "UIScoped". If i want to test a class, e.g. a view, that inherits from the view class that is defined by cdiutils and uses UIScoped then i get following error:

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type org.vaadin.virkki.cdiutils.application.UIContext$UIScoped
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:578)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:608)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:674)
    at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:136)
    at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:763)
    at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:772)
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:165)
    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:161)
    at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:135)
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:157)
    at org.jglue.cdiunit.internal.MockExtension$1.inject(MockExtension.java:49)
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:297)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
    at com.example.ConfigViewTests$Proxy$_$$_WeldClientProxy.showAvailableConfigTypes(ConfigViewTests$Proxy$_$$_WeldClientProxy.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.jglue.cdiunit.CdiRunner$2.evaluate(CdiRunner.java:117)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    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:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Whats the best way to solve this problem?

Thank you very much!

Bryn Cooke

unread,
Mar 13, 2013, 6:42:20 PM3/13/13
to cdi-...@googlegroups.com
Hi,

Did you add VaadinContext as in your @AdditionalClasses in the test? It is an extension so CDI-Unit won't activate it unless it is added to discovery.

Cheers,
Bryn

Bryn Cooke

unread,
Mar 13, 2013, 6:43:23 PM3/13/13
to cdi-...@googlegroups.com
Meant to say:

Did you add VaadinContext in your @AdditionalClasses in the test? It is an extension so CDI-Unit won't activate it unless it is added to discovery.

Cheers,
Bryn
Reply all
Reply to author
Forward
0 new messages