struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/2] struts git commit: WW-4518 Makes Dispatcher immutable
Date Tue, 23 Jun 2015 11:09:26 GMT
WW-4518 Makes Dispatcher immutable


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/3c03b494
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/3c03b494
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/3c03b494

Branch: refs/heads/master
Commit: 3c03b49481d5bdb623f179c93b16d29dcf127024
Parents: 0fada66
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Tue Jun 23 13:09:15 2015 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Tue Jun 23 13:09:15 2015 +0200

----------------------------------------------------------------------
 .../apache/struts2/dispatcher/Dispatcher.java   | 21 ++++-------------
 .../struts2/dispatcher/MockDispatcher.java      | 24 ++++++++++++++++++++
 .../struts2/dispatcher/DispatcherTest.java      | 15 +++++-------
 .../dispatcher/FilterDispatcherTest.java        |  7 +++---
 .../struts2/views/jsp/AbstractTagTest.java      |  4 ++--
 .../apache/struts2/views/jsp/URLTagTest.java    |  1 -
 6 files changed, 41 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
index af5817c..d33fa61 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -92,11 +92,6 @@ public class Dispatcher {
     private static List<DispatcherListener> dispatcherListeners = new CopyOnWriteArrayList<>();
 
     /**
-     * Store ConfigurationManager instance, set on init.
-     */
-    private ConfigurationManager configurationManager;
-
-    /**
      * Store state of StrutsConstants.STRUTS_DEVMODE setting.
      */
     private boolean devMode;
@@ -152,6 +147,11 @@ public class Dispatcher {
     private DispatcherErrorHandler errorHandler;
 
     /**
+     * Store ConfigurationManager instance, set on init.
+     */
+    protected ConfigurationManager configurationManager;
+
+    /**
      * Provide the dispatcher instance for the current thread.
      *
      * @return The dispatcher instance
@@ -868,17 +868,6 @@ public class Dispatcher {
     }
 
     /**
-     * Modify the ConfigurationManager instance
-     *
-     * @param mgr The configuration manager
-     * @deprecated should be removed as is used only in tests
-     */
-    public void setConfigurationManager(ConfigurationManager mgr) {
-        ContainerHolder.clear();
-        this.configurationManager = mgr;
-    }
-
-    /**
      * Expose the dependency injection container.
      * @return Our dependency injection container
      */

http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/main/java/org/apache/struts2/dispatcher/MockDispatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/MockDispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/MockDispatcher.java
new file mode 100644
index 0000000..5576e17
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/MockDispatcher.java
@@ -0,0 +1,24 @@
+package org.apache.struts2.dispatcher;
+
+import com.opensymphony.xwork2.config.ConfigurationManager;
+
+import javax.servlet.ServletContext;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MockDispatcher extends Dispatcher {
+
+    private final ConfigurationManager copyConfigurationManager;
+
+    public MockDispatcher(ServletContext servletContext, Map<String, String> context,
ConfigurationManager configurationManager) {
+        super(servletContext, context);
+        this.copyConfigurationManager = configurationManager;
+    }
+
+    @Override
+    public void init() {
+        super.init();
+        ContainerHolder.clear();
+        this.configurationManager = copyConfigurationManager;
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
index 778a89d..5b5dd7e 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
@@ -176,13 +176,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
     
     public void testConfigurationManager() {
     	Dispatcher du;
-    	InternalConfigurationManager configurationManager = new InternalConfigurationManager();
+    	final InternalConfigurationManager configurationManager = new InternalConfigurationManager();
     	try {
-    		du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
-    		du.setConfigurationManager(configurationManager);
-    		
+    		du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(),
configurationManager);
     		du.init();
-    		
             Dispatcher.setInstance(du);
             
             assertFalse(configurationManager.destroyConfiguration);
@@ -200,8 +197,8 @@ public class DispatcherTest extends StrutsInternalTestCase {
     public void testObjectFactoryDestroy() throws Exception {
 
         final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
-        Dispatcher du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
         ConfigurationManager cm = new ConfigurationManager();
+        Dispatcher du = new MockDispatcher(new MockServletContext(), new HashMap<String,
String>(), cm);
         Mock mockConfiguration = new Mock(Configuration.class);
         cm.setConfiguration((Configuration)mockConfiguration.proxy());
         
@@ -216,7 +213,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
         mockConfiguration.expect("destroy");
         mockConfiguration.matchAndReturn("getPackageConfigs", new HashMap<String, PackageConfig>());
 
-        du.setConfigurationManager(cm);
+        du.init();
         assertFalse(destroyedObjectFactory.destroyed);
         du.cleanup();
         assertTrue(destroyedObjectFactory.destroyed);
@@ -252,8 +249,8 @@ public class DispatcherTest extends StrutsInternalTestCase {
         ConfigurationManager configurationManager = new ConfigurationManager();
         configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());
         
-        Dispatcher dispatcher = new Dispatcher(new MockServletContext(), new HashMap<String,
String>());
-        dispatcher.setConfigurationManager(configurationManager);
+        Dispatcher dispatcher = new MockDispatcher(new MockServletContext(), new HashMap<String,
String>(), configurationManager);
+        dispatcher.init();
         dispatcher.cleanup();
         
         mockInterceptor.verify();

http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
index 136c5c3..f65dc3e 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
@@ -56,10 +56,10 @@ public class FilterDispatcherTest extends StrutsInternalTestCase {
         MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
         MockHttpServletResponse res = new MockHttpServletResponse();
         MockFilterChain chain = new MockFilterChain();
-        final NoOpDispatcher _dispatcher = new NoOpDispatcher(servletContext);
         ConfigurationManager confManager = new ConfigurationManager();
         confManager.setConfiguration(new DefaultConfiguration());
-        _dispatcher.setConfigurationManager(confManager);
+
+        final NoOpDispatcher _dispatcher = new NoOpDispatcher(servletContext, confManager);
         Dispatcher.setInstance(_dispatcher);
 
         
@@ -112,8 +112,9 @@ public class FilterDispatcherTest extends StrutsInternalTestCase {
         protected boolean wrappedRequest = false;
         protected boolean serviceRequest = false;
 
-        public NoOpDispatcher(ServletContext servletContext) {
+        public NoOpDispatcher(ServletContext servletContext, ConfigurationManager cm) {
             super(servletContext, new HashMap());
+            this.configurationManager = cm;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
index 60eb170..5850240 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
@@ -34,6 +34,7 @@ import org.apache.struts2.StrutsInternalTestCase;
 import org.apache.struts2.TestAction;
 import org.apache.struts2.dispatcher.ApplicationMap;
 import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.MockDispatcher;
 import org.apache.struts2.dispatcher.RequestMap;
 import org.apache.struts2.dispatcher.SessionMap;
 
@@ -108,10 +109,9 @@ public abstract class AbstractTagTest extends StrutsInternalTestCase
{
         pageContext.setServletContext(servletContext);
 
         mockContainer = new Mock(Container.class);
-        Dispatcher du = new Dispatcher(pageContext.getServletContext(), new HashMap());
+        MockDispatcher du = new MockDispatcher(pageContext.getServletContext(), new HashMap<String,
String>(), configurationManager);
         du.init();
         Dispatcher.setInstance(du);
-        du.setConfigurationManager(configurationManager);
         session = new SessionMap(request);
         Map<String, Object> extraContext = du.createContextMap(new RequestMap(request),
                 request.getParameterMap(),

http://git-wip-us.apache.org/repos/asf/struts/blob/3c03b494/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
index fb82be2..3196d9c 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
@@ -548,7 +548,6 @@ public class URLTagTest extends AbstractUITagTest {
 
         mockContainer = new Mock(Container.class);
 
-        du.setConfigurationManager(configurationManager);
         session = new SessionMap(request);
         Map<String, Object> extraContext = du.createContextMap(new RequestMap(request),
                 request.getParameterMap(),


Mime
View raw message