5 Replies Latest reply on Sep 3, 2012 6:31 AM by aslak

    NoSuchElementException when trying to retrieve TestRunner

    jdevlin

      Hi all,

       

      I have a simple integration test which attempts to insert a 'Product' into a database. I apologise in advance if syntax highlighting doesn't work, I am still learning how to use these forums.

       

      //package and various imports, omitted for readability 
      
      @RunWith(Arquillian.class)
      public class ProductPersistenceTestCase {
      
        @Deployment
        public static Archive<?> createDeployment() {      
            JavaArchive testJAR = ShrinkWrap.create(JavaArchive.class, "test.jar")
                                            .addPackage(Product.class.getPackage())                                      
                                            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                                            .addAsManifestResource("persistence.xml", "persistence.xml");
            
            testJAR.addPackages(true, "org.fest");
            testJAR.addPackages(true, "org.junit");
            
            return testJAR;
        }
      
      
        @PersistenceContext
        EntityManager em;
        
        @Test
        @Transactional(TransactionMode.ROLLBACK)
        public void shouldPersistProducts() throws Exception {
          Product eraser = new Product(50.0, "ERASER SUPREMO", 75.00, "50");
          em.persist(eraser);
          em.flush();
          em.clear();
          @SuppressWarnings("unchecked")
          List<Product> products = em.createQuery(selectAllInJPQL(Product.class)).getResultList();
          
          assertThat(products).hasSize(1);
          
        }
            
        private String selectAllInJPQL(Class<?> clazz) {
            return "SELECT entity FROM " + clazz.getSimpleName() + " entity";
        }
        
      }
      
      

       

      The above test is shrinkwrapped and deployed to WebLogic 11g 10.3.6 when mvn deploy is executed. When this is accomplished using the Arquillian WebLogic deployer client the test is reported as being in error. The following stack trace is observed in the attached TEST-au.com.unico.portal.model.jpa.ProductPersistenceTestCase.xml file. For the entire stack trace please refer to that file.

       

      -------------------------------------------------------------------------------

      Test set: au.com.unico.portal.model.jpa.ProductPersistenceTestCase

      -------------------------------------------------------------------------------

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 24.9 sec <<< FAILURE!

      shouldPersistProducts(au.com.unico.portal.model.jpa.ProductPersistenceTestCase)  Time elapsed: 0.104 sec  <<< ERROR!

      java.util.NoSuchElementException

                at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:375)

                at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:384)

                at org.jboss.arquillian.container.test.spi.util.TestRunners.getTestRunner(TestRunners.java:60)

       

      In trying to resolve the issue I found this post http://blog.frankel.ch/tag/integration-testing. The author suggests introducing the Arquillian BOM which I have done in the project POM as below.

       

      <dependency>
                                              <groupId>org.jboss.arquillian</groupId>
                                              <artifactId>arquillian-bom</artifactId>
                                              <version>${version.arquillian_core}</version>
                                              <type>pom</type>
                                              <scope>import</scope>
      </dependency>
      

       

      Note that ${version.arquillian_core} resolves to 1.0.0.CR7. I have attached an XML file containing both the dependencyManagement and dependencies block from my Project POM for all of the Arquillian related dependencies (called stripped_down_pom.xml).

       

      Unfortunately this change was to no avail! Still battling on with it thought and hoping the folks here may have some keen insights that will help me understand what may be going on. I hope the above makes sense.

       

      Cheers,

      James

        • 1. Re: NoSuchElementException when trying to retrieve TestRunner
          aslak

          Not sure how you ended up with that pom, but try to set it up like in the getting started guide:

           

          http://arquillian.org/guides/getting_started/#add_the_arquillian_apis

           

          DependencyManagement:

            arquillian-bom type pom scope import

           

          Dependency

            arquillian-junit-container

           

            arquillian-persistence-impl

            arquillian-wls-remote-10.3

          1 of 1 people found this helpful
          • 2. Re: NoSuchElementException when trying to retrieve TestRunner
            jdevlin

            Hi Aslak,

             

            thank you for your reply. I have brought the project POM in line with what you've mentioned and the page you linked (link to pom below). The testable artifact is now being deployed to WebLogic, being reported in error but with a very different stack trace. Please below an excerpt from the surefire test report.

             

            java.lang.IllegalAccessError: tried to access method org/junit/runners/ParentRunner.getTestClass()Lorg/junit/runners/model/TestClass; from class org/jboss/arquillian/junit/Arquillian$2

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

                      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)

             

            I have double checked the version of JUnit being used in the project which is 4.8.1. According to similar accounts of the above message this is the correct version to have in place. I also had a look at the visibility of the compiled ParentRunner.getTestClass() method as placed into the testable archive and it has public visibility.

             

            Please find here (http://pastebin.com/EqEsg50t) the revised dependencyManagement and dependency tag blocks.

             

            Cheers,

            James

            • 3. Re: NoSuchElementException when trying to retrieve TestRunner
              aslak

              Try to upgrade to Arquillian Core 1.0.1.Final

              • 4. Re: NoSuchElementException when trying to retrieve TestRunner
                jdevlin

                Hi Aslak,

                 

                thanks for your help. It turns out that this is a classpath conflict issue present when using the Oracle SOA BPM VM which includes a WebLogic server pre-installed with several other Oracle technologies. Once of those technologies comes packed with JUnit. To fix this issue for anyone else using that VM issue the following command:

                 

                mv /oracle/fmwhome/Oracle_WC1/wikiserver/owc_wiki/WEB-INF/lib/junit.jar .

                 

                Thanks again for your prompt replies we are now able to execute our in-container persistence tests!

                 

                Cheers,

                James

                • 5. Re: NoSuchElementException when trying to retrieve TestRunner
                  aslak

                  Have you reported the issue to Oracle?

                   

                  I'm not sure why wiki software would use JUnit runtime. Sounds like a packaging problem.