1 Reply Latest reply on Apr 24, 2009 9:21 PM by Chad Retz

    Integration Testing Page Scoped Components

    Chad Retz Newbie

      I have and issue where I have two PAGE scope components. Component A injects component B via @In(create=true). Component B uses a @RequestParameter for one of its actions. I only know that value after an initial render.


      Basically, I need to keep a PAGE context active across multiple FacesRequest tests (in a single test case). I set the same viewId and conversationId in the constructor, but the PAGE context is not persisted across FacesRequests.


      I really need this for multiple actions that depend on each other within a single page.


      Is this not supported or am I doing something wrong? Thanks in advance.

        • 1. Re: Integration Testing Page Scoped Components
          Chad Retz Newbie

          I found a ghetto solution:


          Say you have a classes like so:


          @Name("componentA")
          @Scope(PAGE)
          public class ComponentA {
              @Create
              public void create() {
                  //do something
              }
          }



          @Name("componentB")
          @Scope(PAGE)
          public class ComponentB {
              @In
              ComponentA componentA;
          }



          ...just mock 'em w/ conversations like so:


          @Name("componentA")
          @Scope(CONVERSATION)
          @Install(precedence = MOCK)
          public class ComponentAMock extends ComponentA {
              @Create
              @Begin
              public void create() {
                  //do something
              }
          }



          @Name("componentB")
          @Scope(CONVERSATION)
          @Install(precedence = MOCK)
          public class ComponentBMock extends ComponentB {
          
          }



          Granted, this doesn't solve the page context persistence problem (which I am assuming is caused by the fact that the page context is recognized via JSF post back only). But at least you can test multiple interdependent page scoped components.


          I also run this at the end of invokeAction on the last FacesRequest I need in the page scope:


          ((Manager)getInstance(Manager.class)).endConversation(false);



          Still, if anyone can tell me how to persist the page context across FacesRequests, I'd appreciate it...