5 Replies Latest reply on May 29, 2009 12:46 PM by gorbeia1

    Integration test not running page action

    tnicholls

      I have a stateful Session EJB running as a Seam component in conversational scope.  It's a simple registration example and when I test it in the browser everything works fine.


      I have a single page action set up in pages.xml which fires a method to create a long-running conversation when the user goes to the registration page:


           <page view-id="/register.xhtml" action="#{Registration.beginRegistration}"/>
      



      The important bits of my registration bean look like this (with some code omitted such as getters and setters):


      @Stateful 
      @Scope(ScopeType.CONVERSATION)
      @Name("Registration")
      public class Registration implements RegistrationInterface, Serializable {
      
          @Logger Log log;
          
          @PersistenceContext(type=PersistenceContextType.EXTENDED)
          @In EntityManager entityManager;
          
          @In(create=true, required=false, value="account")
          @Out(required=false) Account account; // the account that is going to be created by the user
          
          
          @Begin
          public void beginRegistration() {
               log.info("beginRegistration()");
               account = new Account();
          }
           
          
           @End
           public void register()
            {
               log.info("register()");
              log.info("Hello, " + account.getName());
      
              // details omitted
              entityManager.persist(account);
           
            }
           
      
      
          @Remove   
          @Destroy 
          public void destroy() {}
      
               
      }
      
      



      I've written an integration test as follows:


      public class RegistrationInterfaceTest extends SeamTest {
      
      
           @Test
           public void test() throws Exception {
      
                new FacesRequest("/register.xhtml") {
      
                     @Override
                     protected void updateModelValues() throws Exception {                    
                          //set form input to model attributes
                          setValue("#{account.name}", "Tom");
                          setValue("#{account.email", "tom@blah.blah");
                     } 
                     @Override
                     protected void invokeApplication() {
                          //call action methods here
                          invokeMethod("#{Registration.register}");
                     }
                     @Override
                     protected void renderResponse() {
                          //check model attributes if needed
                          assert getValue("#{account.name}").equals("Tom");
                     }
                }.run();
                
                
           }
      


      ...but it doesn't seem to fire the page action defined in pages.xml .  When I go to the page in a browser I can see the method being fired.


      What might I be doing wrong?  Do I need to post more information?  I'm fairly new to Seam and this is my first foray into using the FacesRequest class.


      Thanks in advance for any help...

        • 1. Re: Integration test not running page action
          tnicholls

          Any help with this would be appreciated.  I am runnning the tests using JBoss Tools and the test environment created by the Seam generator within the Tools.


          Even if someone could point me in the right direction for how to debug why the page action is not being fired in the test, that would be great.


          Just to clarify, if I run up the application in JBoss and access the page /register.xhtml through a browser, the page action is fired.  If I run the above test using new FacesRequest(/register.xhtml) the page action does not fire.

          • 2. Re: Integration test not running page action
            nickarls

            Hmm. On the Old Forums it was claimed that it Should Work(tm).

            • 3. Re: Integration test not running page action
              pmuir

              Tom Nicholls wrote on Feb 25, 2008 02:05 PM:


              Even if someone could point me in the right direction for how to debug why the page action is not being fired in the test, that would be great.



              Yup, you'll need to use a debugger on this. The SeamTest stuff is fairly simple. To use a debugger, run the tests through Eclipse using the debug TestNG runner, and set breakpoints as normal.

              • 4. Re: Integration test not running page action
                gorbeia1

                You are using a FacesRequest. FacesRequest simulates a postback, so it doesn't execute the action. If you want the action to be executed you have to use a NonFacesRequest.

                • 5. Re: Integration test not running page action
                  gorbeia1

                  You are using a FacesRequest. FacesRequest simulates a postback, so it doesn't execute the action. If you want the action to be executed you have to use a NonFacesRequest.