3 Replies Latest reply on Oct 7, 2008 7:54 AM by Peter Treitler

    NullPointerException when using WebClientSpec

    Peter Treitler Newbie

      Hello.

      I've just tried writing a JSFUnit test that uses cookies. From what I've found in the Javadoc it should be done like this:

      WebClientSpec web_client_spec = new WebClientSpec("/categories.jsf");
      web_client_spec.addCookie("mycookie", "test");
      this.session = new JSFSession(web_client_spec);


      With the above code I get the following Exception:
      java.lang.NullPointerException
       at javax.faces.component.UIData.getRows(UIData.java:1022)
       at org.apache.myfaces.component.html.ext.HtmlDataTable.getRows(HtmlDataTable.java:756)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addUIData(ClientIDs.java:116)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addAllIDs(ClientIDs.java:75)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addAllIDs(ClientIDs.java:83)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addAllIDs(ClientIDs.java:83)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addAllIDs(ClientIDs.java:83)
       at org.jboss.jsfunit.jsfsession.ClientIDs.addAllIDs(ClientIDs.java:83)
       at org.jboss.jsfunit.jsfsession.ClientIDs.<init>(ClientIDs.java:62)
       at org.jboss.jsfunit.jsfsession.JSFServerSession.pageCreated(JSFServerSession.java:181)
       at org.jboss.jsfunit.jsfsession.JSFServerSession.<init>(JSFServerSession.java:54)
       at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:84)
       at at.tug.m3.jsf.CategoriesTest.setUp(CategoriesTest.java:36)
       at junit.framework.TestCase.runBare(TestCase.java:132)
       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:42)
       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:48)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       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: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(Thread.java:619)
      


      The problem seems to be caused by a MyFaces Tomahawk AliasBeansScope:
      <t:aliasBeansScope>
       <t:aliasBean alias="#{clipListViewer}" value="#{CategoriesBean.clipListViewer}" />
       <%@ include file="clipList.jsp"%>
      </t:aliasBeansScope


      Now the strange thing is that it works fine when I create the session by passing the URL:
      this.session = new JSFSession("/categories.jsf");


      But I haven't found a way to set a cookie without the WebClientSpec.
      Does anybody know how to do this or how to fix the above problem?

      Thanks,
      Peter