atom feed1 message in net.java.dev.appfuse.usersFwd: Change MockStrutsTestCase to Moc...
FromSent OnAttachments
Matt RaibleApr 13, 2006 7:45 am 
Subject:Fwd: Change MockStrutsTestCase to Mockrunner
From:Matt Raible (mrai@gmail.com)
Date:Apr 13, 2006 7:45:56 am
List:net.java.dev.appfuse.users

FYI...

---------- Forwarded message ---------- From: Helie JEff <heli@yahoo.fr> Date: Apr 13, 2006 8:44 AM Subject: Change MockStrutsTestCase to Mockrunner To: ma@raibledesigns.com

Hi Mat,

I was not satisfied with MockStrutsTestCase so I tried MockRunner to unit test Struts Action. And I succeeded to mock UserService in UserAction with JMock, it may interess you:

public class UserActionTest extends MockObjectTestCase { private ActionMockObjectFactory mockFactory; private ActionTestModule module; private DynaActionForm form; private UserAction action; private UserService userService; private Mock mockUserService;

protected void setUp() throws Exception { super.setUp(); // mockFactory = new ActionMockObjectFactory(); module = new ActionTestModule(mockFactory);

// DynaActionForm definition FormBeanConfig config = new FormBeanConfig(); config.setName("userForm"); config.setType(DynaActionForm.class.getName()); FormPropertyConfig property1 = new FormPropertyConfig(); property1.setName("user"); property1.setType("fr.canam.demo.model.User"); config.addFormPropertyConfig(property1); form = module.createDynaActionForm(config);

// set parameter of DispatchAction mockFactory.getMockActionMapping().setParameter("method");

action = new UserAction();

// mock definition mockUserService = mock(UserService.class);

// mock injection action.setUserService((UserService)mockUserService.proxy()); }

public void testTest() { final User u = new User(); u.setLastName("Johnson"); u.setFirstName("Rod");


mockUserService.expects(once()).method("getUser").with(this.eq(1)).will(returnValue(u));

module.addRequestParameter("method","test"); module.actionPerform(action, form); module.verifyNoActionErrors(); module.verifyNoActionMessages(); module.verifyForward("detail");

assertSame(u,mockFactory.getMockRequest().getAttribute("user")); } </code>

Thanks for Appfuse.

Regards, Jeff

________________________________ Faites de Yahoo! votre page d'accueil sur le web pour retrouver directement vos services préférés : vérifiez vos nouveaux mails, lancez vos recherches et suivez l'actualité en temps réel. Cliquez ici.