use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class ShortRangeFieldValidatorTest method testMinValidation.
public void testMinValidation() throws Exception {
// given
ValidationAction action = prepareAction((short) 1);
ValidatorContext context = new DummyValidatorContext(action, tpf);
ShortRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals("Max is 10, min is 2 but value is 1", context.getFieldErrors().get("shortRange").get(0));
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class ValidatorSupportTest method testConditionalParseExpression.
public void testConditionalParseExpression() {
OgnlValueStack stack = (OgnlValueStack) container.getInstance(ValueStackFactory.class).createValueStack();
stack.getContext().put("something", "somevalue");
ActionContext.of(stack.getContext()).withContainer(container).bind();
ValidatorSupport validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String result1 = validator.parse("${#something}", String.class).toString();
assertEquals(result1, "somevalue");
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class PlexusObjectFactory method buildValidator.
/* (non-Javadoc)
* @see com.opensymphony.xwork2.ObjectFactory#buildValidator(java.lang.String, java.util.Map, java.util.Map)
*/
public Validator buildValidator(String className, Map params, Map extraContext) throws Exception {
Map context = new HashMap();
context.put(PLEXUS_COMPONENT_TYPE, Validator.class.getName());
Validator validator = (Validator) buildBean(className, context);
reflectionProvider.setProperties(params, validator);
return validator;
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class BeanValidationInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
Validator validator = this.beanValidationManager.getValidator();
if (validator == null) {
LOG.debug("There is no Bean Validator configured in class path. Skipping Bean validation..");
return invocation.invoke();
}
LOG.debug("Starting bean validation using validator: {}", validator.getClass());
Object action = invocation.getAction();
ActionProxy actionProxy = invocation.getProxy();
String methodName = actionProxy.getMethod();
LOG.debug("Validating [{}/{}] with method [{}]", invocation.getProxy().getNamespace(), invocation.getProxy().getActionName(), methodName);
if (null == MethodUtils.getAnnotation(getActionMethod(action.getClass(), methodName), SkipValidation.class, true, true)) {
Class<?>[] validationGroup = getValidationGroups(action, methodName);
// performing bean validation on action
performBeanValidation(action, validator, validationGroup);
}
return invocation.invoke();
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class SpringObjectFactoryTest method testFallsBackToDefaultObjectFactoryValidatorBuilding.
public void testFallsBackToDefaultObjectFactoryValidatorBuilding() throws Exception {
Map<String, Object> extraContext = new HashMap<>();
Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(), new HashMap<String, Object>(), extraContext);
assertEquals(RequiredStringValidator.class, validator.getClass());
}
Aggregations