On Jan 16, 2013, at 11:35 PM, christina <[email protected]> wrote:
> Hi,
>
> I want to use ApplicationComposer to unit test (in Eclipse) a EJB with an
> injected PersistenceContext. But I'm getting the following error:
>
> SEVERE - FAIL ... SimpleService: Missing required persistence.xml for
> @PersistenceContext ref "entityManager" to unit "test"
> SEVERE - Invalid EjbModule(name=jax-ws, path=null)
>
> Interstingly the path is null, I suspect I am not setting something required
> in my @Module method? The following test fails:
>
> package au.test;
>
> import static org.junit.Assert.assertNotNull;
> import javax.ejb.EJB;
> import org.apache.openejb.jee.EjbJar;
> import org.apache.openejb.jee.StatelessBean;
> import org.apache.openejb.junit.ApplicationComposer;
> import org.apache.openejb.junit.EnableServices;
> import org.apache.openejb.junit.Module;
> import org.junit.Test;
> import org.junit.runner.RunWith;
>
> @RunWith(ApplicationComposer.class)
> @EnableServices("ejdb")
> public class SimpleServiceApplicationComposerTest
> {
> @EJB
> private SimpleServiceWs simpleService;
>
> @Module
> // @Classes({ SimpleService.class })
> public EjbJar myWebApplication()
> {
> EjbJar ejbJar = new EjbJar("jax-ws");
> ejbJar.addEnterpriseBean(new StatelessBean(SimpleService.class));
> return ejbJar;
> }
>
> @Test
> public void test()
> {
> assertNotNull(simpleService);
> }
> }
The ApplicationComposer doesn't do any searching for descriptor files and
instead relies 100% on meta-data supplied in the test itself. So if you want a
Persistence Unit, you need to add it in the test case like so:
@Module
public PersistenceUnit persistence() {
PersistenceUnit unit = new PersistenceUnit("movie-unit");
unit.setJtaDataSource("movieDatabase");
unit.setNonJtaDataSource("movieDatabaseUnmanaged");
unit.getClazz().add(Movie.class.getName());
unit.setProperty("openjpa.jdbc.SynchronizeMappings",
"buildSchema(ForeignKeys=true)");
return unit;
}
This doc has a more complete example that uses persistence.
http://tomee.apache.org/examples-trunk/application-composer/README.html
Note the `@EnableServices("ejdb")` usage can likely be removed. There is no
'ejdb' service -- likely a misspelling of 'ejbd'. Usually not needed as
@Remote support is enabled for testing without @EnableServices().
-David