Removing unnecessary part of AbstractMatcher#replaceParameters method and adding a test to make sure it is working correctly

This commit is contained in:
Alex Kaiser
2020-04-08 11:23:02 -07:00
parent 47c87bc62c
commit ec56290056
2 changed files with 41 additions and 8 deletions
@@ -158,14 +158,6 @@ public abstract class AbstractMatcher<E> implements Serializable {
map.put(entry.getKey(), convertParam(entry.getValue(), vars));
}
//the values map will contain entries like name->"Lex Luthor" and 1->"Lex Luthor"
//now add the non-numeric values
for (Map.Entry<String,String> entry: vars.entrySet()) {
if (!NumberUtils.isCreatable(entry.getKey())) {
map.put(entry.getKey(), entry.getValue());
}
}
return map;
}
@@ -24,6 +24,7 @@ import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.util.WildcardHelper;
import org.apache.struts2.util.RegexPatternMatcher;
import java.util.HashMap;
import java.util.Map;
@@ -142,6 +143,46 @@ public class ActionConfigMatcherTest extends XWorkTestCase {
}
/**
* Test to make sure the {@link AbstractMatcher#replaceParameters(Map, Map)} method isn't adding values to the
* return value.
*/
public void testReplaceParameters() {
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);
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
assertTrue("The ActionConfig should have the correct number of params",
matched.getParams().size() == 1);
assertTrue("The ExceptionMappingConfigs should have the correct number of params",
matched.getExceptionMappings().get(0).getParams().size() == 1);
assertTrue("The ResultConfigs should have the correct number of params",
matched.getResults().get("successparamOne").getParams().size() == 1);
// Verify the params are still getting their values replaced correctly
assertTrue("The ActionConfig params have replaced values",
"paramOne".equals(matched.getParams().get("first")));
assertTrue("The ActionConfig params have replaced values",
"paramOne".equals(matched.getExceptionMappings().get(0).getParams().get("first")));
assertTrue("The ActionConfig params have replaced values",
"paramOne".equals(matched.getResults().get("successparamOne").getParams().get("first")));
}
private Map<String,ActionConfig> buildActionConfigMap() {
Map<String, ActionConfig> map = new HashMap<>();