Search in sources :

Example 86 with Foo

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

the class ActionConfigMatcherTest method testReplaceParametersWithAppendingParams.

/**
 * Test to make sure the {@link AbstractMatcher#replaceParameters(Map, Map)} method is adding values to the
 * return value.
 */
public void testReplaceParametersWithAppendingParams() {
    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, true);
    ActionConfig matched = replaceMatcher.match("foo/paramOne/paramTwo/paramThree");
    assertNotNull("ActionConfig should be matched", matched);
    assertEquals(4, matched.getParams().size());
    assertEquals(4, matched.getExceptionMappings().get(0).getParams().size());
    assertEquals(4, matched.getResults().get("successparamOne").getParams().size());
    // Verify the params are still getting their values replaced correctly
    assertEquals("paramOne", matched.getParams().get("first"));
    assertEquals("paramOne", matched.getParams().get("one"));
    assertEquals("paramTwo", matched.getParams().get("two"));
    assertEquals("paramThree", matched.getParams().get("three"));
    assertEquals("paramOne", matched.getExceptionMappings().get(0).getParams().get("first"));
    assertEquals("paramOne", matched.getExceptionMappings().get(0).getParams().get("one"));
    assertEquals("paramTwo", matched.getExceptionMappings().get(0).getParams().get("two"));
    assertEquals("paramThree", matched.getExceptionMappings().get(0).getParams().get("three"));
    assertEquals("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 87 with Foo

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

the class ActionConfigMatcherTest method testLooseMatch.

public void testLooseMatch() {
    configMap.put("*!*", configMap.get("bar/*/**"));
    ActionConfigMatcher matcher = new ActionConfigMatcher(new WildcardHelper(), configMap, true);
    // exact match
    ActionConfig m = matcher.match("foo/class/method");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced " + m.getClassName(), "foo.bar.classAction".equals(m.getClassName()));
    assertTrue("Method hasn't been replaced", "domethod".equals(m.getMethodName()));
    // Missing last wildcard
    m = matcher.match("foo/class");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced", "foo.bar.classAction".equals(m.getClassName()));
    assertTrue("Method hasn't been replaced, " + m.getMethodName(), "do".equals(m.getMethodName()));
    // Simple mapping
    m = matcher.match("class!method");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced, " + m.getPackageName(), "package-class".equals(m.getPackageName()));
    assertTrue("Method hasn't been replaced", "method".equals(m.getParams().get("first")));
    // Simple mapping
    m = matcher.match("class");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced", "package-class".equals(m.getPackageName()));
    assertTrue("Method hasn't been replaced", "".equals(m.getParams().get("first")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) WildcardHelper(com.opensymphony.xwork2.util.WildcardHelper)

Example 88 with Foo

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

the class NamespaceMatcherTest method testMatch.

public void testMatch() {
    Set<String> names = new HashSet<>();
    names.add("/bar");
    names.add("/foo/*/bar");
    names.add("/foo/*");
    names.add("/foo/*/jim/*");
    NamespaceMatcher matcher = new NamespaceMatcher(new WildcardHelper(), names);
    assertEquals(3, matcher.compiledPatterns.size());
    assertNull(matcher.match("/asd"));
    assertEquals("/foo/*", matcher.match("/foo/23").getPattern());
    assertEquals("/foo/*/bar", matcher.match("/foo/23/bar").getPattern());
    assertEquals("/foo/*/jim/*", matcher.match("/foo/23/jim/42").getPattern());
    assertNull(matcher.match("/foo/23/asd"));
}
Also used : WildcardHelper(com.opensymphony.xwork2.util.WildcardHelper) HashSet(java.util.HashSet)

Example 89 with Foo

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

the class ChainResultTest method testNamespaceChain.

public void testNamespaceChain() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "chain_with_namespace", null, null);
    ((SimpleAction) proxy.getAction()).setBlah("%{foo}");
    proxy.execute();
    assertTrue(proxy.getInvocation().getResult() instanceof MockResult);
    MockResult result = (MockResult) proxy.getInvocation().getResult();
    assertEquals("%{foo}", result.getInvocation().getProxy().getNamespace());
}
Also used : MockResult(com.opensymphony.xwork2.mock.MockResult)

Example 90 with Foo

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

the class DefaultActionInvocationTester method testActionChainResult.

public void testActionChainResult() throws Exception {
    ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "Foo", null, new HashMap<String, Object>());
    DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
    defaultActionInvocation.init(actionProxy);
    SimpleAction action = (SimpleAction) defaultActionInvocation.getAction();
    action.setFoo(1);
    action.setBar(2);
    defaultActionInvocation.invoke();
    // then
    assertTrue(defaultActionInvocation.result instanceof ActionChainResult);
    Result result = defaultActionInvocation.getResult();
    assertTrue(result instanceof MockResult);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) MockResult(com.opensymphony.xwork2.mock.MockResult) MockResult(com.opensymphony.xwork2.mock.MockResult)

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