assertEquals(1, errors.size());
assertEquals("trim", (String) errors.get(0));
}
public void testStringLength() throws Exception {
Equidae equidae = new Equidae();
equidae.setCow("asdf");
equidae.setDonkey("asdf");
ActionContext.getContext().getValueStack().push(equidae);
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport());
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
Map fieldErrors = context.getFieldErrors();
// cow
assertTrue(fieldErrors.containsKey("cow"));
List errors = (List) fieldErrors.get("cow");
assertEquals(2, errors.size());
assertEquals("noTrim-min5", errors.get(0));
assertEquals("noTrim-min5-max10", errors.get(1));
// donkey
assertTrue(fieldErrors.containsKey("donkey"));
errors = (List) fieldErrors.get("donkey");
assertEquals(2, errors.size());
assertEquals("trim-min5", errors.get(0));
assertEquals("trim-min5-max10", errors.get(1));
equidae.setCow("asdf ");
equidae.setDonkey("asdf ");
ActionContext.getContext().getValueStack().push(equidae);
context = new DelegatingValidatorContext(new ValidationAwareSupport());
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
fieldErrors = context.getFieldErrors();
// cow
assertFalse(fieldErrors.containsKey("cow"));
// donkey
assertTrue(fieldErrors.containsKey("donkey"));
errors = (List) fieldErrors.get("donkey");
assertEquals(2, errors.size());
assertEquals("trim-min5", errors.get(0));
assertEquals("trim-min5-max10", errors.get(1));
equidae.setCow("asdfasdf");
equidae.setDonkey("asdfasdf");
ActionContext.getContext().getValueStack().push(equidae);
context = new DelegatingValidatorContext(new ValidationAwareSupport());
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
fieldErrors = context.getFieldErrors();
// cow
assertFalse(fieldErrors.containsKey("cow"));
// donkey
assertFalse(fieldErrors.containsKey("donkey"));
equidae.setCow("asdfasdf ");
equidae.setDonkey("asdfasdf ");
ActionContext.getContext().getValueStack().push(equidae);
context = new DelegatingValidatorContext(new ValidationAwareSupport());
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
fieldErrors = context.getFieldErrors();
// cow
assertTrue(fieldErrors.containsKey("cow"));
errors = (List) fieldErrors.get("cow");
assertEquals(2, errors.size());
assertEquals("noTrim-min5-max10", errors.get(0));
assertEquals("noTrim-max10", errors.get(1));
// donkey
assertFalse(fieldErrors.containsKey("donkey"));
equidae.setCow("asdfasdfasdf");
equidae.setDonkey("asdfasdfasdf");
ActionContext.getContext().getValueStack().push(equidae);
context = new DelegatingValidatorContext(new ValidationAwareSupport());
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());