Reputation: 182
Does somebody can help me to solve this error with JUnit4.12 and glassfish4.1?
I'm trying to test EJB using JUnit but I got this message from JUnit trace:
javax.ejb.EJBException: Failed to deploy EJB modules - see log for details
at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:149)
Using maven my pom.xml is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.leorm.sga</groupId>
<artifactId>sga-jee-last</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<glassfish.embedded-static-shell.jar>
/opt/servers/glassfish4/glassfish/lib/embedded/glassfish-embedded-static-shell.jar
</glassfish.embedded-static-shell.jar>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
My JUnit test case is:
...
public class PersonaServiceTest {
private PersonaService personaService;
@Before
public void setUp() throws NamingException{
EJBContainer contenedor = EJBContainer.createEJBContainer();
personaService = (PersonaService) contenedor.getContext().lookup("ejb/Persona");
}
@Test
public void test() {
System.out.println("Starting test EJB PersonaService");
assertTrue(personaService != null);
assertEquals(2, personaService.listarPersonas().size());
System.out.println("Count personas is:" + personaService.listarPersonas().size());
this.desplegarPersonas(personaService.listarPersonas());
System.out.println("End test EJB PersonaService");
}
private void desplegarPersonas(List<Persona> personas) {
for(Persona persona: personas){
System.out.println(persona);
}
}
}
The console says:
INFO: [EJBContainerImpl] GlassFish status: STARTED
Oct 18, 2015 11:33:56 AM org.glassfish.ejb.embedded.EJBContainerImpl deploy
INFO: [EJBContainerImpl] Deploying as a ScatteredArchive
Oct 18, 2015 11:33:57 AM org.glassfish.deployment.common.GenericAnnotationDetector scanArchive
WARNING: NCLS-DEPLOYMENT-00009
Oct 18, 2015 11:33:57 AM org.glassfish.api.ActionReport failure
SEVERE: Archive type of /tmp/classes.jar was not recognized
Oct 18, 2015 11:33:57 AM org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
INFO: [EJBContainerProviderImpl] Cleaning up on failure ...
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished
Upvotes: 0
Views: 2519
Reputation: 76
My personal experience with running such test in eclipse as a standalone JUnit (not via maven test) is to use overloaded version of createEJBContainer, in which developer has to specify where to find the compiled bean classes. Assuming EJB classes are located in {currentProject}/target/classes and are using EJB annotations the following solved the same issue for me:
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, new File("target/classes"));
ec = EJBContainer.createEJBContainer(properties);
Upvotes: 3