Author: julien_viet
Date: 2010-09-02 05:27:13 -0400 (Thu, 02 Sep 2010)
New Revision: 4025
Modified:
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/protocol/ProcessResponse.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.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/main/java/org/exoplatform/web/controller/router/SimpleRoute.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:
better impl of rendering
Modified:
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -32,32 +32,13 @@
{
/** . */
- private String ref;
-
- /** . */
private final Map<QualifiedName, String[]> parameters;
public ControllerRefMetaData()
{
- this(null);
- }
-
- public ControllerRefMetaData(String ref)
- {
- this.ref = ref;
this.parameters = new HashMap<QualifiedName, String[]>();
}
- public String getRef()
- {
- return ref;
- }
-
- public void setRef(String ref)
- {
- this.ref = ref;
- }
-
public ControllerRefMetaData addParameter(QualifiedName name, String first, String...
rest)
{
String[] value = new String[1 + rest.length];
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/protocol/ProcessResponse.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/protocol/ProcessResponse.java 2010-09-02
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/protocol/ProcessResponse.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -32,40 +32,32 @@
{
/** . */
- private final String controllerId;
-
- /** . */
private final String path;
/** . */
private final Map<QualifiedName, String[]> parameters;
- public ProcessResponse(String controllerId)
+ public ProcessResponse()
{
- this(controllerId, null, Collections.<QualifiedName, String[]>emptyMap());
+ this(null, Collections.<QualifiedName, String[]>emptyMap());
}
- public ProcessResponse(String controllerId, String path)
+ public ProcessResponse(String path)
{
- this(controllerId, path, Collections.<QualifiedName, String[]>emptyMap());
+ this(path, Collections.<QualifiedName, String[]>emptyMap());
}
- public ProcessResponse(String controllerId, Map<QualifiedName, String[]>
parameters)
+ public ProcessResponse(Map<QualifiedName, String[]> parameters)
{
- this(controllerId, null, parameters);
+ this(null, parameters);
}
- public ProcessResponse(String controllerId, String path, Map<QualifiedName,
String[]> parameters)
+ public ProcessResponse(String path, Map<QualifiedName, String[]> parameters)
{
- if (controllerId == null)
- {
- throw new NullPointerException();
- }
if (parameters == null)
{
throw new NullPointerException();
}
- this.controllerId = controllerId;
this.path = path;
this.parameters = parameters;
}
@@ -75,11 +67,6 @@
return path;
}
- public String getControllerId()
- {
- return controllerId;
- }
-
public Map<QualifiedName, String[]> getParameters()
{
return parameters;
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java 2010-09-02
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -43,12 +43,16 @@
/** . */
final List<String> chunks;
- public PatternRoute(
+ PatternRoute(
+ Route parent,
Pattern pattern,
List<QualifiedName> parameterNames,
List<Pattern> parameterPatterns,
List<String> chunks)
{
+ super(parent);
+
+ //
if (chunks.size() != parameterNames.size() + 1)
{
throw new AssertionError("Was expecting chunk size " + chunks.size() +
" to be equals to " + parameterNames.size() + 1);
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@@ -41,9 +42,12 @@
{
/** . */
- String controllerRef;
+ final Route parent;
/** . */
+ boolean terminal;
+
+ /** . */
final Map<String, SimpleRoute> simpleRoutes;
/** . */
@@ -52,96 +56,153 @@
/** . */
final Map<QualifiedName, String[]> routeParameters;
+ protected Route(Route parent)
+ {
+ if (parent == null)
+ {
+ throw new NullPointerException("No null parent");
+ }
+
+ //
+ this.parent = parent;
+ this.terminal = false;
+ this.simpleRoutes = new LinkedHashMap<String, SimpleRoute>();
+ this.patternRoutes = new ArrayList<PatternRoute>();
+ this.routeParameters = new HashMap<QualifiedName, String[]>();
+ }
+
Route()
{
- this.simpleRoutes = new HashMap<String, SimpleRoute>();
+ this.parent = null;
+ this.terminal = false;
+ this.simpleRoutes = new LinkedHashMap<String, SimpleRoute>();
this.patternRoutes = new ArrayList<PatternRoute>();
this.routeParameters = new HashMap<QualifiedName, String[]>();
}
/**
- * todo: a version that does not string concatenation but instead a buffer
+ * Ok, so this is not the fastest way to do it, but for now it's OK, it's what
is needed, we'll find
+ * a way to optimize it later with some precompilation.
*/
- String render(String controllerId, Map<QualifiedName, String[]> blah)
+ final String render(Map<QualifiedName, String[]> blah)
{
- if (controllerRef != null && controllerRef.equals(controllerId))
+ Route r = find(blah);
+ if (r == null)
{
- for (Map.Entry<QualifiedName, String[]> entry :
routeParameters.entrySet())
+ return null;
+ }
+ else
+ {
+ if (r instanceof PatternRoute || r instanceof SimpleRoute)
{
- String[] a = blah.get(entry.getKey());
- if (a == null || !Arrays.equals(entry.getValue(), a))
- {
- return null;
- }
+ StringBuilder sb = new StringBuilder();
+ r.render(blah, sb);
+ return sb.toString();
}
- return "/";
+ else
+ {
+ return "/";
+ }
}
- else
+ }
+
+ private void render(Map<QualifiedName, String[]> blah, StringBuilder sb)
+ {
+ if (parent != null)
{
- for (Map.Entry<String, SimpleRoute> a : simpleRoutes.entrySet())
+ parent.render(blah, sb);
+ }
+
+ //
+ if (this instanceof SimpleRoute)
+ {
+ SimpleRoute sr = (SimpleRoute)this;
+ sb.append('/').append(sr.value);
+ }
+ else if (this instanceof PatternRoute)
+ {
+ PatternRoute pr = (PatternRoute)this;
+ sb.append('/');
+ int i = 0;
+ while (i < pr.parameterNames.size())
{
- String b = a.getValue().render(controllerId, blah);
- if (b != null)
- {
- if (b.length() > 1)
- {
- return "/" + a.getKey() + b;
- }
- else
- {
- return "/" + a.getKey();
- }
- }
+ sb.append(pr.chunks.get(i));
+ String[] value = blah.get(pr.parameterNames.get(i));
+ sb.append(value[0]);
+ i++;
}
- there:
- for (PatternRoute a : patternRoutes)
+ sb.append(pr.chunks.get(i));
+ }
+ }
+
+ final Route find(Map<QualifiedName, String[]> blah)
+ {
+
+ // Remove what is matched
+ Map<QualifiedName, String[]> abc = new HashMap<QualifiedName,
String[]>(blah);
+
+ // Match first the static parameteters
+ for (Map.Entry<QualifiedName, String[]> a : routeParameters.entrySet())
+ {
+ String[] s = blah.get(a.getKey());
+ if (s == null || !Arrays.equals(a.getValue(), s))
{
- int i = 0;
- while (i < a.parameterNames.size())
- {
- String[] value = blah.get(a.parameterNames.get(i));
- if (value == null || value.length < 1)
- {
- continue there;
- }
- if (!a.parameterPatterns.get(i).matcher(value[0]).matches())
- {
- continue there;
- }
- i++;
- }
+ return null;
+ }
+ else
+ {
+ abc.remove(a.getKey());
+ }
+ }
- //
- i = 0;
- StringBuilder sb = new StringBuilder();
- while (i < a.parameterNames.size())
+ // Match any pattern parameter
+ if (this instanceof PatternRoute)
+ {
+ PatternRoute prt = (PatternRoute)this;
+ for (int i = 0;i < prt.parameterNames.size();i++)
+ {
+ QualifiedName qd = prt.parameterNames.get(i);
+ String[] s = blah.get(qd);
+ if (s == null || !prt.parameterPatterns.get(i).matcher(s[0]).matches())
{
- sb.append(a.chunks.get(i));
- String[] value = blah.get(a.parameterNames.get(i));
- sb.append(value[0]);
- i++;
+ return null;
}
- sb.append(a.chunks.get(i));
-
- //
- String bilto = a.render(controllerId, blah);
- if (bilto != null)
+ else
{
- if (bilto.length() > 1)
- {
- return "/" + sb + bilto;
- }
- else
- {
- return "/" + sb.toString();
- }
+ abc.remove(qd);
}
}
}
+
+ //
+ if (abc.isEmpty() && terminal)
+ {
+ return this;
+ }
+
+ //
+ for (SimpleRoute route : simpleRoutes.values())
+ {
+ Route a = route.find(abc);
+ if (a != null)
+ {
+ return a;
+ }
+ }
+ for (PatternRoute route : patternRoutes)
+ {
+ Route a = route.find(abc);
+ if (a != null)
+ {
+ return a;
+ }
+ }
+
+ //
return null;
}
- ProcessResponse route(ControllerContext context)
+ final ProcessResponse route(ControllerContext context)
{
String path = context.getPath();
@@ -155,9 +216,9 @@
// The '/' means the current controller if any, otherwise it may be
processed by the pattern matching
if (path.length() == 1)
{
- if (controllerRef != null)
+ if (terminal)
{
- ret = new ProcessResponse(controllerRef, context.getPath(),
context.getParameters());
+ ret = new ProcessResponse(context.getPath(), context.getParameters());
}
}
else
@@ -269,13 +330,12 @@
/** . */
private static final Pattern PARAMETER_REGEX =
Pattern.compile("^(?:\\{([^\\}]*)\\})?(.*)$");
- Route append(
+ final Route append(
String path,
- String controllerRef,
Map<QualifiedName, String[]> parameters)
{
Route route = append(path);
- route.controllerRef = controllerRef;
+ route.terminal = true;
route.routeParameters.putAll(parameters);
return route;
}
@@ -329,7 +389,7 @@
}
else
{
- SimpleRoute route = new SimpleRoute(path.substring(0, pos));
+ SimpleRoute route = new SimpleRoute(this, path.substring(0, pos));
simpleRoutes.put(route.value, route);
next = route;
}
@@ -391,7 +451,7 @@
// Julien : should the pattern end with a $ ?????? I don't see that for
now
// we need to figure out clearly
Pattern pattern = builder.build();
- PatternRoute route = new PatternRoute(pattern, parameterNames,
parameterPatterns, chunks);
+ PatternRoute route = new PatternRoute(this, pattern, parameterNames,
parameterPatterns, chunks);
patternRoutes.add(route);
next = route;
}
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -47,16 +47,16 @@
for (Map.Entry<String, ControllerRefMetaData> routeMetaData :
metaData.getRoutes().entrySet())
{
String path = routeMetaData.getKey();
- root.append(path, routeMetaData.getValue().getRef(),
routeMetaData.getValue().getParameters());
+ root.append(path, routeMetaData.getValue().getParameters());
}
//
this.root = root;
}
- public String render(String controllerId, Map<QualifiedName, String[]> blah)
+ public String render(Map<QualifiedName, String[]> blah)
{
- return root.render(controllerId, blah);
+ return root.render(blah);
}
public ControllerResponse process(ControllerContext controllerContext) throws
IOException
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-02
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -29,8 +29,11 @@
/** . */
final String value;
- public SimpleRoute(String value)
+ SimpleRoute(Route parent, String value)
{
+ super(parent);
+
+ //
this.value = value;
}
}
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -36,29 +36,28 @@
public abstract class AbstractTestController extends TestCase
{
- public void assertProcessResponse(String controllerId, String path,
Map<QualifiedName, String[]> parameters, ControllerResponse response)
+ public void assertProcessResponse(String path, Map<QualifiedName, String[]>
parameters, ControllerResponse response)
{
assertNotNull("Was not expecting a null response", response);
assertEquals(ProcessResponse.class, response.getClass());
- assertEquals(controllerId, ((ProcessResponse)response).getControllerId());
// todo check path and define semantic
// assertEquals(path, ((ProcessResponse)response).getPath());
assertEquals(parameters, ((ProcessResponse)response).getParameters());
}
- public void assertProcessResponse(String controllerId, ControllerResponse response)
+ public void assertProcessResponse(ControllerResponse response)
{
- assertProcessResponse(controllerId, null, Collections.<QualifiedName,
String[]>emptyMap(), response);
+ assertProcessResponse(null, Collections.<QualifiedName, String[]>emptyMap(),
response);
}
- public void assertProcessResponse(String controllerId, String path, ControllerResponse
response)
+ public void assertProcessResponse(String path, ControllerResponse response)
{
- assertProcessResponse(controllerId, path, Collections.<QualifiedName,
String[]>emptyMap(), response);
+ assertProcessResponse(path, Collections.<QualifiedName, String[]>emptyMap(),
response);
}
- public void assertProcessResponse(String controllerId, Map<QualifiedName,
String[]> parameters, ControllerResponse response)
+ public void assertProcessResponse(Map<QualifiedName, String[]> parameters,
ControllerResponse response)
{
- assertProcessResponse(controllerId, null, parameters, response);
+ assertProcessResponse(null, parameters, response);
}
public void assertEquals(Map<QualifiedName, String[]> expectedParameters,
Map<QualifiedName, String[]> parameters)
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -34,7 +34,7 @@
public class TestBuildRoute extends TestCase
{
- private ControllerRefMetaData ref1 = new ControllerRefMetaData("ref1");
+ private ControllerRefMetaData ref1 = new ControllerRefMetaData();
public void testRoot()
{
@@ -45,7 +45,6 @@
routerMD.addRoute(path, ref1);
Router router = new Router(routerMD);
Route expectedRoute = new Route();
- expectedRoute.controllerRef = "ref1";
assertEquals(expectedRoute, router.root);
}
}
@@ -59,8 +58,7 @@
routerMD.addRoute(path, ref1);
Router router = new Router(routerMD);
Route expectedRoute = new Route();
- SimpleRoute a = new SimpleRoute("a");
- a.controllerRef = "ref1";
+ SimpleRoute a = new SimpleRoute(expectedRoute, "a");
expectedRoute.simpleRoutes.put("a", a);
assertEquals(expectedRoute, router.root);
}
@@ -138,7 +136,6 @@
private void assertEquals(Route expectedRoute, Route route)
{
assertEquals(expectedRoute.getClass(), route.getClass());
- assertEquals(expectedRoute.controllerRef, route.controllerRef);
assertEquals(expectedRoute.simpleRoutes.keySet(), route.simpleRoutes.keySet());
for (Map.Entry<String, SimpleRoute> entry :
expectedRoute.simpleRoutes.entrySet())
{
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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -36,14 +36,14 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
assertNull(router.process(new ControllerContext("")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/")));
//
assertNull(router.process(new ControllerContext("/a")));
@@ -55,11 +55,11 @@
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/a", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a")));
//
assertNull(router.process(new ControllerContext("a")));
@@ -68,7 +68,7 @@
assertNull(router.process(new ControllerContext("a/")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a/")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a/")));
//
assertNull(router.process(new ControllerContext("")));
@@ -89,17 +89,17 @@
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/a/b", new ControllerRefMetaData());
Router router = new Router( routerMD);
//
assertNull(router.process(new ControllerContext("a/b")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a/b")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a/b")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a/b/")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a/b/")));
//
assertNull(router.process(new ControllerContext("a/b/")));
@@ -123,47 +123,47 @@
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p}", new ControllerRefMetaData());
Router router = new Router(routerMD);
- assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a"}), router.process(new ControllerContext("/a")));
}
public void testParameterPropagationToDescendants() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new
ControllerRefMetaData("ref1").addParameter("p", "a"));
- routerMD.addRoute("/a", new ControllerRefMetaData("ref2"));
+ routerMD.addRoute("/", new
ControllerRefMetaData().addParameter("p", "a"));
+ routerMD.addRoute("/a", new ControllerRefMetaData());
Router router = new Router(routerMD);
- assertProcessResponse("ref2", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a"}), router.process(new ControllerContext("/a")));
}
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new
ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p:.*}", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{""}), router.process(new
ControllerContext("/")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{""}), router.process(new ControllerContext("/")));
//
- assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a"}), router.process(new ControllerContext("/a")));
//
assertNull(router.process(new ControllerContext("a")));
//
- assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a/b"}), router.process(new
ControllerContext("/a/b")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a/b"}), router.process(new ControllerContext("/a/b")));
}
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new
ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p:a}", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a"}), router.process(new ControllerContext("/a")));
//
assertNull(router.process(new ControllerContext("a")));
@@ -178,20 +178,20 @@
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData("ref1"));
- routerMD.addRoute("/{p:a}/b", new
ControllerRefMetaData("ref2"));
+ routerMD.addRoute("/a", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:a}/b", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
assertNull(router.process(new ControllerContext("a")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a")));
//
- assertProcessResponse("ref1", Collections.<QualifiedName,
String[]>emptyMap(), router.process(new ControllerContext("/a/")));
+ assertProcessResponse(Collections.<QualifiedName, String[]>emptyMap(),
router.process(new ControllerContext("/a/")));
//
- assertProcessResponse("ref2", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a/b")));
+ assertProcessResponse(Collections.singletonMap(new QualifiedName("p"),
new String[]{"a"}), router.process(new ControllerContext("/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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -41,15 +41,15 @@
protected void setUp() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- ControllerRefMetaData portalControllerRef = new
ControllerRefMetaData("site");
+ ControllerRefMetaData portalControllerRef = new ControllerRefMetaData();
portalControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "portal");
- routerMD.addRoute("/private/{{gtn}sitename}/{{gtn}path:.*}",
portalControllerRef);
- ControllerRefMetaData groupControllerRef = new
ControllerRefMetaData("site");
+ routerMD.addRoute("/private/{{gtn}sitename}{{gtn}path:.*}",
portalControllerRef);
+ ControllerRefMetaData groupControllerRef = new ControllerRefMetaData();
groupControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "group");
- routerMD.addRoute("/groups/{{gtn}sitename}/{{gtn}path:.*}",
groupControllerRef);
- ControllerRefMetaData userControllerRef = new
ControllerRefMetaData("site");
+ routerMD.addRoute("/groups/{{gtn}sitename}{{gtn}path:.*}",
groupControllerRef);
+ ControllerRefMetaData userControllerRef = new ControllerRefMetaData();
userControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "user");
- routerMD.addRoute("/users/{{gtn}sitename}/{{gtn}path:.*}",
userControllerRef);
+ routerMD.addRoute("/users/{{gtn}sitename}{{gtn}path:.*}",
userControllerRef);
//
this.router = new Router(routerMD);
@@ -63,8 +63,8 @@
expectedParameters.put(new QualifiedName("gtn", "path"), new
String[]{""});
//
- assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic")));
- assertEquals("/private/classic", router.render("site",
expectedParameters));
+ assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/private/classic")));
+ assertEquals("/private/classic", router.render(expectedParameters));
}
public void testPrivateClassicSlash() throws Exception
@@ -73,11 +73,11 @@
Map<QualifiedName, String[]> expectedParameters = new
HashMap<QualifiedName, String[]>();
expectedParameters.put(new QualifiedName("gtn", "sitename"),
new String[]{"classic"});
expectedParameters.put(new QualifiedName("gtn", "sitetype"),
new String[]{"portal"});
- expectedParameters.put(new QualifiedName("gtn", "path"), new
String[]{""});
+ expectedParameters.put(new QualifiedName("gtn", "path"), new
String[]{"/"});
//
- assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic/")));
- assertEquals("/private/classic", router.render("site",
expectedParameters));
+ assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/private/classic/")));
+ assertEquals("/private/classic/", router.render(expectedParameters));
}
public void testPrivateClassicHome() throws Exception
@@ -85,10 +85,10 @@
Map<QualifiedName, String[]> expectedParameters = new
HashMap<QualifiedName, String[]>();
expectedParameters.put(new QualifiedName("gtn", "sitename"),
new String[]{"classic"});
expectedParameters.put(new QualifiedName("gtn", "sitetype"),
new String[]{"portal"});
- expectedParameters.put(new QualifiedName("gtn", "path"), new
String[]{"home"});
+ expectedParameters.put(new QualifiedName("gtn", "path"), new
String[]{"/home"});
//
- assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic/home")));
- assertEquals("/private/classic/home", router.render("site",
expectedParameters));
+ assertProcessResponse(expectedParameters, router.process(new
ControllerContext("/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
09:22:53 UTC (rev 4024)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-02
09:27:13 UTC (rev 4025)
@@ -35,83 +35,84 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/", router.render(Collections.<QualifiedName,
String[]>emptyMap()));
}
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/a", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a", router.render(Collections.<QualifiedName,
String[]>emptyMap()));
}
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/a/b", new ControllerRefMetaData());
Router router = new Router( routerMD);
//
- assertEquals("/a/b", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a/b", router.render(Collections.<QualifiedName,
String[]>emptyMap()));
}
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p}", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"})));
+ assertNull(router.render(Collections.<QualifiedName, String[]>emptyMap()));
}
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new
ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p:.*}", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new String[]{""})));
+ assertEquals("/", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{""})));
//
- assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"})));
//
- assertEquals("/a/b", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a/b"})));
+ assertEquals("/a/b", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{"a/b"})));
}
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new
ControllerRefMetaData("ref1"));
+ routerMD.addRoute("/{p:a}", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"})));
//
- assertNull(router.render("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"ab"})));
+ assertNull(router.render(Collections.singletonMap(new QualifiedName("p"),
new String[]{"ab"})));
}
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new ControllerRefMetaData("ref1"));
- routerMD.addRoute("/{p:a}/b", new
ControllerRefMetaData("ref2"));
+ routerMD.addRoute("/a", new ControllerRefMetaData());
+ routerMD.addRoute("/{p:a}/b", new ControllerRefMetaData());
Router router = new Router(routerMD);
//
- assertEquals("/a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a", router.render(Collections.<QualifiedName,
String[]>emptyMap()));
//
- assertEquals("/a/b", router.render("ref2",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a/b", router.render(Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"})));
}
}