[WW-4528] handling ChainingInterceptor excludes and includes lists as

comma separated String like ParameterFilterInterceptor do
This commit is contained in:
Yasser Zamani
2017-02-03 02:01:50 +03:30
parent 0023d9664b
commit 0437efc6f9
3 changed files with 29 additions and 11 deletions
@@ -21,6 +21,7 @@ import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.Unchainable;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
@@ -210,12 +211,21 @@ public class ChainingInterceptor extends AbstractInterceptor {
return excludes;
}
/**
* Sets the list of parameter names to exclude from copying (all others will be included).
*
* @param excludes the excludes list as comma separated String
*/
public void setExcludes(String excludes) {
this.excludes = TextParseUtil.commaDelimitedStringToSet(excludes);
}
/**
* Sets the list of parameter names to exclude from copying (all others will be included).
*
* @param excludes the excludes list
*/
public void setExcludes(Collection<String> excludes) {
public void setExcludesCollection(Collection<String> excludes) {
this.excludes = excludes;
}
@@ -228,12 +238,22 @@ public class ChainingInterceptor extends AbstractInterceptor {
return includes;
}
/**
* Sets the list of parameter names to include when copying (all others will be excluded).
*
* @param includes the includes list as comma separated String
*/
public void setIncludes(String includes) {
this.includes = TextParseUtil.commaDelimitedStringToSet(includes);
}
/**
* Sets the list of parameter names to include when copying (all others will be excluded).
*
* @param includes the includes list
*/
public void setIncludes(Collection<String> includes) {
public void setIncludesCollection(Collection<String> includes) {
this.includes = includes;
}
@@ -103,8 +103,7 @@ public class ChainingInterceptorTest extends XWorkTestCase {
interceptor.setCopyErrors("true");
interceptor.setCopyMessages("true");
Collection<String> excludes = new ArrayList<>();
excludes.add("count");
String excludes = "count";
interceptor.setExcludes(excludes);
interceptor.intercept(invocation);
@@ -112,7 +111,7 @@ public class ChainingInterceptorTest extends XWorkTestCase {
assertEquals(bean.getBirth(), action.getBirth());
assertEquals(bean.getName(), action.getName());
assertEquals(0, action.getCount());
assertEquals(excludes, interceptor.getExcludes());
assertEquals(interceptor.getExcludes().iterator().next(), "count");
}
public void testTwoExcludesPropertiesChained() throws Exception {
@@ -125,15 +124,14 @@ public class ChainingInterceptorTest extends XWorkTestCase {
stack.push(bean);
stack.push(action);
Collection<String> excludes = new ArrayList<>();
excludes.add("name");
excludes.add("count");
String excludes = "name,count";
interceptor.setExcludes(excludes);
interceptor.intercept(invocation);
assertEquals(bean.getBirth(), action.getBirth());
assertEquals(null, action.getName());
assertEquals(0, action.getCount());
assertEquals(excludes, interceptor.getExcludes());
assertEquals(interceptor.getExcludes().iterator().next(), "count");
assertEquals(interceptor.getExcludes().iterator().next(), "name");
}
public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {
@@ -454,7 +454,7 @@ public class OgnlUtilTest extends XWorkTestCase {
final ValueStack stack = ActionContext.getContext().getValueStack();
Object result = Ognl.getValue(ognlUtil.compile("{\"foo\",'ruby','b','tom'}"), context, foo);
foo.setIncludes((Collection) result);
foo.setIncludesCollection((Collection) result);
assertEquals(4, foo.getIncludes().size());
assertEquals("foo", foo.getIncludes().toArray()[0]);
@@ -473,7 +473,7 @@ public class OgnlUtilTest extends XWorkTestCase {
result = ActionContext.getContext().getValueStack().findValue("{\"foo\",'ruby','b','tom'}");
foo.setIncludes((Collection) result);
foo.setIncludesCollection((Collection) result);
assertEquals(ArrayList.class, result.getClass());
assertEquals(4, foo.getIncludes().size());