SeamTest (TestNG), Maven 2, and Embeddable EJB3
bsmithjj Jun 20, 2006 3:12 PMHas anyone successfully run unit tests with a Maven 2 pom.xml for a Seam project?
I am having some trouble getting this to work... here is what I have attempted to do:
1. I downloaded the latest Embeddable EJB3 (Alpha 8 - patch 2)(?)
2. installed the .jar's with this distro in my .m2 repository
3. added them to my pom.xml with test
{code}
 org.jboss.ejb3.microcontainer
 jboss-ejb3-all
 Alpha8.P2
 test
 org.jboss.ejb3.microcontainer
 hibernate-all
 Alpha8.P2
 test
 org.jboss.ejb3.microcontainer
 thirdparty-all
 Alpha8.P2
 test
{code}
4. Created a components.xml pasted below:
{code}
<?xml version="1.0" encoding="UTF-8"?>
 true
 true
 <!-- 120 second conversation timeout -->
 120000
 java:/appssoSessionFactory
{code}
NOTE: I am using Hibernate Session with EJB3-style annotations for the hibernate mappings.
5. In pom.xml, I have added the dependency:
{code}
 org.testng
 testng
 4.7
 test
 jdk15
{code}
per the instructions for running TestNG test cases (this works as expected for normal TestNG test cases).
6. I copy the default microcontainer config files from the conf directory to my target/test-classes/conf directory (so that these resources will be in the classpath of the test runner)
7. Here is my test case:
{code}
public class UserEditorTest extends SeamTest {
 @Logger
 private Log log;
 @Test
 public void test_SessionStarter_create_delete_User() throws Exception {
 new Script() {
 @Override
 protected void updateModelValues() {
 log.info("updateModelValues()");
 User user = (User)Component.getInstance("user", true);
 assert user != null;
 user.setaNumber("A123456");
 }
 @Override
 protected void invokeApplication() {
 UserEditor userEditor = (UserEditor)Component.getInstance("userEditor", true);
 String outcome = userEditor.createUser();
 assert "success".equals(outcome);
 }
 @Override
 protected void renderResponse() {
 User user = (User) Component.getInstance("user", false);
 assert user != null;
 assert user.getId()>0;
 log.info("user -> "+user);
 }
 }.run();
 }
}
{code}
8. Here is my problem (when invoking the maven-test plugin):
{code}
14:22:39,891 INFO org.hibernate.impl.SessionFactoryObjectFactory.(addInstance:86) - Factory name: java:/appssoSessionFa
ctory
14:22:39,907 INFO org.hibernate.util.NamingHelper.(getInitialContext:26) - JNDI InitialContext properties:{}
14:22:39,938 ERROR org.hibernate.util.NamingHelper.(getInitialContext:33) - Could not obtain initial context
javax.naming.NamingException: Local server is not initialized
 at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
 at javax.naming.InitialContext.init(InitialContext.java:223)
 at javax.naming.InitialContext.(InitialContext.java:175)
 at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
 at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:89)
 at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:291)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
 at com.evergreen.userlinks.HibernateUtil.(HibernateUtil.java:23)
 at com.evergreen.userlinks.biz.UserLinkActionsTest.test_SessionStarter_add_delete_link(UserLinkActionsTest.java:
38)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.maven.surefire.battery.AbstractBattery.executeTestMethod(AbstractBattery.java:124)
 at org.apache.maven.surefire.battery.AbstractBattery.executeTestMethods(AbstractBattery.java:70)
 at org.apache.maven.surefire.battery.AbstractBattery.execute(AbstractBattery.java:49)
 at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220)
 at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215)
 at org.apache.maven.surefire.Surefire.run(Surefire.java:163)
 at org.apache.maven.surefire.Surefire.run(Surefire.java:87)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:313)
 at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:221)
 at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:371)
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:47
5)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.jav
a:306)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
 at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
 at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
14:22:39,954 WARN org.hibernate.impl.SessionFactoryObjectFactory.(addInstance:98) - Could not bind factory to JNDI
javax.naming.NamingException: Local server is not initialized
 at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
 at javax.naming.InitialContext.init(InitialContext.java:223)
 at javax.naming.InitialContext.(InitialContext.java:175)
 at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
 at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:89)
 at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:291)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
 at com.evergreen.userlinks.HibernateUtil.(HibernateUtil.java:23)
 at com.evergreen.userlinks.biz.UserLinkActionsTest.test_SessionStarter_add_delete_link(UserLinkActionsTest.java:
38)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.maven.surefire.battery.AbstractBattery.executeTestMethod(AbstractBattery.java:124)
 at org.apache.maven.surefire.battery.AbstractBattery.executeTestMethods(AbstractBattery.java:70)
 at org.apache.maven.surefire.battery.AbstractBattery.execute(AbstractBattery.java:49)
 at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220)
 at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215)
 at org.apache.maven.surefire.Surefire.run(Surefire.java:163)
 at org.apache.maven.surefire.Surefire.run(Surefire.java:87)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:313)
 at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:221)
 at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:371)
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:47
5)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.jav
a:306)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
 at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
 at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
14:22:39,954 INFO org.hibernate.tool.hbm2ddl.SchemaUpdate.(execute:115) - Running hbm2ddl schema update
{code}
9. There's actually a bit more - it appears that the Hibernate bootstrapping is working, there is logging showing the creation of a Hibernate SessionFactory, etc.
It appears that the EJB3 microcontainer is not being started - and thus, the Local JNDI Server is not available...has anyone been able to get maven 2 - TestNG - with Seam - to work?
Thanks
 
     
    