5 Replies Latest reply on Mar 30, 2017 8:32 AM by mjobanek Branched to a new discussion.

    UI Scoped Class can't be tested

    julius278

      Hello,

      I'm new here, I'm in the first semester of my study and have a problem with a project...

      and yes, my english is also a little problem

       

      I tried to test some code of a Maven Project that uses Java and CDI and everything works fine with Arquillian.

      In the beginning I had some problems but now nearly everthing works.

       

      Nearly... there is a class with the annotation @UIScoped and there is always the error report:

       

      java.lang.RuntimeException: Could not inject members

        at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:135)

           ... and so on...

       

      The test only runs on an embedded container (weld ee) is that the problem?

      When I comment the scope out everthing works and there is the "green bar"...

       

      Does anybody have a solution?

       

      Thanks for your help

        • 1. Re: UI Scoped Class can't be tested
          bmajsak

          Hey Julius,

           

          welcome in the community. Your english is not a problem at all I could easily follow.

           

          Would it be possible to share the code? I would suspect that in fact weld-ee embedded might be the culprit here as it has most of the scopes mocked. Have you tried against different container e.g. Wildfly? Have a look at out Chameleon project - it greatly simplifies configuration of containers.

           

          https://github.com/arquillian/arquillian-container-chameleon

          • 2. Re: UI Scoped Class can't be tested
            julius278

            This is the Code from the UserSelection (with getter and setter Methods).

             

            import java.util.Date;

            import com.vaadin.cdi.UIScoped;

             

            @UIScoped

            public class UserSelection {

                private Stelle Stelle;

                private Punkt punkt;

                private int duration;

                private Date date;

            }

             

            I also tried the JBoss AS 7.1.1.Final managed Container, there was an error message... something with couldn't start container... after a while..

            This is my Test:

             

            import javax.inject.Inject;

            import org.jboss.arquillian.container.test.api.Deployment;

            import org.jboss.arquillian.junit.Arquillian;

            import org.jboss.shrinkwrap.api.ShrinkWrap;

            import org.jboss.shrinkwrap.api.asset.EmptyAsset;

            import org.jboss.shrinkwrap.api.spec.JavaArchive;

            import org.junit.Test;

            import org.junit.runner.RunWith;

             

            @RunWith(Arquillian.class)

            public class BeispielKlasseTest {

              @Inject

              BeispielKlasse beispielKlasse;

             

              @Deployment

              public static JavaArchive createDeployment(){

              return ShrinkWrap.create(JavaArchive.class)

              .addClasses(BeispielKlasse.class, BeispielBean.class)

              .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

              }

              @Test

              public void shouldInjectBean(){

              assertNotNull(beispielKlasse.getBean());

              assertEquals("HelloWorld", beispielKlasse.getBean().s1);

              }

              @Test

              public void test() {

              fail("Not yet implemented");

              }

            }

             

            This test does not include the UserSelection with the UIScoped annotation but it container can't start...

             

            My pom.xml looks like this...:

             

            <dependencyManagement>

                 <dependencies>

                     <dependency>

                         <groupId>org.jboss.arquillian</groupId>

                         <artifactId>arquillian-bom</artifactId>

                         <version>1.1.12.Final</version>

                         <scope>import</scope>

                         <type>pom</type>

                     </dependency>

                 </dependencies>

              </dependencyManagement>

             

            <dependencies>

              <dependency>

              <groupId>org.vaadin.addon</groupId>

              <artifactId>v-leaflet</artifactId>

              <version>1.0.3</version>

              </dependency>

             

              <dependency>

              <groupId>org.apache.commons</groupId>

              <artifactId>commons-lang3</artifactId>

              </dependency>

             

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-server</artifactId>

              </dependency>

             

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client</artifactId>

              <scope>provided</scope>

              </dependency>

             

            <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client-compiler</artifactId>

              <scope>provided</scope>

              </dependency>

             

            <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-themes</artifactId>

              </dependency>

             

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client-compiled</artifactId>

              </dependency>

             

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-cdi</artifactId>

              </dependency>

             

              <dependency>

              <groupId>javax</groupId>

              <artifactId>javaee-api</artifactId>

              </dependency>

             

              <dependency>

              <groupId>org.jboss.resteasy</groupId>

              <artifactId>resteasy-jackson2-provider</artifactId>

              </dependency>

             

              <dependency>

              <groupId>org.hibernate</groupId>

              <artifactId>hibernate-validator-cdi</artifactId>

              </dependency>

             

              <dependency>

              <groupId>org.vaadin.addons</groupId>

              <artifactId>popupbutton</artifactId>

              <version>2.6.0</version>

              </dependency>

             

              <dependency>

              <groupId>org.vaadin.addons</groupId>

              <artifactId>vaadin-combobox-multiselect</artifactId>

              <version>1.1.14</version>

              </dependency>

             

              <dependency>

              <groupId>org.vaadin.addons</groupId>

              <artifactId>filteringtable</artifactId>

              <version>0.9.15.v7</version>

              </dependency>

             

              <dependency>

              <groupId>it.zero11.vaadin</groupId>

              <artifactId>asyncfiltercombobox</artifactId>

              <version>0.2.0</version>

              </dependency>

             

              <dependency>

                        <groupId>junit</groupId>

                        <artifactId>junit</artifactId>

                        <version>4.12</version>

                        <scope>test</scope>

                    </dependency>

                 

                    <!-- Arquillian JUnit Integration -->

              <dependency>

                 <groupId>org.jboss.arquillian.junit</groupId>

                 <artifactId>arquillian-junit-container</artifactId>

                 <scope>test</scope>

              </dependency>

             

            <dependency>

                   <groupId>org.jboss.bom</groupId>

                   <artifactId>jboss-javaee-6.0-with-tools</artifactId>

                   <version>1.0.0.Final</version>

                   <type>pom</type>

                   <scope>import</scope>

              </dependency>

            </dependencies>

             

            <profiles>

              <profile>

                     <id>arquillian-weld-ee-embedded</id>

                     <dependencies>

                         <dependency>

                             <groupId>org.jboss.spec</groupId>

                             <artifactId>jboss-javaee-7.0</artifactId>

                             <version>1.0.3.Final</version>

                             <type>pom</type>

                             <scope>provided</scope>

                         </dependency>

             

                         <dependency>

                             <groupId>org.jboss.arquillian.container</groupId>

                             <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>

                             <version>1.0.0.CR9</version>

                             <scope>test</scope>

                         </dependency>

             

                         <dependency>

                             <groupId>org.jboss.weld</groupId>

                             <artifactId>weld-core</artifactId>

                             <version>2.3.5.Final</version>

                             <scope>test</scope>

                         </dependency>

             

                         <dependency>

                             <groupId>org.slf4j</groupId>

                             <artifactId>slf4j-simple</artifactId>

                             <version>1.6.4</version>

                             <scope>test</scope>

                         </dependency>

                     </dependencies>

                 </profile>

               

            <!-- embedded glassfish container -->

                 <profile>

                 <id>arquillian-glassfish-embedded</id>

                 <dependencies>

                     <dependency>

                         <groupId>org.jboss.arquillian.container</groupId>

                         <artifactId>arquillian-glassfish-embedded-3.1</artifactId>

                         <version>1.0.0.CR4</version>

                         <scope>test</scope>

                     </dependency>

                     <dependency>

                         <groupId>org.glassfish.main.extras</groupId>

                         <artifactId>glassfish-embedded-all</artifactId>

                         <version>3.1.2</version>

                         <scope>provided</scope>

                     </dependency>

                 </dependencies>

              </profile>

             

              <profile>

              <id>arquillian-chameleon-container</id>

              <dependencies>

              <dependency>

                 <groupId>org.jboss.arquillian.junit</groupId>

                 <artifactId>arquillian-junit-container</artifactId>

                 <scope>test</scope>

              </dependency>

             

              <dependency>

                 <groupId>org.arquillian.container</groupId>

                 <artifactId>arquillian-container-chameleon</artifactId>

                 <version>1.0.0.Final-SNAPSHOT</version>

                 <scope>test</scope>

              </dependency>

              </dependencies>

              </profile>

             

            <!-- JBoss AS managed -->

              <profile>

                 <id>arquillian-jbossas-managed</id>

                 <dependencies>

                     <dependency>

                         <groupId>org.jboss.spec</groupId>

                         <artifactId>jboss-javaee-7.0</artifactId>

                         <version>1.0.3.Final</version>

                         <type>pom</type>

                         <scope>provided</scope>

                     </dependency>

                     <dependency>

                         <groupId>org.jboss.as</groupId>

                         <artifactId>jboss-as-arquillian-container-managed</artifactId>

                         <version>7.1.1.Final</version>

                         <scope>test</scope>

                     </dependency>

                 </dependencies>

              </profile>

             

              </profiles>

             

             

             

             

            The integration of the chameleon project was not successful...

            And the Glassfish embedded container also doesn't work...

             

            I'm not sure where my problem is...

            • 3. Re: UI Scoped Class can't be tested
              bmajsak

              I also tried the JBoss AS 7.1.1.Final managed Container, there was an error message... something with couldn't start container... after a while..

              This could happen if you run it using JDK 8. AS7 is not working with this version and it just hangs during startup. Try with WildFly instead.

              • 4. Re: UI Scoped Class can't be tested
                julius278

                java.lang.RuntimeException: Could not inject members

                  at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:135)

                  at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.enrich(CDIInjectionEnricher.java:78)

                  at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:55)

                  at org.jboss.arquillian.container.test.impl.ClientTestInstanceEnricher.enrich(ClientTestInstanceEnricher.java:51)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

                  at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

                  at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createBeforeContext(ContainerEventController.java:124)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

                  at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

                  at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:108)

                  at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:242)

                  at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:431)

                  at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:55)

                  at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:260)

                  at org.jboss.arquillian.junit.Arquillian$7$1.invoke(Arquillian.java:324)

                  at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.execute(ClientBeforeAfterLifecycleEventExecuter.java:99)

                  at org.jboss.arquillian.container.test.impl.execution.ClientBeforeAfterLifecycleEventExecuter.on(ClientBeforeAfterLifecycleEventExecuter.java:72)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

                  at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

                  at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createBeforeContext(ContainerEventController.java:124)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)

                  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:498)

                  at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)

                  at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                  at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

                  at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

                  at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.fireCustomLifecycle(EventTestRunnerAdaptor.java:159)

                  at org.jboss.arquillian.junit.Arquillian$7.evaluate(Arquillian.java:317)

                  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

                  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

                  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

                  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.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:205)

                  at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:431)

                  at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:55)

                  at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:219)

                  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

                  at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:167)

                  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.runTests(RemoteTestRunner.java:459)

                  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(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)

                Caused by: java.lang.IllegalStateException: No bean store container bound for session

                  at com.vaadin.cdi.internal.UIScopedContext.getSessionBoundBeanStoreContainer(UIScopedContext.java:123)

                  at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:70)

                  at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:59)

                  at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:96)

                  at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)

                  at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)

                  at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:842)

                  at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)

                  at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:364)

                  at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:375)

                  at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70)

                  at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)

                  at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)

                  at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)

                  at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:145)

                  at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:125)

                  ... 109 more

                • 5. Re: UI Scoped Class can't be tested
                  mjobanek

                  According to the exception, it doesn't seem to be an Arquillian issue - the exception comes from Vaadin code.

                  Have you tried to ask on Vaadin forum if they have any experience with it?

                   

                  Found something similar: Vaadin Forum - vaadin.com