This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5382-stale-config in repository https://gitbox.apache.org/repos/asf/struts.git
commit 32584c355112bbdb9a89b6b12984b8d989ba77cf Author: Kusal Kithul-Godage <g...@kusal.io> AuthorDate: Sat Dec 30 23:55:12 2023 +1100 WW-5382 Fix StrutsInternalTestCase --- .../org/apache/struts2/StrutsInternalTestCase.java | 21 +++++++++++---------- .../org/apache/struts2/config/SettingsTest.java | 2 +- core/src/test/resources/struts.properties | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java b/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java index 30616303f..5aad82969 100644 --- a/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java +++ b/core/src/test/java/org/apache/struts2/StrutsInternalTestCase.java @@ -18,12 +18,14 @@ */ package org.apache.struts2; +import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.XWorkTestCase; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.struts2.dispatcher.Dispatcher; import org.apache.struts2.dispatcher.PrepareOperations; import org.apache.struts2.util.StrutsTestCaseHelper; import org.apache.struts2.views.jsp.StrutsMockServletContext; + import java.util.HashMap; import java.util.Map; @@ -38,22 +40,22 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase { /** * Sets up the configuration settings, XWork configuration, and * message resources - * + * * @throws java.lang.Exception */ @Override protected void setUp() throws Exception { - super.setUp(); PrepareOperations.clearDevModeOverride(); // Clear DevMode override every time (consistent ThreadLocal state for tests). initDispatcher(null); } - + protected Dispatcher initDispatcher(Map<String,String> params) { servletContext = new StrutsMockServletContext(); dispatcher = StrutsTestCaseHelper.initDispatcher(servletContext, params); configurationManager = dispatcher.getConfigurationManager(); configuration = configurationManager.getConfiguration(); container = configuration.getContainer(); + actionProxyFactory = container.getInstance(ActionProxyFactory.class); container.inject(dispatcher); return dispatcher; } @@ -66,14 +68,13 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase { * @return instance of {@see Dispatcher} */ protected Dispatcher initDispatcherWithConfigs(String configs) { - Map<String, String> params = new HashMap<String, String>(); + Map<String, String> params = new HashMap<>(); params.put("config", configs); return initDispatcher(params); } @Override protected void tearDown() throws Exception { - super.tearDown(); // maybe someone else already destroyed Dispatcher if (dispatcher != null && dispatcher.getConfigurationManager() != null) { dispatcher.cleanup(); @@ -83,14 +84,14 @@ public abstract class StrutsInternalTestCase extends XWorkTestCase { } /** - * Compare if two objects are considered equal according to their fields as accessed + * Compare if two objects are considered equal according to their fields as accessed * via reflection. - * - * Utilizes {@link EqualsBuilder#reflectionEquals(java.lang.Object, java.lang.Object, boolean)} to perform + * + * Utilizes {@link EqualsBuilder#reflectionEquals(java.lang.Object, java.lang.Object, boolean)} to perform * the check, and compares transient fields as well. This may fail when run while a security manager is * active, due to a need to user reflection. - * - * + * + * * @param obj1 the first {@link Object} to compare against the other. * @param obj2 the second {@link Object} to compare against the other. * @return true if the objects are equal based on field comparisons by reflection, false otherwise. diff --git a/core/src/test/java/org/apache/struts2/config/SettingsTest.java b/core/src/test/java/org/apache/struts2/config/SettingsTest.java index c31a53adb..90b824ae4 100644 --- a/core/src/test/java/org/apache/struts2/config/SettingsTest.java +++ b/core/src/test/java/org/apache/struts2/config/SettingsTest.java @@ -36,7 +36,7 @@ public class SettingsTest extends StrutsInternalTestCase { Settings settings = new DefaultSettings(); assertEquals("12345", settings.get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE)); - assertEquals("\temp", settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR)); + assertEquals("\\temp", settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR)); assertEquals("test,org/apache/struts2/othertest", settings.get( StrutsConstants.STRUTS_CUSTOM_PROPERTIES)); assertEquals("testvalue", settings.get("testkey")); diff --git a/core/src/test/resources/struts.properties b/core/src/test/resources/struts.properties index baf748156..7d905d214 100644 --- a/core/src/test/resources/struts.properties +++ b/core/src/test/resources/struts.properties @@ -24,7 +24,7 @@ struts.i18n.encoding=ISO-8859-1 struts.locale=de_DE -struts.multipart.saveDir=\temp +struts.multipart.saveDir=\\temp struts.multipart.maxSize=12345 ### Load custom property files (does not override struts.properties!)