1 Reply Latest reply on Oct 12, 2007 4:25 PM by Pete Muir

    Log and EntityManager are not injected in integration test

    Ivan B Novice


      I'm at the very beginning of adding integration testing to my Seam application, and I have the following problem. The EntityManager and Log objects used inside the action bean are nulls during invoking the tests, unless I set them manually (which AFAIK I should not).

      ( To clarify, the test just tries to access rootCategories context variable which is set in the SFSB, also shown below)

      public void test() throws Exception {

      String cid = new FacesRequest("/addCategory.seam") {

      protected void invokeApplication() throws Exception {

      Here is the SFSB:

      public class CategoryBean {

      Log log;

      @In(create = true)
      private EntityManager em;

      @Out(required = false)
      private List<Category> rootCategories;

      public CategoryBean() {

      public List<Category> findRootCategories() {
      log.info("Refreshing the list of root Categories");
      Query query = em.createQuery("select c from Category c where c.parentCategory.id = 1 and c.id <> 1");
      List list = query.getResultList();
      for (Object o : list) {
      System.out.println("o = " + o);
      return list;

      public void remove() {


      Now I run into NullPointerException inside findRootCategories() method, because neither em no log objects are intialized. Unit testing works fine, btw, when I add the following lines to the test body:

      EntityManagerFactory emf =
      EntityManager em = emf.createEntityManager();
      setField(categoryBean, "em", em);
      setField(categoryBean, "log", Logging.getLog(CategoryBean.class));

      Can anyone give a hint?