1 2 Previous Next 16 Replies Latest reply on Nov 1, 2010 12:52 PM by iapazmino

    ejb test never gets executed

    iapazmino

      Hi, I'm trying to make a pretty simple test for an ejb service but it never gets executed.

      I'm using jbossas 5.

      I added the following to my pom to make the arquillian test

      - the jbossas-remote-5.1 profile without the test-resources tag so it looks for resources in src/test/resources

      - arquillian-junit:1.0.0-SNAPSHOT dependency

       

      I also added

      - a jndi.properties file in src/test/resources

       

      The test class includes the following additions

      - @RunWith(Arquillian.class)

      - @Deployment
          public static JavaArchive createTestArchive() {
          //ByteArrayAsset manifestCotent = new ByteArrayAsset("<beans/>".getBytes());
          //ArchivePath manifestFile = ArchivePaths.create("beans.xml");
          JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
          archive.addClasses(EmployeeService.class, EmployeeServiceBean.class);
          //archive.addManifestResource(manifestCotent, manifestFile);
          return archive;
          }//I have no idea what this method is doing...

       

      Before running I made sure jbossas 5.1 was running, then executed mvn test -Pjbossas-remote-5.1

      But the test wasn't run.

       

      -------------------------------------------------------
      T E S T S
      -------------------------------------------------------
      There are no tests to run.

       

      Results :

       

      Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

       

      What am I missing? I also made sure the $JBOSS_HOME var is set.

        • 1. Re: ejb test never gets executed
          dan.j.allen

          Where is your @Test method? Do you have one? The @Test method is the actual test code.

           

          The purpose of the @Deployment method is to create a deployable archive, in your case an EJB-JAR. That contains the code you want to test. Unlike a regular JUnit test, Arquillian doesn't just look at the whole classpath for code to test. It looks in the deployment.

           

          See this example to help you get started: Testing an EJB

          • 2. Re: ejb test never gets executed
            iapazmino

            that's actually the example I used as a guide. Sure, I have a @Test method:

             

                @Test
                public void createEmployee() throws SQLException {
                assertNotNull("Service wasn't injected. ", employeeService);

                ...

                employeeService.save(employee);
                assertNotNull("Employee id wasn't assigned. ", employee.getEmployeeId());
                log.info("employee id = " + employee.getEmployeeId());
                }

            • 3. Re: ejb test never gets executed
              dan.j.allen

              Got it. Then likely your Maven configuration is the culprit. Perhaps you have the tests skipped or not matched properly. You should be able to force the test to be executed using -Dtest=TestClassName

              • 4. Re: ejb test never gets executed
                iapazmino

                nice, now it did execute the test, but it failed

                initializationError(ec.pazmino.example.ejb.lunch.test.CreateEmployeeTest)  Time elapsed: 0.012 sec  <<< ERROR!
                org.jboss.arquillian.impl.event.FiredEventException: org.jboss.arquillian.spi.LifecycleException: Could not connect to container

                • 5. Re: ejb test never gets executed
                  dan.j.allen

                  Is JBoss AS running? The remote containers expect the container to be started. If you want the container to start automatically, use the jbossas-managed-5.1 container.

                   

                  Also, the test outpul will be written to a file in target/surefire-reports. If you run the test in Eclipse, you can see the output directly.

                  • 6. Re: ejb test never gets executed
                    iapazmino

                    Yes, jbossas was running. I chechked some more for a while and saw java.naming.provider.url is never set anywhere and port 1090 is alredy user for smx service. Anyway, I changed to managed container, so I deleted the jndi.properties file and instead I created an arquillian.xml file with the following content just to set the server instance I want to use

                     

                    <jboss:container>
                        <jboss:profileName>test-field</jboss:profileName>
                    </jboss:container>

                     

                    when running the mvn test -Dtest=CreateEmployeeTest -Pjbossas-managed-5.1 command, the configuration builds just fine but then stariting the server fails with the following error:

                     

                    Results :

                     

                    Tests in error:
                      ec.pazmino.example.ejb.lunch.test.CreateEmployeeTest

                     

                    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

                     

                    Testsuite shutdown hook found server "test-field" still running; stopping it.
                    Shutting down server: test-field
                    java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException

                     

                    then fails to stop the server

                     

                    Failed to shutdown server "test-field". Destroying the process.
                    Testsuite shutdown hook failed to stop server(s) on shutdown.
                    org.jboss.jbossas.servermanager.ServerShutdownException: Failed to shutdown server.Process was destroyed.
                        at org.jboss.jbossas.servermanager.ServerController.stopServer(ServerController.java:501)
                        at org.jboss.jbossas.servermanager.ServerManager$1.run(ServerManager.java:80)
                    Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException

                     

                    the report made by surefire reads

                     

                    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.592 sec <<< FAILURE!
                    ec.pazmino.example.ejb.lunch.test.CreateEmployeeTest  Time elapsed: 0 sec  <<< ERROR!
                    java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/HttpServlet

                    ...

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                        at org.jboss.arquillian.protocol.servlet_2_5.ProtocolDeploymentAppender.createAuxiliaryArchive(ProtocolDeploymentAppender.java:38)
                        at org.jboss.arquillian.protocol.servlet_2_5.ServletProtocolDeploymentPackager.generateDeployment(ServletProtocolDeploymentPackager.java:42)
                        at org.jboss.arquillian.impl.ClientDeploymentGenerator.generate(ClientDeploymentGenerator.java:68)
                        at org.jboss.arquillian.impl.handler.ArchiveGenerator.callback(ArchiveGenerator.java:52)
                        at org.jboss.arquillian.impl.handler.ArchiveGenerator.callback(ArchiveGenerator.java:42)
                        at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
                        at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
                        at org.jboss.arquillian.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:96)
                        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:162)
                        at org.jboss.arquillian.junit.Arquillian$3$1.evaluate(Arquillian.java:186)
                        at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
                        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:182)
                        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

                    ...

                    • 7. Re: ejb test never gets executed
                      dan.j.allen

                      You've been bitten by What's the cause of this exception: java.lang.ClassFormatError: Absent Code?

                       

                      I'm surprised you weren't able to get the remote container working. The JBoss AS client looks for those values in jndi.properties, so it should be able to connect to the server if you provide it and JBoss AS is running on standard ports.

                      • 8. Re: ejb test never gets executed
                        iapazmino

                        thanks, it did start the server. But, I didn't deploy the archive.

                        In the pom the packaging for the project is jar and at the deployment annotated field the return is a java archive, but the exception thrown complains an inexistent ear

                         

                        1    ERROR Server  - MbeanException

                        org.jboss.deployment.DeploymentException: Failed to deploy: file:/home/iapazmino/workspace/sandbox/lunch-ejb/test.ear

                        ...

                        Caused by: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

                         

                        *** DEPLOYMENTS IN ERROR: Name -> Error

                         

                        vfszip:/home/iapazmino/workspace/sandbox/lunch-ejb/test.ear/ -> org.jboss.deployers.spi.DeploymentException: Error deploying test.jar: failed to initialize bean container

                         


                        DEPLOYMENTS IN ERROR:
                          Deployment "vfszip:/home/iapazmino/workspace/sandbox/lunch-ejb/test.ear/" is in error due to the following reason(s): java.lang.NullPointerException

                        • 9. Re: ejb test never gets executed
                          dan.j.allen

                          Just to clarify, the packaging in your Maven pom is completely unrelated to the packaging of the ShrinkWrap (@Deployment) archive. The whole idea of Arquillian is that you can separate your test deployments from the deployment that your build creates.

                           

                          Hmm, it's hard to tell from your output what the source of the problem is. I'd need the stacktraces. Rather than post the stacktraces directly in the forum, it's best to link them from pastebin.com.

                          • 10. Re: ejb test never gets executed
                            iapazmino

                            Clear as water, thanks.

                             

                            here is the exception thrown http://arquillian.pastebin.com/5ssUqQDZ

                            and here is the surefire report http://arquillian.pastebin.com/udiSV1Dg

                            • 11. Re: ejb test never gets executed
                              iapazmino

                              I have changed the java archive creation line to JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "target/test.jar");

                              and the error report changed to http://arquillian.pastebin.com/LJbCj1La

                              I'm not sure if it's an step backward or fordward...

                              • 12. Re: ejb test never gets executed
                                dan.j.allen

                                The name of the ShrinkWrap archive is the name that goes in the EAR. So by changing it to "target/test.jar" it's going to try to put that in the EAR that way...and that will likely fail.

                                 

                                If you want to see the final archive that's produced, read how to dump it to disk in the container configuration section of the refguide.

                                 

                                Based on the exception report, it looks like you are getting a plain old deployment exception, which means the cause is what you have in the archive, not necessarily anything that Arquillian/ShrinkWrap is doing.

                                 

                                Dump the archive to disk and see if you can attach the file. Also, show your entire test file in pastebin. To debug, I probably have to reproduce on my end.

                                • 13. Re: ejb test never gets executed
                                  iapazmino

                                  Thanks a lot.

                                  I tried something I don't think it was clear to me in the example but I thought it might help. The service injected to the test needs indirectly of three or four classes classes more, so I added all of them to the java archive. Then it started complaining it couldn't find the service, so, it felt to me it's necessary to point out you have to include all of the classes involved in the test.

                                   

                                  changed from

                                  archive.addClasses(EmployeeService.class, EmployeeServiceBean.class);

                                  to

                                  archive.addClasses(EmployeeService.class, EmployeeServiceBean.class, CommonDao.class, EmployeeDao.class, Employee.class);

                                   

                                  next, the ejb couldn't be found. I had named mi service

                                  @Stateless(name = "EmployeeService")
                                  public class EmployeeServiceBean implements EmployeeService

                                   

                                  so my test class was looking for the service by its name

                                  @EJB(name = "EmployeeService")
                                  private EmployeeService employeeService;

                                   

                                  but this caused the test enrichment to fail

                                  Caused by: javax.naming.NamingException: No EJB found in JNDI, tried the following names: java:global/test.ear/test/EmployeeServiceBean, java:global/test.ear/test/EmployeeService, java:global/test/EmployeeService, java:global/test/EmployeeServiceBean, java:global/test/EmployeeService/no-interface, test/EmployeeServiceBean/local, test/EmployeeServiceBean/remote, test/EmployeeService/no-interface, EmployeeServiceBean/local, EmployeeServiceBean/remote, EmployeeService/no-interface

                                   

                                  this felt to me like a bug maybe. I deleted both naming parameters from the annotations and worked just fine. I mean it found the the ejb resource. Now, the new jar archive carries the datadource but can't be bound http://arquillian.pastebin.com/wAs9Crtg

                                  • 14. Re: ejb test never gets executed
                                    iapazmino

                                    Noticed too that it needs both parameters set to make a closer-to-correct injection of resources.

                                    the surefire report above is injecting the resource only with the mapped name but whe using also name attribute reads as follows

                                     

                                    -------------------------------------------------------------------------------
                                    Test set: ec.pazmino.example.ejb.lunch.test.CreateEmployeeTest
                                    -------------------------------------------------------------------------------
                                    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.983 sec <<< FAILURE!
                                    createEmployee(ec.pazmino.example.ejb.lunch.test.CreateEmployeeTest)  Time elapsed: 1.058 sec  <<< ERROR!
                                    javax.ejb.EJBException: java.lang.RuntimeException: Unable to inject jndi dependency: env/lunchDS into property ec.pazmino.example.ejb.lunch.facade.EmployeeServiceBean.dataSource: lunchDS not bound

                                     

                                    deploying the ear directly into the server doesn't have any problem

                                    1 2 Previous Next