use of com.opensymphony.xwork2.util.Bar 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.Bar 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.Bar in project struts by apache.
the class StrutsLocalizedTextProviderTest method testFindTextInChildProperty.
public void testFindTextInChildProperty() throws Exception {
ModelDriven action = new ModelDrivenAction2();
TestBean2 bean = (TestBean2) action.getModel();
Bar bar = new Bar();
bean.setBarObj(bar);
Mock mockActionInvocation = new Mock(ActionInvocation.class);
mockActionInvocation.expectAndReturn("hashCode", 0);
mockActionInvocation.expectAndReturn("getAction", action);
ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
ActionContext.getContext().getValueStack().push(action);
ActionContext.getContext().getValueStack().push(action.getModel());
String message = localizedTextProvider.findText(ModelDrivenAction2.class, "invalid.fieldvalue.barObj.title", Locale.getDefault());
assertEquals("Title is invalid!", message);
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class StrutsLocalizedTextProviderTest method testActionGetText.
public void testActionGetText() throws Exception {
ModelDrivenAction2 action = new ModelDrivenAction2();
container.inject(action);
TestBean2 bean = (TestBean2) action.getModel();
Bar bar = new Bar();
bean.setBarObj(bar);
Mock mockActionInvocation = new Mock(ActionInvocation.class);
mockActionInvocation.expectAndReturn("getAction", action);
ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
ActionContext.getContext().getValueStack().push(action);
ActionContext.getContext().getValueStack().push(action.getModel());
String message = action.getText("barObj.title");
assertEquals("Title:", message);
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class NamedVariablePatternMatcherTest method testMatch.
@Test
public void testMatch() {
NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
Map<String, String> vars = new HashMap<>();
CompiledPattern pattern = new CompiledPattern(Pattern.compile("foo([^/]+)"), Arrays.asList("bar"));
assertTrue(matcher.match(vars, "foobaz", pattern));
assertEquals("baz", vars.get("bar"));
}
Aggregations