4 Replies Latest reply on Mar 30, 2012 4:14 PM by Bernard Labno

    Arquillian Testcases for Seam 3 @ConversationScoped class

    brin jack Newbie

      Arquillian Testcases for Seam 3 @ConversationScoped class fails if it has the following.

       

      @Inject

          private Conversation conversation;


      is present in the class. If all these are removed the testcases work.


      @PostConstruct
          public void init() {
              if (conversation.isTransient()) {
                  conversation.begin();
              }
          }

          @Remove
          public void destroy() {
              log.debug("destroy()");
              if (!conversation.isTransient()) {
                  conversation.end();
              }
          }


      Please suggest a solution for the same.

      error :

       

      Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type @ConversationScoped

      at org.jboss.weld.conversation.ConversationImpl.checkConversationActive(ConversationImpl.java:79)

      at org.jboss.weld.conversation.ConversationImpl.isTransient(ConversationImpl.java:234)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:597)

      at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)

      at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)

      at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)

      at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)

      at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)

      at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)

      at org.jboss.weld.conversation.ConversationImpl_$$_javassist_98.isTransient(ConversationImpl_$$_javassist_98.java)

      at com.corelogic.terradactyl.ejb.customer.CustomerAction.init(CustomerAction.java:418)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:597)

      at com.sun.ejb.containers.interceptors.BeanCallbackInterceptor.intercept(InterceptorManager.java:1006)

      at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:61)

      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:390)

      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:373)

      at com.sun.ejb.containers.StatefulSessionContainer.afterInstanceCreation(StatefulSessionContainer.java:742)

      ... 83 more

      Feb 22, 2012 9:51:55 AM org.hibernate.impl.SessionFactoryImpl close

      INFO: closing

      classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)

      SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@e1f52a

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 313.614 sec <<< FAILURE!

       

      Thanks.

        • 1. Re: Arquillian Testcases for Seam 3 @ConversationScoped class
          zeeman Novice

          I had a similar issue before, from Arq tests the conversation scope is not active because you don't even have a session. So you either have to activate the session & conversation scope yourself or use JSFUnit and let it take care of that.

           

          At the end I got sick of doing that and I only do Arq tests from back-end services as it won't work well for UI action beans. Maybe someone has a better way of testing UI action beans.

          • 2. Re: Arquillian Testcases for Seam 3 @ConversationScoped class
            Jason Porter Master

            You could do JSFUnit like you mentioned, or use Drone / Selenium.

            • 3. Re: Arquillian Testcases for Seam 3 @ConversationScoped class
              hantsy bai Master

              I encountered the same problem before, so you must use JSFUnit and Arquillian together and package as war  to test it.

              I think the conversation is too jsf specific and depends on the web container...if it can be seperated from jsf and designed as a standalone feature and not depends on web container, I think it will be better to test.

              • 4. Re: Arquillian Testcases for Seam 3 @ConversationScoped class
                Bernard Labno Master

                How about injecting BoundConversationContext ?

                 

                {code:java}@RunWith(Arquillian.class)

                public class UserLoginCIT {

                 

                    @Inject

                    IdentityImpl identity;

                 

                    @Inject

                    CredentialsImpl credentials;

                 

                    @Inject

                    @Bound

                    BoundConversationContext conversationContext;

                 

                    @Deployment

                    public static WebArchive createDeployment()

                    {

                        return new Packager(UserLoginCIT.class).buildPackage();

                    }

                 

                    @Test

                    public void userLogIn()

                    {

                        conversationContext.associate(new MutableBoundRequest(new HashMap<String, Object>(), new HashMap<String, Object>()));

                        conversationContext.activate();

                        System.out.println("Credentials = " + credentials);

                        credentials.setUsername(UserLoginTestHelper.JACK_USER_USERNAME);

                        credentials.setPassword(UserLoginTestHelper.EXAMPLE_USER_PASSWORD);

                        identity.login();

                        Assert.assertEquals(true, identity.isLoggedIn());

                    }

                }{code:java}