1 Reply Latest reply on Nov 20, 2008 7:28 AM by Stan Silvert

    Issue while running jsf unit test in web sphere processs ser

    Mritunjay Kumar Newbie

      Hi,
      I want to run jsf unit test in for the application which is deployed in web sphere process erver.
      For this i have two jsp pages index.jsp and hello.jsp
      code for the index.jsp.



      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <f:view>

      A Simple JavaServer Faces Application


      <h:form>
      <h3>
      Please enter your name
      </h3>



      Name:


      <h:inputText value="#{person.name}" rendered="#{!empty person.name}" id="personName" />




      <h:commandButton value="Say Hello" action="sayHello" />
      <h:commandButton value="Say Bye" action="sayBye" />

      </h:form>

      </f:view>


      now here is code for hello.jsp

      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>


      <f:view>

      Hello World!


      <h:form>
      <h3>
      Hello,
      <h:outputText value="#{person.name}" rendered="#{!empty person.name}" id="personName" />
      </h3>

      <h:commandLink id="Cancel" action="index" immediate="true">
      <h:outputText value="Cancel" />
      </h:commandLink>
      </h:form>

      </f:view>



      My test case is HelloJsfUnitTest.java

      package test;

      import java.io.IOException;

      import junit.framework.Test;
      import junit.framework.TestSuite;

      import org.apache.cactus.ServletTestCase;
      import org.jboss.jsfunit.facade.JSFClientSession;
      import org.jboss.jsfunit.facade.JSFServerSession;
      import org.xml.sax.SAXException;

      public class HelloJSFUnitTest extends ServletTestCase {

      private JSFClientSession client;
      private JSFServerSession server;

      // JUnit suite() method
      public static Test suite()
      {
      return new TestSuite( HelloJSFUnitTest.class );
      }

      // optional JUnit setUp() method
      public void setUp() throws IOException, SAXException
      {
      this.client = new JSFClientSession( "/hello.faces");
      this.server = new JSFServerSession(client);
      }

      // one or more JUnit test methods
      public void testHelloWorld() throws IOException, SAXException
      {
      client.setParameter("personName", "Rishabh");
      client.submit();
      assertEquals("Rishabh", server.getManagedBeanValue("#{person.name}"));
      assertTrue(client.getWebResponse().getText().contains("Hello, Rishabh"));
      }

      }

      When i run this HelloJsfUnitTest.java, i am getting exception:
      java.lang.NullPointerException
      at org.jboss.jsfunit.facade.ClientIDs.(ClientIDs.java:61)
      at org.jboss.jsfunit.facade.JSFClientSession.updateInternalState(JSFClientSession.java:211)
      at org.jboss.jsfunit.facade.JSFClientSession.doWebRequest(JSFClientSession.java:201)
      at org.jboss.jsfunit.facade.JSFClientSession.doInitialRequest(JSFClientSession.java:131)
      at org.jboss.jsfunit.facade.JSFClientSession.(JSFClientSession.java:121)
      at test.HelloJSFUnitTest.setUp(HelloJSFUnitTest.java:31)
      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:1075)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1016)
      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:771)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:679)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:546)
      at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
      at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:115)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
      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:165)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
      0.078

      Please help me solving this issue.

      I have another test case JSFUnitTest
      package test;

      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.framework.WebClientSpec;
      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
      WebClientSpec wcSpec = new WebClientSpec("/index.faces");
      wcSpec.setInitialRequestStrategy(new WebSphereRequestStrategy());
      JSFSession jsfSession = new JSFSession(wcSpec);


      // 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("personName");
      assertTrue(prompt.isRendered());

      // Test a managed bean
      assertEquals("Rishabh", server.getManagedBeanValue("#{person.name}"));
      }
      }

      This JSFUnit test is running file. but i have problem in running HelloJSFUnitTest.
      Please help me solving this issue as soon as possible.
      Regards,
      Mritunjay