injection doesnt seem to work and testing again
wiggy Apr 13, 2010 12:19 AMgetting stuff i dont understand, (see earlier problems i was having in http://seamframework.org/Community/HavingProblemsWithTestNGAndSeam220GAJBossTools)
Can anyone explain whats going wrong and i dont get injection, and i have to code round the failure 
I went back and created simple test, but not using UI framework like this 
import org.jboss.seam.mock.SeamTest;
import org.jboss.seam.mock.AbstractSeamTest.ComponentTest;
import org.testng.annotations.Test;
public class TestDummyConv extends SeamTest
{
     @Test
     public void testPaginatingNodeList () throws Exception
     {
          new ComponentTest ()
          {
               protected void testComponents () throws Exception 
               {
                    String res = (String) invokeMethod ("#{dummyConv.sayHello}");
                    assert res.equals("hello will");
               }
          
          }.run ();
     }
}
where my class under test looks like this 
@Name ("dummyConv")
@Scope (ScopeType.CONVERSATION)
@AutoCreate
public class DummyConv 
{
        /** */
    @Logger 
    Log log;
    
    @In (required=false, create=true)
    NodeList nl;
    @In (required=false, create=true)
    NodeHome nh;
     public String sayHello ()
     {
          
          if (log == null)
               System.out.println ("null logger injection ");
          if (nl == null)
          {
               System.out.println ("null nodeList injection ");
               nl = (NodeList) Component.getInstance("nodeList", true);
               if (nl != null) 
                    System.out.println ("created nodeList by Component.getInstance ") ;
               else
                    System.out.println ("couldnt create nodeList by Component.getInstance ") ;
          }
          if (nh == null)
               System.out.println ("null nodeHome injection ");
          return "hello will";
     }
}
with test trace looking this 
[Parser] Running: C:\Users\will\AppData\Local\Temp\testng-eclipse\testng-customsuite.xml WARN [org.jboss.seam.Component] Component class should be serializable: dummyConv WARN [org.jboss.seam.security.permission.PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required. null nodeList injection setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@10772d2 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@10772d2 setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList_$$_javassist_seam_2@615f19 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList_$$_javassist_seam_2@615f19 created nodeList by Component.getInstance null nodeHome injection PASSED: testPaginatingNodeList =============================================== org.domain.forsterslist.richfaces.datamodel.TestDummyConv Tests run: 1, Failures: 0, Skips: 0 =============================================== =============================================== forstersList-test Total tests run: 1, Failures: 0, Skips: 0 ===============================================
when i run this test i dont seem to get injection at all, despite running the
@In (create=true) option.
if i manually create an instance from Component.getInstance i get a result, if i don't do this the nh variable stays null.
as i used EL to drive the test i thought this would force the container to create the nodeHome instance for me - but it doesnt.
worse NodeHome, and NodeList are actually marked as @AutoCreate
@Name("nodeHome")
@AutoCreate
public class NodeHome extends EntityHome<Node>
{
    /**
      * 
      */
     private static final long serialVersionUID = 1L;
     @RequestParameter Long nodeId;
...
when i run a more complicated test on another class i get more problematic error - heres the test 
import org.jboss.seam.Component;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Test;
public class TestPaginatingNodeList extends SeamTest
{
     @Test
     public void testPaginatingNodeList () throws Exception
     {
          new ComponentTest ()
          {
               protected void testComponents () throws Exception 
               {
                    String res = (String) invokeMethod ("#{paginatingNodeListDataModel.sayHello}");
                    assert res.equals("hello will");
               }
          
          }.run ();
     }
}
which results in a stack trace that the following,  again you can see all the injections fail.  
[Parser] Running: C:\Users\will\AppData\Local\Temp\testng-eclipse\testng-customsuite.xml WARN [org.jboss.seam.Component] Component class should be serializable: dummyConv WARN [org.jboss.seam.security.permission.PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required. null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList@c907ff injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@2bf6c0 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@2bf6c0 injection failed for nodeHome on paginating node list null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList_$$_javassist_seam_1@10277cd injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@10772d2 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@10772d2 injection failed for nodeHome on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@12a642 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@12a642 setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList_$$_javassist_seam_2@1af4abb null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList_$$_javassist_seam_2@1af4abb FAILED: testPaginatingNodeList javax.el.ELException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: nodeHome at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348) at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58) at org.jboss.el.parser.AstValue.invoke(AstValue.java:96) at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175) at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.invokeMethod(AbstractSeamTest.java:136) at org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList$1.testComponents(TestPaginatingNodeList.java:16) at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162) at org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList.testPaginatingNodeList(TestPaginatingNodeList.java:20) Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: nodeHome at org.jboss.seam.Component.newInstance(Component.java:2144) at org.jboss.seam.Component.getInstance(Component.java:2021) at org.jboss.seam.Component.getInstance(Component.java:1983) at org.jboss.seam.Component.getInstance(Component.java:1977) at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2349) at org.jboss.seam.Component.getValueToInject(Component.java:2301) at org.jboss.seam.Component.injectAttributes(Component.java:1736) at org.jboss.seam.Component.inject(Component.java:1554) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList_$$_javassist_seam_1.sayHello(PaginatingNodeList_$$_javassist_seam_1.java) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335) ... 31 more Caused by: java.lang.IllegalArgumentException: Stack must not be null at org.jboss.seam.core.ConversationEntry.<init>(ConversationEntry.java:45) at org.jboss.seam.core.ConversationEntries.createConversationEntry(ConversationEntries.java:53) at org.jboss.seam.core.Manager.createConversationEntry(Manager.java:664) at org.jboss.seam.core.Manager.beginConversation(Manager.java:685) at org.jboss.seam.core.ConversationInterceptor.beginConversation(ConversationInterceptor.java:229) at org.jboss.seam.core.ConversationInterceptor.beginConversationIfNecessary(ConversationInterceptor.java:166) at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:57) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) at org.jboss.seam.util.Work.workInTransaction(Work.java:47) at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at org.domain.forsterslist.session.NodeHome_$$_javassist_seam_3.create(NodeHome_$$_javassist_seam_3.java) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) at org.jboss.seam.Component.callComponentMethod(Component.java:2249) at org.jboss.seam.Component.callCreateMethod(Component.java:2172) at org.jboss.seam.Component.newInstance(Component.java:2132) ... 51 more ... Removed 30 stack frames =============================================== org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList Tests run: 1, Failures: 1, Skips: 0 =============================================== =============================================== forstersList-test Total tests run: 1, Failures: 1, Skips: 0 ===============================================
so i then added a UI test  to the class, which passes but only cos i code round all the injection failures,  heres the revised test class 
public class TestPaginatingNodeList extends SeamTest
{
     @Test
     public void testPaginatingNodeList () throws Exception
     {
          new ComponentTest ()
          {
               protected void testComponents () throws Exception 
               {
                    String res = (String) invokeMethod ("#{paginatingNodeListDataModel.sayHello}");
                    assert res.equals("hello will");
               }
          
          }.run ();
     }
     
