NoSuchElementException when trying to retrieve TestRunner
jdevlin Aug 29, 2012 9:44 PMHi 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
-
stripped_down_pom.xml.zip 1.1 KB