1 2 3 Previous Next 32 Replies Latest reply on Nov 19, 2007 1:15 PM by youngm

    Integration Testing with TestNG and embeddedEjb

    Rob Newbie

      I have a lot problems to let run Integration Tests.

      The main problem is to grab the loaded Components from the Container.

      It seems that they are not loaded. I'm not able to get the by hand from the JNDI.

      here the Request:

      new FacesRequest() {
      
       @Override
       protected void invokeApplication() {
      
       Object test = JndiUtil.lookup("mediportal/KomunikatyManagerBean/local", KomunikatyManagerBean.class);
       KomunikatyManager komunikatyManager = (KomunikatyManager) getInstance(KomunikatyManagerBean.class);
       invokeMethod("#{komunikatyManager.nowy}");
       }
      
      }.run();
      


      here the console output for this component, while starting embeddedEjb:
      12:40:11,812 INFO [Initialization] Installing components...
      12:40:12,375 INFO [Component] Component: komunikatyManager, scope: CONVERSATION, type: STATEFUL_SESSION_BEAN, class: pl.alternativ.med.portal.komunikaty.KomunikatyManagerBean, JNDI: mediportal/KomunikatyManagerBean/local
      


      and finally the error message:
      14:07:01,609 INFO [Initialization] done initializing Seam
      Start Nowy Test-----------------------------------------
      14:07:01,734 INFO [Ejb] stopping the embedded EJB container
      14:07:01,765 ERROR [AbstractKernelController] Internal error during uninstall current state not found: name=jboss.j2ee:jar=test-build,name=MailMDB,service=EJB3 state=**ERROR** error=javax.naming.NameNotFoundException: DefaultJMSProvider not bound
      14:07:01,765 ERROR [AbstractKernelController] Internal error during uninstall: toState=ControllerState@262730{Not Installed} context=name=jboss.j2ee:jar=test-build,name=MailMDB,service=EJB3 state=**ERROR** error=javax.naming.NameNotFoundException: DefaultJMSProvider not bound
      14:07:01,765 ERROR [AbstractKernelController] Internal error during uninstall current state not found: name=jboss.j2ee:jar=test-build,name=PlikiKlientowMDB,service=EJB3 state=**ERROR** error=javax.naming.NameNotFoundException: DefaultJMSProvider not bound
      14:07:01,765 ERROR [AbstractKernelController] Internal error during uninstall: toState=ControllerState@262730{Not Installed} context=name=jboss.j2ee:jar=test-build,name=PlikiKlientowMDB,service=EJB3 state=**ERROR** error=javax.naming.NameNotFoundException: DefaultJMSProvider not bound
      14:07:01,796 INFO [SessionFactoryImpl] closing
      14:07:01,796 INFO [SchemaExport] Running hbm2ddl schema export
      14:07:01,796 INFO [SchemaExport] exporting generated schema to database
      14:07:01,812 INFO [SchemaExport] schema export complete
      FAILED: testNowyKomunikat
      org.jbpm.util.JndiLookupException: couldn't fetch 'mediportal/KomunikatyManagerBean/local' from jndi
       at org.jbpm.util.JndiUtil.lookup(JndiUtil.java:41)
       at pl.alternativ.med.portal.test.komunikaty.KomunikatyTest$1.invokeApplication(KomunikatyTest.java:49)
       at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:489)
       at pl.alternativ.med.portal.test.komunikaty.KomunikatyTest.testNowyKomunikat(KomunikatyTest.java:54)
      Caused by: javax.naming.NameNotFoundException: mediportal not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
       at javax.naming.InitialContext.lookup(Unknown Source)
       at org.jbpm.util.JndiUtil.lookup(JndiUtil.java:36)
       ... 24 more
      ... Removed 21 stack frames
      
      



      I'm really running out of ideas! Before the startup is looking good,

      init the DS is working,
      Mapping of the beans,
      import of data,

      I have no idea why i can't grab any of the Components or where they are gone! The configuration i have checked million times.

      I would be pleased if somebody could give some new ideas or hints.

        • 1. Re: Integration Testing with TestNG and embeddedEjb
          Pete Muir Master

          Embedded JBoss exposes stuff at #{ejbName}/local not ear-name/#{ejbName}/local

          • 2. Re: Integration Testing with TestNG and embeddedEjb
            Rob Newbie

            ok i see. But my Problem is that nothing is workin, even grabbin the component out of the JNDI. (nothing else the seam.core.Component is doing)

            What can be the problem? That I can't get anything of the seems to be loaded Components?

            Object test = JndiUtil.lookup("mediportal/KomunikatyManagerBean/local", KomunikatyManagerBean.class);
            
            KomunikatyManager komunikatyManager = (KomunikatyManager)
            getInstance(KomunikatyManagerBean.class);
            


            this 2 lines just test stuff. cuz the
            invokeMethod("#{komunikatyManager.nowy}");
            


            Is not working for same reason...
            Console output:
            FAILED: testNowyKomunikat
            org.jboss.seam.InstantiationException: Could not instantiate Seam component: komunikatyManager
             at org.jboss.seam.Component.newInstance(Component.java:1740)
             at org.jboss.seam.Component.getInstance(Component.java:1643)
             at org.jboss.seam.Component.getInstance(Component.java:1610)
             at org.jboss.seam.Component.getInstance(Component.java:1604)
             at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
             at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
             at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:73)
             at com.sun.el.parser.AstValue.getTarget(AstValue.java:67)
             at com.sun.el.parser.AstValue.invoke(AstValue.java:170)
             at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:286)
             at org.jboss.seam.util.UnifiedELMethodBinding.invoke(UnifiedELMethodBinding.java:36)
             at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
             at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
             at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
             at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
             at org.jboss.seam.mock.SeamTest$Request.invokeMethod(SeamTest.java:401)
             at pl.alternativ.med.portal.test.komunikaty.KomunikatyTest$1.invokeApplication(KomunikatyTest.java:51)
             at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:489)
             at pl.alternativ.med.portal.test.komunikaty.KomunikatyTest.testNowyKomunikat(KomunikatyTest.java:54)
            Caused by: javax.naming.NameNotFoundException: mediportal not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
             at javax.naming.InitialContext.lookup(Unknown Source)
             at org.jboss.seam.Component.instantiateSessionBean(Component.java:1107)
             at org.jboss.seam.Component.instantiate(Component.java:1093)
             at org.jboss.seam.Component.newInstance(Component.java:1736)
             ... 39 more
            ... Removed 21 stack frames
            


            thx a lot for response!

            • 3. Re: Integration Testing with TestNG and embeddedEjb
              Pete Muir Master

              As I said that JNDI pattern is *wrong* for embedded ejb3. It should be

              Object test = JndiUtil.lookup("KomunikatyManagerBean/local", KomunikatyManagerBean.class);
              
              KomunikatyManager komunikatyManager = (KomunikatyManager)
              getInstance(KomunikatyManagerBean.class);


              • 4. Re: Integration Testing with TestNG and embeddedEjb
                Rob Newbie

                 

                "pete.muir@jboss.org" wrote:
                As I said that JNDI pattern is *wrong* for embedded ejb3. It should be


                Super this is working right now! Sorry that i didn't get what u have meant, i changed the jndipattern in the ant build.

                Thx for your support!

                • 5. Re: Integration Testing with TestNG and embeddedEjb
                  Devika Pillai Newbie

                  My Seam application has Spring beans injected into some of the components. When i try to do an integration testing, I get this exception

                  Error writing 'searchTerm' on type com.test.seam.ui.backing.SearchBean_$$_javassist_0
                   at javax.el.BeanELResolver.setValue(BeanELResolver.java:112)
                   at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
                   at com.sun.el.parser.AstValue.setValue(AstValue.java:140)
                   at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:255)
                   at org.jboss.seam.util.UnifiedELValueBinding.setValue(UnifiedELValueBinding.java:44)
                   at org.jboss.seam.mock.SeamTest$Request.setValue(SeamTest.java:374)
                   at test.testNG.UITestNG$1.updateModelValues(UITestNG.java:55)
                   at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:476)
                   at test.testNG.UITestNG.testRegister(UITestNG.java:74)
                  Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: searchBean.searchService
                   at org.jboss.seam.Component.getValueToInject(Component.java:1919)
                   at org.jboss.seam.Component.injectAttributes(Component.java:1368)
                   at org.jboss.seam.Component.inject(Component.java:1195)
                   at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                   at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                   at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
                   at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
                   at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
                   atcom.test.seam.ui.backing.SearchBean_$$_javassist_0.setSearchTerm(SearchBean_$$_javassist_0.java)
                   at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
                   ... 30 more
                  


                  I have added the SpringContextLoader in the components.xml file and my application context is getting loaded.
                  Correct me if I am wrong, I believe that I dont have to specify @In(required=false) because I want the service object to be injected when the seam component is installed. So, is there anything other than this that i need to do to get the Spring beans injected into my Seam component during Integration testing. Please help, I am totally struggling with this.
                  Thanks.....


                  • 6. Re: Integration Testing with TestNG and embeddedEjb
                    youngm Novice

                    A couple of things.

                    When i try to do an integration testing, I get this exception


                    So your app works just fine when running in a web container?

                    I have added the SpringContextLoader in the components.xml file and my application context is getting loaded.


                    When you added the SpringContextLoader did you remove the spring ContextLoaderListener from the web.xml?

                    I'm assuming your injection point looks like?

                    @In("#{searchBean}")SearchBean searchBean;
                    



                    • 7. Re: Integration Testing with TestNG and embeddedEjb
                      Devika Pillai Newbie

                      1. Yes my application works fine in a web container.
                      2. Yes, I removed the ContextLoaderListener from web.xml.
                      3. Yes, I have the @In (value="#searchService") specified in the searchBean. But no required=false.

                      Is there any other configuration required?
                      One more thing i found is this is not just with the Spring beans. Injection itself is not working when I try integration testing with JSF EL expressions.
                      But, If i set value through a component like



                      SearchBean searchBean = (SearchBean) Component.getInstance("searchBean");
                      
                      searchBean.setSearchTerm("1111");
                      

                      it works. Am I missing something here?
                      I appreciate your help.

                      • 8. Re: Integration Testing with TestNG and embeddedEjb
                        youngm Novice

                        What version of seam are you using?

                        • 9. Re: Integration Testing with TestNG and embeddedEjb
                          Devika Pillai Newbie

                          Seam 1.2.1 with Tomcat 6.0.10.

                          • 10. Re: Integration Testing with TestNG and embeddedEjb
                            youngm Novice

                            Can you try with 2.0 CR2? Or is upgrading out of the question at this point?

                            • 11. Re: Integration Testing with TestNG and embeddedEjb
                              Devika Pillai Newbie

                              Frankly speaking I tried to upgrade to 2.0 CR1 and had to struggle with lots of issues. I couldn't even get a lrc working. So i reverted back to 1.2.1.
                              And I have been facing issues with EL in 1.2.1


                              1. Not getting the #{conversationList} component.
                              2. Not getting the #{localeSelector} component. (both are throwing UnSupportedOperationException)
                              3. And now, not getting the injection working with JSF EL in integration testing.

                              The weird thing is all this is related to EL, though I am getting some of the built-in Seam components(eg: conversationEntries). Could you please help me out with this.

                              Thanks in advance.

                              • 12. Re: Integration Testing with TestNG and embeddedEjb
                                youngm Novice

                                Can you put together the simplest testcase you can where an expression is not being evaluated in an integration test so I can give it a try?

                                • 13. Re: Integration Testing with TestNG and embeddedEjb
                                  Devika Pillai Newbie

                                  These are the classes that I have


                                  Employee.java

                                  package test.injection;
                                  
                                  import org.jboss.seam.ScopeType;
                                  import org.jboss.seam.annotations.In;
                                  import org.jboss.seam.annotations.Name;
                                  import org.jboss.seam.annotations.Scope;
                                  
                                  @Name("employeeBean")
                                  @Scope(ScopeType.SESSION)
                                  public class Employee {
                                  
                                   private String name;
                                  
                                   @In("#{departmentSpring}")
                                   private Department department;
                                  
                                   public String getName() {
                                   return name;
                                   }
                                  
                                   public void setName(String name) {
                                   this.name = name;
                                   }
                                  
                                   public String addEmployee(){
                                   return "/success.xhtml";
                                   }
                                  
                                  }

                                  Department.java
                                  package test.injection;
                                  
                                  
                                  public class Department {
                                  
                                   private String departmentName;
                                  
                                   public String getDepartmentName() {
                                   return departmentName;
                                   }
                                  
                                   public void setDepartmentName(String departmentName) {
                                   this.departmentName = departmentName;
                                   }
                                  
                                  }
                                  
                                  

                                  InjectionTestNG.java
                                  package test.testNG;
                                  
                                  import org.jboss.seam.mock.SeamTest;
                                  import org.testng.annotations.Test;
                                  
                                  public class InjectionTestNG extends SeamTest{
                                  
                                   @Test
                                   public void testInjection() throws Exception {
                                   new FacesRequest(){
                                  
                                   @Override
                                   protected void updateModelValues(){
                                   setValue("#{employeeBean.name}","MyName");
                                   }
                                  
                                   @Override
                                   protected void invokeApplication(){
                                   invokeMethod("#{employeeBean.addEmployee}");
                                   }
                                  
                                   @Override
                                   protected void renderResponse(){
                                   assert (getValue("#{employeeBean.name}").equals("MyName"));
                                   }
                                   }.run();
                                   }
                                  
                                  
                                  }
                                  
                                  


                                  applicationContext.xml
                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
                                  
                                  
                                  <beans>
                                   <bean id="departmentSpring" class="test.injection.Department" />
                                  </beans>
                                  


                                  And this is the exception stack trace
                                  FAILED: testInjection
                                  javax.el.ELException: Error writing 'name' on type test.injection.Employee_$$_javassist_0
                                   at javax.el.BeanELResolver.setValue(BeanELResolver.java:112)
                                   at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
                                   at com.sun.el.parser.AstValue.setValue(AstValue.java:154)
                                   at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:258)
                                   at org.jboss.seam.util.UnifiedELValueBinding.setValue(UnifiedELValueBinding.java:44)
                                   at org.jboss.seam.mock.SeamTest$Request.setValue(SeamTest.java:374)
                                   at test.testNG.InjectionTestNG$1.updateModelValues(InjectionTestNG.java:23)
                                   at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:476)
                                   at test.testNG.InjectionTestNG.testInjection(InjectionTestNG.java:35)
                                  Caused by: javax.el.PropertyNotFoundException: ELResolver cannot handle a null base Object with identifier 'departmentSpring'
                                   at com.sun.el.lang.ELSupport.throwUnhandled(ELSupport.java:52)
                                   at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:75)
                                   at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
                                   at org.jboss.seam.util.UnifiedELValueBinding.getValue(UnifiedELValueBinding.java:34)
                                   at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:69)
                                   at org.jboss.seam.Component.getValueToInject(Component.java:1877)
                                   at org.jboss.seam.Component.injectAttributes(Component.java:1368)
                                   at org.jboss.seam.Component.inject(Component.java:1195)
                                   at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                                   at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                                   at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
                                   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
                                   at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
                                   at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
                                   at test.injection.Employee_$$_javassist_0.setName(Employee_$$_javassist_0.java)
                                   at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
                                   ... 30 more
                                  ... Removed 26 stack frames
                                  


                                  Thanks !!!

                                  • 14. Re: Integration Testing with TestNG and embeddedEjb
                                    youngm Novice

                                    Can you add your component.xml too?

                                    1 2 3 Previous Next