Ville Myrskyneva
Ville Myrskyneva

Reputation: 1640

JPA + EJB testing with embedded glassfish v3

Trying to set up a JPA+EJB testing after these instructions: http://ctpjava.blogspot.fi/2009/10/unit-testing-ejbs-and-jpa-with.html

There seems to be few problems that I can't seem to get quite right. First I get this error (which I am able to work around, but it still needs to be fixed):

SEVERE: EJB6004:Specified application server installation location [C:\Users\<userName>\.m2\repository\org\glassfish\extras\glassfish-embedded-all\domains\domain1] does not exist.

Found this site, which gives the (more correct?) properties to set: http://docs.oracle.com/cd/E18930_01/html/821-2424/gjlde.html

And modified my testing setup to this:

import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
...
@BeforeClass
public static void createContainer() {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(EJBContainer.MODULES, new File("target/classes"));
    properties.put("installation.root", "./src/test/glassfish");
    properties.put("configuration.file", "./src/test/glassfish/domains/domain1/config/domain.xml");
    container = EJBContainer.createEJBContainer(properties);
    ctx = container.getContext();
}

And in pom.xml I have the following that seems to be required for this:

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.9.1.0</version>
        <scope>test</scope>
    </dependency>

    <!-- Must be before java-ee -->
    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

The error pointed into user directory and I was able to get pass this by setting up the required stuff there (and got past this), but that is not a proper place, since everything must be available via SVN.

According to the latter link I think I have the correct properties set, but those seem to be ignored. Maybe I am missing something obvious?

Upvotes: 3

Views: 2844

Answers (1)

Ville Myrskyneva
Ville Myrskyneva

Reputation: 1640

Missed this text in the properties link:

Properties that can be passed to the EJBContainer#createEJBContainer(Properties) method are summarized in the following table. All properties are in the org.glassfish.ejb.embedded.glassfish package. For example, the full name of the installation.root property is org.glassfish.ejb.embedded.glassfish.installation.root.

So the answer was to have:

org.glassfish.ejb.embedded.glassfish.

Before each property

Thus:

org.glassfish.ejb.embedded.glassfish.installation.root

intead of:

installation.root

Upvotes: 4

Related Questions