1 Reply Latest reply on Apr 3, 2011 1:37 PM by lorokl

    Testing with @Startup bean

    lorokl

      Hello,


      Sorry for language mistakes.


      I've got a problem with unit test. In project there is a bean annotated with @Startup wich uses EntityManager. I didn't wrote any test for this bean.



      ...
      @Name("autostart")
      @Scope(ScopeType.APPLICATION)
      @AutoCreate
      @Startup
      public class AutoStart implements Serializable{
              
              @Logger
              private Log log;
      
              @In(value = "entityManager", create=true)
              private EntityManager em;
              
      
              @In(value = "identityStore")
              private IdentityStore is;
              ...
      


      Now, when I run seam test command I got a following error:



         ...
         [testng] FAILED CONFIGURATION: @BeforeSuite startSeam
         [testng] org.jboss.seam.InstantiationException: Could not instantiate Seam component: autostart
         [testng]     at org.jboss.seam.Component.newInstance(Component.java:2170)
         [testng]     at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
         [testng]     at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
         [testng]     at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:143)
         [testng]     at org.jboss.seam.init.Initialization.init(Initialization.java:744)
         [testng]     at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:929)
         [testng]     at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:69)
         [testng] Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/entityManager
         [testng]     at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:261)
         [testng]     at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
         [testng]     at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
         [testng]     at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
         [testng]     at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
         [testng]     at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
         [testng]     at org.jboss.seam.Component.unwrap(Component.java:2301)
         [testng]     at org.jboss.seam.Component.getInstance(Component.java:2044)
         [testng]     at org.jboss.seam.Component.getInstance(Component.java:1986)
         [testng]     at org.jboss.seam.Component.getInstance(Component.java:1980)
         [testng]     at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2375)
         [testng]     at org.jboss.seam.Component.getValueToInject(Component.java:2327)
         [testng]     at org.jboss.seam.Component.injectAttributes(Component.java:1739)
         [testng]     at org.jboss.seam.Component.inject(Component.java:1557)
         [testng]     at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
         [testng]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]     at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
         [testng]     at org.jboss.seam.util.Work.workInTransaction(Work.java:61)
         [testng]     at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
         [testng]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]     at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
         [testng]     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]     at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
         [testng]     at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
         [testng]     at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
         [testng]     at com.osk_manager2.action.AutoStart_$$_javassist_seam_3.autostart(AutoStart_$$_javassist_seam_3.java)
         [testng]     at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
         [testng]     at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
         [testng]     at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
         [testng]     at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
         [testng]     at org.jboss.seam.Component.newInstance(Component.java:2158)
         [testng]     ... 21 more
         [testng] Caused by: javax.naming.NameNotFoundException: entityManager not bound
         [testng]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
         [testng]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
         [testng]     at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
         [testng]     at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
         [testng]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
         [testng]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
         [testng]     at javax.naming.InitialContext.lookup(InitialContext.java:392)
         [testng]     at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:257)
         [testng]     ... 59 more
         [testng] ... Removed 23 stack frames
         ....
      


      I've followed by first reply in this thread: Link but it didn't helped.
      My perstistance-test.xml is the same as persistence-dev.xml which runs well on server.


      Anyone can help me with solving this problem?

        • 1. Re: Testing with @Startup bean
          lorokl

          I have a solution, wrong value of jboss.entity.manager.factory.jndi.name property in perstistence-test.xml


          It should look like this:


          <property name="jboss.entity.manager.factory.jndi.name" value="java:/entityManager"/>



          By the way, interesting that in persistence-dev.xml different entity manager JNDI name is acceptable.