How to test EJB from JUnit Test case using "JBoss EJB 3.1 Embeddable"?
jbossuser71 Mar 8, 2011 2:11 PMHello All,
I am trying to test my EJBs from JUnit framework as part of build (ant) - I am using "JBoss EJB 3.1 Embeddable".
I have followed all the instructions specified in http://community.jboss.org/wiki/EJB31Embeddable link.
I have a proper JBoss 6.0.Final AS installation - the standalone embeddable delegates to JBoss Embedded AS to boot up an AS instance in my JVM.
I am able to start the EJBContainer with following Junit test case.
public class HelloBeanTest {
@Test
public void testEjb() throws NamingException {
EJBContainer container = EJBContainer.createEJBContainer();
container.close();
}
}
Now, in order to invoke the EJBs from my test case, I put my J2EE application's "ejb.jar" in the classpath which contains "META-INF\persistence.xml" file. All other dependent and 3rd party jars are also put in the classpath.
I find that Jboss is getting all bean definitions from "persistence.xml" file - but soon it dies, when it tries to start the Persistence unit, without throwing any error or hint and the junit test case fails.
Note: there is no problem with my application deployment if I start Jboss in usual way - but from JUnit I could not start the JBoss in embedded way!
Also during startup I get lots of following "Warning" - which suggests to configure an exclusion filter - but I do not know how to do that using ant. I am using ant for running Junit test cases. The console output is shown below.
================================
[junit] 15:14:02,783 WARN [ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/apache/tiles/servlet/context/ServletTilesRequestContext while loading org.springframework.web.servlet.view.tiles2.TilesView$1; configure an exclusion filter so "/C:/Workspace/DM1.0/dependencies/repository/
spring/spring-framework-3.0.5.RELEASE/dist/org.springframework.web.servlet-3.0.5.RELEASE.jar" is not processed
[junit] 15:14:02,787 WARN [ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/apache/tiles/preparer/PreparerFactory while loading org.springframework.web.servlet.view.tiles2.AbstractSpringPreparerFactory; configure an exclusion filter so "/C:/Workspace/DM1.0/dependencies/repository/spring/spring-framework-3.0.5.RELEASE/dist/org.springframework.web.servlet-3.0.5.RELEASE.jar" is not processed
[junit] 15:14:02,793 WARN [ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/apache/tiles/preparer/PreparerFactory while loading org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory; configure an exclusion filter so "/C:/Workspace/DM1.0/dependencies/repository/spring/spring-framework-3.0.5.RELEASE/dist/org.springframework.web.servlet-3.0.5.RELEASE.jar" is not processed
[junit] 15:14:02,799 WARN [ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/apache/tiles/servlet/context/ServletTilesApplicationContext while loading org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext; configure an exclusion filter so "/C:/Workspace/DM1.0/dependencies/repository/spring/spring-framework-3.0.5.RELEASE/dist/org.springframework.web.servlet-3.0.5.RELEASE.jar" is not processed
.
.
.
[junit] 15:14:02,827 WARN [ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/apache/tiles/Initial
izable while loading org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory; configure an exclusion filter so "/C:/Workspace/DM1.0/dependencies/repository/spri
ng/spring-framework-3.0.5.RELEASE/dist/org.springframework.web.servlet-3.0.5.RELEASE.jar" is not processed
[junit] Boot Log available in: C:\Users\mondalku\AppData\Local\Temp\
[junit] 15:14:08,045 INFO [AbstractJBossASServerBase] Server Configuration:
[junit]
[junit] JBOSS_HOME URL: file:/C:/Workspace/DM1.0/dependencies/repository/appserver/
[junit] Bootstrap: $JBOSS_HOME\server/default/conf/bootstrap.xml
[junit] Common Base: $JBOSS_HOME\common/
[junit] Common Library: $JBOSS_HOME\common/lib/
[junit] Server Name: default
[junit] Server Base: $JBOSS_HOME\server/
[junit] Server Library: $JBOSS_HOME\server/default/lib/
[junit] Server Config: $JBOSS_HOME\server/default/conf/
[junit] Server Home: $JBOSS_HOME\server/default/
[junit] Server Data: $JBOSS_HOME\server/default/data/
[junit] Server Log: $JBOSS_HOME\server/default/log/
[junit] Server Temp: $JBOSS_HOME\server/default/tmp/
[junit]
[junit] 15:14:08,098 INFO [AbstractServer] Starting: JBossAS [6.0.0.Final "Neo"]
[junit] 15:14:11,314 INFO [ServerInfo] Java version: 1.6.0_23,Sun Microsystems Inc.
[junit] 15:14:11,315 INFO [ServerInfo] Java Runtime: Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
[junit] 15:14:11,315 INFO [ServerInfo] Java VM: Java HotSpot(TM) Client VM 19.0-b09,Sun Microsystems Inc.
[junit] 15:14:11,315 INFO [ServerInfo] OS-System: Windows Vista 6.0,x86
.
.
.
.
[junit] 15:14:48,650 INFO [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:jar=server,name=UserStatBean,service=EJB3
[junit] 15:14:48,651 INFO [org.jboss.ejb3.deployers.JBossASKernel] with dependencies:
[junit] 15:14:48,651 INFO [org.jboss.ejb3.deployers.JBossASKernel] and demands:
[junit] 15:14:48,744 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss-switchboard:appName=se,module=server,name=UserStatBean; Required: Create
[junit] 15:14:48,744 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss.ejb:service=EJBTimerService; Required: Described
[junit] 15:14:48,744 INFO [org.jboss.ejb3.deployers.JBossASKernel] persistence.unit:unitName=server#edmPU; Required: Described
[junit] 15:14:48,745 INFO [org.jboss.ejb3.deployers.JBossASKernel] jboss-injector:topLevelUnit=server,unit=server,bean=UserStatBean; Required: Described
[junit] 15:14:48,757 INFO [org.jboss.ejb3.deployers.JBossASKernel] and supplies:
[junit] 15:14:48,757 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:UserStatBean/remote
[junit] 15:14:48,757 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:UserStatBean
[junit] 15:14:48,757 INFO [org.jboss.ejb3.deployers.JBossASKernel] Class:com.im.server.edm.api.UserStatRemote
[junit] 15:14:48,758 INFO [org.jboss.ejb3.deployers.JBossASKernel] jndi:UserStatBean/remote-com..im.server.edm.api.UserStatRemote
[junit] 15:14:48,758 INFO [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:jar=server,name=UserStatBean,service=EJB3) to KernelDeployment of: server
[junit] 15:14:49,014 INFO [org.jboss.jpa.deployment.PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=server#edmPU
[junit] Test com.im.server.edm.ejb.ProjectBeanTest FAILED
BUILD SUCCESSFUL
Total time: 1 minute 17 seconds
===================================
As part of classpath I have to keep following JBoss JARs.
But I am not sure if I have to keep all the JARs which are avaiable in {JBOSS}/common/lib and {JBOSS}/lib (??) folders.
jboss-ejb3-embedded-standalone.jar
jboss-ejb-api_3.1_spec.jar
javassist.jar
commons-collections.jar
validation-api.jar
hibernate-jpa-2.0-api.jar
hibernate-entitymanager.jar
hibernate-commons-annotations.jar
commons-collections.jar
log4j.jar
slf4j-api-1.6.1.jar
jboss-ejb3-ext-api.jar
mail.jar
quartz.jar
hibernate-core.jar
jboss-servlet-api_3.0_spec.jar
dom4j.jar
commons-logging-1.1.1.jar
Any help/suggestion will be much appreciated.
- Kuntal
-
junit_error.txt.zip 12.6 KB