2 Replies Latest reply on Feb 22, 2010 2:35 AM by Nikolay Elenkov

    Questions about integration tests with SeamTest

    Piotr Sobczyk Newbie

      I'm a newbie in topic integration testing with SeamTest. I have two questions that seem to be easy:


      1. In many test cases from Seam examples I noticed such assertion in afterRequest method:


      assert !isRenderResponseBegun();



      What exactly it is supposed to check? There is no documentation for these methods and it's hard to find it out.


      I will paste an excerpt from Blog example to give it a context:


      String id = new FacesRequest(){
               @Override
               protected void updateModelValues() throws Exception
               {
                  ( (SearchService) getInstance(SearchService.class) ).setSearchPattern("seam");
               }
               @Override
               protected String getInvokeApplicationOutcome()
               {
                  return "/search.xhtml";
               }
               @Override
               protected void afterRequest()
               {
                  assert !isRenderResponseBegun();
               }
            }.run();



      Why Render Response phase should not begun in this test?


      2. I noticed that there is exception when I'm trying to put (Non)FacesRequest object inside method annotated as @BeforeClass:


      @BeforeClass
      public void startup() throws Exception{
           new FacesRequest(){
                @Override
                protected void updateModelValues() throws Exception {
                     setValue("#{identity.username}","user");
                     setValue("#{identity.password}","secret");
                }
                @Override
                protected void invokeApplication() throws Exception{
                     invokeMethod("#{identity.login}");
                }
           }.run();
      }



      And there is an exception:


      java.lang.NullPointerException
          at org.jboss.seam.mock.MockExternalContext$3.getAttribute(MockExt.java:369)
          at org.jboss.seam.mock.MockExternalContext$AttributeMap.get(Mockext.java:393)
          at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:49
          at org.jboss.seam.Component.getInstance(Component.java:1999)
          at org.jboss.seam.Component.getInstance(Component.java:1994)
          at org.jboss.seam.Component.getInstance(Component.java:1967)
          at org.jboss.seam.web.Session.getInstance(Session.java:122)
          at org.jboss.seam.contexts.FacesLifecycle.endRequest(FacesLifecycle.java:126)
          at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeam



      It seems that inside @AfterClass,@BeforeMethod and @AfterMethod methods everything works allright.


      So what is the pattern to extract code common for all test cases that need to make request (logging in is the best example) to the one place if @BeforeClass method is wrong place? I didn't see any attempts to do so in example tests but it's kind of a must in real life applications. Any hints?

        • 1. Re: Questions about integration tests with SeamTest
          Piotr Sobczyk Newbie

          Could anybody answer at least my first question? It doesn't seem to be difficult for someone that has a bit experience with Seam testing framework.

          • 2. Re: Questions about integration tests with SeamTest
            Nikolay Elenkov Master

            Piotr Sobczyk wrote on Feb 12, 2010 21:46:


            1. In many test cases from Seam examples I noticed such assertion in afterRequest method:

            assert !isRenderResponseBegun();



            What exactly it is supposed to check? There is no documentation for these methods and it's hard to find it out.


            Probably because there is a redirect before, which skips render response.




            2. I noticed that there is exception when I'm trying to put (Non)FacesRequest object inside method annotated as @BeforeClass:

            ...
            So what is the pattern to extract code common for all test cases that need to make request (logging in is the best example) to the one place if @BeforeClass method is wrong place? I didn't see any attempts to do so in example tests but it's kind of a must in real life applications. Any hints?



            The embedded container is started from @BeforeClass, all the mocking, etc is not available if you don't start id. So you shouldn't use FacessRequest, etc in @BeforeClass. You can't really have common log in as far as I know, because you can't have a mock session that spans methods (not 100% on this though). Look at the source of SeamTest and the mock components, you might get some ideas though.


            HTH