7 Replies Latest reply: Mar 16, 2011 4:02 AM by Stephan Pabinger RSS

NullPointerException - getCurrentViewID

Stephan Pabinger Newbie

Hi,

 

I'm currently trying to include JSFUnit into my JEE6, Seam3, Richfaces, Arquillian project.

I was able to run the getting stated example described at http://community.jboss.org/wiki/JSFUnit200GettingStartedExample.

 

However, when I include this test into my project I get a NullPointerException

 

testInitialPage(at.icbi.seqbench.jsfunit.HelloJSFTest)  Time elapsed: 2,664.141 sec  <<< ERROR!
java.lang.NullPointerException
    at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:79)
    at at.icbi.seqbench.jsfunit.HelloJSFTest.testInitialPage(HelloJSFTest.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

 

Specifically, the attributes clientIDs and currentFacesContext are null in JSFServerSession server.

 

Test class looks as follows:

@RunWith(Arquillian.class)
public class HelloJSFTest
{

  @Deployment
  public static WebArchive createDeployment()
  {
    Class clazz = org.jboss.jsfunit.cdi.InitialPage.class;
    WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
        .setWebXML(new File("src/test/resources/jsf/web.xml"))
        .addPackage(Package.getPackage("at.icbi.seqbench.jsfunit"))
        // my test package
        .addResource(new File("src/test/resources/jsf", "index.xhtml")).addWebResource(EmptyAsset.INSTANCE, "beans.xml")
        .addWebResource(new File("src/test/resources/jsf/faces-config.xml"), "faces-config.xml")
        .addManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));

    return war;
  }

  @Test
  @InitialPage("/index.faces")
  public void testInitialPage(JSFServerSession server, JSFClientSession client) throws IOException
  {
    // Test navigation to initial viewID
    Assert.assertEquals("/index.xhtml", server.getCurrentViewID());

    // Set the param and submit
    client.setValue("name", "MyName");
    client.click("submit_button");

    // Assert that the greeting component is in the component tree and rendered
    UIComponent greeting = server.findComponent("greeting");
    Assert.assertTrue(greeting.isRendered());

    // Test a managed bean using EL. We cheat and use the request object.
    Assert.assertEquals("MyName", server.getManagedBeanValue("#{request.getParameter('form1:name')}"));
  }

}

 

 

Does anybody have a hint for my problem?

Thanks,

Stephan

  • 1. Re: NullPointerException - getCurrentViewID
    Stan Silvert Master

    I think I see your problem.  You need two beans.xml files.  It's a little strange and it might change in the future.  But for now I'm pretty sure you need both of these

     

    .addWebResource(EmptyAsset.INSTANCE, "beans.xml")
    .addManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
    
    

     

    Stan

  • 2. Re: NullPointerException - getCurrentViewID
    Stephan Pabinger Newbie

    Hi Stan,

     

    thanks for your answer. I checked my code and both beans.xml files have been already included to the WAR (the first one is a bit hidden behind .addResource(new File("src/test/resources/jsf", "index.xhtml")) ).

     

    Therefore, I'm still stuck with this problem. Any other suggestions?

     

    Thanks,

    Stephan

  • 3. NullPointerException - getCurrentViewID
    Stan Silvert Master

    I think perhaps the JSFUnit filter is not running?  Are you running on a servlet 3 container?  If so, which one?

     

    If not you might be able to get this to work if you copy the declarations from the web-fragment.xml file that is inside arquillian-jsfunit.jar.  Put these declarations in your web.xml.  Note that the arquilllian-jsfunit.jar is created on the fly so you should find it in WEB-INF/lib.

     

    Stan

  • 4. NullPointerException - getCurrentViewID
    Stan Silvert Master

    Also, I might not be able to respond in a timely manner.

     

    Stan

  • 5. Re: NullPointerException - getCurrentViewID
    Saif KHan Newbie

    Hi,

     

    I am having the same issue with the getting started application. I have changed the pom.xml and using embedded tomcat 6.

    Actually the test method:

     

    @Test

       @InitialPage("/index.faces")

       public void testInitialPage(JSFServerSession server, JSFClientSession client) throws IOException { ....

     

     

     

    is getting null server. So this statement throws NullPointerException

     

    Assert.assertEquals("/index.xhtml", server.getCurrentViewID());

     

     

     

    Following is my web.xml

     

    <?xml version="1.0"?>

    <web-app xmlns="http://java.sun.com/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

        version="3.0"> 

     

     

        <listener>

                <listener-class>com.sun.faces.config.ConfigureListener</listener-class>

        </listener>

     

        <servlet>

          <servlet-name>ServletTestRunner</servlet-name>

          <servlet-class>org.jboss.arquillian.protocol.servlet_3.ServletTestRunner</servlet-class>

       </servlet>

       <servlet-mapping>

          <servlet-name>ServletTestRunner</servlet-name>

          <url-pattern>/ArquillianServletRunner</url-pattern>

       </servlet-mapping>

     

      <servlet>

        <servlet-name>Faces Servlet</servlet-name>

        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

        <load-on-startup>1</load-on-startup>

      </servlet>

     

      <servlet-mapping>

        <servlet-name>Faces Servlet</servlet-name>

        <url-pattern>*.faces</url-pattern>

      </servlet-mapping>

     

      <welcome-file-list>

        <welcome-file>index.html</welcome-file>

      </welcome-file-list> 

     

    </web-app>

     

     

     

    I am using the exact embedded-tomcat-6 pom code as given in arquillian-reference. I am really stuck here.

     

    Regards

  • 6. NullPointerException - getCurrentViewID
    Stan Silvert Master

    I haven't tried this on Tomcat 6 yet.  In order to use the JSFUnit annotations, you will need to follow the Arquillian instructions for CDI.  See http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#container.tomcat-embedded-6.

     

    You might need to get some help from the Arquillian forum to get that working.

     

    Stan

  • 7. NullPointerException - getCurrentViewID
    Stephan Pabinger Newbie

    Hi Stan,

     

    I'm running the test using a JBoss 6.final remote container configuration. How can I check if the JSFUnit filter is running?

     

    Thanks,

    Stephan