use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class DoubleRangeFieldValidatorTest method testRangeValidationWithError.
public void testRangeValidationWithError() throws Exception {
// Explicitly set an out-of-range double for DoubleRangeValidatorTest
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("percentage", 100.12);
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, context);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> errorMessages = errors.get("percentage");
assertNotNull("Expected double range validation error message.", errorMessages);
assertEquals(1, errorMessages.size());
String errorMessage = errorMessages.get(0);
assertNotNull("Expecting: percentage must be between 0.1 and 10.1, current value is 100.12.", errorMessage);
assertEquals("percentage must be between 0.1 and 10.1, current value is 100.12.", errorMessage);
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class DoubleRangeFieldValidatorTest method testRangeValidationNoError.
public void testRangeValidationNoError() throws Exception {
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("percentage", 1.234567d);
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "percentage", null, context);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> errorMessages = errors.get("percentage");
assertNull("Expected no double range validation error message.", errorMessages);
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ValidatorAnnotationTest method testAnnotatedMethodSuccess2.
public void testAnnotatedMethodSuccess2() throws Exception {
HashMap<String, Object> params = new HashMap<>();
// make it not fail
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 testAnnotatedMethodFailure.
public void testAnnotatedMethodFailure() throws Exception {
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create().build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasActionErrors());
Collection errors = ((ValidationAware) proxy.getAction()).getActionErrors();
assertEquals(1, errors.size());
assertEquals("Need param1 or param2.", errors.iterator().next());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ValidatorAnnotationTest method testNotAnnotatedMethodSuccess.
public void testNotAnnotatedMethodSuccess() 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("", "notAnnotatedMethod", null, extraContext);
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
Collection errors = ((ValidationAware) proxy.getAction()).getActionErrors();
assertEquals(0, errors.size());
}
Aggregations