use of com.opensymphony.xwork2.validator.ValidationException in project struts by apache.
the class AnnotationActionValidatorManagerTest method testShortCircuitNoErrors.
public void testShortCircuitNoErrors() {
// get validators
List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
assertEquals(10, validatorList.size());
try {
AnnotationUser user = new AnnotationUser();
user.setName("Mark");
user.setEmail("mark@mycompany.com");
user.setEmail2("mark@mycompany.com");
ValidatorContext context = new DummyValidatorContext(user, tpf);
annotationActionValidatorManager.validate(user, null, context);
assertFalse(context.hasErrors());
} catch (ValidationException ex) {
ex.printStackTrace();
fail("Validation error: " + ex.getMessage());
}
}
use of com.opensymphony.xwork2.validator.ValidationException 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.ValidationException in project struts by apache.
the class AnnotationActionValidatorManagerTest method testSkipAllActionLevelShortCircuit2.
public void testSkipAllActionLevelShortCircuit2() {
// get validators
List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
assertEquals(10, validatorList.size());
try {
AnnotationUser user = new AnnotationUser();
user.setName("Mark");
// * mark both email to starts with mark to get pass the action-level validator,
// so we could concentrate on testing the field-level validators (AnnotationUser-validation.xml)
// * make both email the same to pass the action-level validator at
// AnnotationUserMarker-validation.xml
user.setEmail("mark_bad_email_for_field_val@foo.com");
user.setEmail2("mark_bad_email_for_field_val@foo.com");
ValidatorContext context = new DummyValidatorContext(user, tpf);
annotationActionValidatorManager.validate(user, null, context);
assertTrue(context.hasFieldErrors());
// check field errors
// we have an error in this field level, email does not ends with mycompany.com
List l = context.getFieldErrors().get("email");
assertNotNull(l);
// because email-field-val is short-circuit
assertEquals(1, l.size());
assertEquals("Email not from the right company.", l.get(0));
// check action errors
l = (List) context.getActionErrors();
assertFalse(context.hasActionErrors());
assertEquals(0, l.size());
} catch (ValidationException ex) {
ex.printStackTrace();
fail("Validation error: " + ex.getMessage());
}
}
use of com.opensymphony.xwork2.validator.ValidationException in project struts by apache.
the class AnnotationActionValidatorManagerTest method testGetValidatorsForGivenMethodNameWithoutReloading.
public void testGetValidatorsForGivenMethodNameWithoutReloading() throws ValidationException {
FileManager fileManager = container.getInstance(FileManagerFactory.class).getFileManager();
List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias, "execute");
// disable configuration reload/devmode
fileManager.setReloadingConfigs(false);
// 17 in the class level + 0 in the alias
assertEquals(12, validatorList.size());
validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias, "execute");
// expect same number of validators
assertEquals(12, validatorList.size());
}
use of com.opensymphony.xwork2.validator.ValidationException in project struts by apache.
the class URLValidatorTest method testValidUrlCaseInsensitive.
public void testValidUrlCaseInsensitive() throws Exception {
// given
final Map<String, Object> fieldErrors = new HashMap<>();
URLValidator validator = new URLValidator() {
@Override
public String getFieldName() {
return "url";
}
@Override
protected Object getFieldValue(String name, Object object) throws ValidationException {
return object;
}
@Override
protected void addFieldError(String propertyName, Object object) {
fieldErrors.put(propertyName, object);
}
};
// when
validator.validate("http://localhost:8080/myapp");
// then
assertTrue(fieldErrors.isEmpty());
// when
validator.validate("http://LOCALHOST:8080/MYAPP");
// then
assertTrue(fieldErrors.isEmpty());
// when
validator.validate("http://www.appache.org/TEST");
// then
assertTrue(fieldErrors.isEmpty());
}
Aggregations