0 Replies Latest reply on Jan 29, 2010 1:09 PM by Mathias Peters

    Injecting components into App scoped comp.

    Mathias Peters Newbie

      Hi,


      I'm pretty sure my problem has been solved already elsewhere but I cannot find it:


      I have an app-scoped class EPaperSetup in which I inject an EntityManager. The component has a setup-method annotated with @Create where the entity manager is used. This works fine during the normal startup. When I use a SeamTest dreived class with testNG none of the injected components is there and I get a NullPointerException when accessing the entity manager.


      Could point me in a direction?
      What other info do you need?


      Thanks a lot!


      Here 's my code for EPaperSetup:


      @Startup (depends="epaperConfiguration")
      @Name("EPaperSetup")
      @Scope(ScopeType.APPLICATION)
      public class EPaperSetup{
      
      ...
      @In
      EntityManager entityManager;
      ...
      @Create
      public void setup() throws NoSuchAlgorithmException, UnsupportedEncodingException
      {
          EntityTransaction t = entityManager.getTransaction();
      ...
      }
      
      }
      



      The test:



      
      
      public class ListUserRoleActionTestNG extends SeamTest {
        
           private EntityManagerFactory emf;
           private EntityManager em;
           
           
           @Test
           public void testGetUserRoles() throws Exception {
             new FacesRequest()
             {
                  @Override
                  protected void invokeApplication()
                  {
                       invokeMethod("#{listUserRoleAction.userRoles}");
                  }
             }.run();
           }
      
      }
      
      



      and the error:



      FAILED CONFIGURATION: @BeforeSuite startSeam
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: EPaperSetup
           at org.jboss.seam.Component.newInstance(Component.java:2144)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:296)
           at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
           at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
           at org.jboss.seam.init.Initialization.init(Initialization.java:740)
           at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:919)
           at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
      Caused by: java.lang.NullPointerException
           at i2.dnb.epaper.system.EPaperSetup.setup(EPaperSetup.java:52)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)




      As I said before, I'm pretty sure this is a newbie error and somebody solved it.
      Thanks for your help and best regards,
      Mathias