Getting Seam Integration tests and persistence to work
stefans Nov 24, 2009 5:14 PMHi
I've been working on this for the last couple of days and just can't seem to get it all right. I have an older Seam Project setup that has been migrated several times and is now up to Seam Version 2.1.2.GA. Therefore both the project folder and the configs and build scripts are all quite out of date. Now I've been trying to get Seam Integration tests to work and have made quite some progress. Regular integration tests work, as long as they do not try to injectan entityManager along the way. As soon as seam tries to instanciate an entityManager(factory) the following exception occurs
[testng] org.jboss.seam.InstantiationException: Could not instantiate Seam component: DeploymentAction [testng] at org.jboss.seam.Component.newInstance(Component.java:2144) [testng] at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304) [testng] at org.jboss.seam.contexts.Contexts.startup(Contexts.java:296) [testng] at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278) [testng] at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:113) [testng] at org.jboss.seam.init.Initialization.init(Initialization.java:740) [testng] at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:919) [testng] at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58) [testng] Caused by: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:/SPICSwoundEntityManagerFactory [testng] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:91) [...] [testng] Caused by: javax.naming.NameNotFoundException: SPICSwoundEntityManagerFactory not bound [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:542) [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:550) [testng] at org.jnp.server.NamingServer.getObject(NamingServer.java:556) [testng] at org.jnp.server.NamingServer.lookup(NamingServer.java:296) [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669) [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629) [testng] at javax.naming.InitialContext.lookup(InitialContext.java:392) [testng] at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241) [testng] ... 170 more
The setup in general: I created a custom -ds.xml under /bootstrap/deploy/ pointing to a PostgreSQL Database. the persistence.xml activates hbm2ddl create and the database structure is created successfully (it fails if the database name, user or password are mistyped) So I figure it must be some error with the configuration of components.xml, components.properties and/or persistence.xml.
So here are the (in my eyes) relevant configuration segments. Any pointers are really welcome as I am slowly getting desperate here ;)
persistence-test.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="someproject"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/someprojectDatasource</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.hbm2ddl.auto" value="create"/> <property name="hibernate.jdbc.batch_size" value="20"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/someprojectEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
components.xml
<core:init debug="@debug@" jndi-pattern="@jndiPattern@"/> <core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid"/> <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="@puJndiName@"/> <security:identity remember-me="true"/> <security:jpa-identity-store user-class="rise.spics.entities.User" role-class="rise.spics.entities.UserRole" /> <security:jpa-permission-store user-permission-class="rise.spics.entities.UserPermission"/>
components-test.properties (influenced by https://jira.jboss.org/jira/browse/JBSEAM-4393)
jndiPattern=#{ejbName}/local debug=true seamBootstrapsPu=true seamEmfRef=#{null} puJndiName=@puJndiName@
if the last two properties are replaced by
seamEmfRef=#{entityManagerFactory} puJndiName=#{null}
the abvoementioned error (stack trace) is replaced by the following error - at the same time of the execution
[testng] Caused by: javax.naming.NameNotFoundException: entityManager not bound [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:542) [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:550) [testng] at org.jnp.server.NamingServer.getObject(NamingServer.java:556) [testng] at org.jnp.server.NamingServer.lookup(NamingServer.java:296) [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669) [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629) [testng] at javax.naming.InitialContext.lookup(InitialContext.java:392) [testng] at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241)
If there is any information missing in this puzzle, please let me know! As mentioned, I am really grateful for any pointers. thanks!