0 Replies Latest reply on Jun 29, 2012 6:06 AM by Ste Gr

    JSFUnit 2.0.0.Beta2 + RequestScoped

    Ste Gr Newbie

      Hi,

       

      I have a outputText on the page which will be conditionally rendered. The condition variable is in a request scoped bean and the default value is false. Additionally I have a commandButton with an action method which will set the variable to true so the outputText gets rendered. If I display the page source I see the generated html for the outputText, but the findComponent() method for this component and component.isRendered() still tells me, that it is not rendered.

      After some debugging I found out, that there are multiple instances of the request scoped bean involed in a single request. That doesn't look like the normal behaviour in the JSF lifecycle, does it? Any chance to get this fixed?

       

      The first instance will be created when the page is rendered => OK

      - I can get the view ID, view root and the UIComponent of the button without an problem

       

      The second instance will be created when I get the UIComponent of the outputText => WRONG

       

      The third instance will be created when I click on the button => OK, since it is a new request

      - The action and page rendering uses this instance

       

      Not the strange thing: After the new request I try to get the new UIComponent of the outputText. It does not create a new instance of the bean but it uses the second instance...

       

      @RunWith(Arquillian.class)

      @InitialPage("/pages/index.jsf")

      public class JSFUnitTest

      {

          @JSFUnitResource

          private JSFSession _jsfSession;

       

          @JSFUnitResource

          private JSFServerSession _server;

       

          @JSFUnitResource

          private JSFClientSession _client;

       

         /* SNIP */

       

          @Test

          public void test_1() throws IOException

          {               

              // INSTANCE #1 will be used

              System.out.println("########## VIEW ID");

              Assert.assertEquals("/pages/index.xhtml", _server.getCurrentViewID());

       

              UIViewRoot root = _server.getFacesContext().getViewRoot();

              System.out.println("########## ViewRoot: " + root);

       

              UIComponent fireButton = root.findComponent("fire-form:fire-link");

       

              // INSTANCE #2 will be used

              UIComponent outputText = root.findComponent("fire-form:fired-text");

       

       

              System.out.println("########## BUTTON [" + fireButton.isRendered() + "]");

              Assert.assertTrue(fireButton != null);

              Assert.assertTrue(fireButton.isRendered());

              Assert.assertTrue(fireButton instanceof UICommand);

       

              System.out.println("########## TEXT #1 [" + outputText + " || " + outputText.isRendered() + "]");

              Assert.assertTrue(outputText != null);

              Assert.assertFalse(outputText.isRendered());

              Assert.assertTrue(outputText instanceof UIOutput);

       

       

              System.out.println("########## CLICK");

              _client.click(fireButton.getClientId());

       

       

              // INSTANCE #3 will be used

              root = _server.getFacesContext().getViewRoot();

              System.out.println("########## ViewRoot: " + root);

       

       

              // INSTANCE #2 will be used

              outputText = root.findComponent("fire-form:fired-text");

              System.out.println("########## TEXT #2 [" + outputText + " || " + outputText.isRendered() + "]");

              Assert.assertTrue(outputText != null);

              Assert.assertTrue(outputText.isRendered());

              Assert.assertTrue(outputText instanceof UIOutput);

          }

      }

       

      It doesn't matter if I use root.findComponent() or _server.findComponent(). Do you have any idea, what's going wrong?