Author: julien_viet
Date: 2010-08-19 10:42:30 -0400 (Thu, 19 Aug 2010)
New Revision: 3872
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java
Log:
re enable commented unit tests
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-08-19
13:56:24 UTC (rev 3871)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-08-19
14:42:30 UTC (rev 3872)
@@ -307,12 +307,12 @@
String parameterName;
if (colon == -1)
{
- regex = "([^/]+)";
+ regex = "[^/]+";
parameterName = parameterDef;
}
else
{
- regex = "(" + parameterDef.substring(colon + 1) +
")";
+ regex = parameterDef.substring(colon + 1);
parameterName = parameterDef.substring(0, colon);
}
@@ -332,7 +332,9 @@
//
+ builder.appendExpression("(");
builder.appendExpression(regex);
+ builder.appendExpression(")");
parameterNames.add(parameterQName);
parameterPatterns.add(Pattern.compile("^" + regex +
"$"));
previous = end.get(i) + 1;
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-08-19
13:56:24 UTC (rev 3871)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-08-19
14:42:30 UTC (rev 3872)
@@ -25,6 +25,7 @@
import org.exoplatform.web.controller.metadata.RouterMetaData;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
import java.util.regex.Pattern;
@@ -67,7 +68,6 @@
}
}
-/*
public void testParameterSegment()
{
String[] paths = {"/{a}","{a}"};
@@ -76,11 +76,18 @@
RouterMetaData routerMD = new RouterMetaData();
routerMD.addRoute(path, ref1);
Router router = new Router(routerMD);
- Route expectedRoute = new Route();
- PatternRoute a = new PatternRoute(Pattern.compile("^([^/]+)"),
Arrays.asList(new QualifiedName("a")));
- a.controllerRef = "ref1";
- expectedRoute.patternRoutes.add(a);
- assertEquals(expectedRoute, router.root);
+
+ //
+ assertEquals(0, router.root.simpleRoutes.size());
+ assertEquals(1, router.root.patternRoutes.size());
+ PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals("^([^/]+)", patternRoute.pattern.toString());
+ assertEquals(Collections.singletonList(new QualifiedName("a")),
patternRoute.parameterNames);
+ assertEquals(1, patternRoute.parameterPatterns.size());
+ assertEquals("^[^/]+$",
patternRoute.parameterPatterns.get(0).toString());
+ assertEquals(2, patternRoute.chunks.size());
+ assertEquals("", patternRoute.chunks.get(0));
+ assertEquals("", patternRoute.chunks.get(1));
}
}
@@ -92,11 +99,18 @@
RouterMetaData routerMD = new RouterMetaData();
routerMD.addRoute(path, ref1);
Router router = new Router(routerMD);
- Route expectedRoute = new Route();
- PatternRoute a = new PatternRoute(Pattern.compile("^([^/]+)"),
Arrays.asList(new QualifiedName("q", "a")));
- a.controllerRef = "ref1";
- expectedRoute.patternRoutes.add(a);
- assertEquals(expectedRoute, router.root);
+
+ //
+ assertEquals(0, router.root.simpleRoutes.size());
+ assertEquals(1, router.root.patternRoutes.size());
+ PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals("^([^/]+)", patternRoute.pattern.toString());
+ assertEquals(Collections.singletonList(new QualifiedName("q",
"a")), patternRoute.parameterNames);
+ assertEquals(1, patternRoute.parameterPatterns.size());
+ assertEquals("^[^/]+$",
patternRoute.parameterPatterns.get(0).toString());
+ assertEquals(2, patternRoute.chunks.size());
+ assertEquals("", patternRoute.chunks.get(0));
+ assertEquals("", patternRoute.chunks.get(1));
}
}
@@ -108,14 +122,20 @@
RouterMetaData routerMD = new RouterMetaData();
routerMD.addRoute(path, ref1);
Router router = new Router(routerMD);
- Route expectedRoute = new Route();
- PatternRoute a = new PatternRoute(Pattern.compile("^(.*)"),
Arrays.asList(new QualifiedName("a")));
- a.controllerRef = "ref1";
- expectedRoute.patternRoutes.add(a);
- assertEquals(expectedRoute, router.root);
+
+ //
+ assertEquals(0, router.root.simpleRoutes.size());
+ assertEquals(1, router.root.patternRoutes.size());
+ PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals("^(.*)", patternRoute.pattern.toString());
+ assertEquals(Collections.singletonList(new QualifiedName("a")),
patternRoute.parameterNames);
+ assertEquals(1, patternRoute.parameterPatterns.size());
+ assertEquals("^.*$",
patternRoute.parameterPatterns.get(0).toString());
+ assertEquals(2, patternRoute.chunks.size());
+ assertEquals("", patternRoute.chunks.get(0));
+ assertEquals("", patternRoute.chunks.get(1));
}
}
-*/
private void assertEquals(Route expectedRoute, Route route)
{