Search in sources :

Example 11 with Bar

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());
}
Also used : TextProviderFactory(com.opensymphony.xwork2.TextProviderFactory) ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) ConversionData(com.opensymphony.xwork2.conversion.impl.ConversionData) ConversionErrorFieldValidator(com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)

Example 12 with Bar

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());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) HashMap(java.util.HashMap) Collection(java.util.Collection) ValidationAware(com.opensymphony.xwork2.interceptor.ValidationAware)

Example 13 with Bar

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);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Example 14 with Bar

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);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Example 15 with Bar

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"));
}
Also used : HashMap(java.util.HashMap) CompiledPattern(com.opensymphony.xwork2.util.NamedVariablePatternMatcher.CompiledPattern) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)17 Bar (com.opensymphony.xwork2.util.Bar)14 Foo (com.opensymphony.xwork2.util.Foo)13 ValueStack (com.opensymphony.xwork2.util.ValueStack)12 ActionProxy (com.opensymphony.xwork2.ActionProxy)9 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)9 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)7 ValidationAware (com.opensymphony.xwork2.interceptor.ValidationAware)7 List (java.util.List)6 Map (java.util.Map)6 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)5 Mock (com.mockobjects.dynamic.Mock)4 ActionContext (com.opensymphony.xwork2.ActionContext)4 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)4 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)3 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)3 MockResult (com.opensymphony.xwork2.mock.MockResult)3 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)3 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)3 ActionSupport (com.opensymphony.xwork2.ActionSupport)2