cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r940355 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/configuration/rop/server/ main/java/org/apache/cayenne/configuration/web/ test/java/org/apache/cayenne/configuration/rop/server/ test/ja...
Date Mon, 03 May 2010 03:30:01 GMT
Author: aadamchik
Date: Mon May  3 03:30:00 2010
New Revision: 940355

URL: http://svn.apache.org/viewvc?rev=940355&view=rev
Log:
CAY-1420 Migrate ROP server-side components to DI-based stack

* unit tests
* naming refactoring
* changing CayenneFilter/ROPHessianServlet location mapping rules to specify an explicit location
  this will allow path symbols in the location and will avoid unobvious naming conventions

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java?rev=940355&r1=940354&r2=940355&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
Mon May  3 03:30:00 2010
@@ -31,6 +31,7 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.configuration.web.WebConfiguration;
 import org.apache.cayenne.configuration.web.WebUtil;
 import org.apache.cayenne.di.Module;
+import org.apache.cayenne.event.EventBridge;
 import org.apache.cayenne.remote.RemoteService;
 import org.apache.cayenne.remote.hessian.HessianConfig;
 import org.apache.cayenne.remote.hessian.service.HessianService;
@@ -44,14 +45,15 @@ import com.caucho.hessian.server.Hessian
  * <ul>
  * <li>configuration-location (optional) - a name of Cayenne configuration XML file
that
  * will be used to load Cayenne stack. If missing, the servlet name will be used to derive
- * the location using the following naming convention: if servlet name is "foo",
- * configuration file name is name is "cayenne-foo.xml".
+ * the location. ".xml" extension will be appended to the servlet name to get the
+ * location, so a servlet named "cayenne-foo" will result in location "cayenne-foo.xml".
  * <li>extra-modules (optional) - a comma or space-separated list of class names, with
  * each class implementing {@link Module} interface. These are the custom modules loaded
  * after the two standard ones that allow users to override any Cayenne runtime aspects,
  * e.g. {@link RequestHandler}. Each custom module must have a no-arg constructor.
  * </ul>
- * <p>
+ * All other parameters passed to the servlet are considered to be related to the
+ * {@link EventBridge} initialization.
  * 
  * @since 3.1
  */
@@ -65,9 +67,9 @@ public class ROPHessianServlet extends H
 
         WebConfiguration configAdapter = new WebConfiguration(configuration);
 
-        String configurationLocation = configAdapter.getCayenneConfigurationLocation();
+        String configurationLocation = configAdapter.getConfigurationLocation();
         Map<String, String> eventBridgeParameters = configAdapter
