Hi,
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)
@Test
public void test() throws Exception {
String cid = new FacesRequest("/addCategory.seam") {
@Override
protected void invokeApplication() throws Exception {
getValue("#{rootCategories}");
}
}
@Local(CategoryManager.class)
@Stateful
@Name("categoryBean")
public class CategoryBean {
@Logger
Log log;
@In(create = true)
private EntityManager em;
@Out(required = false)
private List<Category> rootCategories;
public CategoryBean() {
}
@Factory("rootCategories")
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;
}
@Remove
@Destroy
public void remove() {
}
}
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("MyCardsPersistenceUnit");
EntityManager em = emf.createEntityManager();
setField(categoryBean, "em", em);
setField(categoryBean, "log", Logging.getLog(CategoryBean.class));
This should work - post your log.