5 Replies Latest reply on Dec 6, 2007 5:21 PM by Pete Muir

    Null Pointer Exception During Integration Testing

    neilac333 Novice

      I am integration testing my first component, and I am finding a NullPointerException that I cannot find an explanation for.

      Here is the class I am testing:

      @Name("searchAction")
      public final class searchAction extends Object {
       private String name;
       @In
       private SearchDelegate search;
       @Logger
       private Log logger;
      
      ...and so on
      


      Here is my test:

      public void testSearchActionComponent() throws Exception {
       logger.debug("Starting method testSearchActionComponent");
      
       new ComponentTest() {
      
       protected void testComponents() throws Exception
       {
       setValue("#{searchAction.name}", "Benzoic");
       }
      
       }.run();
       }
      
      



      Finally, here is the exception:

      java.lang.NullPointerException
       at org.jboss.seam.servlet.ServletApplicationMap.get(ServletApplicationMap.java:54)
       at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:48)
       at org.jboss.seam.Component.getInstance(Component.java:1843)
       at org.jboss.seam.Component.getInstance(Component.java:1821)
       at org.jboss.seam.Component.getInstance(Component.java:1816)
       at org.jboss.seam.core.Expressions.instance(Expressions.java:253)
       at org.jboss.seam.mock.BaseSeamTest$ComponentTest.setValue(BaseSeamTest.java:160)
       at model.test.SearchActionAdvancedTest$2.testComponents(Unknown Source)
       at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:170)
       at model.test.SearchActionAdvancedTest.testComponent(Unknown Source)
      


      As you can see, I am not really even testing anything. I just wanted to see if this minimalist approach would pass, but it is not.

      Please let me know if you need more information. Any insight is appreciated.

      Thanks.

        • 1. Re: Null Pointer Exception During Integration Testing
          Pete Muir Master

          Post the whole of the log output from TestNG

          • 2. Re: Null Pointer Exception During Integration Testing
            neilac333 Novice

            I am not sure what sort of output you mean. I have checked the TestNG documentation, and there does not seem to be any specialized logging besides writing my own custom TestListenerAdapter.

            I was actually just about to ask if there is a way to determine what Seam is looking for from the ServletApplicationMap. I tried setting all the logging levels in log4j.xml in the bootstrap folder to the level of DEBUG, and I ran Ant in -verbose mode. I am still not getting any useful information.

            All I have so far is this:

            DEBUG [model.test.SearchActionAdvancedTest] Starting method testSearchActionComponent
            DEBUG [org.jboss.seam.contexts.TestLifecycle] >>> Begin test
            DEBUG [org.jboss.seam.contexts.TestLifecycle] <<< End test
            


            Obviously, that isn't much. Let me know how to add more logging beyond the measures I have described already, and I will be sure to provide that output as soon as possible.

            Thanks.

            • 3. Re: Null Pointer Exception During Integration Testing
              neilac333 Novice

              So I commented everything out in my test and tried this:

              Assert.assertEquals(getValue("#{identity.loggedIn}"), false);
              


              And I get the same NPE for a component that is BUILT_IN. It seems to me that I am either missing a JAR file in the classpath, or more likely I am missing a configuration file. The classpath for TestNG points to the bootstrap directory at the top level of the Seam 2.0 GA distribution. The only thing I have altered is log4j.xml--in order to set every logging level to DEBUG.

              I have noticed components.xml is not in that directory. Should I add it and/or other files to get my tests running?

              Thanks for any insight.

              • 4. Re: Null Pointer Exception During Integration Testing
                neilac333 Novice

                I should probably mention that I am running my test by compiling all my code into a JAR file, which is included on the classpath of TestNG. This JAR has seam.properties located in the META-INF directory. Is this OK for my test to work?

                If anyone has managed to get SeamTest to work for integration tests with Seam 2.0 GA, I would appreciate any insights.

                Thanks.

                • 5. Re: Null Pointer Exception During Integration Testing
                  Pete Muir Master

                  Did you use seam-gen to set up your project? Tests defintely work here.