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"));
}
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")));
}
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"));
}
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());
}
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);
}
Aggregations