[jboss-user] [JBoss Seam] - Log and EntityManager are not injected in integration test
vanyatka
do-not-reply at jboss.com
Thu Oct 11 11:59:20 EDT 2007
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)
anonymous wrote : @Test
| public void test() throws Exception {
|
| String cid = new FacesRequest("/addCategory.seam") {
|
| @Override
| protected void invokeApplication() throws Exception {
| getValue("#{rootCategories}");
| }
| }
|
Here is the SFSB:
anonymous wrote : @Local(CategoryManager.class)
| @Stateful
| @Name("categoryBean")
| public class CategoryBean {
|
| @Logger
| Log log;
|
| @In(create = true)
| private EntityManager em;
|
| @Out(required = false)
| private List rootCategories;
|
| public CategoryBean() {
| }
|
| @Factory("rootCategories")
| public List 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() {
| }
|
| }
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:
anonymous wrote : EntityManagerFactory emf =
| Persistence.createEntityManagerFactory("MyCardsPersistenceUnit");
| EntityManager em = emf.createEntityManager();
| setField(categoryBean, "em", em);
| setField(categoryBean, "log", Logging.getLog(CategoryBean.class));
|
Can anyone give a hint?
Thanks,
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094177#4094177
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094177
More information about the jboss-user
mailing list