Author: julien_viet
Date: 2010-09-02 09:15:14 -0400 (Thu, 02 Sep 2010)
New Revision: 4029
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java
Removed:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/Controller.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/ControllerContext.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java
Log:
simplify for now
Deleted:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/Controller.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/Controller.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/Controller.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.exoplatform.web.controller;
-
-import org.exoplatform.web.controller.protocol.ControllerResponse;
-
-import java.io.IOException;
-
-/**
- * The controller is responsible for processing a controller context.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public interface Controller
-{
-
- /**
- * Process an incoming context and returns a response.
- *
- * @param controllerContext the context to process
- * @return the response
- * @throws IOException any io exception
- */
- ControllerResponse process(ControllerContext controllerContext) throws IOException;
-
-
-}
Deleted:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/ControllerContext.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/ControllerContext.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/ControllerContext.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.exoplatform.web.controller;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p>The controller context captures the state of a stage in the decoding of a
request. The controller context
- * should not be mutated, if a new controller with modified state is needed, a new
controller should be created
- * with the new state.</p>
- *
- * <p>The context augments the http request and response with additional state.
Usually this state is obtained
- * from a processing context and is used by a controller to create a response.</p>
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class ControllerContext
-{
-
- /** The current path. */
- final String path;
-
- /** The current parameters. */
- final Map<QualifiedName, String> parameters;
-
- public ControllerContext(String path)
- {
- this.path = path;
- this.parameters = new HashMap<QualifiedName, String>();
- }
-
- public ControllerContext(String path, Map<QualifiedName, String> parameters)
- {
- this.path = path;
- this.parameters = parameters;
- }
-
- public Map<QualifiedName, String> getParameters()
- {
- return parameters;
- }
-
- public String getPath()
- {
- return path;
- }
-}
Deleted:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.exoplatform.web.controller.metadata;
-
-import org.exoplatform.web.controller.QualifiedName;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class ControllerRefMetaData
-{
-
- /** . */
- private final Map<QualifiedName, String> parameters;
-
- public ControllerRefMetaData()
- {
- this.parameters = new HashMap<QualifiedName, String>();
- }
-
- public ControllerRefMetaData addParameter(QualifiedName name, String value)
- {
- parameters.put(name, value);
- return this;
- }
-
- public ControllerRefMetaData addParameter(String name, String value)
- {
- return addParameter(new QualifiedName(name), value);
- }
-
- public Map<QualifiedName, String> getParameters()
- {
- return parameters;
- }
-}
Copied:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java
(from rev 4027,
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java)
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java
(rev 0)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.web.controller.metadata;
+
+import org.exoplatform.web.controller.QualifiedName;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class RouteMetaData
+{
+
+ /** . */
+ private final Map<QualifiedName, String> parameters;
+
+ public RouteMetaData()
+ {
+ this.parameters = new HashMap<QualifiedName, String>();
+ }
+
+ public RouteMetaData addParameter(QualifiedName name, String value)
+ {
+ parameters.put(name, value);
+ return this;
+ }
+
+ public RouteMetaData addParameter(String name, String value)
+ {
+ return addParameter(new QualifiedName(name), value);
+ }
+
+ public Map<QualifiedName, String> getParameters()
+ {
+ return parameters;
+ }
+}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -30,14 +30,14 @@
{
/** . */
- private final Map<String, ControllerRefMetaData> routes;
+ private final Map<String, RouteMetaData> routes;
public RouterMetaData()
{
- this.routes = new HashMap<String, ControllerRefMetaData>();
+ this.routes = new HashMap<String, RouteMetaData>();
}
- public void addRoute(String pathTemplate, ControllerRefMetaData controller)
+ public void addRoute(String pathTemplate, RouteMetaData controller)
{
if (pathTemplate == null)
{
@@ -52,7 +52,7 @@
routes.put(pathTemplate, controller);
}
- public Map<String, ControllerRefMetaData> getRoutes()
+ public Map<String, RouteMetaData> getRoutes()
{
return routes;
}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -19,9 +19,7 @@
package org.exoplatform.web.controller.router;
-import org.exoplatform.web.controller.ControllerContext;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.protocol.ProcessResponse;
import java.util.ArrayList;
import java.util.HashMap;
@@ -201,12 +199,19 @@
return null;
}
- final ProcessResponse route(ControllerContext context)
+ /**
+ * Note : the parameters arguments is modified, I don't like it much but as this
is only used
+ * by the framework, there is no side effects, but I should investigate about doing
this in a
+ * better way.
+ *
+ * @param path the path
+ * @param parameters the parameters
+ * @return null or the parameters when it matches
+ */
+ final Map<QualifiedName, String> route(String path, Map<QualifiedName,
String> parameters)
{
- String path = context.getPath();
+ Map<QualifiedName, String> ret = null;
- ProcessResponse ret = null;
-
// Anything that does not begin with '/' returns null
if (path.length() > 0 && path.charAt(0) == '/')
{
@@ -217,7 +222,7 @@
{
if (terminal)
{
- ret = new ProcessResponse(context.getPath(), context.getParameters());
+ ret = parameters;
}
}
else
@@ -235,8 +240,6 @@
Route route = simpleRoutes.get(segment);
if (route != null)
{
- Map<QualifiedName, String> parameters = context.getParameters();
-
// Determine next path
String nextPath;
if (pos == path.length())
@@ -248,11 +251,8 @@
nextPath = path.substring(pos);
}
- // Build next controller context
- ControllerContext nextContext = new ControllerContext(nextPath,
parameters);
-
// Delegate the process to the next route
- ProcessResponse response = route.route(nextContext);
+ Map<QualifiedName, String> response = route.route(nextPath,
parameters);
// If we do have a response we return it
if (response != null)
@@ -262,45 +262,44 @@
}
}
- // Try to find a pattern matching route
- for (PatternRoute route : patternRoutes)
+ // Try to find a pattern matching route otherwise
+ if (ret == null)
{
- Matcher matcher = route.pattern.matcher(path.substring(1));
-
- // We match
- if (matcher.find())
+ for (PatternRoute route : patternRoutes)
{
- // Update parameters
- Map<QualifiedName, String> parameters = new
HashMap<QualifiedName, String>(context.getParameters());
- int group = 1;
- for (QualifiedName parameterName : route.parameterNames)
- {
- parameters.put(parameterName, matcher.group(group++));
- }
+ Matcher matcher = route.pattern.matcher(path.substring(1));
- // Build next controller context
- int nextPos = matcher.end() + 1;
- String nextPath;
- if (path.length() == nextPos)
+ // We match
+ if (matcher.find())
{
- nextPath = "/";
- }
- else
- {
- nextPath = path.substring(nextPos);
- }
+ // Update parameters
+ int group = 1;
+ for (QualifiedName parameterName : route.parameterNames)
+ {
+ parameters.put(parameterName, matcher.group(group++));
+ }
- //
- ControllerContext nextContext = new ControllerContext(nextPath,
parameters);
+ // Build next controller context
+ int nextPos = matcher.end() + 1;
+ String nextPath;
+ if (path.length() == nextPos)
+ {
+ nextPath = "/";
+ }
+ else
+ {
+ nextPath = path.substring(nextPos);
+ }
- // Delegate to next route
- ProcessResponse response = route.route(nextContext);
+ // Delegate to next route
+ Map<QualifiedName, String> response = route.route(nextPath,
parameters);
- // If we do have a response we return it
- if (response != null)
- {
- ret = response;
- break;
+ // If we do have a response we return it
+ if (response != null)
+ {
+ ret = response;
+ break;
+ }
}
}
}
@@ -312,10 +311,9 @@
{
for (Map.Entry<QualifiedName, String> entry :
routeParameters.entrySet())
{
- if (!ret.getParameters().containsKey(entry.getKey()))
+ if (!ret.containsKey(entry.getKey()))
{
- // julien : should do a safe put all here on String[]
- ret.getParameters().put(entry.getKey(), entry.getValue());
+ ret.put(entry.getKey(), entry.getValue());
}
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -19,21 +19,19 @@
package org.exoplatform.web.controller.router;
-import org.exoplatform.web.controller.Controller;
-import org.exoplatform.web.controller.ControllerContext;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.ControllerRefMetaData;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
import org.exoplatform.web.controller.metadata.RouterMetaData;
-import org.exoplatform.web.controller.protocol.ControllerResponse;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class Router implements Controller
+public class Router
{
/** . */
@@ -44,7 +42,7 @@
Route root = new Route();
//
- for (Map.Entry<String, ControllerRefMetaData> routeMetaData :
metaData.getRoutes().entrySet())
+ for (Map.Entry<String, RouteMetaData> routeMetaData :
metaData.getRoutes().entrySet())
{
String path = routeMetaData.getKey();
root.append(path, routeMetaData.getValue().getParameters());
@@ -59,8 +57,8 @@
return root.render(parameters);
}
- public ControllerResponse process(ControllerContext controllerContext) throws
IOException
+ public Map<QualifiedName, String> process(String path) throws IOException
{
- return root.route(controllerContext);
+ return root.route(path, new HashMap<QualifiedName, String>());
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -35,31 +35,6 @@
*/
public abstract class AbstractTestController extends TestCase
{
-
- public void assertProcessResponse(String path, Map<QualifiedName, String>
parameters, ControllerResponse response)
- {
- assertNotNull("Was not expecting a null response", response);
- assertEquals(ProcessResponse.class, response.getClass());
- // todo check path and define semantic
- // assertEquals(path, ((ProcessResponse)response).getPath());
- assertEquals(parameters, ((ProcessResponse)response).getParameters());
- }
-
- public void assertProcessResponse(ControllerResponse response)
- {
- assertProcessResponse(null, Collections.<QualifiedName, String>emptyMap(),
response);
- }
-
- public void assertProcessResponse(String path, ControllerResponse response)
- {
- assertProcessResponse(path, Collections.<QualifiedName, String>emptyMap(),
response);
- }
-
- public void assertProcessResponse(Map<QualifiedName, String> parameters,
ControllerResponse response)
- {
- assertProcessResponse(null, parameters, response);
- }
-
public void assertEquals(Map<QualifiedName, String> expectedParameters,
Map<QualifiedName, String> parameters)
{
Assert.assertEquals(expectedParameters.keySet(), parameters.keySet());
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -21,7 +21,7 @@
import junit.framework.TestCase;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.ControllerRefMetaData;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
import org.exoplatform.web.controller.metadata.RouterMetaData;
import java.util.Collections;
@@ -34,7 +34,7 @@
public class TestBuildRoute extends TestCase
{
- private ControllerRefMetaData ref1 = new ControllerRefMetaData();
+ private RouteMetaData ref1 = new RouteMetaData();
public void testRoot()
{
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -19,9 +19,8 @@
package org.exoplatform.web.controller.router;
-import org.exoplatform.web.controller.ControllerContext;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.ControllerRefMetaData;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
import org.exoplatform.web.controller.metadata.RouterMetaData;
import java.util.Collections;
@@ -36,162 +35,162 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new ControllerRefMetaData());
+ routerMD.addRoute("/", new RouteMetaData());
Router router = new Router(routerMD);
//
- assertNull(router.process(new ControllerContext("")));
+ assertNull(router.process(""));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/"));
//
- assertNull(router.process(new ControllerContext("/a")));
+ assertNull(router.process("/a"));
//
- assertNull(router.process(new ControllerContext("a")));
+ assertNull(router.process("a"));
}
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData());
+ routerMD.addRoute("/a", new RouteMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a"));
//
- assertNull(router.process(new ControllerContext("a")));
+ assertNull(router.process("a"));
//
- assertNull(router.process(new ControllerContext("a/")));
+ assertNull(router.process("a/"));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a/")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a/"));
//
- assertNull(router.process(new ControllerContext("")));
+ assertNull(router.process(""));
//
- assertNull(router.process(new ControllerContext("/")));
+ assertNull(router.process("/"));
//
- assertNull(router.process(new ControllerContext("/b")));
+ assertNull(router.process("/b"));
//
- assertNull(router.process(new ControllerContext("b")));
+ assertNull(router.process("b"));
//
- assertNull(router.process(new ControllerContext("/a/b")));
+ assertNull(router.process("/a/b"));
}
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new ControllerRefMetaData());
+ routerMD.addRoute("/a/b", new RouteMetaData());
Router router = new Router( routerMD);
//
- assertNull(router.process(new ControllerContext("a/b")));
+ assertNull(router.process("a/b"));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a/b")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a/b"));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a/b/")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a/b/"));
//
- assertNull(router.process(new ControllerContext("a/b/")));
+ assertNull(router.process("a/b/"));
//
- assertNull(router.process(new ControllerContext("")));
+ assertNull(router.process(""));
//
- assertNull(router.process(new ControllerContext("/")));
+ assertNull(router.process("/"));
//
- assertNull(router.process(new ControllerContext("/b")));
+ assertNull(router.process("/b"));
//
- assertNull(router.process(new ControllerContext("b")));
+ assertNull(router.process("b"));
//
- assertNull(router.process(new ControllerContext("/a/b/c")));
+ assertNull(router.process("/a/b/c"));
}
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p}", new RouteMetaData());
Router router = new Router(routerMD);
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(new ControllerContext("/a")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(("/a")));
}
public void testParameterPropagationToDescendants() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new
ControllerRefMetaData().addParameter("p", "a"));
- routerMD.addRoute("/a", new ControllerRefMetaData());
+ routerMD.addRoute("/", new RouteMetaData().addParameter("p",
"a"));
+ routerMD.addRoute("/a", new RouteMetaData());
Router router = new Router(routerMD);
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(new ControllerContext("/a")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(("/a")));
}
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:.*}", new RouteMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
""), router.process(new ControllerContext("/")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
""), router.process("/"));
//
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(new ControllerContext("/a")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process("/a"));
//
- assertNull(router.process(new ControllerContext("a")));
+ assertNull(router.process(("a")));
//
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a/b"), router.process(new ControllerContext("/a/b")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a/b"), router.process("/a/b"));
}
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:a}", new RouteMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(new ControllerContext("/a")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process("/a"));
//
- assertNull(router.process(new ControllerContext("a")));
+ assertNull(router.process("a"));
//
- assertNull(router.process(new ControllerContext("/ab")));
+ assertNull(router.process("/ab"));
//
- assertNull(router.process(new ControllerContext("ab")));
+ assertNull(router.process("ab"));
}
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData());
- routerMD.addRoute("/{p:a}/b", new ControllerRefMetaData());
+ routerMD.addRoute("/a", new RouteMetaData());
+ routerMD.addRoute("/{p:a}/b", new RouteMetaData());
Router router = new Router(routerMD);
//
- assertNull(router.process(new ControllerContext("a")));
+ assertNull(router.process(("a")));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a"));
//
- assertProcessResponse(Collections.<QualifiedName, String>emptyMap(),
router.process(new ControllerContext("/a/")));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.process("/a/"));
//
- assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(new ControllerContext("/a/b")));
+ assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process("/a/b"));
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -19,9 +19,8 @@
package org.exoplatform.web.controller.router;
-import org.exoplatform.web.controller.ControllerContext;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.ControllerRefMetaData;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
import org.exoplatform.web.controller.metadata.RouterMetaData;
import java.util.HashMap;
@@ -41,15 +40,15 @@
protected void setUp() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- ControllerRefMetaData portalControllerRef = new ControllerRefMetaData();
+ RouteMetaData portalControllerRef = new RouteMetaData();
portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
portalControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "portal");
routerMD.addRoute("/private/{{gtn}sitename}{{gtn}path:.*}",
portalControllerRef);
- ControllerRefMetaData groupControllerRef = new ControllerRefMetaData();
+ RouteMetaData groupControllerRef = new RouteMetaData();
portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
groupControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "group");
routerMD.addRoute("/groups/{{gtn}sitename}{{gtn}path:.*}",
groupControllerRef);
- ControllerRefMetaData userControllerRef = new ControllerRefMetaData();
+ RouteMetaData userControllerRef = new RouteMetaData();
portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
userControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "user");
routerMD.addRoute("/users/{{gtn}sitename}{{gtn}path:.*}",
userControllerRef);
@@ -67,13 +66,13 @@
expectedParameters.put(new QualifiedName("gtn", "path"),
"");
//
- assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/private/classic")));
+ assertEquals(expectedParameters, router.process("/private/classic"));
assertEquals("/private/classic", router.render(expectedParameters));
}
public void testPrivateClassicSlash() throws Exception
{
- router.process(new ControllerContext("/private/classic/"));
+ router.process("/private/classic/");
Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
expectedParameters.put(new QualifiedName("gtn", "controller"),
"site");
expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
@@ -81,7 +80,7 @@
expectedParameters.put(new QualifiedName("gtn", "path"),
"/");
//
- assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/private/classic/")));
+ assertEquals(expectedParameters, router.process("/private/classic/"));
assertEquals("/private/classic/", router.render(expectedParameters));
}
@@ -94,7 +93,7 @@
expectedParameters.put(new QualifiedName("gtn", "path"),
"/home");
//
- assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/private/classic/home")));
+ assertEquals(expectedParameters,
router.process("/private/classic/home"));
assertEquals("/private/classic/home",
router.render(expectedParameters));
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-02
13:02:07 UTC (rev 4028)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-02
13:15:14 UTC (rev 4029)
@@ -20,7 +20,7 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.ControllerRefMetaData;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
import org.exoplatform.web.controller.metadata.RouterMetaData;
import java.util.Collections;
@@ -35,7 +35,7 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new ControllerRefMetaData());
+ routerMD.addRoute("/", new RouteMetaData());
Router router = new Router(routerMD);
//
@@ -45,7 +45,7 @@
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData());
+ routerMD.addRoute("/a", new RouteMetaData());
Router router = new Router(routerMD);
//
@@ -55,7 +55,7 @@
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new ControllerRefMetaData());
+ routerMD.addRoute("/a/b", new RouteMetaData());
Router router = new Router( routerMD);
//
@@ -65,7 +65,7 @@
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p}", new RouteMetaData());
Router router = new Router(routerMD);
//
@@ -76,7 +76,7 @@
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:.*}", new RouteMetaData());
Router router = new Router(routerMD);
//
@@ -92,7 +92,7 @@
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:a}", new RouteMetaData());
Router router = new Router(routerMD);
//
@@ -105,8 +105,8 @@
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData());
- routerMD.addRoute("/{p:a}/b", new ControllerRefMetaData());
+ routerMD.addRoute("/a", new RouteMetaData());
+ routerMD.addRoute("/{p:a}/b", new RouteMetaData());
Router router = new Router(routerMD);
//