mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4528 Supports includes/excludes as lists
This commit is contained in:
@@ -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,15 @@ 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());
|
||||
assertTrue(interceptor.getExcludes().contains("count"));
|
||||
assertTrue(interceptor.getExcludes().contains("name"));
|
||||
assertTrue(interceptor.getExcludes().size() == 2);
|
||||
}
|
||||
|
||||
public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2002-2006,2009 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.struts2.TestResult;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link ChainingInterceptor} with a configuration provider.
|
||||
*
|
||||
*/
|
||||
public class ChainingInterceptorWithConfigTest extends XWorkTestCase {
|
||||
|
||||
static String CHAINED_ACTION = "chainedAction";
|
||||
static String CHAINTO_ACTION = "chaintoAction";
|
||||
ObjectFactory objectFactory;
|
||||
|
||||
public void testTwoExcludesPropertiesChained() throws Exception {
|
||||
assertNotNull(objectFactory);
|
||||
ActionProxy proxy = actionProxyFactory.createActionProxy("", CHAINED_ACTION, null, null);
|
||||
SimpleAction chainedAction = (SimpleAction) proxy.getAction();
|
||||
chainedAction.setBar(1);
|
||||
chainedAction.setFoo(1);
|
||||
chainedAction.setBlah("WW-4528");
|
||||
proxy.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
XmlConfigurationProvider provider = new XmlConfigurationProvider("xwork-default.xml");
|
||||
container.inject(provider);
|
||||
this.objectFactory = container.getInstance(ObjectFactory.class);
|
||||
loadConfigurationProviders(provider, new MockConfigurationProvider());
|
||||
}
|
||||
|
||||
|
||||
private class MockConfigurationProvider implements ConfigurationProvider {
|
||||
private Configuration config;
|
||||
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
this.config = configuration;
|
||||
}
|
||||
|
||||
public boolean needsReload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void destroy() { }
|
||||
|
||||
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
if (!builder.contains(ObjectFactory.class)) {
|
||||
builder.factory(ObjectFactory.class);
|
||||
}
|
||||
if (!builder.contains(ActionProxyFactory.class)) {
|
||||
builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
HashMap<String, String> interceptorParams = new HashMap<>();
|
||||
interceptorParams.put("excludes", "blah,bar");
|
||||
|
||||
HashMap successParams1 = new HashMap();
|
||||
successParams1.put("propertyName", "baz");
|
||||
successParams1.put("expectedValue", 1);
|
||||
|
||||
HashMap successParams2 = new HashMap();
|
||||
successParams2.put("propertyName", "blah");
|
||||
successParams2.put("expectedValue", null);
|
||||
|
||||
InterceptorConfig chainingInterceptorConfig = new InterceptorConfig.Builder("chainStack", ChainingInterceptor.class.getName()).build();
|
||||
PackageConfig packageConfig = new PackageConfig.Builder("default")
|
||||
.addActionConfig(CHAINED_ACTION, new ActionConfig.Builder("defaultPackage", CHAINED_ACTION, SimpleAction.class.getName())
|
||||
.addResultConfig(new ResultConfig.Builder(Action.ERROR, ActionChainResult.class.getName()).addParam("actionName", CHAINTO_ACTION).build())
|
||||
.build())
|
||||
.addActionConfig(CHAINTO_ACTION, new ActionConfig.Builder("defaultPackage", CHAINTO_ACTION, SimpleAction.class.getName())
|
||||
.addInterceptors(Collections.singletonList(new InterceptorMapping("chainStack", objectFactory.buildInterceptor(chainingInterceptorConfig, interceptorParams))))
|
||||
.addResultConfig(new ResultConfig.Builder(Action.SUCCESS, TestResult.class.getName()).addParams(successParams1).build())
|
||||
.addResultConfig(new ResultConfig.Builder(Action.ERROR, TestResult.class.getName()).addParams(successParams2).build())
|
||||
.build())
|
||||
.build();
|
||||
config.addPackageConfig("defaultPackage", packageConfig);
|
||||
config.addPackageConfig("default", new PackageConfig.Builder(packageConfig).name("default").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user