Hi,

I am having trouble with unit testing my validation logic in Struts2.

here's the code.

1) In UserLookupAction-validation.xml I have
<field name="memberId">
        <field-validator type="requiredstring">
           <message>You must enter a value for 
${getText("memberId.label")}.</message>
       </field-validator>
</field>

2) In UserLookupActionTest.java I have the following method

public void setUp() throws Exception {
        super.setUp();
        ObjectFactory.setObjectFactory( new ObjectFactory() ); 
}

public void testValidationFailed() throws ValidationException {
        ActionValidatorManager avm = 
ActionValidatorManagerFactory.getInstance();
        UserLookupAction action = new UserLookupAction();
        action.setSession(sessionMap);
        action.setMemberId(null);

        avm.validate(action,"UserLookupAction");
        Map fieldErrors = action.getFieldErrors();
        assertTrue(action.hasErrors());
}

3) UserLookupActionTest extends from TestCase and not from StrutsTestCase but I 
think I am doing ObjectFactory.setObjectFactory( new ObjectFactory() ); as an 
alternative to that so it should not cause a problem.

When I run the testValidationFailed method above, the ActionValidatorManager 
instance gets initialized but it has no properties. Afterwards, when I call 
validate method on it, it executes but then fieldErrors map is empty and the 
action.hasErrors() returns null so the assertion fails. Can someone tell me 
what is wrong here? Any help would be appreciated. This validation logic seems 
to work when I run the app.

Thanks
Pranav



      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



      

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to