views:

174

answers:

1

Stripes allows you to validate your form input values using the @Validate annotation on your member variables. Does anyone have any experience testing these annotations directly. I could do this by testing the validation errors that come back from the ActionBean, but this seems a little long winded and I would like a more direct method of testing if an input value is valid.

I'm not that familiar with the innards of the Framework yet, and I was hoping someone could give me some direction on where to start. TIA.

+1  A: 

One method I've used is Stripes' built in MockRoundtrip. It is useful for simulating a complete test of an action bean event outside the container.

Example from the documentation:

 MockServletContext context = ...;
 MockRoundtrip trip = new MockRoundtrip(context, CalculatorActionBean.class);
 trip.setParameter("numberOne", "2");
 trip.setParameter("numberTwo", "2");
 trip.execute();
 CalculatorActionBean bean = trip.getActionBean(CalculatorActionBean.class);
 Assert.assertEquals(bean.getResult(), 4, "two plus two should equal four");
 Assert.assertEquals(trip.getDestination(), ""/quickstart/index.jsp");

Additionally, you could use trip.getValidationErrors() and assert that your error is in there.

lucas