6 Replies Latest reply on Feb 26, 2010 9:13 AM by Stan Silvert

    Can I use JSFUnit with Spring?

    Edenilton Barbosa Newbie

      Hi,

      I'm trying o run some tests with JSFunit, but I'm with problems. My application use Spring to inject services.

      When I test the application without to use Spring, the result is correct.

      But when I use the Spring and try to run test:

      assertEquals("/jsp/jeep/Escolhe_Numero_Jeep.jsp", server.getCurrentViewID());
      


      gives NullPointerException, even the server variable is not null.

      Because of that, I'm imagining that the JSFUnit maybe don't works in this case.

      Thanks.

        • 1. Re: Can I use JSFUnit with Spring?
          Stan Silvert Master

          Can you post the stack trace?

          Stan

          • 2. Re: Can I use JSFUnit with Spring?
            Edenilton Barbosa Newbie

             

            "stan.silvert@jboss.com" wrote:
            Can you post the stack trace?

            Stan


            Here's:
            java.lang.NullPointerException
            at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:76)
            at br.com.vivo.vivo360.jeep.test.jsfunit.EscolheNumeroJeepTest.testFirst(EscolheNumeroJeepTest.java:50)
            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:217)
            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:217)
            at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
            at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
            at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
            at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:217)
            at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
            at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
            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:116)
            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:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            at java.lang.Thread.run(Unknown Source)
            
            
            



            This is shown on browser.


            Here's my Test:

            
            public class EscolheNumeroJeepTest extends ServletTestCase{
            
             private static JSFSession session;
             private static JSFClientSession client;
             private static JSFServerSession server;
            
             public static Test suite(){
             return new TestSuite(EscolheNumeroJeepTest.class);
             }
            
             @Override
             protected void setUp() throws Exception, SAXException {
             super.setUp();
            
             session = new JSFSession("/jsp/jeep/Escolhe_Numero_Jeep.jsf");
             client = session.getJSFClientSession();
             server = session.getJSFServerSession();
            
             }
             public void testFirst() throws IOException, SAXException{
            
             assertEquals("/jsp/jeep/Escolhe_Numero_Jeep.jsp", server.getCurrentViewID());
             }
            }
            
            



            Thank you, Stan.

            • 3. Re: Can I use JSFUnit with Spring?
              Stan Silvert Master

              JSFUnit isn't getting the FacesContext, which is the key to everything JSFUnit does.

              If I understand correctly, your JSFUnit test works as long as your Spring jar is not present? If that is true then I suspect that a FacesContextFactory is being installed by Spring and that factory is not respecting the delegation model. You might be able to find out if you look inside the jar and see a faces-context.xml that declares a FacesContextFactory.

              Stan

              • 4. Re: Can I use JSFUnit with Spring?
                Alexander Jesse Newbie

                Maybe renaming the JSFUnit-jar to something like ZZZ-jsfunit... might help.
                According to the current JSF (1.x) rules for initializing faces-config hidden in the jars, the jars will be initialized according to the sorted list of the jar-names. And with that rule JSFUnit comes after facelets but before Spring...

                Just a possibilty...

                • 5. Re: Can I use JSFUnit with Spring?
                  tamara rojo Newbie

                  Hi,

                  I'm new using Jsfunit. I have the same error which is discussed here and I can not fix it. I changed the name of the jar and still have the same problem. Can anyone help me please? Any ideas?

                   

                  Thanks.

                  • 6. Re: Can I use JSFUnit with Spring?
                    Stan Silvert Master

                    Hi Tamara,

                     

                    Unfortunately, I don't have the manpower to address Spring compatibility head on right now.  This jira task contains a couple of links that describe workarounds.

                     

                    https://jira.jboss.org/jira/browse/JSFUNIT-235

                     

                    If someone out there wants to help I'd certainly like to integrate a real fix for Spring.

                     

                    Stan