2 Replies Latest reply on May 23, 2008 7:59 PM by kapitanpetko

    pages.xml and SeamTest

    kapitanpetko

      Hello,


      I migrated my navigation rules from faces-config.xml to
      pages.xml and now most of my SeamTests are failing. It seems
      that conversations are not propagated from one FacesRequest to the other, because I keep getting NPE when trying to get component properties.


      My setup is fairly simple, I have something like the following in pages.xml, and I am trying to persist and entity in my test. (set values in updateModelValues, save in invokeApplication, the usual)



      <page view-id="/user-list.xhtml" login-required="true">
      <restrict>#{s:hasRole('ADMINISTRATOR')}</restrict>
      
      <navigation>
      <rule if-outcome="edit">
      <redirect view-id="/user-update.xhtml"/>
      </rule>
      
      <rule if-outcome="details">
      <redirect view-id="/user-details.xhtml"/>
      </rule>
      </navigation>
      </page>
      
      <page view-id="/user-registration.xhtml" login-required="true" action="#{userManager.initRegistration}">
      <restrict>#{s:hasRole('ADMINISTRATOR')}</restrict>
      <navigation>
      <rule if-outcome="confirm">
      <redirect view-id="/user-details.xhtml"/>
      </rule>
      </navigation>
      </page>
      



      Is there something special I need to do or am I missing something obvious? I have tried different combinations of from-outcome, begin-conversation, etc. to no avail.


      The same pages.xml works fine in JBoss.


      I am using JBoss 4.2.2 and Seam 2.0.2.GA.


      TIA

        • 1. Re: pages.xml and SeamTest
          kapitanpetko

          Nikolay Elenkov wrote on May 20, 2008 07:28 PM:


          My setup is fairly simple, I have something like the following in pages.xml, and I am trying to persist and entity in my test. (set values in updateModelValues, save in invokeApplication, the usual)



          Here is some code that used to work with navigation in faces-config:


            @Test
              public void testRegister() throws Exception {
                  new FacesRequest("/login.xhtml") {
          
                      @Override
                      protected void updateModelValues() throws Exception {
                          assert !isSessionInvalid();
                          setValue("#{identity.username}", "admin");
                          setValue("#{identity.password}", "foobar");
                      }
          
                      @Override
                      protected void invokeApplication() {
                          invokeAction("#{identity.login}");
                      }
          
                      @Override
                      protected void renderResponse() {
                          assert !Manager.instance().isLongRunningConversation();
                          assert getValue("#{identity.loggedIn}").equals(true);
                          assertEquals("admin", getValue("#{identity.username}"));
                          assert getValue("#{identity.hasRole('ADMINISTRATOR')}").equals(
                                  true);
                      }
          
                  }.run();
          
                  String cid = new FacesRequest("/user-list.xhtml") {
                      @Override
                      protected void invokeApplication() {
                          assert invokeAction("#{userManager.register}").equals(
                                  "register-system-user");
                          setOutcome("/user-registration.seam");
                      }
          
                      @Override
                      protected void renderResponse() {
                          assert Manager.instance().isLongRunningConversation();
                          assert getValue("#{identity.loggedIn}").equals(true);
                          assertEquals("admin", getValue("#{identity.username}"));
                          assert getValue("#{identity.hasRole('ADMINISTRATOR')}").equals(
                                  true);
                      }
          
                  }.run();
          
                  cid = new FacesRequest("/user-registration.xhtml", cid) {
          
                      @Override
                      protected void updateModelValues() throws Exception {
                          assert !isSessionInvalid();
                          assert Manager.instance().isLongRunningConversation();    // (1) 
          
                          setValue("#{user.userName}", "user");                     // (2)
                          setValue("#{user.password}", "foobaz");
                          setValue("#{user.confirmPassword}", "foobaz");
                      }
          
                      @Override
                      protected void invokeApplication() {
                          invokeAction("#{userManager.confirmRegistration}");
                          setOutcome("/user-details.seam");
                      }
          
                      @Override
                      protected void renderResponse() {
                          assert Manager.instance().isLongRunningConversation();
          
                          assertEquals(getRenderedViewId(),
                                  "/user-registration.xhtml");
          
                          assertEquals(getValue("#{user.userName}"), "user");
                          // ...
                      }
          
                  }.run();
              }
          



          The assert (1) fails, and, naturally, if I comment it out, I get a 'user resolved to null' error at 2.


          • 2. Re: pages.xml and SeamTest
            kapitanpetko

            I don't have the code with me, but here's what works:


            protected void invokeApplication() {
              ...
            
             setOutcome("user-registration.seam"); // no leading /
            }
            



            And apperently SeamTest doesn't like the


            <page view-id="*"> <rule from-action="..."> 
            



            combination... Unfortunately I don't have the time to dig deeper into this.