Share

Mockrunner

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

test with DynaActionForm

  1. nobody

    2006-04-13 12:14:45 UTC
    Hi,

    I tried mockrunner because with MockStrutsTestCase, it's difficult to mock objects.
    With mockrunner, I would like to test my Action with a DynaActionForm. I see there is a method createDynaActionForm(), but I have to give a FormBeanConfig in parameter. In my test, I would like to use the DynaActionForm that is define in my struts-config.xml, if not possible I would like to be able to build the DynaActionForm.
    Do you have some sample ? Do you any alternative ?

    Thanks for this framework. I will use it for testing my taglib too.

    Jeff
  2. 2006-04-13 12:34:12 UTC
    Hi Jeff,

    Mockrunner does not read the struts-config.xml. Unfortunately I don't have a DynaActionForm example but it's easy to create a FormBeanConfig. Have a look at the unit test method com.mockrunner.test.web.ActionTestModuleTest#testDynaActionForm() to get an idea how to deal with the FormBeanConfig and createDynaActionForm.

    Regards,

    Alwin
  3. nobody

    2006-04-13 13:36:54 UTC
    Here is my code that works, I test a DispatchAction with a DynaActionForm and I mock the service, next Step integrate with JMock, Thanks Alwin:

    public class UserActionTest extends BasicActionTestCaseAdapter {
    private DynaActionForm form;
    private UserAction action;

    protected void setUp() throws Exception {
    super.setUp();
    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);

    getActionMockObjectFactory().getMockActionMapping().setParameter("method");
    form = createDynaActionForm(config);
    action = new UserAction();
    action.setUserService(new UserServiceMock());
    }

    public void testTest() {
    addRequestParameter("method","test");
    actionPerform(action, form);
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward("detail");
    }
    }

    Regards,
    Jeff
< Previous | 1 | Next >

Add a Reply

You can use Markdown syntax in your reply.

Preview

Monitor this

Log in to monitor this topic. Not registered? Create an account to receive email updates when replies are posted to this topic. If you do not log in or register, your reply will be added anonymously.