Search in sources :

Example 31 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class AnnotationActionValidatorManagerTest method testDefaultMessageInterpolation.

public void testDefaultMessageInterpolation() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotatedTestBean.class, "beanMessageBundle");
    assertEquals(3, validatorList.size());
    try {
        AnnotatedTestBean bean = new AnnotatedTestBean();
        bean.setName("foo");
        bean.setCount(99);
        ValidatorContext context = new DummyValidatorContext(bean, tpf);
        annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
        assertTrue(context.hasErrors());
        assertTrue(context.hasFieldErrors());
        List<String> l = context.getFieldErrors().get("count");
        assertNotNull(l);
        assertEquals(1, l.size());
        assertEquals("Smaller Invalid Count: 99", l.get(0));
    } catch (ValidationException ex) {
        ex.printStackTrace();
        fail("Validation error: " + ex.getMessage());
    }
}
Also used : AnnotatedTestBean(com.opensymphony.xwork2.AnnotatedTestBean) List(java.util.List)

Example 32 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class AnnotationActionValidatorManagerTest method testMessageInterpolation.

public void testMessageInterpolation() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotatedTestBean.class, "beanMessageBundle");
    assertEquals(3, validatorList.size());
    try {
        AnnotatedTestBean bean = new AnnotatedTestBean();
        bean.setName("foo");
        bean.setCount(150);
        ValidatorContext context = new DummyValidatorContext(bean, tpf);
        annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
        assertTrue(context.hasErrors());
        assertTrue(context.hasFieldErrors());
        List<String> l = context.getFieldErrors().get("count");
        assertNotNull(l);
        assertEquals(1, l.size());
        assertEquals("Count must be between 1 and 100, current value is 150.", l.get(0));
    } catch (ValidationException ex) {
        ex.printStackTrace();
        fail("Validation error: " + ex.getMessage());
    }
}
Also used : AnnotatedTestBean(com.opensymphony.xwork2.AnnotatedTestBean) List(java.util.List)

Example 33 with Foo

use of com.opensymphony.xwork2.util.Foo 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)

Example 34 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class ConfigurationTest method testGlobalResults.

public void testGlobalResults() {
    try {
        ActionProxy proxy = actionProxyFactory.createActionProxy("", "Foo", null, null);
        assertNotNull(proxy.getConfig().getResults().get("login"));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 35 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class ConfigurationTest method testInterceptorParamInheritance.

public void testInterceptorParamInheritance() {
    try {
        ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "TestInterceptorParamInheritance", null, null);
        assertEquals(1, proxy.getConfig().getInterceptors().size());
        MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0).getInterceptor();
        assertEquals("expectedFoo", testInterceptor.getExpectedFoo());
        proxy.execute();
        assertTrue(testInterceptor.isExecuted());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) MockInterceptor(com.opensymphony.xwork2.mock.MockInterceptor)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)53 HashMap (java.util.HashMap)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)23 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)20 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)19 StrutsException (org.apache.struts2.StrutsException)19 OgnlException (ognl.OgnlException)18 IntrospectionException (java.beans.IntrospectionException)17 InappropriateExpressionException (ognl.InappropriateExpressionException)17 MethodFailedException (ognl.MethodFailedException)17 NoSuchPropertyException (ognl.NoSuchPropertyException)17 ActionProxy (com.opensymphony.xwork2.ActionProxy)16 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)8 Bar (com.opensymphony.xwork2.util.Bar)8 Map (java.util.Map)8 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)7 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)7 StubValueStack (com.opensymphony.xwork2.StubValueStack)6