6 Replies Latest reply on Jul 29, 2008 7:55 PM by Francisco Jose Peredo Noguez

    integration test problem

    Seto Kaiba Newbie

      How to write a test to assert if not logined the redirection occurs? I try to write a test to assertEquals(getRenderedViewId,/security/login.xhtml) in the renderResponse phase, but it doesn't effect. The code won't run at all. I mark login-required in the pages.xml. So the result shows that the redirection occurs so renderResponse phase not run at all. So how could I write a test to assert if it is redirected to the correct page? Thanks.

        • 1. Re: integration test problem
          Seto Kaiba Newbie

          No one reply for it? Anyone helps?

          • 2. Re: integration test problem
            Daniel Hinojosa Master

            Probably no one has helped because you didn't post any code.


            You have stuff you can post on here?

            • 3. Re: integration test problem
              Seto Kaiba Newbie
              @Test
              
              public void test changePassword(){
              
              new FacesRequest("/security/changePassword.xhtml"){
              
              @Override
              
              protected void renderResponse(){
              
              assertEquals(getRenderedViewId(),"/security/login.xhtml");
              
              }
              
              }.run();
              
              }


              Because of the redirection, the renderResponse phase isn't entered at all. So my test has no effect. So if I want to assert the redirection. How to?

              • 4. Re: integration test problem
                Pete Muir Master

                In the next request (thats what a redirect does if you think about it...)

                • 5. Re: integration test problem
                  Lars Huber Newbie

                  How looks the next Request like? Could you give an example, please. Do you use a NonFacesRequest or a FacesRequest. For example if you have this entry in the pages.xml. How do you check that it really redirects to home.xhtml and the param message is set?



                            <navigation>
                                 <rule if-outcome="persisted">
                                      <end-conversation before-redirect="true" />
                                      <redirect view-id="/home.xhtml">
                                           <param name="message"
                                                value="msg.AccountCreatedConfirmationSent" />
                                      </redirect>
                                 </rule>
                            </navigation>
                  


                   

                  • 6. Re: integration test problem
                    Francisco Jose Peredo Noguez Master

                    Hi!



                    Seto Kaiba wrote on Feb 20, 2008 02:28:


                    @Test
                    public void test changePassword(){
                    new FacesRequest("/security/changePassword.xhtml"){
                    @Override
                    protected void renderResponse(){
                    assertEquals(getRenderedViewId(),"/security/login.xhtml");
                    }
                    }.run();
                    }


                    Because of the redirection, the renderResponse phase isn't entered at all. So my test has no effect. So if I want to assert the redirection. How to?


                    I was having a similar problem, and the closest I could get to verifying if security was working was this:


                    
                    @Test
                    public void test changePassword(){
                    new NonFacesRequest("/security/changePassword.xhtml"){
                    
                    @Override
                    protected void afterRequest() {                    
                      Assert.assertFalse(this.isRenderResponseBegun(), "Response was rendered and that was not expected");
                    }
                    
                    }.run();
                    }
                    
                    



                    Hope this helps others trying to do something like this.


                    Regards,