     @Test
     public void uiTestPaginationNodeList () throws Exception
     {
          new FacesRequest () 
          {
               @Override 
               protected void invokeApplication ()
               {
                    String res = (String) invokeMethod ("#{paginatingNodeListDataModel.sayHello}");
                    assert res.equals("hello will");
                    
               }
          }.run ();
     }
}
on class in build as 
  
@Name("paginatingNodeListDataModel")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class PaginatingNodeList
    extends PaginatingDataModel<Node, Long>
{
    /** */
    private static final long serialVersionUID = 2672142810059859813L;
    /** 
     * force instance to be generated - @In only does lookup
     * */
    @In (required=false, create=true)
    private NodeList nodeList;
    
    @In (required=false, create=true)
    private NodeHome nodeHome;
    /** */
    @In (required=false)
    Node currentEntity;
    /** */
    @Logger 
    Log log;
    private int rows;
     private List<SelectItem> pagesToScroll;
     private Integer scrollerPage;
...     
which gives a stack trace like 
[Parser] Running: C:\Users\will\AppData\Local\Temp\testng-eclipse\testng-customsuite.xml WARN [org.jboss.seam.Component] Component class should be serializable: dummyConv WARN [org.jboss.seam.security.permission.PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required. null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList@57ae46 injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@72a921 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@72a921 injection failed for nodeHome on paginating node list null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList_$$_javassist_seam_2@1187f9 injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@f6178d null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@f6178d injection failed for nodeHome on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@bc56a2 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@bc56a2 setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList_$$_javassist_seam_3@850f8 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList_$$_javassist_seam_3@850f8 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList@8163c6 injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@bd8b9c null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@bd8b9c injection failed for nodeHome on paginating node list null logger setMaxScroller pages are 1 on object org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList_$$_javassist_seam_2@18c8ca injection failed for nodeList on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@1266392 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@1266392 injection failed for nodeHome on paginating node list setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList@1531f73 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList@1531f73 setScroller page called from nodeList constructor for object org.domain.forsterslist.session.NodeList_$$_javassist_seam_3@35dfb4 null logger setMaxScroller pages are 1 on object org.domain.forsterslist.session.NodeList_$$_javassist_seam_3@35dfb4 PASSED: uiTestPaginationNodeList FAILED: testPaginatingNodeList javax.el.ELException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: nodeHome at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348) at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58) at org.jboss.el.parser.AstValue.invoke(AstValue.java:96) at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175) at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.invokeMethod(AbstractSeamTest.java:136) at org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList$1.testComponents(TestPaginatingNodeList.java:15) at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162) at org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList.testPaginatingNodeList(TestPaginatingNodeList.java:19) Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: nodeHome at org.jboss.seam.Component.newInstance(Component.java:2144) at org.jboss.seam.Component.getInstance(Component.java:2021) at org.jboss.seam.Component.getInstance(Component.java:1983) at org.jboss.seam.Component.getInstance(Component.java:1977) at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2349) at org.jboss.seam.Component.getValueToInject(Component.java:2301) at org.jboss.seam.Component.injectAttributes(Component.java:1736) at org.jboss.seam.Component.inject(Component.java:1554) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at org.domain.forsterslist.richfaces.datamodel.PaginatingNodeList_$$_javassist_seam_2.sayHello(PaginatingNodeList_$$_javassist_seam_2.java) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335) ... 31 more Caused by: java.lang.IllegalArgumentException: Stack must not be null at org.jboss.seam.core.ConversationEntry.<init>(ConversationEntry.java:45) at org.jboss.seam.core.ConversationEntries.createConversationEntry(ConversationEntries.java:53) at org.jboss.seam.core.Manager.createConversationEntry(Manager.java:664) at org.jboss.seam.core.Manager.beginConversation(Manager.java:685) at org.jboss.seam.core.ConversationInterceptor.beginConversation(ConversationInterceptor.java:229) at org.jboss.seam.core.ConversationInterceptor.beginConversationIfNecessary(ConversationInterceptor.java:166) at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:57) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) at org.jboss.seam.util.Work.workInTransaction(Work.java:47) at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at org.domain.forsterslist.session.NodeHome_$$_javassist_seam_4.create(NodeHome_$$_javassist_seam_4.java) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) at org.jboss.seam.Component.callComponentMethod(Component.java:2249) at org.jboss.seam.Component.callCreateMethod(Component.java:2172) at org.jboss.seam.Component.newInstance(Component.java:2132) ... 51 more ... Removed 30 stack frames =============================================== org.domain.forsterslist.richfaces.datamodel.TestPaginatingNodeList Tests run: 2, Failures: 1, Skips: 0 =============================================== =============================================== forstersList-test Total tests run: 2, Failures: 1, Skips: 0 ===============================================
 
    