Can you post your applicationContext.xml file with your accountManager bean definition?

Matt

On Jan 7, 2009, at 11:38 AM, nn4l wrote:


I have created a basic Appfuse Struts application (with full-source) by
following the video and the tutorial.

I started with a model/Account.java class and later added
dao/hibernate/AccountDaoHibernate.java, dao/hibernate/AccountDao.java,
service/impl/AccountManagerImpl.java service/AccountManager.java, and
modified webapp/action/AccountAction.java so that it uses my new
AccountManager instead of the GenericManager. I also had to modify several xml files to get everything running, the tutorial is not too clear on this.

Everything works just fine and I have also verified that all of my new
classes are in fact used.

Now I have added the corresponding test classes but the test case fails in accountManager.save(account) with a null pointer Exception. The reason is that the dao object in my AccountManager object is null. Surprisingly the AccountDaoHibernate object itself is created (I put a breakpoint in the
constructor) during execution of
applicationContext.getBean("accountManager"). But it is not associated with
the AccountManager object.

My guess is that some of the xml files are incorrect, or that something else is missing when executing the tests from IDEA. So the accountManager bean is not properly initialized. However the web application itself runs just fine when started with mvn jetty:run, so it must be related to the test classes
and test code.

Here is the failing test code. I am not sure which other files to post, I don't want to clutter this post with lots of unrelated code. Just let me
know which other files I should post.

package project.webapp.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import project.service.AccountManager;
import project.model.Account;
import org.springframework.mock.web.MockHttpServletRequest;

public class AccountActionTest extends BaseActionTestCase {
   private AccountAction action;

   @Override @SuppressWarnings("unchecked")
   protected void onSetUpInTransaction() throws Exception {
       action = new AccountAction();
       AccountManager accountManager = (AccountManager)
applicationContext.getBean("accountManager");
       action.setAccountManager(accountManager);

       // add a test account to the database
       Account account = new Account();

       // enter all required fields
       account.setHostname("mail.test.com");
       account.setTyp(1);

       accountManager.save(account);
   }
}
--
View this message in context: 
http://www.nabble.com/Manager-object-not-properly-initialized-during-test-tp21337598s2369p21337598.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to