Search in sources :

Example 36 with Foo

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

the class ConfigurationTest method testPackageExtension.

public void testPackageExtension() {
    try {
        ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "Bar", null, null);
        assertEquals(4, proxy.getConfig().getInterceptors().size());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 37 with Foo

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

the class ActionConfigMatcherTest method testReplaceParametersWithNoAppendingParams.

/**
 * Test to make sure the {@link AbstractMatcher#replaceParameters(Map, Map)} method isn't adding values to the
 * return value.
 */
public void testReplaceParametersWithNoAppendingParams() {
    Map<String, ActionConfig> map = new HashMap<>();
    HashMap<String, String> params = new HashMap<>();
    params.put("first", "{1}");
    ActionConfig config = new ActionConfig.Builder("package", "foo/{one}/{two}/{three}", "foo.bar.Action").addParams(params).addExceptionMapping(new ExceptionMappingConfig.Builder("foo{1}", "java.lang.{2}Exception", "success{1}").addParams(new HashMap<>(params)).build()).addResultConfig(new ResultConfig.Builder("success{1}", "foo.{2}").addParams(params).build()).setStrictMethodInvocation(false).build();
    map.put("foo/{one}/{two}/{three}", config);
    ActionConfigMatcher replaceMatcher = new ActionConfigMatcher(new RegexPatternMatcher(), map, false, false);
    ActionConfig matched = replaceMatcher.match("foo/paramOne/paramTwo/paramThree");
    assertNotNull("ActionConfig should be matched", matched);
    // Verify all The ActionConfig, ExceptionConfig, and ResultConfig have the correct number of params
    assertEquals("The ActionConfig should have the correct number of params", 1, matched.getParams().size());
    assertEquals("The ExceptionMappingConfigs should have the correct number of params", 1, matched.getExceptionMappings().get(0).getParams().size());
    assertEquals("The ResultConfigs should have the correct number of params", 1, matched.getResults().get("successparamOne").getParams().size());
    // Verify the params are still getting their values replaced correctly
    assertEquals("The ActionConfig params have replaced values", "paramOne", matched.getParams().get("first"));
    assertEquals("The ActionConfig params have replaced values", "paramOne", matched.getExceptionMappings().get(0).getParams().get("first"));
    assertEquals("The ActionConfig params have replaced values", "paramOne", matched.getResults().get("successparamOne").getParams().get("first"));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) HashMap(java.util.HashMap) RegexPatternMatcher(org.apache.struts2.util.RegexPatternMatcher)

Example 38 with Foo

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

the class ActionConfigMatcherTest method buildActionConfigMap.

private Map<String, ActionConfig> buildActionConfigMap() {
    Map<String, ActionConfig> map = new HashMap<>();
    HashMap<String, String> params = new HashMap<>();
    params.put("first", "{1}");
    params.put("second", "{2}");
    ActionConfig config = new ActionConfig.Builder("package-{1}", "foo/*/*", "foo.bar.{1}Action").methodName("do{2}").addParams(params).addExceptionMapping(new ExceptionMappingConfig.Builder("foo{1}", "java.lang.{2}Exception", "success{1}").addParams(new HashMap<>(params)).build()).addInterceptor(new InterceptorMapping(null, null)).addResultConfig(new ResultConfig.Builder("success{1}", "foo.{2}").addParams(params).build()).setStrictMethodInvocation(false).build();
    map.put("foo/*/*", config);
    config = new ActionConfig.Builder("package-{1}", "bar/*/**", "bar").methodName("do{1}_{1}").addParam("first", "{2}").setStrictMethodInvocation(false).build();
    map.put("bar/*/**", config);
    config = new ActionConfig.Builder("package", "eventAdd!*", "bar").methodName("{1}").setStrictMethodInvocation(false).build();
    map.put("addEvent!*", config);
    map.put("noWildcard", new ActionConfig.Builder("", "", "").build());
    return map;
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) HashMap(java.util.HashMap) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) ExceptionMappingConfig(com.opensymphony.xwork2.config.entities.ExceptionMappingConfig)

Example 39 with Foo

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

the class ActionConfigMatcherTest method testCheckSubstitutionsMatch.

public void testCheckSubstitutionsMatch() {
    ActionConfig m = matcher.match("foo/class/method");
    assertTrue("Class hasn't been replaced", "foo.bar.classAction".equals(m.getClassName()));
    assertTrue("Method hasn't been replaced", "domethod".equals(m.getMethodName()));
    assertTrue("Package isn't correct", "package-class".equals(m.getPackageName()));
    assertTrue("First param isn't correct", "class".equals(m.getParams().get("first")));
    assertTrue("Second param isn't correct", "method".equals(m.getParams().get("second")));
    ExceptionMappingConfig ex = m.getExceptionMappings().get(0);
    assertTrue("Wrong name, was " + ex.getName(), "fooclass".equals(ex.getName()));
    assertTrue("Wrong result", "successclass".equals(ex.getResult()));
    assertTrue("Wrong exception", "java.lang.methodException".equals(ex.getExceptionClassName()));
    assertTrue("First param isn't correct", "class".equals(ex.getParams().get("first")));
    assertTrue("Second param isn't correct", "method".equals(ex.getParams().get("second")));
    ResultConfig result = m.getResults().get("successclass");
    assertTrue("Wrong name, was " + result.getName(), "successclass".equals(result.getName()));
    assertTrue("Wrong classname", "foo.method".equals(result.getClassName()));
    assertTrue("First param isn't correct", "class".equals(result.getParams().get("first")));
    assertTrue("Second param isn't correct", "method".equals(result.getParams().get("second")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ExceptionMappingConfig(com.opensymphony.xwork2.config.entities.ExceptionMappingConfig)

Example 40 with Foo

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

the class ActionConfigMatcherTest method testShouldMatch.

public void testShouldMatch() {
    ActionConfig matched = matcher.match("foo/class/method");
    assertNotNull("ActionConfig should be matched", matched);
    assertTrue("ActionConfig should have properties, had " + matched.getParams().size(), matched.getParams().size() == 2);
    assertTrue("ActionConfig should have interceptors", matched.getInterceptors().size() == 1);
    assertTrue("ActionConfig should have ex mappings", matched.getExceptionMappings().size() == 1);
    assertTrue("ActionConfig should have external refs", matched.getExceptionMappings().size() == 1);
    assertTrue("ActionConfig should have results", matched.getResults().size() == 1);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

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