use of com.opensymphony.xwork2.test.Equidae in project struts by apache.
the class ScopedModelDrivenInterceptorTest method testScopedModelDrivenActionWithSetClassName.
public void testScopedModelDrivenActionWithSetClassName() throws Exception {
inter.setScope("request");
inter.setClassName("com.opensymphony.xwork2.test.Equidae");
inter.setName("queen");
ScopedModelDriven action = new MyEquidaeScopedModelDrivenAction();
MockActionInvocation mai = new MockActionInvocation();
MockActionProxy map = new MockActionProxy();
ActionConfig ac = new ActionConfig.Builder("", "", "").build();
map.setConfig(ac);
mai.setAction(action);
mai.setProxy(map);
inter.intercept(mai);
inter.destroy();
assertNotNull(action.getModel());
assertNotNull(action.getScopeKey());
assertEquals("queen", action.getScopeKey());
Object model = ActionContext.getContext().get(action.getScopeKey());
assertNotNull(model);
assertTrue("Model should be an Equidae object", model instanceof Equidae);
}
use of com.opensymphony.xwork2.test.Equidae in project struts by apache.
the class StringValidatorTest method testRequiredStringWithNullValue.
public void testRequiredStringWithNullValue() throws Exception {
Equidae equidae = new Equidae();
equidae.setHorse(null);
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
}
use of com.opensymphony.xwork2.test.Equidae in project struts by apache.
the class StringValidatorTest method testStringLength.
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(), tpf);
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(), tpf);
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(), tpf);
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(), tpf);
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(), tpf);
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
assertTrue(fieldErrors.containsKey("donkey"));
errors = (List) fieldErrors.get("donkey");
assertEquals(2, errors.size());
assertEquals("trim-min5-max10", errors.get(0));
assertEquals("trim-max10", errors.get(1));
}
use of com.opensymphony.xwork2.test.Equidae in project struts by apache.
the class StringValidatorTest method testRequiredString.
public void testRequiredString() throws Exception {
Equidae equidae = new Equidae();
// everything should fail
equidae.setHorse("");
ActionContext.getContext().getValueStack().push(equidae);
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
Map fieldErrors = context.getFieldErrors();
assertTrue(fieldErrors.containsKey("horse"));
assertEquals(2, ((List) fieldErrors.get("horse")).size());
// trim = false should fail
equidae.setHorse(" ");
ActionContext.getContext().getValueStack().push(equidae);
context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
fieldErrors = context.getFieldErrors();
assertTrue(fieldErrors.containsKey("horse"));
List errors = (List) fieldErrors.get("horse");
assertEquals(1, errors.size());
assertEquals("trim", (String) errors.get(0));
}
Aggregations