2 Replies Latest reply on Oct 22, 2012 4:01 PM by munir_salim

    NullPointer in @EJB

    munir_salim

      Hello!

       

      I am new in arquillian... I managed to perform the tests of the tutorials.. but when I try to implement in my project it fail.

       

      Following this example: https://github.com/arquillian/arquillian-examples/tree/master/ejb31-jbembedded

       

      The class HelloEJB and HelloEJBIT is exactly like the example.

       

      This is my pom.xml:


      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <modelVersion>4.0.0</modelVersion>

       

          <artifactId>theproject-services-impl</artifactId>

          <packaging>ejb</packaging>

       

          <name>EJB Services layer IMPL</name>

          <url>http://wiki.xxx.com.br/display/theproject/Home</url>

       

          <parent>

              <groupId>com.xxx.yyy.theproject</groupId>

              <artifactId>theproject-parent</artifactId>

              <version>1.0.0</version>

          </parent>

       

          <properties>

              <version.junit>4.8.2</version.junit>

       

              <!-- Versioning -->

              <version.org.jboss.arquillian>1.0.0.CR7</version.org.jboss.arquillian>

       

              <!-- The target version of AS to be used -->

              <version.org.jboss.jbossas>6.1.0.Final</version.org.jboss.jbossas>

       

              <!-- JBOSS_HOME (We'll unpack into here -->

              <JBOSS_HOME>C:/jboss-6.1.0.Final</JBOSS_HOME>

          </properties>

       

          <build>

              <plugins>

                  <plugin>

                      <artifactId>maven-ejb-plugin</artifactId>

                      <version>2.3</version>

                      <configuration>

                          <ejbVersion>3.0</ejbVersion>

                      </configuration>

                  </plugin>

                  <plugin>

                       <groupId>org.codehaus.mojo</groupId>

                       <artifactId>jboss-maven-plugin</artifactId>

                       <configuration>

                          <!-- Link the plugin to your local install via OS environment variable JBOSS_HOME -->

                          <jbossHome>${JBOSS_HOME}</jbossHome>

                          <!-- Your JBoss domain (optional) -->

                          <serverName>default</serverName>

                       </configuration>

                    </plugin>

              </plugins>

          </build>

       

          <repositories>

              <repository>

                  <id>JBoss</id>

                  <name>JBoss Repository</name>

                  <url>https://repository.jboss.org/nexus/content/groups/public/</url>

              </repository>

          </repositories>

       

          <dependencyManagement>

              <dependencies>

       

                  <!-- org.jboss.jbossas -->

                  <dependency>

                      <groupId>org.jboss.jbossas</groupId>

                      <artifactId>jboss-as-server</artifactId>

                      <version>${version.org.jboss.jbossas}</version>

                      <type>pom</type>

                      <scope>import</scope>

                  </dependency>

                  <dependency>

                      <groupId>org.jboss.arquillian</groupId>

                      <artifactId>arquillian-bom</artifactId>

                      <version>1.0.0.CR7</version>

                      <scope>import</scope>

                      <type>pom</type>

                  </dependency>

              </dependencies>

       

          </dependencyManagement>

       

          <dependencies>

       

              <!-- Test Dependencies -->

       

              <!-- Arquillian Test Harness -->

              <dependency>

                  <groupId>org.jboss.arquillian.container</groupId>

                  <artifactId>arquillian-jbossas-embedded-6</artifactId>

                  <version>1.0.0.Alpha5</version>

              </dependency>

              <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

              </dependency>

             

              <dependency>

                  <groupId>org.jboss.spec</groupId>

                  <artifactId>jboss-javaee-6.0</artifactId>

                  <version>3.0.1.Final</version>

                  <scope>provided</scope>

                  <type>pom</type>

              </dependency>

       

              <!-- JUnit -->

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <version>${version.junit}</version>

              </dependency>

       

              <!-- JBossAS -->

              <dependency>

                  <groupId>org.jboss.jbossas</groupId>

                  <artifactId>jboss-as-depchain</artifactId>

                  <version>${version.org.jboss.jbossas}</version>

                  <type>pom</type>

                  <scope>compile</scope>

                  <!-- Should be "test", but I can't find the GAV for JPA APIs -->

              </dependency>

       

              <dependency>

                  <groupId>${project.groupId}</groupId>

                  <version>${project.version}</version>

                  <artifactId>theproject-services-api</artifactId>

              </dependency>

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-entitymanager</artifactId>

                  <version>${hibernate.entitymanager}</version>

                  <scope>provided</scope>

                  <exclusions>

                      <exclusion>

                          <artifactId>hibernate-jpa-2.0-api</artifactId>

                          <groupId>org.hibernate.javax.persistence</groupId>

                      </exclusion>

                      <exclusion>

                          <artifactId>javassist</artifactId>

                          <groupId>javassist</groupId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>javax.mail</groupId>

                  <artifactId>mail</artifactId>

                  <version>1.4.3</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>javax.xml.ws</groupId>

                  <artifactId>jaxws-api</artifactId>

                  <version>2.2</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>xxx</groupId>

                  <artifactId>GBIO</artifactId>

                  <version>0.4.10</version>

              </dependency>

              <dependency>

                  <groupId>xxx.NDO</groupId>

                  <artifactId>prediction</artifactId>

                  <version>0.4.1</version>

                  <exclusions>

                      <exclusion>

                          <groupId>javax.xml.ws</groupId>

                          <artifactId>jaxws-api</artifactId>

                      </exclusion>

                      <exclusion>

                          <groupId>com.sun.xml.ws</groupId>

                          <artifactId>jaxws-rt</artifactId>

                      </exclusion>

                      <exclusion>

                          <artifactId>listener</artifactId>

                          <groupId>com.xxx</groupId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>org.jboss.ejb3</groupId>

                  <artifactId>jboss-ejb3-ext-api</artifactId>

                  <version>1.0.0</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>javax.jms</groupId>

                  <artifactId>jms</artifactId>

                  <version>1.1</version>

                  <scope>provided</scope>

              </dependency>

       

              <dependency>

                  <groupId>quartz</groupId>

                  <artifactId>quartz</artifactId>

                  <version>1.6.0</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>com.xxx</groupId>

                  <artifactId>listener</artifactId>

                  <version>0.0.3</version>

                  <exclusions>

                      <exclusion>

                          <groupId>javax.xml.ws</groupId>

                          <artifactId>jaxws-api</artifactId>

                      </exclusion>

                      <exclusion>

                          <groupId>com.sun.xml.ws</groupId>

                          <artifactId>jaxws-rt</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>commons-net</groupId>

                  <artifactId>commons-net</artifactId>

                  <version>2.0</version>

              </dependency>

              <dependency>

                  <groupId>org.jboss.ws</groupId>

                  <artifactId>jbossws-jboss510</artifactId>

                  <version>3.4.0.GA</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>net.sf.jtidy</groupId>

                  <artifactId>jtidy</artifactId>

                  <version>r938</version>

              </dependency>

              <dependency>

                  <groupId>org.antlr</groupId>

                  <artifactId>stringtemplate</artifactId>

                  <version>4.0.2</version>

              </dependency>

              <dependency>

                  <groupId>org.jboss.client.eap</groupId>

                  <artifactId>jbossws-native-core</artifactId>

                  <version>5.1.0.EAP</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>joda-time</groupId>

                  <artifactId>joda-time</artifactId>

                  <version>1.6</version>

              </dependency>

          </dependencies>

          <profiles>

              <profile>

       

                  <!-- Declare the jbossas-embedded-6 integration test profile -->

                  <id>jbossas-embedded-6</id>

                  <activation>

                      <activeByDefault>true</activeByDefault>

                  </activation>

       

                  <build>

       

                      <plugins>

       

                          <!-- FailSafe Plugin. Expects test suffix "IT". -->

                          <plugin>

                              <artifactId>maven-failsafe-plugin</artifactId>

                              <version>2.6</version>

       

                              <executions>

                                  <execution>

                                      <id>integration-test</id>

                                      <phase>integration-test</phase>

                                      <goals>

                                          <goal>integration-test</goal>

                                      </goals>

                                      <configuration>

       

                                          <additionalClasspathElements>

                                              <additionalClasspathElement>${JBOSS_HOME}/client/jbossws-native-client.jar

                                              </additionalClasspathElement>

                                              <additionalClasspathElement>${JBOSS_HOME}/server/default/deploy/jbossweb.sar

                                              </additionalClasspathElement>

                                          </additionalClasspathElements>

                                          <trimStackTrace>false</trimStackTrace>

                                          <printSummary>true</printSummary>

       

                                          <forkMode>pertest</forkMode>

       

                                          <!-- Caution: no linebreak here !-->

                                           <argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed -Djboss.home=${JBOSS_HOME} -Djboss.boot.server.log.dir=${JBOSS_HOME} -Dorg.jboss.reflect.spi.TypeInfoFactory=org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory</argLine>

       

                                      </configuration>

                                  </execution>

       

                                  <execution>

                                      <id>verify</id>

                                      <goals>

                                          <goal>verify</goal>

                                      </goals>

                                  </execution>

       

                              </executions>

                          </plugin>

       

                      </plugins>

       

                  </build>

       

              </profile>

       

       

              <profile>

                  <id>mcom-jaxb-input</id>

                  <build>

                      <plugins>

                          <plugin>

                              <groupId>com.sun.tools.xjc.maven2</groupId>

                              <artifactId>maven-jaxb-plugin</artifactId>

                              <executions>

                                  <execution>

                                      <goals>

                                          <goal>generate</goal>

                                      </goals>

                                  </execution>

                              </executions>

                              <configuration>

                                  <generatePackage>com.xxx.yyy.theproject.generated.xml.mcom.input</generatePackage>

                                  <includeSchemas>

                                      <includeSchema>**/MCOM_Entrada.xsd</includeSchema>

                                  </includeSchemas>

                                  <strict>true</strict>

                                  <verbose>true</verbose>

                                  <removeOldOutput>true</removeOldOutput>

                              </configuration>

                          </plugin>

                      </plugins>

                  </build>

              </profile>

       

              <profile>

                  <id>mcom-jaxb-output</id>

                  <build>

                      <plugins>

                          <plugin>

                              <groupId>com.sun.tools.xjc.maven2</groupId>

                              <artifactId>maven-jaxb-plugin</artifactId>

                              <executions>

                                  <execution>

                                      <goals>

                                          <goal>generate</goal>

                                      </goals>

                                  </execution>

                              </executions>

                              <configuration>

                                  <generatePackage>com.xxx.yyy.theproject.generated.xml.mcom.output</generatePackage>

                                  <includeSchemas>

                                      <includeSchema>**/MCOM_Saida.xsd</includeSchema>

                                  </includeSchemas>

                                  <strict>true</strict>

                                  <verbose>true</verbose>

                                  <removeOldOutput>true</removeOldOutput>

                              </configuration>

                          </plugin>

                      </plugins>

                  </build>

              </profile>

              <profile>

                  <id>wsdl</id>

                  <properties>

                      <deploy-env>xxx</deploy-env>

                  </properties>

                  <build>

                      <plugins>

                          <plugin>

                              <groupId>org.codehaus.mojo</groupId>

                              <artifactId>jaxws-maven-plugin</artifactId>

                              <executions>

                                  <execution>

                                      <goals>

                                          <goal>wsimport</goal>

                                      </goals>

                                      <configuration>

                                          <sourceDestDir>${project.basedir}/src/main/java</sourceDestDir>

                                          <wsdlUrls>

                                              <wsdlUrl>${project.basedir}/${mcom.wsdl.archive}.wsdl</wsdlUrl>

                                          </wsdlUrls>

                                          <packageName>com.xxx.yyy.theproject.sap.xi.${mcom.wsdl.package}</packageName>

                                      </configuration>

                                  </execution>

                              </executions>

                              <dependencies>

                                  <dependency>

                                      <groupId>com.sun.xml.ws</groupId>

                                      <artifactId>jaxws-tools</artifactId>

                                      <version>2.1.1</version>

                                  </dependency>

                              </dependencies>

                          </plugin>

                      </plugins>

                  </build>

              </profile>

              <profile>

                  <id>wsdl-maplink</id>

                  <properties>

                      <deploy-env>xxx</deploy-env>

                  </properties>

                  <build>

                      <plugins>

                          <plugin>

                              <groupId>org.apache.axis2</groupId>

                              <artifactId>axis2-wsdl2code-maven-plugin</artifactId>

                              <version>1.4</version>

                              <executions>

                                  <execution>

                                      <goals>

                                          <goal>wsdl2code</goal>

                                      </goals>

                                      <configuration>

                                          <packageName>com.xxx.yyy.theproject.services.maplink.authentication</packageName>

                                          <wsdlFile>${project.basedir}/src/main/resources/wsdls_maplink/authentication.wsdl</wsdlFile>

                                          <databindingName>xmlbeans</databindingName>

                                      </configuration>

                                  </execution>

                              </executions>

                          </plugin>

                      </plugins>

                  </build>

              </profile>

          </profiles>

      </project>

       

       

      And I got this error when run JUnit:

       

      java.lang.NullPointerException

          at com.xxx.yyy.theproject.services.HelloEJBTest.testHelloEJB(HelloEJBTest.java:35)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

          at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)

          at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)

          at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

          at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:53)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

          at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

          at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)

          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)

          at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)

          at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

          at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)

          at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)

          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)

          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

       

       

      Sorry if it's a newbie question. But I learned all discussions of this forum and search a lot in google and not find anything. I have no more alternatives.

       

      Thx!

        • 1. Re: NullPointer in @EJB
          meetoblivion

          Hi

           

          When your test case runs, do you see JBoss AS 6 embedded start up?  Did you install the application server and setup your JBOSS_HOME environment variable?

          • 2. Re: NullPointer in @EJB
            munir_salim

            Hi John,

             

            I change the the version of dependency arquillian jbossass 1.0.0.Alpha5 to 1.0.0.CR3 and it works!

            I dont know why...

             

            Now the server is starting.

            I am getting another error, but with the server starting I believe i'm closer to done =)

             

            Thank you very much!