Nilesh Agrawal
Nilesh Agrawal

Reputation: 3042

Use of EJBcontainer in junit?

I am new to JUNIT, and trying to learn through some projects ( https://github.com/apache/tomee/blob/trunk/examples/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java ).I am unable to figure out in which case do we use ejb container, what is its use and what are this properties.

 @BeforeClass
        public static void start() throws IOException {
            final File webApp = Archive.archive().copyTo("WEB-INF/classes", jarLocation(UserDAO.class)).asDir();
            final Properties p = new Properties();
            p.setProperty(EJBContainer.APP_NAME, "rest-example");
            p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web feature
            p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath());
            p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1"); // random port
            container = EJBContainer.createEJBContainer(p);
        }

Upvotes: 0

Views: 888

Answers (1)

Romain Manni-Bucau
Romain Manni-Bucau

Reputation: 3422

EJBContainer is a way to run a container. TomEE has 3 flavors: * openejb: fully embedded (JavaSE like) * tomee-embedded: deploy a war pointing on the war path with EJBContainer.MODULES * tomee-remote: same as tomee-embedded but in a remote JVM

Properties are configuration of the container. Portable ones (EJBContainer) defines modules (applications path, if not specified use classpath to find it for openejb case), provider (which implementation to use) and app_name (ejb module names, I would recommand you to not rely on it if you don't need it). You can also pass not portable properties. In OpenEJB case this can define datasources for instance.

Note also OpenEJB has some JUnit runners and rules wrapping this code (http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-junit/src/test/java/org/apache/openejb/junit/TestResourceEJBContainerRule.java for instance)

Upvotes: 1

Related Questions