-                .getOtherInitializationParameters();
+                .getOtherParameters();
 
         Collection<Module> modules = configAdapter
                 .createModules(

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java?rev=940355&r1=940354&r2=940355&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
Mon May  3 03:30:00 2010
@@ -42,8 +42,8 @@ import org.apache.cayenne.di.Module;
  * <ul>
  * <li>configuration-location - (optional) a name of Cayenne configuration XML file
that
  * will be used to load Cayenne stack. If missing, the filter name will be used to derive
- * the location using the following naming convention: if filter name is "foo",
- * configuration file name is name is "cayenne-foo.xml".
+ * the location. ".xml" extension will be appended to the filter name to get the location,
+ * so a filter named "cayenne-foo" will result in location "cayenne-foo.xml".
  * <li>extra-modules - (optional) a comma or space-separated list of class names, with
  * each class implementing {@link Module} interface. These are the custom modules loaded
  * after the two standard ones that allow users to override any Cayenne runtime aspects,
@@ -66,7 +66,7 @@ public class CayenneFilter implements Fi
 
         WebConfiguration configAdapter = new WebConfiguration(config);
 
-        String configurationLocation = configAdapter.getCayenneConfigurationLocation();
+        String configurationLocation = configAdapter.getConfigurationLocation();
 
         Collection<Module> modules = configAdapter.createModules(new CayenneServerModule(
                 configurationLocation), new CayenneWebModule());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java?rev=940355&r1=940354&r2=940355&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java
Mon May  3 03:30:00 2010
@@ -38,7 +38,7 @@ import org.apache.cayenne.util.Util;
 
 /**
  * A class that provides access to common Cayenne web configuration parameters retrieved
- * either from a filter or servlet configuration.
+ * either from a FilterConfig or a ServletConfig configuration.
  * 
  * @since 3.1
  */
@@ -76,15 +76,28 @@ public class WebConfiguration {
     }
 
     /**
-     * Returns a non-null location of a Cayenne configuration, extracted from the filter
-     * or servlet configuration parameters.
+     * Returns a non-null location of an XML Cayenne configuration, extracted from the
+     * filter or servlet configuration parameters.
      */
-    public String getCayenneConfigurationLocation() {
+    public String getConfigurationLocation() {
         String configurationLocation = configuration
                 .getInitParameter(CONFIGURATION_LOCATION_PARAMETER);
-        return configurationLocation == null ? configurationLocation = "cayenne-"
-                + configuration.getFilterName()
-                + ".xml" : configurationLocation;
+
+        if (configurationLocation != null) {
+            return configurationLocation;
+        }
+
+        String name = configuration.getFilterName();
+
+        if (name == null) {
+            return null;
+        }
+
+        if (!name.endsWith(".xml")) {
+            name = name + ".xml";
+        }
+
+        return name;
     }
 
     /**
@@ -141,10 +154,10 @@ public class WebConfiguration {
     }
 
     /**
-     * Returns a map of parameters from the underlying FilterConfig or ServletConfig
-     * object.
+     * Returns a map of all init parameters from the underlying FilterConfig or
+     * ServletConfig object.
      */
-    public Map<String, String> getInitializationParameters() {
+    public Map<String, String> getParameters() {
         Enumeration<?> en = configuration.getInitParameterNames();
 
         if (!en.hasMoreElements()) {
@@ -161,13 +174,13 @@ public class WebConfiguration {
     }
 
     /**
-     * Returns servlet or filter configuration parameters, excluding those recognized by
+     * Returns servlet or filter init parameters, excluding those recognized by
      * WebConfiguration. Namely 'configuration-location' and 'extra-modules' parameters
-     * are removed.
+     * are removed from the returned map.
      */
-    public Map<String, String> getOtherInitializationParameters() {
+    public Map<String, String> getOtherParameters() {
 
-        Map<String, String> parameters = getInitializationParameters();
+        Map<String, String> parameters = getParameters();
 
         if (!parameters.isEmpty()) {
             parameters.remove(CONFIGURATION_LOCATION_PARAMETER);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java?rev=940355&r1=940354&r2=940355&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
Mon May  3 03:30:00 2010
@@ -38,7 +38,8 @@ public class ROPHessianServletTest exten
     public void testInitWithServletName() throws Exception {
 
         MockServletConfig config = new MockServletConfig();
-        config.setServletName("org.apache.cayenne.configuration.rop.server.test-config");
+        config
+                .setServletName("cayenne-org.apache.cayenne.configuration.rop.server.test-config");
 
         MockServletContext context = new MockServletContext();
         config.setServletContext(context);
@@ -81,7 +82,7 @@ public class ROPHessianServletTest exten
 
     public void testInitWithStandardModules() throws Exception {
 
-        String name = "org.apache.cayenne.configuration.rop.server.test-config";
+        String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
 
         MockServletConfig config = new MockServletConfig();
         config.setServletName(name);
@@ -95,7 +96,7 @@ public class ROPHessianServletTest exten
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("cayenne-" + name + ".xml", runtime.getInjector().getInstance(
+        assertEquals(name + ".xml", runtime.getInjector().getInstance(
                 RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
         assertEquals(2, runtime.getModules().length);
         assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
@@ -106,7 +107,7 @@ public class ROPHessianServletTest exten
 
     public void testInitWithExtraModules() throws Exception {
 
-        String name = "org.apache.cayenne.configuration.rop.server.test-config";
+        String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
 
         MockServletConfig config = new MockServletConfig();
         config.setServletName(name);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java?rev=940355&r1=940354&r2=940355&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
Mon May  3 03:30:00 2010
@@ -48,8 +48,10 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("cayenne-abc.xml", runtime.getInjector().getInstance(
-                RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
+        assertEquals("abc.xml", runtime
+                .getInjector()
+                .getInstance(RuntimeProperties.class)
+                .get(RuntimeProperties.CONFIGURATION_LOCATION));
     }
 
     public void testInitWithLocation() throws Exception {
@@ -76,7 +78,7 @@ public class CayenneFilterTest extends T
     public void testInitWithStandardModules() throws Exception {
 
         MockFilterConfig config = new MockFilterConfig();
-        config.setFilterName("abc");
+        config.setFilterName("cayenne-abc");
 
         MockServletContext context = new MockServletContext();
         config.setupServletContext(context);

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java?rev=940355&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebConfigurationTest.java
Mon May  3 03:30:00 2010
@@ -0,0 +1,224 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.configuration.web;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+
+import com.mockrunner.mock.web.MockFilterConfig;
+import com.mockrunner.mock.web.MockServletConfig;
+
+public class WebConfigurationTest extends TestCase {
+
+    public void testFilterCreateModules_Standard() throws Exception {
+
+        MockFilterConfig config = new MockFilterConfig();
+        WebConfiguration configuration = new WebConfiguration(config);
+
+        Module m1 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Module m2 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Collection<Module> modules = configuration.createModules(m1, m2);
+        assertEquals(2, modules.size());
+
+        Iterator<Module> it = modules.iterator();
+        assertSame(m1, it.next());
+        assertSame(m2, it.next());
+    }
+
+    public void testFilterCreateModules_Extra() throws Exception {
+
+        MockFilterConfig config = new MockFilterConfig();
+        String exra = String.format(
+                "%s, \n%s",
+                MockModule1.class.getName(),
+                MockModule2.class.getName());
+        config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra);
+
+        WebConfiguration configuration = new WebConfiguration(config);
+
+        Module m1 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Module m2 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Collection<Module> modules = configuration.createModules(m1, m2);
+        assertEquals(4, modules.size());
+
+        Iterator<Module> it = modules.iterator();
+        assertSame(m1, it.next());
+        assertSame(m2, it.next());
+        assertTrue(it.next() instanceof MockModule1);
+        assertTrue(it.next() instanceof MockModule2);
+    }
+
+    public void testServletCreateModules_Extra() throws Exception {
+
+        MockServletConfig config = new MockServletConfig();
+        String exra = String.format(
+                "%s, \n%s",
+                MockModule1.class.getName(),
+                MockModule2.class.getName());
+        config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra);
+
+        WebConfiguration configuration = new WebConfiguration(config);
+
+        Module m1 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Module m2 = new Module() {
+
+            public void configure(Binder binder) {
+            }
+        };
+
+        Collection<Module> modules = configuration.createModules(m1, m2);
+        assertEquals(4, modules.size());
+
+        Iterator<Module> it = modules.iterator();
+        assertSame(m1, it.next());
+        assertSame(m2, it.next());
+        assertTrue(it.next() instanceof MockModule1);
+        assertTrue(it.next() instanceof MockModule2);
+    }
+
+    public void testFilterConfigurationLocation_Name() {
+        MockFilterConfig config1 = new MockFilterConfig();
+        config1.setFilterName("cayenne-x");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        assertEquals("cayenne-x.xml", configuration1.getConfigurationLocation());
+
+        MockFilterConfig config2 = new MockFilterConfig();
+        config2.setFilterName("cayenne-y.xml");
+
+        WebConfiguration configuration2 = new WebConfiguration(config2);
+        assertEquals("cayenne-y.xml", configuration2.getConfigurationLocation());
+
+        MockFilterConfig config3 = new MockFilterConfig();
+        config3.setFilterName("a/b/c/cayenne-z.xml");
+
+        WebConfiguration configuration3 = new WebConfiguration(config3);
+        assertEquals("a/b/c/cayenne-z.xml", configuration3.getConfigurationLocation());
+    }
+
+    public void testServletConfigurationLocation_Name() {
+        MockServletConfig config1 = new MockServletConfig();
+        config1.setServletName("cayenne-x");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        assertEquals("cayenne-x.xml", configuration1.getConfigurationLocation());
+
+        MockServletConfig config2 = new MockServletConfig();
+        config2.setServletName("cayenne-y.xml");
+
+        WebConfiguration configuration2 = new WebConfiguration(config2);
+        assertEquals("cayenne-y.xml", configuration2.getConfigurationLocation());
+
+        MockServletConfig config3 = new MockServletConfig();
+        config3.setServletName("a/b/c/cayenne-z.xml");
+
+        WebConfiguration configuration3 = new WebConfiguration(config3);
+        assertEquals("a/b/c/cayenne-z.xml", configuration3.getConfigurationLocation());
+    }
+
+    public void testFilterConfigurationLocation_Parameter() {
+        MockFilterConfig config1 = new MockFilterConfig();
+        config1.setFilterName("cayenne-x");
+        config1.setInitParameter(
+                WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
+                "cayenne-y.xml");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        assertEquals("cayenne-y.xml", configuration1.getConfigurationLocation());
+    }
+
+    public void testServletConfigurationLocation_Parameter() {
+        MockServletConfig config1 = new MockServletConfig();
+        config1.setServletName("cayenne-x");
+        config1.setInitParameter(
+                WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
+                "cayenne-y.xml");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        assertEquals("cayenne-y.xml", configuration1.getConfigurationLocation());
+    }
+
+    public void testFilterParameters() {
+        MockFilterConfig config1 = new MockFilterConfig();
+        config1.setFilterName("cayenne-x");
+        config1.setInitParameter(
+                WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
+                "cayenne-y.xml");
+        config1.setInitParameter("test", "xxx");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        Map<String, String> parameters = configuration1.getParameters();
+        assertNotSame(parameters, configuration1.getParameters());
+        assertEquals(parameters, configuration1.getParameters());
+
+        assertEquals(2, parameters.size());
+        assertEquals("cayenne-y.xml", parameters
+                .get(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER));
+        assertEquals("xxx", parameters.get("test"));
+    }
+
+    public void testFilterOtherParameters() {
+        MockFilterConfig config1 = new MockFilterConfig();
+        config1.setFilterName("cayenne-x");
+        config1.setInitParameter(
+                WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
+                "cayenne-y.xml");
+        config1.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, "M1,M2");
+        config1.setInitParameter("test", "xxx");
+
+        WebConfiguration configuration1 = new WebConfiguration(config1);
+        Map<String, String> parameters = configuration1.getOtherParameters();
+        assertNotSame(parameters, configuration1.getOtherParameters());
+        assertEquals(parameters, configuration1.getOtherParameters());
+
+        assertEquals(1, parameters.size());
+        assertEquals("xxx", parameters.get("test"));
+    }
+}



Mime
View raw message