WW-5304 Drops deprecated methods and fields in ActionContext

This commit is contained in:
Lukasz Lenart
2023-04-09 16:00:03 +02:00
parent 7f3c1c2944
commit f0f9e42fa9
82 changed files with 417 additions and 562 deletions
@@ -65,7 +65,7 @@ public class ActionContextTest extends XWorkTestCase {
assertTrue(ActionContext.getContext().getApplication().containsKey(APPLICATION_KEY));
assertTrue(ActionContext.getContext().getSession().containsKey(SESSION_KEY));
assertTrue(ActionContext.getContext().getParameters().contains(PARAMETERS_KEY));
assertEquals(ActionContext.getContext().getName(), ACTION_NAME);
assertEquals(ActionContext.getContext().getActionName(), ACTION_NAME);
}
public void testGetContext() {
@@ -38,7 +38,7 @@ public class ActionContextThreadLocalTest extends TestCase {
}
public void testSetContext() {
ActionContext context = ActionContext.of(new HashMap<>()).bind();
ActionContext context = ActionContext.of().bind();
assertEquals(context, ActionContext.getContext());
}
@@ -95,11 +95,11 @@ public class ActionInvocationTest extends XWorkTestCase {
HashMap<String, Object> params = new HashMap<>();
params.put("blah", "this is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of()
.withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", "Foo", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "Foo", null, extraContext.getContextMap());
proxy.execute();
assertEquals("this is blah", proxy.getInvocation().getStack().findValue("[1].blah"));
} catch (Exception e) {
@@ -93,7 +93,7 @@ public class ActionNestingTest extends XWorkTestCase {
ValueStack stack = ActionContext.getContext().getValueStack();
assertEquals(VALUE, stack.findValue(KEY));
Map<String, Object> extraContext = ActionContext.of(new HashMap<>())
Map<String, Object> extraContext = ActionContext.of()
.withValueStack(stack)
.getContextMap();
@@ -159,7 +159,7 @@ public class ActionSupportTest extends XWorkTestCase {
ActionContext.getContext().withLocale(Locale.ITALY);
assertEquals(Locale.ITALY, as.getLocale());
ActionContext.of(new HashMap<>()).bind();
ActionContext.of().bind();
assertEquals(defLocale, as.getLocale()); // ActionContext will create a new context, when it was set to null before
}
@@ -367,13 +367,13 @@ public class DefaultActionInvocationTest extends XWorkTestCase {
HashMap<String, Object> params = new HashMap<>();
params.put("blah", "this is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of()
.withParameters(HttpParameters.create(params).build());
DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocation(extraContext, true);
DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocation(extraContext.getContextMap(), true);
container.inject(defaultActionInvocation);
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "LazyFoo", null, extraContext);
ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "LazyFoo", null, extraContext.getContextMap());
defaultActionInvocation.init(actionProxy);
defaultActionInvocation.invoke();
@@ -129,7 +129,7 @@ public class DefaultTextProviderTest extends XWorkTestCase {
protected void setUp() throws Exception {
super.setUp();
ActionContext.of(new HashMap<>()).withLocale(Locale.CANADA).bind();
ActionContext.of().withLocale(Locale.CANADA).bind();
container.getInstance(LocalizedTextProvider.class).addDefaultResourceBundle(DefaultTextProviderTest.class.getName());
@@ -20,6 +20,7 @@ package com.opensymphony.xwork2;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import org.apache.struts2.config.StrutsXmlConfigurationProvider;
import org.apache.struts2.dispatcher.HttpParameters;
import java.util.HashMap;
import java.util.Map;
@@ -53,9 +54,9 @@ public class ProxyInvocationTest extends XWorkTestCase {
private Map<String, Object> createDummyContext() {
Map<String, Object> params = new HashMap<>();
params.put("blah", "this is blah");
Map<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, params);
return extraContext;
return ActionContext.of()
.withParameters(HttpParameters.create(params).build())
.getContextMap();
}
@Override
@@ -53,8 +53,8 @@ public class ConfigurationTest extends XWorkTestCase {
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("/nonAbstract", "test", null, null);
assertTrue(proxy.getActionName().equals("test"));
assertTrue(proxy.getConfig().getClassName().equals(SimpleAction.class.getName()));
assertEquals("test", proxy.getActionName());
assertEquals(proxy.getConfig().getClassName(), SimpleAction.class.getName());
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -65,11 +65,11 @@ public class ConfigurationTest extends XWorkTestCase {
HashMap<String, String> params = new HashMap<>();
params.put("blah", "this is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of()
.withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("/does/not/exist", "Foo", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("/does/not/exist", "Foo", null, extraContext.getContextMap());
proxy.execute();
assertEquals("this is blah", proxy.getInvocation().getStack().findValue("[1].blah"));
} catch (Exception e) {
@@ -94,13 +94,12 @@ public class ConfigurationTest extends XWorkTestCase {
ActionConfig config = configuration.getActionConfig("", "WildCard/Simple/input");
assertNotNull(config);
assertTrue("Wrong class name, " + config.getClassName(),
"com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
assertTrue("Wrong method name", "input".equals(config.getMethodName()));
assertEquals("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction", config.getClassName());
assertEquals("Wrong method name", "input", config.getMethodName());
Map<String, String> p = config.getParams();
assertTrue("Wrong parameter, " + p.get("foo"), "Simple".equals(p.get("foo")));
assertTrue("Wrong parameter, " + p.get("bar"), "input".equals(p.get("bar")));
assertEquals("Wrong parameter, " + p.get("foo"), "Simple", p.get("foo"));
assertEquals("Wrong parameter, " + p.get("bar"), "input", p.get("bar"));
}
public void testWildcardNamespace() {
@@ -109,12 +108,11 @@ public class ConfigurationTest extends XWorkTestCase {
ActionConfig config = configuration.getActionConfig("/animals/dog", "commandTest");
assertNotNull(config);
assertTrue("Wrong class name, " + config.getClassName(),
"com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
assertEquals("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction", config.getClassName());
Map<String, String> p = config.getParams();
assertTrue("Wrong parameter, " + p.get("0"), "/animals/dog".equals(p.get("0")));
assertTrue("Wrong parameter, " + p.get("1"), "dog".equals(p.get("1")));
assertEquals("Wrong parameter, " + p.get("0"), "/animals/dog", p.get("0"));
assertEquals("Wrong parameter, " + p.get("1"), "dog", p.get("1"));
}
public void testGlobalResults() {
@@ -206,7 +204,7 @@ public class ConfigurationTest extends XWorkTestCase {
assertNotNull(configuration.getActionConfig("", MockConfigurationProvider.FOO_ACTION_NAME));
}
public void testMultipleContainerProviders() throws Exception {
public void testMultipleContainerProviders() {
// to start from scratch
configurationManager.destroyConfiguration();
// to build basic configuration
@@ -59,7 +59,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testSqlTimeType() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(mxLocale);
ActionContext context = ActionContext.of().withLocale(mxLocale);
Object value = converter.convertValue(context.getContextMap(), null, null, null, TIME_01_59_10, Time.class);
assertEquals("01:59:10", value.toString());
@@ -68,7 +68,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testSqlTimestampType() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(mxLocale);
ActionContext context = ActionContext.of().withLocale(mxLocale);
Object value = converter.convertValue(context.getContextMap(), null, null, null, INPUT_TIME_STAMP_STR,
Timestamp.class);
@@ -83,8 +83,9 @@ public class DateConverterTest extends StrutsInternalTestCase {
ValueStack stack = new StubValueStack();
stack.push(new StubTextProvider(map));
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(new Locale("es_MX", "MX"))
.withValueStack(stack);
ActionContext context = ActionContext.of()
.withLocale(new Locale("es_MX", "MX"))
.withValueStack(stack);
Object value = converter.convertValue(context.getContextMap(), null, null, null, DATE_STR, Date.class);
assertTrue(value.toString().startsWith(DATE_CONVERTED));
@@ -98,7 +99,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
ValueStack stack = new StubValueStack();
stack.push(new StubTextProvider(map));
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(new Locale("es_MX", "MX"))
ActionContext context = ActionContext.of().withLocale(new Locale("es_MX", "MX"))
.withValueStack(stack);
try {
@@ -113,7 +114,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testTypeConversionExceptionWhenUsingLongConstructor() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(mxLocale);
ActionContext context = ActionContext.of().withLocale(mxLocale);
try {
converter.convertValue(context.getContextMap(), null, null, null, INPUT_WHEN_LONG_CONSTRUCTOR_STR, null);
@@ -127,7 +128,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testLocalDateTimeType() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>());
ActionContext context = ActionContext.of();
Object value = converter.convertValue(context.getContextMap(), null, null, null, LOCALDATETIME_STR,
LocalDateTime.class);
@@ -142,7 +143,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
ValueStack stack = new StubValueStack();
stack.push(new StubTextProvider(map));
ActionContext context = ActionContext.of(new HashMap<>()).withLocale(mxLocale)
ActionContext context = ActionContext.of().withLocale(mxLocale)
.withValueStack(stack);
Object value = converter.convertValue(context.getContextMap(), null, null, null, LOCALDATETIME1_STR,
@@ -153,7 +154,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testLocalDateTimeTypeConversionExceptionWhenParseError() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>());
ActionContext context = ActionContext.of();
try {
converter.convertValue(context.getContextMap(), null, null, null, INVALID_LOCALDATETIME,
@@ -168,7 +169,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testLocalDateType() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>());
ActionContext context = ActionContext.of();
Object value = converter.convertValue(context.getContextMap(), null, null, null, LOCALDATE_STR,
LocalDate.class);
@@ -178,7 +179,7 @@ public class DateConverterTest extends StrutsInternalTestCase {
public void testLocalTimeType() {
DateConverter converter = new DateConverter();
ActionContext context = ActionContext.of(new HashMap<>());
ActionContext context = ActionContext.of();
Object value = converter.convertValue(context.getContextMap(), null, null, null, LOCALTIME_STR,
LocalTime.class);
@@ -64,7 +64,7 @@ public class XWorkBasicConverterTest extends XWorkTestCase {
ValueStack stack = new StubValueStack();
stack.push(new StubTextProvider(map));
ActionContext context = ActionContext.of(new HashMap<>())
ActionContext context = ActionContext.of()
.withLocale(new Locale("es_MX", "MX"))
.withValueStack(stack);
@@ -83,7 +83,7 @@ public class XWorkBasicConverterTest extends XWorkTestCase {
Locale locale = new Locale("pl", "PL");
ActionContext context = ActionContext.of(new HashMap<>())
ActionContext context = ActionContext.of()
.withLocale(locale)
.withValueStack(stack);
@@ -102,7 +102,7 @@ public class XWorkBasicConverterTest extends XWorkTestCase {
Locale locale = new Locale("fr", "FR");
ActionContext context = ActionContext.of(new HashMap<>())
ActionContext context = ActionContext.of()
.withLocale(locale)
.withValueStack(stack);
@@ -121,7 +121,7 @@ public class XWorkBasicConverterTest extends XWorkTestCase {
Locale locale = new Locale("en", "US");
ActionContext context = ActionContext.of(new HashMap<>())
ActionContext context = ActionContext.of()
.withLocale(locale)
.withValueStack(stack);
@@ -26,6 +26,7 @@ import com.opensymphony.xwork2.util.Bar;
import com.opensymphony.xwork2.util.Cat;
import com.opensymphony.xwork2.util.Foo;
import com.opensymphony.xwork2.util.FurColor;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import ognl.OgnlRuntime;
import ognl.TypeConverter;
@@ -46,43 +47,12 @@ import static org.junit.Assert.assertArrayEquals;
import java.util.Date;
import java.util.Set;
/**
* @author $Author$
* @version $Revision$
*/
public class XWorkConverterTest extends XWorkTestCase {
Map<String, Object> context;
XWorkConverter converter;
OgnlValueStack stack;
// public void testConversionToSetKeepsOriginalSetAndReplacesContents() {
// ValueStack stack = ValueStackFactory.getFactory().createValueStack();
//
// Map stackContext = stack.getContext();
// stackContext.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.TRUE);
// stackContext.put(XWorkMethodAccessor.DENY_METHOD_EXECUTION, Boolean.TRUE);
// stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
//
// String[] param = new String[] {"abc", "def", "ghi"};
// List paramList = Arrays.asList(param);
//
// List originalList = new ArrayList();
// originalList.add("jkl");
// originalList.add("mno");
//
// User user = new User();
// user.setList(originalList);
// stack.push(user);
//
// stack.setValue("list", param);
//
// List userList = user.getList();
// assertEquals(3,userList.size());
// assertEquals(paramList,userList);
// assertSame(originalList,userList);
// }
public void testArrayToNumberConversion() {
String[] value = new String[]{"12345"};
assertEquals(12345, converter.convertValue(context, null, null, null, value, Integer.class));
@@ -131,7 +101,7 @@ public class XWorkConverterTest extends XWorkTestCase {
TextProvider tp = new StubTextProvider(lookupMap);
StubValueStack valueStack = new StubValueStack();
valueStack.push(tp);
context.put(ActionContext.VALUE_STACK, valueStack);
context.put(ValueStack.VALUE_STACK, valueStack);
String dateToFormat = "2017---06--15";
Object unparseableDate = converter.convertValue(context, null, null, null, dateToFormat, Date.class);
@@ -477,7 +447,7 @@ public class XWorkConverterTest extends XWorkTestCase {
}
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
@@ -658,7 +628,7 @@ public class XWorkConverterTest extends XWorkTestCase {
assertEquals(OgnlRuntime.NoConversionPossible, converter.convertValue(context, null, null, null, "aa123", Double.class));
assertEquals(1234d, converter.convertValue(context, null, null, null, "1,234", Double.class));
assertEquals(1234.12, converter.convertValue(context, null, null, null, "1,234.12", Double.class));
// WRONG: locale separator is wrongly placed
// WRONG: locale separator is wrongly placed
assertEquals(123d, converter.convertValue(context, null, null, null, "1,23", Double.class));
assertEquals(1.234, converter.convertValue(context, null, null, null, "1.234", Double.class));
assertEquals(OgnlRuntime.NoConversionPossible, converter.convertValue(context, null, null, null, "1.234,12", Double.class));
@@ -675,14 +645,14 @@ public class XWorkConverterTest extends XWorkTestCase {
assertEquals(1234.12, converter.convertValue(context, null, null, null, "1.234,12", Double.class));
}
public void testStringToEnum() {
assertEquals(FurColor.BLACK, converter.convertValue(context, null, null, null, "BLACK", FurColor.class));
assertEquals(OgnlRuntime.NoConversionPossible, converter.convertValue(context, null, null, null, "black", FurColor.class));
assertEquals(OgnlRuntime.NoConversionPossible, converter.convertValue(context, null, null, null, "red", FurColor.class));
}
// Testing for null result on non-primitive Number types supplied as empty String or
// Testing for null result on non-primitive Number types supplied as empty String or
public void testNotPrimitiveDefaultsToNull() {
assertNull(converter.convertValue(context, null, null, null, null, Double.class));
assertNull(converter.convertValue(context, null, null, null, "", Double.class));
@@ -829,4 +799,4 @@ class ListAction {
this.ints = ints;
}
}
}
@@ -164,15 +164,15 @@ public class AliasInterceptorTest extends XWorkTestCase {
}
public void testNotExisting() throws Exception {
Map<String, Object> params = new HashMap<>();
Map<String, Object> httpParams = new HashMap<>();
httpParams.put("notExisting", "from http parameter");
params.put(ActionContext.PARAMETERS, HttpParameters.create(httpParams).build());
ActionContext context = ActionContext.of()
.withParameters(HttpParameters.create(httpParams).build());
XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(provider);
loadConfigurationProviders(provider);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", null, params);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", null, context.getContextMap());
SimpleAction actionOne = (SimpleAction) proxy.getAction();
// prevent ERROR result
@@ -154,7 +154,7 @@ public class ChainingInterceptorTest extends XWorkTestCase {
mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getStack", stack);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of(new HashMap<>()).bind());
mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of().bind());
mockInvocation.expectAndReturn("getResult", new ActionChainResult());
invocation = (ActionInvocation) mockInvocation.proxy();
interceptor = new ChainingInterceptor();
@@ -183,7 +183,7 @@ public class DefaultWorkflowInterceptorTest extends XWorkTestCase {
EasyMock.replay(action);
EasyMock.replay(proxy);
ActionContext.of(new HashMap<>())
ActionContext.of()
.withActionInvocation(invocation)
.bind();
}
@@ -293,7 +293,7 @@ public class ExceptionMappingInterceptorTest extends XWorkTestCase {
stack = ActionContext.getContext().getValueStack();
mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getStack", stack);
mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of(new HashMap<>()).bind());
mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of().bind());
interceptor = new ExceptionMappingInterceptor();
interceptor.init();
}
@@ -64,64 +64,64 @@ public class ParameterFilterInterceptorTest extends XWorkTestCase {
runFilterTest(null,null,true,new String[] {"blah", "bladeblah", "bladebladeblah"});
assertEquals(0, getParameterNames().size());
}
public void testBasicAllowed() throws Exception {
runFilterTest("blah",null,true,new String[] {"blah"});
assertEquals(1, getParameterNames().size());
assertEquals(1, getParameterNames().size());
}
public void testBasicBlocked() throws Exception {
runFilterTest(null,"blah",false,new String[] {"blah"});
assertEquals(0, getParameterNames().size());
}
assertEquals(0, getParameterNames().size());
}
public void testAllSubpropertiesBlocked() throws Exception {
runFilterTest(null,"blah",false,new String[] {"blah.deblah", "blah.somethingelse", "blah(22)"});
assertEquals(0, getParameterNames().size());
assertEquals(0, getParameterNames().size());
}
public void testAllSubpropertiesAllowed() throws Exception {
runFilterTest("blah",null,true,
new String[] {"blah.deblah", "blah.somethingelse", "blah(22)"});
assertEquals(3, getParameterNames().size());
assertEquals(3, getParameterNames().size());
}
public void testTreeBlocking() throws Exception {
runFilterTest("blah.deblah","blah,blah.deblah.deblah",false,
new String[] {"blah", "blah.deblah", "blah.deblah.deblah"});
assertEquals(1, getParameterNames().size());
assertEquals(getParameterNames().iterator().next(),"blah.deblah");
}
public void testEnsureOnlyPropsBlocked() throws Exception {
runFilterTest(null,"blah",false,new String[] {"blahdeblah"});
assertEquals(1, getParameterNames().size());
assertEquals(1, getParameterNames().size());
}
private void runFilterTest(String allowed, String blocked, boolean defaultBlocked, String[] paramNames) throws Exception {
interceptor.setAllowed(allowed);
interceptor.setBlocked(blocked);
interceptor.setDefaultBlock(defaultBlocked);
setUpParameters(paramNames);
runAction();
}
private void setUpParameters(String [] paramNames) {
Map<String, String> params = new HashMap<>();
for (String paramName : paramNames) {
params.put(paramName, "irrelevant what this is");
}
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
}
private Collection<String> getParameterNames() {
return ActionContext.getContext().getParameters().keySet();
}
public void runAction() throws Exception {
interceptor.intercept(invocation);
}
}
@@ -24,8 +24,8 @@ import com.opensymphony.xwork2.ActionSupport;
import junit.framework.TestCase;
import org.apache.struts2.dispatcher.HttpParameters;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
@@ -38,15 +38,12 @@ import static org.easymock.EasyMock.verify;
*/
public class ParameterRemoverInterceptorTest extends TestCase {
protected Map<String, Object> contextMap;
protected ActionContext context;
protected ActionInvocation actionInvocation;
private ActionContext context;
private ActionInvocation actionInvocation;
@Override
protected void setUp() throws Exception {
contextMap = new LinkedHashMap<>();
context = ActionContext.of(contextMap).bind();
context = ActionContext.of();
actionInvocation = createMock(ActionInvocation.class);
expect(actionInvocation.getAction()).andStubReturn(new SampleAction());
expect(actionInvocation.getInvocationContext()).andStubReturn(context);
@@ -54,7 +51,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
}
public void testInterception1() throws Exception {
contextMap.put(ActionContext.PARAMETERS, HttpParameters.create(new LinkedHashMap<String, Object>() {
context.withParameters(HttpParameters.create(new LinkedHashMap<String, Object>() {
{
put("param1", new String[]{"paramValue1"});
put("param2", new String[]{"paramValue2"});
@@ -70,7 +67,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
interceptor.setParamValues("paramValue1,paramValue2");
interceptor.intercept(actionInvocation);
HttpParameters params = (HttpParameters) contextMap.get(ActionContext.PARAMETERS);
HttpParameters params = context.getParameters();
assertEquals(params.keySet().size(), 2);
assertTrue(params.contains("param3"));
assertTrue(params.contains("param"));
@@ -82,7 +79,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
public void testInterception2() throws Exception {
contextMap.put(ActionContext.PARAMETERS, HttpParameters.create(new LinkedHashMap<String, Object>() {
context.withParameters(HttpParameters.create(new LinkedHashMap<String, Object>() {
{
put("param1", new String[]{"paramValue2"});
put("param2", new String[]{"paramValue1"});
@@ -96,7 +93,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
interceptor.setParamValues("paramValue1,paramValue2");
interceptor.intercept(actionInvocation);
HttpParameters params = (HttpParameters) contextMap.get(ActionContext.PARAMETERS);
HttpParameters params = context.getParameters();
assertEquals(params.keySet().size(), 0);
verify(actionInvocation);
@@ -104,7 +101,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
public void testInterception3() throws Exception {
contextMap.put(ActionContext.PARAMETERS, HttpParameters.create(new LinkedHashMap<String, Object>() {
context.withParameters(HttpParameters.create(new LinkedHashMap<String, Object>() {
{
put("param1", new String[]{"paramValueOne"});
put("param2", new String[]{"paramValueTwo"});
@@ -118,7 +115,7 @@ public class ParameterRemoverInterceptorTest extends TestCase {
interceptor.setParamValues("paramValue1,paramValue2");
interceptor.intercept(actionInvocation);
HttpParameters params = (HttpParameters) contextMap.get(ActionContext.PARAMETERS);
HttpParameters params = context.getParameters();
assertEquals(params.keySet().size(), 2);
assertTrue(params.contains("param1"));
assertTrue(params.contains("param2"));
@@ -220,10 +220,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("@java.lang.System@exit(1).dummy", "dumb value");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext.getContextMap());
assertEquals(Action.SUCCESS, proxy.execute());
String property = System.getProperty("xwork.security.test");
@@ -239,10 +238,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("name", nameVal);
params.put("count", "15");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext.getContextMap());
assertEquals(Action.SUCCESS, proxy.execute());
ModelDrivenAction action = (ModelDrivenAction) proxy.getAction();
@@ -265,10 +263,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("('\u0023'%2b'session['user5']')(unused)", "0wn3d");
params.put("('\\u0023'%2b'session['user5']')(unused)", "0wn3d");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
ValueStack stack = proxy.getInvocation().getStack();
HashMap<String, Object> session = new HashMap<>();
stack.getContext().put("session", session);
@@ -340,10 +337,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("('(aaa)(('\\u0023context[\\'xwork.MethodAccessor.denyMethodExecution\\']\\u003d\\u0023foo')(\\u0023foo\\u003dnew java.lang.Boolean(\"true\")))", "");
params.put("(asdf)(('\\u0023rt.exit(1)')(\\u0023rt\\u003d@java.lang.Runtime@getRuntime()))", "1");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
ValueStack stack = proxy.getInvocation().getStack();
// when
@@ -361,10 +357,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("blah", "This is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
}
@@ -376,10 +371,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("theProtectedMap[' p0p1 ']", "test3");
params.put("theProtectedMap[' p0 p1 ']", "test4");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
Map<String, String> existingMap = ((SimpleAction) proxy.getAction()).getTheProtectedMap();
assertEquals(0, existingMap.size());
@@ -389,10 +383,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("theProtectedMap['名字']", "test1");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
Map<String, String> existingMap = ((SimpleAction) proxy.getAction()).getTheProtectedMap();
assertEquals(1, existingMap.size());
@@ -445,10 +438,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
}
};
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
ParametersInterceptor pi = (ParametersInterceptor) config.getInterceptors().get(0).getInterceptor();
@@ -476,10 +468,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
}
};
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
ParametersInterceptor pi = (ParametersInterceptor) config.getInterceptors().get(0).getInterceptor();
@@ -499,10 +490,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("protectedMap.foo", "This is blah");
params.put("theProtectedMap.boo", "This is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
SimpleAction action = (SimpleAction) proxy.getAction();
assertEquals(1, action.getTheProtectedMap().size());
@@ -515,10 +505,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
params.put("theSemiProtectedMap.foo", "This is blah");
params.put("theProtectedMap.boo", "This is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
SimpleAction action = (SimpleAction) proxy.getAction();
assertEquals(1, action.getTheProtectedMap().size());
@@ -539,10 +528,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
"@java.lang.Runtime@getRuntime().exec('mkdir /tmp/PWNAGE'))(meh)");
params.put("top['blah'](0)", "true");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
@SuppressWarnings("unused")
SimpleAction action = (SimpleAction) proxy.getAction();
@@ -557,10 +545,9 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new LinkedHashMap<>();
params.put("existingMap.boo", "This is blah");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
SimpleAction action = (SimpleAction) proxy.getAction();
assertEquals(1, action.getTheExistingMap().size());
@@ -576,12 +563,11 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("not_a_property", "There is no action property named like this");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
container.inject(config.getInterceptors().get(0).getInterceptor());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
final String actionMessage = "" + ((SimpleAction) proxy.getAction()).getActionMessages().toArray()[0];
assertTrue(actionMessage.contains("Error setting expression 'not_a_property' with value 'There is no action property named like this'"));
@@ -595,12 +581,11 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("not_a_property", "There is no action property named like this");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionConfig config = configuration.getRuntimeConfiguration().getActionConfig("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME);
container.inject(config.getInterceptors().get(0).getInterceptor());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((SimpleAction) proxy.getAction()).getActionMessages().isEmpty());
}
@@ -763,11 +748,10 @@ public class ParametersInterceptorTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("beanList.name", new String[]{"Superman"});
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("",
MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext);
MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
SimpleAction action = (SimpleAction) proxy.getAction();
assertNotNull(action);
@@ -124,7 +124,7 @@ public class ScopedModelDrivenInterceptorTest extends XWorkTestCase {
User user = new User();
user.setName("King George");
Map session = new HashMap();
ActionContext.getContext().setSession(session);
ActionContext.getContext().withSession(session);
ActionContext.getContext().getSession().put("king", user);
ScopedModelDriven action = new MyUserScopedModelDrivenAction();
@@ -130,7 +130,7 @@ public class StaticParametersInterceptorTest extends XWorkTestCase {
User user = new User();
ActionContext.getContext().getValueStack().push(user);
ActionContext.getContext().setParameters(HttpParameters.create().build());
ActionContext.getContext().withParameters(HttpParameters.create().build());
int before = ActionContext.getContext().getValueStack().size();
interceptor.setMerge("false");
interceptor.intercept(mai);
@@ -152,7 +152,7 @@ public class StaticParametersInterceptorTest extends XWorkTestCase {
Map<String, String> existingParams = new HashMap<>();
existingParams.put("name", "Akash");
ActionContext.getContext().setParameters(HttpParameters.create(existingParams).build());
ActionContext.getContext().withParameters(HttpParameters.create(existingParams).build());
int before = ActionContext.getContext().getValueStack().size();
interceptor.setOverwrite("true");
@@ -175,7 +175,7 @@ public class StaticParametersInterceptorTest extends XWorkTestCase {
Map<String, String> existingParams = new HashMap<>();
existingParams.put("name", "Akash");
ActionContext.getContext().setParameters(HttpParameters.create(existingParams).build());
ActionContext.getContext().withParameters(HttpParameters.create(existingParams).build());
int before = ActionContext.getContext().getValueStack().size();
interceptor.setOverwrite("false");
@@ -87,7 +87,7 @@ public class ValidationErrorAwareTest extends XWorkTestCase {
EasyMock.replay(action);
EasyMock.replay(proxy);
ActionContext.of(new HashMap<>())
ActionContext.of()
.withActionInvocation(invocation)
.bind();
}
@@ -101,7 +101,7 @@ public class ValidationInterceptorPrefixMethodInvocationTest extends XWorkTestCa
EasyMock.replay(action);
EasyMock.replay(proxy);
ActionContext.of(new HashMap<>())
ActionContext.of()
.withActionInvocation(invocation)
.bind();
}
@@ -55,8 +55,8 @@ public class AnnotationParameterFilterInterceptorTest extends TestCase {
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(parameterMap).build());
Action action = new BlockingByDefaultAction();
stack.push(action);
@@ -92,8 +92,8 @@ public class AnnotationParameterFilterInterceptorTest extends TestCase {
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(parameterMap).build());
Action action = new AllowingByDefaultAction();
stack.push(action);
@@ -131,8 +131,8 @@ public class AnnotationParameterFilterInterceptorTest extends TestCase {
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(parameterMap).build());
stack.push(new BlockingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
@@ -170,8 +170,8 @@ public class AnnotationParameterFilterInterceptorTest extends TestCase {
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(parameterMap).build());
stack.push(new AllowingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
@@ -42,11 +42,10 @@ public class MyBeanActionTest extends XWorkTestCase {
params.put("annotatedBeanList(1234567890).name", "This is the bla bean by annotation");
params.put("annotatedBeanList(1234567891).name", "This is the 2nd bla bean by annotation");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", null, extraContext.getContextMap());
proxy.execute();
assertEquals(2, Integer.parseInt(proxy.getInvocation().getStack().findValue("beanList.size").toString()));
assertEquals(MyBean.class.getName(), proxy.getInvocation().getStack().findValue("beanList.get(0)").getClass().getName());
@@ -85,11 +84,10 @@ public class MyBeanActionTest extends XWorkTestCase {
params.put("annotatedBeanMap[1234567890].name", "This is the bla bean by annotation");
params.put("annotatedBeanMap[1234567891].name", "This is the 2nd bla bean by annotation");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", null, extraContext.getContextMap());
proxy.execute();
MyBeanAction action = (MyBeanAction) proxy.getInvocation().getAction();
@@ -44,13 +44,12 @@ public class DateRangeValidatorTest extends XWorkTestCase {
public void testRangeValidation() throws Exception {
Calendar date = Calendar.getInstance();
date.set(2002, Calendar.NOVEMBER, 20);
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("date", date.getTime());
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
context.put(ActionContext.LOCALE, Locale.US); // Force US Locale for date conversion tests on JDK9+
ActionContext context = ActionContext.of().withParameters(HttpParameters.create(params).build())
.withLocale(Locale.US); // Force US Locale for date conversion tests on JDK9+
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, context);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, context.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -67,7 +67,7 @@ public class DefaultActionValidatorManagerTest extends XWorkTestCase {
actionValidatorManager.setValidatorFactory((ValidatorFactory)mockValidatorFactory.proxy());
stubValueStack = new StubValueStack();
ActionContext.of(new HashMap<>())
ActionContext.of()
.withValueStack(stubValueStack)
.bind();
@@ -52,12 +52,11 @@ public class DoubleRangeFieldValidatorTest extends XWorkTestCase {
public void testRangeValidationWithError() throws Exception {
//Explicitly set an out-of-range double for DoubleRangeValidatorTest
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("percentage", 100.12);
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext context = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, context);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, context.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -73,12 +72,11 @@ public class DoubleRangeFieldValidatorTest extends XWorkTestCase {
}
public void testRangeValidationNoError() throws Exception {
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("percentage", 1.234567d);
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext context = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "percentage", null, context);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "percentage", null, context.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -200,12 +198,11 @@ public class DoubleRangeFieldValidatorTest extends XWorkTestCase {
public void testRangeValidationWithExpressionsFail() throws Exception {
//Explicitly set an out-of-range double for DoubleRangeValidatorTest
Map<String, Object> context = new HashMap<>();
HashMap<String, Object> params = new HashMap<>();
params.put("percentage", 100.12);
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext context = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.EXPRESSION_VALIDATION_ACTION, null, context);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.EXPRESSION_VALIDATION_ACTION, null, context.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -311,7 +308,7 @@ public class DoubleRangeFieldValidatorTest extends XWorkTestCase {
loadConfigurationProviders(provider, new MockConfigurationProvider());
val = new DoubleRangeFieldValidator();
val.setValueStack(ActionContext.getContext().getValueStack());
ActionContext.getContext().setParameters(HttpParameters.create().build());
ActionContext.getContext().withParameters(HttpParameters.create().build());
tpf = container.getInstance(TextProviderFactory.class);
}
@@ -71,10 +71,9 @@ public class ExpressionValidatorTest extends XWorkTestCase {
params.put("foo", "5");
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasActionErrors());
@@ -94,10 +93,9 @@ public class ExpressionValidatorTest extends XWorkTestCase {
params.put("foo", "10");
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
@@ -41,11 +41,10 @@ public class IntRangeValidatorTest extends XWorkTestCase {
HashMap<String, String> params = new HashMap<>();
params.put("bar", "5");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -38,11 +38,10 @@ public class LongRangeValidatorTest extends XWorkTestCase {
HashMap<String, String> params = new HashMap<>();
params.put("longFoo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -44,13 +44,12 @@ public class ModelDrivenValidationTest extends XWorkTestCase {
Map<String, Object> params = new HashMap<>();
params.put("count", new String[]{"11"});
Map<String, Object> context = new HashMap<>();
context.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext context = ActionContext.of().withParameters(HttpParameters.create(params).build());
XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
container.inject(provider);
loadConfigurationProviders(provider);
ActionProxy proxy = actionProxyFactory.createActionProxy(null, "TestModelDrivenValidation", null, context);
ActionProxy proxy = actionProxyFactory.createActionProxy(null, "TestModelDrivenValidation", null, context.getContextMap());
assertEquals(Action.SUCCESS, proxy.execute());
ModelDrivenAction action = (ModelDrivenAction) proxy.getAction();
@@ -38,11 +38,10 @@ public class ShortRangeValidatorTest extends XWorkTestCase {
HashMap<String, Object> params = new HashMap<>();
params.put("shortFoo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -54,7 +54,7 @@ public class SimpleActionValidationTest extends XWorkTestCase {
params.put("date", "12/23/2002");
params.put("percentage", "1.23456789");
Map<String, Object> extraContext = ActionContext.of(new HashMap<>())
Map<String, Object> extraContext = ActionContext.of()
.withParameters(HttpParameters.create(params).build())
.bind()
.getContextMap();
@@ -67,7 +67,7 @@ public class SimpleActionValidationTest extends XWorkTestCase {
assertFalse(validationAware.hasFieldErrors());
params.put("bar", "42");
extraContext = ActionContext.of(new HashMap<>())
extraContext = ActionContext.of()
.withParameters(HttpParameters.create(params).build())
.bind()
.getContextMap();
@@ -106,11 +106,10 @@ public class SimpleActionValidationTest extends XWorkTestCase {
//valid values
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -131,11 +130,10 @@ public class SimpleActionValidationTest extends XWorkTestCase {
HashMap<String, Object> params = new HashMap<>();
params.put("foo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
ValueStack stack = ActionContext.getContext().getValueStack();
stack.getActionContext().withLocale(Locale.US);
@@ -183,11 +181,10 @@ public class SimpleActionValidationTest extends XWorkTestCase {
HashMap<String, Object> params = new HashMap<>();
params.put("bar", "42");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -218,11 +215,10 @@ public class SimpleActionValidationTest extends XWorkTestCase {
// this should cause a message
params.put("bean.count", "100");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_SUBPROPERTY_NAME, null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_SUBPROPERTY_NAME, null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
@@ -42,10 +42,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
params.put("foo", "5");
params.put("bar", "7");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "notAnnotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "notAnnotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
@@ -54,11 +53,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
}
public void testNotAnnotatedMethodSuccess2() throws Exception {
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create().build());
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create().build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "notAnnotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "notAnnotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
@@ -67,11 +64,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
}
public void testAnnotatedMethodFailure() throws Exception {
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create().build());
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create().build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasActionErrors());
Collection errors = ((ValidationAware) proxy.getAction()).getActionErrors();
@@ -88,10 +83,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
params.put("param1", "key1");
params.put("param2", "key2");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
@@ -102,10 +96,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
//make it not fail
params.put("param2", "key2");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
@@ -116,10 +109,9 @@ public class ValidatorAnnotationTest extends XWorkTestCase {
//make it not fail
params.put("param1", "key1");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext);
ActionProxy proxy = actionProxyFactory.createActionProxy("", "annotatedMethod", null, extraContext.getContextMap());
proxy.execute();
assertFalse(((ValidationAware) proxy.getAction()).hasActionErrors());
}
@@ -462,10 +462,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.GERMANY, contextMap.get(ActionContext.LOCALE)); // Expect the Dispatcher defaultLocale value "de_DE" from the test configuration.
assertEquals(Locale.GERMANY, context.getLocale()); // Expect the Dispatcher defaultLocale value "de_DE" from the test configuration.
mock.verify();
}
@@ -488,10 +488,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.CANADA_FRENCH, contextMap.get(ActionContext.LOCALE)); // Expect the Dispatcher defaultLocale value.
assertEquals(Locale.CANADA_FRENCH, context.getLocale()); // Expect the Dispatcher defaultLocale value.
mock.verify();
}
@@ -516,10 +516,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.UK, contextMap.get(ActionContext.LOCALE)); // Expect the request set value from Mock.
assertEquals(Locale.UK, context.getLocale()); // Expect the request set value from Mock.
mock.verify();
}
@@ -544,10 +544,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.getDefault(), contextMap.get(ActionContext.LOCALE)); // Expect the system default value, when BOTH Dispatcher default Locale AND request access fail.
assertEquals(Locale.getDefault(), context.getLocale()); // Expect the system default value, when BOTH Dispatcher default Locale AND request access fail.
mock.verify();
}
@@ -574,10 +574,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.CANADA_FRENCH, contextMap.get(ActionContext.LOCALE)); // Expect the request set value from Mock.
assertEquals(Locale.CANADA_FRENCH, context.getLocale()); // Expect the request set value from Mock.
mock.verify();
}
@@ -604,10 +604,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
// When
testDispatcher.prepare(request, response);
Map<String, Object> contextMap = createTestContextMap(testDispatcher, request, response);
ActionContext context = ActionContext.of(createTestContextMap(testDispatcher, request, response));
// Then
assertEquals(Locale.getDefault(), contextMap.get(ActionContext.LOCALE)); // Expect the system default value when Mock request access fails.
assertEquals(Locale.getDefault(), context.getLocale()); // Expect the system default value when Mock request access fails.
mock.verify();
}
@@ -29,25 +29,25 @@ import com.opensymphony.xwork2.mock.MockActionInvocation;
import org.apache.struts2.dispatcher.HttpParameters;
/**
* Unit test for ChecboxInterceptor.
* Unit test for ChecboxInterceptor.
*/
public class CheckboxInterceptorTest extends StrutsInternalTestCase {
private CheckboxInterceptor interceptor;
private MockActionInvocation ai;
private Map<String, Object> param;
protected void setUp() throws Exception {
super.setUp();
param = new HashMap<>();
interceptor = new CheckboxInterceptor();
ai = new MockActionInvocation();
ai.setInvocationContext(ActionContext.getContext());
}
private void prepare(ActionInvocation ai) {
ai.getInvocationContext().setParameters(HttpParameters.create(param).build());
ai.getInvocationContext().withParameters(HttpParameters.create(param).build());
}
public void testNoParam() throws Exception {
@@ -68,7 +68,7 @@ public class CheckboxInterceptorTest extends StrutsInternalTestCase {
interceptor.init();
interceptor.intercept(ai);
interceptor.destroy();
assertEquals(1, ai.getInvocationContext().getParameters().keySet().size());
}
@@ -81,7 +81,7 @@ public class CheckboxInterceptorTest extends StrutsInternalTestCase {
interceptor.init();
interceptor.intercept(ai);
interceptor.destroy();
assertEquals(2, ai.getInvocationContext().getParameters().keySet().size());
}
@@ -204,5 +204,5 @@ public class CheckboxInterceptorTest extends StrutsInternalTestCase {
assertEquals("yes", parameters.get("superpower").getValue());
assertEquals("no", parameters.get("cool").getValue());
}
}
@@ -34,15 +34,15 @@ public class ClearSessionInterceptorTest extends StrutsInternalTestCase {
public void testCreateSession() throws Exception {
ClearSessionInterceptor interceptor = new ClearSessionInterceptor();
MockActionInvocation invocation = new MockActionInvocation();
ActionContext context = ActionContext.of(new HashMap<>()).bind();
ActionContext context = ActionContext.of().bind();
Map<String, Object> session = new HashMap<>();
session.put("Test1", "Test1");
session.put("Test2", "Test2");
session.put("Test3", "Test3");
context.setSession(session);
context.withSession(session);
invocation.setInvocationContext(context);
interceptor.intercept(invocation);
assertEquals(0, session.size());
}
}
@@ -30,25 +30,25 @@ import com.opensymphony.xwork2.mock.MockActionInvocation;
import org.apache.struts2.dispatcher.HttpParameters;
/**
* Unit test for DateTextFieldInterceptor.
* Unit test for DateTextFieldInterceptor.
*/
public class DateTextFieldInterceptorTest extends StrutsInternalTestCase {
private DateTextFieldInterceptor interceptor;
private MockActionInvocation ai;
private Map<String, Object> param;
protected void setUp() throws Exception {
super.setUp();
param = new HashMap<>();
interceptor = new DateTextFieldInterceptor();
ai = new MockActionInvocation();
ai.setInvocationContext(ActionContext.getContext());
}
public void testNoParam() throws Exception {
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
interceptor.init();
interceptor.intercept(ai);
@@ -62,7 +62,7 @@ public class DateTextFieldInterceptorTest extends StrutsInternalTestCase {
param.put("__month_name", new String[]{"06"});
param.put("__day_name", new String[]{"15"});
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
interceptor.init();
interceptor.intercept(ai);
@@ -74,7 +74,7 @@ public class DateTextFieldInterceptorTest extends StrutsInternalTestCase {
assertFalse(parameters.contains("__day_name"));
assertTrue(parameters.contains("name"));
assertEquals(1, parameters.keySet().size());
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2000-06-15");
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2000-06-15");
assertEquals(date, parameters.get("name").getObject());
}
@@ -234,7 +234,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
mai.setResultCode("success");
mai.setInvocationContext(ActionContext.getContext());
ActionContext.getContext().setParameters(HttpParameters.create().build());
ActionContext.getContext().withParameters(HttpParameters.create().build());
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, createMultipartRequestMaxSize(req, 2000));
interceptor.intercept(mai);
@@ -256,7 +256,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
mai.setResultCode("success");
mai.setInvocationContext(ActionContext.getContext());
ActionContext.getContext().setParameters(HttpParameters.create().build());
ActionContext.getContext().withParameters(HttpParameters.create().build());
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, createMultipartRequestMaxSize(req, 2000));
interceptor.intercept(mai);
@@ -287,7 +287,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
mai.setResultCode("success");
mai.setInvocationContext(ActionContext.getContext());
Map<String, Object> param = new HashMap<>();
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, createMultipartRequestMaxSize(req, 2000));
interceptor.intercept(mai);
@@ -348,7 +348,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
mai.setResultCode("success");
mai.setInvocationContext(ActionContext.getContext());
Map<String, Object> param = new HashMap<String, Object>();
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, createMultipartRequestMaxSize(req, 2000));
interceptor.setAllowedTypes("text/html");
@@ -401,7 +401,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
mai.setResultCode("success");
mai.setInvocationContext(ActionContext.getContext());
Map<String, Object> param = new HashMap<>();
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
ActionContext.getContext().put(ServletActionContext.HTTP_REQUEST, createMultipartRequestMaxFiles(req, 3));
interceptor.setAllowedTypes("text/html");
@@ -427,7 +427,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
"Unit test of FileUploadInterceptor" +
"\r\n" +
"-----1234--\r\n");
req.setContent(content.getBytes("US-ASCII"));
req.setContent(content.getBytes(StandardCharsets.US_ASCII));
MyFileupAction action = container.inject(MyFileupAction.class);
@@ -466,7 +466,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
"Unit test of FileUploadInterceptor" +
"\r\n" +
"-----1234--\r\n");
req.setContent(content.getBytes("US-ASCII"));
req.setContent(content.getBytes(StandardCharsets.US_ASCII));
MyFileupAction action = container.inject(MyFileupAction.class);
@@ -278,7 +278,7 @@ public class I18nInterceptorTest extends TestCase {
Map<String, Serializable> params = new HashMap<>();
params.put(key, value);
mai.getInvocationContext().setParameters(HttpParameters.create(params).build());
mai.getInvocationContext().withParameters(HttpParameters.create(params).build());
}
public void setUp() throws Exception {
@@ -287,7 +287,7 @@ public class I18nInterceptorTest extends TestCase {
interceptor.init();
session = new HashMap<>();
ac = ActionContext.of(new HashMap<>())
ac = ActionContext.of()
.bind()
.withSession(session)
.withParameters(HttpParameters.create().build());
@@ -66,8 +66,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
action.addActionMessage("some action message 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create().build());
HttpSession mockedSession = EasyMock.createControl().createMock(HttpSession.class);
HttpServletRequest mockedRequest = EasyMock.createControl().createMock(HttpServletRequest.class);
@@ -141,9 +141,10 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
EasyMock.replay(mockedRequest);
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
actionContext.setSession(sessionMap);
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.withSession(sessionMap)
.bind();
mockActionInvocation.getInvocationContext();
EasyMock.expectLastCall().andReturn(actionContext);
@@ -193,9 +194,10 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
action.addFieldError("field1", "some field error 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
actionContext.setSession(sessionMap);
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.withSession(sessionMap)
.bind();
HttpSession mockedSession = EasyMock.createControl().createMock(HttpSession.class);
HttpServletRequest mockedRequest = EasyMock.createControl().createMock(HttpServletRequest.class);
@@ -236,8 +238,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("operationMode", new String[]{MessageStoreInterceptor.RETRIEVE_MODE});
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(paramMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(paramMap).build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -259,8 +261,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("operationMode", new String[]{MessageStoreInterceptor.STORE_MODE});
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(paramMap).build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create(paramMap).build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -279,8 +281,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
public void testRequestOperationMode3() {
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
ActionContext actionContext = ActionContext.of().bind();
actionContext.withParameters(HttpParameters.create().build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -43,8 +43,9 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
public void testSessionWasInvalidated() {
// given
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.bind();
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
@@ -84,8 +85,9 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
public void testResponseWasComitted() {
// given
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.bind();
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
@@ -131,9 +133,10 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
action.addFieldError("field1", "some field error 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
actionContext.setSession(sessionMap);
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.withSession(sessionMap)
.bind();
HttpSession mockedSession = EasyMock.createControl().createMock(HttpSession.class);
HttpServletRequest mockedRequest = EasyMock.createControl().createMock(HttpServletRequest.class);
@@ -212,9 +215,10 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
action.addFieldError("field1", "some field error 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create().build());
actionContext.setSession(sessionMap);
ActionContext actionContext = ActionContext.of()
.withParameters(HttpParameters.create().build())
.withSession(sessionMap)
.bind();
HttpSession mockedSession = EasyMock.createControl().createMock(HttpSession.class);
HttpServletRequest mockedRequest = EasyMock.createControl().createMock(HttpServletRequest.class);
@@ -283,4 +287,4 @@ public class MessageStorePreResultListenerTest extends StrutsInternalTestCase {
}
}
}
@@ -44,7 +44,7 @@ public class MultiselectInterceptorTest extends StrutsInternalTestCase {
interceptor = new MultiselectInterceptor();
ai = new MockActionInvocation();
ai.setInvocationContext(ActionContext.getContext());
ActionContext.getContext().setParameters(HttpParameters.create(param).build());
ActionContext.getContext().withParameters(HttpParameters.create(param).build());
}
public void testNoParam() throws Exception {
@@ -81,7 +81,7 @@ public class MultiselectInterceptorTest extends StrutsInternalTestCase {
param.put("__multiselect_superpower", "");
assertTrue(param.containsKey("__multiselect_superpower"));
ai.getInvocationContext().setParameters(HttpParameters.create(param).build());
ai.getInvocationContext().withParameters(HttpParameters.create(param).build());
interceptor.init();
interceptor.intercept(ai);
@@ -99,7 +99,7 @@ public class MultiselectInterceptorTest extends StrutsInternalTestCase {
param.put("__multiselect_superpower", "");
assertTrue(param.containsKey("__multiselect_superpower"));
ai.getInvocationContext().setParameters(HttpParameters.create(param).build());
ai.getInvocationContext().withParameters(HttpParameters.create(param).build());
interceptor.init();
interceptor.intercept(ai);
@@ -120,7 +120,7 @@ public class MultiselectInterceptorTest extends StrutsInternalTestCase {
assertTrue(param.containsKey("__multiselect_superpower"));
assertTrue(param.containsKey("__multiselect_cool"));
ai.getInvocationContext().setParameters(HttpParameters.create(param).build());
ai.getInvocationContext().withParameters(HttpParameters.create(param).build());
interceptor.init();
interceptor.intercept(ai);
@@ -89,7 +89,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
MockActionInvocation mai = createActionInvocation(mock);
HttpParameters params = HttpParameters.create().build();
mai.getInvocationContext().setParameters(params);
mai.getInvocationContext().withParameters(params);
mock.withParameters(params);
expectLastCall().times(1);
@@ -105,7 +105,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
MockActionInvocation mai = createActionInvocation(mock);
Map<String, Object> session = new HashMap<String, Object>();
mai.getInvocationContext().setSession(session);
mai.getInvocationContext().withSession(session);
mock.withSession(session);
expectLastCall().times(1);
@@ -98,7 +98,7 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
request.getParameterMap().put(TokenHelper.DEFAULT_TOKEN_NAME, new String[]{
token
});
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionContext.of(extraContext).withParameters(HttpParameters.create(params).build());
}
protected void setUp() throws Exception {
@@ -125,7 +125,7 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
oldContext = ActionContext.of(stack.getContext()).bind();
}
protected ActionProxy buildProxy(String actionName) throws Exception {
protected ActionProxy buildProxy(String actionName) {
return actionProxyFactory.createActionProxy("", actionName, null, extraContext);
}
}
@@ -294,7 +294,7 @@ public class ServletRedirectResultTest extends StrutsInternalTestCase implements
ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
ValueStack mockValueStack = control.createMock(ValueStack.class);
ActionContext actionContext = ActionContext.of(new HashMap<>()).withContainer(container);
ActionContext actionContext = ActionContext.of().withContainer(container);
expect(mockInvocation.getStack()).andReturn(mockValueStack);
expect(mockValueStack.getActionContext()).andReturn(actionContext);
@@ -69,8 +69,9 @@ public class InvocationSessionStoreTest extends StrutsInternalTestCase {
ActionContext actionContext = ActionContext.getContext();
InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
ActionContext actionContext2 = ActionContext.of(new HashMap<>()).bind();
actionContext2.setSession(session);
ActionContext actionContext2 = ActionContext.of()
.withSession(session)
.bind();
assertEquals(actionContext2, ActionContext.getContext());
@@ -91,7 +92,7 @@ public class InvocationSessionStoreTest extends StrutsInternalTestCase {
ByteArrayInputStream bais = new ByteArrayInputStream(b);
ObjectInputStream ois = new ObjectInputStream(bais);
session = (Map<String, Object>) ois.readObject();
ActionContext.getContext().setSession(session);
ActionContext.getContext().withSession(session);
ois.close();
bais.close();
@@ -116,7 +117,7 @@ public class InvocationSessionStoreTest extends StrutsInternalTestCase {
InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
ActionContext actionContext2 = ActionContext.of(new HashMap<>())
ActionContext actionContext2 = ActionContext.of()
.withSession(session)
.withPageContext(mockPreviousPageContext)
.bind();
@@ -71,7 +71,7 @@ public class TokenHelperTest extends TestCase {
params.put(TokenHelper.TOKEN_NAME_FIELD, new String[]{tokenName});
params.put(tokenName, new String[]{token});
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
assertTrue(TokenHelper.validToken());
}
@@ -87,9 +87,10 @@ public class TokenHelperTest extends TestCase {
protected void setUp() throws Exception {
session = new HashMap<>();
Map<String, Object> ctxMap = new TreeMap<>();
ActionContext ctx = ActionContext.of(ctxMap).bind();
ctx.setSession(session);
ctx.setParameters(HttpParameters.create().build());
ActionContext ctx = ActionContext.of(ctxMap)
.withSession(session)
.withParameters(HttpParameters.create().build())
.bind();
}
protected void tearDown() {
@@ -438,7 +438,7 @@ public class ActionTagTest extends AbstractTagTest {
tag.setNamespace("");
tag.setName("testActionTagAction");
tag.setExecuteResult(true);
ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInv.proxy());
ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInv.proxy());
ActionInvocation oldInvocation = ActionContext.getContext().getActionInvocation();
assertNotNull(oldInvocation);
@@ -471,7 +471,7 @@ public class ActionTagTest extends AbstractTagTest {
Map<String, String[]> params = new HashMap<>();
params.put("user", new String[]{"Santa Claus"});
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
tag.doStartTag();
@@ -505,7 +505,7 @@ public class ActionTagTest extends AbstractTagTest {
Map<String, String[]> params = new HashMap<>();
params.put("user", new String[]{"Santa Claus"});
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
tag.doStartTag();
setComponentTagClearTagState(tag, true); // Ensure component tag state clearing is set true (to match tag).
@@ -540,7 +540,7 @@ public class ActionTagTest extends AbstractTagTest {
Map<String, String[]> params = new HashMap<>();
params.put("user", new String[]{"Santa Claus"});
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
tag.doStartTag();
@@ -573,7 +573,7 @@ public class ActionTagTest extends AbstractTagTest {
Map<String, String[]> params = new HashMap<>();
params.put("user", new String[] { "Santa Claus" });
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
ActionContext.getContext().withParameters(HttpParameters.create(params).build());
tag.doStartTag();
setComponentTagClearTagState(tag, true); // Ensure component tag state clearing is set true (to match tag).
@@ -55,7 +55,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleFloatFormat_clearTagStateSet() throws Exception {
// given
context.put(ActionContext.LOCALE, Locale.US);
ActionContext.of(context).withLocale(Locale.US);
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.0f);
@@ -85,7 +85,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleCurrencyUSFormat() throws Exception {
// given
context = ActionContext.of(context).withLocale(Locale.US).getContextMap();
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.0f);
@@ -110,7 +110,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleCurrencyUSFormat_clearTagStateSet() throws Exception {
// given
context.put(ActionContext.LOCALE, Locale.US);
ActionContext.of(context).withLocale(Locale.US);
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.0f);
@@ -140,7 +140,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleCurrencyPLFormat() throws Exception {
// given
context = ActionContext.of(context).withLocale(new Locale("pl", "PL")).getContextMap();
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.0f);
@@ -170,7 +170,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleCurrencyPLFormat_clearTagStateSet() throws Exception {
// given
context.put(ActionContext.LOCALE, new Locale("pl", "PL"));
ActionContext.of(context).withLocale(new Locale("pl", "PL"));
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.0f);
@@ -187,7 +187,7 @@ public class NumberTagTest extends AbstractTagTest {
tag.doEndTag();
// then
NumberFormat format = NumberFormat.getCurrencyInstance((Locale) context.get(ActionContext.LOCALE));
NumberFormat format = NumberFormat.getCurrencyInstance(ActionContext.of(context).getLocale());
format.setRoundingMode(RoundingMode.CEILING);
String expected = format.format(120.0f);
@@ -234,7 +234,7 @@ public class NumberTagTest extends AbstractTagTest {
public void testSimpleRoundingCeiling_clearTagStateSet() throws Exception {
// given
context.put(ActionContext.LOCALE, Locale.US);
ActionContext.of(context).withLocale(new Locale("pl", "PL"));
TestAction testAction = (TestAction) action;
testAction.setFloatNumber(120.45f);
@@ -251,7 +251,7 @@ public class NumberTagTest extends AbstractTagTest {
tag.doEndTag();
// then
NumberFormat format = NumberFormat.getInstance((Locale) context.get(ActionContext.LOCALE));
NumberFormat format = NumberFormat.getInstance(ActionContext.of(context).getLocale());
format.setRoundingMode(RoundingMode.DOWN);
String expected = format.format(120.45f);
@@ -397,8 +397,9 @@ public class TextTagTest extends AbstractTagTest {
final StringBuffer buffer = writer.getBuffer();
buffer.delete(0, buffer.length());
ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack();
newStack.getContext().put(ActionContext.LOCALE, foreignLocale);
newStack.getContext().put(ActionContext.CONTAINER, container);
ActionContext.of(newStack.getContext())
.withLocale(foreignLocale)
.withContainer(container);
newStack.push(container.inject(TestAction1.class));
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack);
assertNotSame(ActionContext.getContext().getValueStack().peek(), newStack.peek());
@@ -466,7 +467,7 @@ public class TextTagTest extends AbstractTagTest {
Locale foreignLocale = getForeignLocale();
assertNotSame(defaultLocale, foreignLocale);
ActionContext.getContext().setLocale(defaultLocale);
ActionContext.getContext().withLocale(defaultLocale);
String key = "simpleKey";
String value_default = getLocalizedMessage(defaultLocale);
tag.setPerformClearTagStateForTagPoolingServers(true); // Explicitly request tag state clearing.
@@ -489,9 +490,9 @@ public class TextTagTest extends AbstractTagTest {
String value_int = getLocalizedMessage(foreignLocale);
assertFalse(value_default.equals(value_int));
ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack(stack);
newStack.getContext().put(ActionContext.LOCALE, foreignLocale);
newStack.getContext().put(ActionContext.CONTAINER, container);
assertNotSame(newStack.getContext().get(ActionContext.LOCALE), ActionContext.getContext().getLocale());
ActionContext.of(newStack.getContext())
.withLocale(foreignLocale)
.withContainer(container);
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack);
assertEquals(ActionContext.getContext().getValueStack().peek(), newStack.peek());
tag.setName(key); // Required as WW-5124 fix clears tag state.
@@ -294,22 +294,22 @@ public class URLTagTest extends AbstractUITagTest {
*/
public void testIterableParameters() throws Exception {
tag.setValue("/TestAction.action?p0=z");
tag.doStartTag();
//Iterable
List<ValueHolder> list = new ArrayList<>();
list.add(new ValueHolder("a"));
list.add(new ValueHolder("b"));
tag.component.addParameter("p1", list);
//String[]
tag.component.addParameter("p2", new String[] { "d", "e" });
//ValueHolder[]
tag.component.addParameter("p3", new ValueHolder[] {
new ValueHolder("f"), new ValueHolder("g") });
tag.doEndTag();
assertEquals("/TestAction.action?p0=z&amp;p1=a&amp;p1=b&amp;p2=d&amp;p2=e&amp;p3=f&amp;p3=g", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
@@ -1524,11 +1524,11 @@ public class URLTagTest extends AbstractUITagTest {
public void testEmptyActionCustomMapper() throws Exception {
Map<String,String> props = new HashMap<>();
props.put("config", "struts-default.xml,struts-plugin.xml,struts.xml,org/apache/struts2/views/jsp/WW3090-struts.xml");
this.tearDown();
Dispatcher du = this.initDispatcher(props);
/**
* create our standard mock objects
*/
@@ -1565,7 +1565,7 @@ public class URLTagTest extends AbstractUITagTest {
response);
// let's not set the locale -- there is a test that checks if Dispatcher actually picks this up...
// ... but generally we want to just use no locale (let it stay system default)
extraContext.remove(ActionContext.LOCALE);
ActionContext.of(extraContext).withLocale(null);
stack.getContext().putAll(extraContext);
context.put(ServletActionContext.HTTP_REQUEST, request);
@@ -1577,7 +1577,7 @@ public class URLTagTest extends AbstractUITagTest {
.withServletResponse(response)
.withServletContext(servletContext)
.bind();
// Make sure we have an action invocation available
ActionContext.getContext().withActionInvocation(new DefaultActionInvocation(null, true));
DefaultActionProxyFactory apFactory = new DefaultActionProxyFactory();
@@ -1593,9 +1593,9 @@ public class URLTagTest extends AbstractUITagTest {
tag.setPageContext(pageContext);
JspWriter jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
request.setRequestURI("/context/someAction.action");
tag.setAction(null);
tag.setValue(null);
tag.doStartTag();
@@ -1610,14 +1610,14 @@ public class URLTagTest extends AbstractUITagTest {
assertTrue("Tag state after doEndTag() under default tag clear state is inequal to new Tag with pageContext/parent set. " +
"May indicate that clearTagStateForTagPoolingServers() calls are not working properly.",
strutsBodyTagsAreReflectionEqual(tag, freshTag));
writer = new StringWriter();
jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
tag.doStartTag();
tag.doEndTag();
assertEquals("/hello.action-blue", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
@@ -1625,16 +1625,16 @@ public class URLTagTest extends AbstractUITagTest {
assertTrue("Tag state after doEndTag() under default tag clear state is inequal to new Tag with pageContext/parent set. " +
"May indicate that clearTagStateForTagPoolingServers() calls are not working properly.",
strutsBodyTagsAreReflectionEqual(tag, freshTag));
writer = new StringWriter();
jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
tag.doStartTag();
tag.doEndTag();
assertEquals("/hello.action-red", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
// URLTag clears component in doEndTag and has no additional state set here, so it compares as equal with the default tag clear state as well.
assertTrue("Tag state after doEndTag() under default tag clear state is inequal to new Tag with pageContext/parent set. " +
@@ -1645,11 +1645,11 @@ public class URLTagTest extends AbstractUITagTest {
public void testEmptyActionCustomMapper_clearTagStateSet() throws Exception {
Map<String,String> props = new HashMap<String, String>();
props.put("config", "struts-default.xml,struts-plugin.xml,struts.xml,org/apache/struts2/views/jsp/WW3090-struts.xml");
this.tearDown();
Dispatcher du = this.initDispatcher(props);
action = this.getAction();
stack = ActionContext.getContext().getValueStack();
context = stack.getContext();
@@ -1708,9 +1708,9 @@ public class URLTagTest extends AbstractUITagTest {
tag.setPageContext(pageContext);
JspWriter jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
request.setRequestURI("/context/someAction.action");
tag.setAction(null);
tag.setValue(null);
tag.doStartTag();
@@ -1726,32 +1726,32 @@ public class URLTagTest extends AbstractUITagTest {
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " +
"May indicate that clearTagStateForTagPoolingServers() calls are not working properly.",
strutsBodyTagsAreReflectionEqual(tag, freshTag));
writer = new StringWriter();
jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
tag.doStartTag();
setComponentTagClearTagState(tag, true); // Ensure component tag state clearing is set true (to match tag).
tag.doEndTag();
assertEquals("/hello.action-blue", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " +
"May indicate that clearTagStateForTagPoolingServers() calls are not working properly.",
strutsBodyTagsAreReflectionEqual(tag, freshTag));
writer = new StringWriter();
jspWriter = new StrutsMockJspWriter(writer);
pageContext.setJspWriter(jspWriter);
tag.doStartTag();
setComponentTagClearTagState(tag, true); // Ensure component tag state clearing is set true (to match tag).
tag.doEndTag();
assertEquals("/hello.action-red", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " +
"May indicate that clearTagStateForTagPoolingServers() calls are not working properly.",
@@ -2135,7 +2135,7 @@ public class URLTagTest extends AbstractUITagTest {
return "Foo is: " + title;
}
}
public static class ValueHolder {
private String value;
@@ -2147,13 +2147,13 @@ public class URLTagTest extends AbstractUITagTest {
public String toString() {
return value;
}
}
@SuppressWarnings("unused")
public static class RedBlueActionMapper extends DefaultActionMapper {
@Override
public String getUriFromActionMapping(ActionMapping mapping) {
String baseUri = super.getUriFromActionMapping(mapping);
@@ -2168,6 +2168,6 @@ public class URLTagTest extends AbstractUITagTest {
return baseUri + "-blue";
}
}
}
}
@@ -136,7 +136,7 @@ public class HiddenTest extends AbstractUITagTest {
MockActionInvocation ai = new MockActionInvocation();
ai.setAction(action);
ActionContext.getContext().setActionInvocation(ai);
ActionContext.getContext().withActionInvocation(ai);
HiddenTag tag = new HiddenTag();
tag.setPageContext(pageContext);
@@ -167,7 +167,7 @@ public class HiddenTest extends AbstractUITagTest {
MockActionInvocation ai = new MockActionInvocation();
ai.setAction(action);
ActionContext.getContext().setActionInvocation(ai);
ActionContext.getContext().withActionInvocation(ai);
HiddenTag tag = new HiddenTag();
tag.setPerformClearTagStateForTagPoolingServers(true); // Explicitly request tag state clearing.