use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSize.
public void testModelDrivenActionSize() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("j");
action.getModel().setEmail("jogep@apache.org");
action.getModel().getAddress().setStreet("st");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
System.out.println(fieldErrors);
assertNotNull(fieldErrors);
assertEquals(2, fieldErrors.size());
assertTrue(fieldErrors.get("name").size() > 0);
assertEquals(fieldErrors.get("name").get(0), "nameSize");
assertTrue(fieldErrors.get("address.street").size() > 0);
assertEquals(fieldErrors.get("address.street").get(0), "streetSize");
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class ValidateAction method testModelDrivenParameters.
public void testModelDrivenParameters() throws Exception {
Map<String, Object> params = new HashMap<>();
final String fooVal = "com.opensymphony.xwork2.interceptor.ParametersInterceptorTest.foo";
params.put("foo", fooVal);
final String nameVal = "com.opensymphony.xwork2.interceptor.ParametersInterceptorTest.name";
params.put("name", nameVal);
params.put("count", "15");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext);
assertEquals(Action.SUCCESS, proxy.execute());
ModelDrivenAction action = (ModelDrivenAction) proxy.getAction();
TestBean model = (TestBean) action.getModel();
assertEquals(nameVal, model.getName());
assertEquals(15, model.getCount());
assertEquals(fooVal, action.getFoo());
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class OValValidationInterceptorTest method testModelDrivenAction.
public void testModelDrivenAction() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName(null);
action.getModel().setEmail(null);
action.getModel().getAddress().setStreet("short");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(3, fieldErrors.size());
assertValue(fieldErrors, "person.name", Collections.singletonList("person.name cannot be null"));
assertValue(fieldErrors, "person.email", Collections.singletonList("person.email cannot be null"));
assertValue(fieldErrors, "person.address.street", Collections.singletonList("person.address.street cannot be shorter than 7 characters"));
}
Aggregations