1 Reply Latest reply on Jul 22, 2009 9:43 AM by acerberus

    Redirect messes up SeamTest - Bug?

    acerberus

      I think there is a bug in SeamTest concerning the handling of redirects. If a redirect occurs (via pageflow, manually via setOutcome or via the return value of an action during the invokeApplicationPhase) conversations are lost and cannot be propagated to the a following FacesRequest.


      The things that got me started on this were that I could not propagate conversations properly during tests. See my forum entries:




      Could one of the Seam gurus please crosscheck that? Or am I doing something completely irational here and there is a perfectly good reason why this cannot work?


      Here is a simple SeamTest to illustrate the conversation propagation behavior:



           @Test
           public void testSeamBug1() throws Exception{
                final String cid = new FacesRequest(){
                     @Override
                     protected void invokeApplication(){
                          Conversation.instance().begin();
                          assert isLongRunningConversation();
                          setOutcome("/someViewId.xhtml");
                     }
                }.run();
                
                new FacesRequest("/someViewId.xhtml", cid) {
                     @Override
                     protected void invokeApplication(){
                         assert isLongRunningConversation();
                    }
      
               }.run();
           }
      


      If setOutcome is removed then the assertion holds.


      A workaround that I found, which is however hardly satisfying is to squeeze a dummy NonFacesRequest in between the two FacesRequests. This example here works perfectly and the conversation is propagated correctly:



           @Test
           public void testSeamBug2() throws Exception{
               final String cid = new FacesRequest(){
                     @Override
                     protected void invokeApplication(){
                          Conversation.instance().begin();
                          assert isLongRunningConversation();
                          setOutcome("/someViewId.xhtml");
                     }
                }.run();
                
                  /* a dummy request to save the conversation */
               new NonFacesRequest("/someViewId.xhtml", cid) {
                    @Override
                    protected void renderResponse(){
                         assert isLongRunningConversation();
                    }
      
               }.run();
                
               new FacesRequest("/someViewId.xhtml", cid) {
                     @Override
                     protected void invokeApplication(){
                         assert isLongRunningConversation();
                    }
      
               }.run();
           }
      



      Does anyone have an explanation about what is going on here?


      Cheers
      Arno