use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ExpressionValidatorTest method testExpressionValidatorFailure.
public void testExpressionValidatorFailure() throws Exception {
HashMap<String, Object> params = new HashMap<>();
params.put("date", "12/23/2002");
params.put("foo", "5");
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasActionErrors());
Collection errors = ((ValidationAware) proxy.getAction()).getActionErrors();
assertEquals(1, errors.size());
String message = (String) errors.iterator().next();
assertNotNull(message);
assertEquals("Foo must be greater than Bar. Foo = 5, Bar = 7.", message);
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class IntRangeValidatorTest method testRangeValidation.
public void testRangeValidation() {
HashMap<String, String> params = new HashMap<>();
params.put("bar", "5");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> errorMessages = errors.get("bar");
assertEquals(1, errorMessages.size());
String errorMessage = errorMessages.get(0);
assertNotNull(errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class LongRangeValidatorTest method testRangeValidation.
public void testRangeValidation() {
HashMap<String, String> params = new HashMap<>();
params.put("longFoo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List errorMessages = (List) errors.get("longFoo");
assertEquals(1, errorMessages.size());
String errorMessage = (String) errorMessages.get(0);
assertNotNull(errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ValidatorAnnotationTest method testAnnotatedMethodSuccess.
public void testAnnotatedMethodSuccess() throws Exception {
HashMap<String, Object> params = new HashMap<>();
// make it not fail
params.put("param1", "key1");
params.put("param2", "key2");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ValidatorAnnotationTest method testAnnotatedMethodSuccess3.
public void testAnnotatedMethodSuccess3() throws Exception {
HashMap<String, Object> params = new HashMap<>();
// make it not fail
params.put("param1", "key1");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
Aggregations