6 Replies Latest reply on Sep 9, 2008 10:30 PM by Mike Bockus

    JSFServerSession null

    Victoria S Newbie

       

      
       // Send an HTTP request for the initial page
       JSFSession jsfSession = new JSFSession("/index.jsp");
      


      Hi Victoria,

      Luckily, this does look like a simple one. The initial page needs to map to the FacesServlet. The above line should something like:
      JSFSession jsfSession = new JSFSession("/index.jsf");


      See the javadoc for JSFSession here for more details:
      http://www.jboss.org/file-access/default/members/jsfunit/freezone/apidocs/org/jboss/jsfunit/jsfsession/JSFSession.html#JSFSession(java.lang.String)

      Thanks for using JSFUnit.

      Stan

        • 1. Re: JSFServerSession null
          Stan Silvert Master

          Oops, looks like I wiped out the original post. Here is the original text:

          Hello,

          I've downloaded the new version (B3) and have been trying to get a few tests to work. After a little struggling with the jar files, It's now got past the class not found exceptions and on to a new one:

          java.lang.NullPointerException
          at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:69)

          The same thing occurs for the two tests I have,
          Here's the code for one test(you might recognise it):

          | package uk.co.inl.tracking.presentation.junit.scanner;
          |
          | import java.io.IOException;
          |
          | import javax.faces.component.UIComponent;
          |
          | import junit.framework.Test;
          | import junit.framework.TestSuite;
          | import org.jboss.jsfunit.jsfsession.JSFClientSession;
          | import org.jboss.jsfunit.jsfsession.JSFServerSession;
          | import org.jboss.jsfunit.jsfsession.JSFSession;
          | import org.xml.sax.SAXException;
          |
          |
          | public class JSFUnitTest extends org.apache.cactus.ServletTestCase
          | {
          | public static Test suite()
          | {
          | return new TestSuite( JSFUnitTest.class );
          | }
          |
          | public void testInitialPage() throws IOException, SAXException
          | {
          | // Send an HTTP request for the initial page
          | JSFSession jsfSession = new JSFSession("/index.jsp");
          |
          | // A JSFClientSession emulates the browser and lets you test HTML
          | JSFClientSession client = jsfSession.getJSFClientSession();
          |
          | // A JSFServerSession gives you access to JSF state
          | JSFServerSession server = jsfSession.getJSFServerSession();
          |
          | // Test navigation to initial viewID
          | assertEquals("/index.jsp", server.getCurrentViewID());
          |
          | // Assert that the prompt component is in the component tree and rendered
          | UIComponent prompt = server.findComponent("greeting");
          | assertTrue(prompt.isRendered());
          |
          | // Test a managed bean
          | assertEquals("Stan", server.getManagedBeanValue("#{foo.text}"));
          | }
          | }
          |

          when it gets to assertEquals("/index.jsp", server.getCurrentViewID());
          server is not null, but the two fields inside are null and hence getCurrentViewID() will throw the following exception:

          null

          java.lang.NullPointerException
          at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:69)
          at uk.co.inl.scripttracking.presentation.junit.scanner.JSFUnitTest.testInitialPage(JSFUnitTest.java:34)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
          at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
          at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
          at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
          at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
          at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
          at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
          at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
          at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:42)
          at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
          at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
          at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
          at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:48)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:122)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Unknown Source)


          I'm hoping it's something really simple.
          Any ideas?
          Thank you
          Victoria

          • 2. Re: JSFServerSession null
            Victoria S Newbie

            Hi Stan,

            Thank you for the response.
            I must admit I was being lazy. Anyway, after your responce, I added the faces stuff and tried again, but no luck. Probably something to do with the fact that I'd created a new project and had left something vital out. So I decided to try again and place the JSFUnit tests in my main project and have now got the tests working well.

            Thank you
            Victoria

            P.s The new version (B3) is very good. I had some tests written in htmlunit before which were very complicated and long. The same tests have been re-written using JSFUnit with less code and complications.

            • 3. Re: JSFServerSession null
              Stan Silvert Master

               

              "Victoria122" wrote:
              Hi Stan,

              P.s The new version (B3) is very good. I had some tests written in htmlunit before which were very complicated and long. The same tests have been re-written using JSFUnit with less code and complications.


              Great to hear. Thanks for using JSFUnit.

              Stan

              • 4. Re: JSFServerSession null
                Mike Bockus Newbie

                I'm still seeing a very similar issue. This is my first time trying JSFUnit, so I'm trying to get a simple testcase to work. I'm getting a JSFServerSession back from the JSFSession, but both the clientIDs and currentFacesContext are null. This results in a NPE for any calls using the JSFServerSession.

                Here's my test case:

                import java.io.IOException;
                import javax.faces.component.UIComponent;
                import junit.framework.Test;
                import junit.framework.TestSuite;
                import org.apache.cactus.ServletTestCase;
                import org.jboss.jsfunit.jsfsession.JSFClientSession;
                import org.jboss.jsfunit.jsfsession.JSFServerSession;
                import org.jboss.jsfunit.jsfsession.JSFSession;
                import org.xml.sax.SAXException;
                
                public class JSFUnitTest extends ServletTestCase {
                
                 public static Test suite()
                 {
                 return new TestSuite( JSFUnitTest.class );
                 }
                
                 public void testInitialPage() throws IOException, SAXException
                 {
                 // Send an HTTP request for the initial page
                 JSFSession jsfSession = new JSFSession("/test.faces");
                
                 // A JSFClientSession emulates the browser and lets you test HTML
                 JSFClientSession client = jsfSession.getJSFClientSession();
                
                 // A JSFServerSession gives you access to JSF state
                 JSFServerSession server = jsfSession.getJSFServerSession();
                
                 // Test navigation to initial viewID
                 try{
                 assertEquals("/test.jsp", server.getCurrentViewID());
                 }
                 catch(Throwable e)
                 {
                 e.printStackTrace();
                 }
                
                 // Assert that the prompt component is in the component tree and rendered
                 UIComponent prompt = server.findComponent("text1");
                 assertTrue(prompt.isRendered());
                
                 // Test a managed bean
                 //assertEquals("Stan", server.getManagedBeanValue("#{foo.text}"));
                 }
                
                }
                

                Both of the actions on the server(JSFServerSession) object result in a NPE. Here's the stacktrace:
                java.lang.NullPointerException
                at org.jboss.jsfunit.jsfsession.JSFServerSession.findComponent(JSFServerSession.java:94)
                at com.ibm.jsf.unittest.ui.JSFUnitTest.testInitialPage(JSFUnitTest.java)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
                at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
                at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
                at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
                at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
                at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
                at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
                at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
                at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:42)
                at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
                at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
                at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
                at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:48)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)
                at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
                at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:122)
                at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
                at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
                at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
                at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:701)
                at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:646)
                at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)
                at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
                at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
                at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
                at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
                at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
                at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
                at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
                at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
                at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
                at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
                at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
                at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
                at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
                at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
                at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
                at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
                


                Is there something I could be missing in my configuration? I added the required filters and servlets mentioned in the "Getting Started" guide. All JSFUnit and the web content that it's trying to test is deployed in a single war file. I can access my "Hello World" jsp file at /test.faces without any problems. Any ideas? Let me know if you need more details. Thanks, Mike

                • 5. Re: JSFServerSession null
                  Stan Silvert Master

                  Hi,

                  You need a workaround for WebSphere. I just created a new wiki page for it. Please let me know if the wiki solves your problem:
                  http://wiki.jboss.org/wiki/JSFUnitOnWebSphere

                  Stan

                  • 6. Re: JSFServerSession null
                    Mike Bockus Newbie

                    Hi Stan,

                    Yes, the workaround you documented worked like a charm! Thanks!

                    Mike