use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class AnnotationXWorkConverterTest method testStringToCustomTypeUsingCustomConverter.
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
assertNotNull("conversion failed", bar);
assertEquals(123, bar.getSomethingElse());
assertEquals("blah", bar.getTitle());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class SimpleActionValidationTest method testMessageKey.
public void testMessageKey() {
HashMap<String, Object> params = new HashMap<>();
params.put("foo", "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);
ValueStack stack = ActionContext.getContext().getValueStack();
stack.getActionContext().withLocale(Locale.US);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> fooErrors = errors.get("foo");
assertEquals(1, fooErrors.size());
String errorMessage = fooErrors.get(0);
assertNotNull(errorMessage);
assertEquals("Foo Range Message", errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class ConversionErrorFieldValidatorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, ConversionData> conversionErrors = new HashMap<>();
conversionErrors.put("foo", new ConversionData("bar", Integer.class));
ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
validator = new ConversionErrorFieldValidator();
validationAware = new ValidationAwareSupport();
DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.getInstance(TextProviderFactory.class));
stack.push(validatorContext);
validator.setValidatorContext(validatorContext);
validator.setFieldName("foo");
validator.setValueStack(ActionContext.getContext().getValueStack());
assertEquals(0, validationAware.getFieldErrors().size());
}
use of com.opensymphony.xwork2.util.Foo 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());
}
use of com.opensymphony.xwork2.util.Foo in project struts by apache.
the class VisitorFieldValidatorTest method testArrayValidation.
public void testArrayValidation() throws Exception {
TestBean[] beanArray = action.getTestBeanArray();
TestBean testBean = beanArray[0];
testBean.setName("foo");
validate("validateArray");
assertTrue(action.hasFieldErrors());
Map<String, List<String>> fieldErrors = action.getFieldErrors();
// 4 errors for the array, one for context
assertEquals(5, fieldErrors.size());
assertTrue(fieldErrors.containsKey("testBeanArray[1].name"));
// the error from the action should be there too
assertTrue(fieldErrors.containsKey("context"));
List<String> errors = fieldErrors.get("testBeanArray[1].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[2].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[3].name");
assertEquals(1, errors.size());
errors = fieldErrors.get("testBeanArray[4].name");
assertEquals(1, errors.size());
}
Aggregations