use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class ModelDrivenValidationTest method testModelDrivenValidation.
public void testModelDrivenValidation() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("count", new String[] { "11" });
Map<String, Object> context = new HashMap<>();
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(provider);
loadConfigurationProviders(provider);
ActionProxy proxy = actionProxyFactory.createActionProxy(null, "TestModelDrivenValidation", null, context);
assertEquals(Action.SUCCESS, proxy.execute());
ModelDrivenAction action = (ModelDrivenAction) proxy.getAction();
assertTrue(action.hasFieldErrors());
assertTrue(action.getFieldErrors().containsKey("count"));
assertEquals("count must be between 1 and 10, current value is 11.", ((List) action.getFieldErrors().get("count")).get(0));
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionEmailField.
public void testModelDrivenActionEmailField() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("name");
action.getModel().setEmail("notamail");
action.getModel().getAddress().setStreet("street");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(1, fieldErrors.size());
assertTrue(fieldErrors.get("email").size() > 0);
assertEquals(fieldErrors.get("email").get(0), "emailNotValid");
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSkipValidationByInterface.
public void testModelDrivenActionSkipValidationByInterface() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenActionSkipValidationByInterface", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName(null);
action.getModel().setEmail(null);
action.getModel().getAddress().setStreet(null);
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(0, fieldErrors.size());
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSuccess.
public void testModelDrivenActionSuccess() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("name");
action.getModel().setEmail("jogep@apache.org");
action.getModel().getAddress().setStreet("street");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(0, fieldErrors.size());
}
use of com.opensymphony.xwork2.ModelDrivenAction in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenAction.
public void testModelDrivenAction() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName(null);
action.getModel().setEmail(null);
action.getModel().getAddress().setStreet(null);
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(3, fieldErrors.size());
assertTrue(fieldErrors.get("name").size() > 0);
assertEquals(fieldErrors.get("name").get(0), "nameNotNull");
assertTrue(fieldErrors.get("email").size() > 0);
assertEquals(fieldErrors.get("email").get(0), "emailNotNull");
assertTrue(fieldErrors.get("address.street").size() > 0);
assertEquals(fieldErrors.get("address.street").get(0), "streetNotNull");
}
Aggregations