Author: julien_viet
Date: 2010-11-27 16:53:26 -0500 (Sat, 27 Nov 2010)
New Revision: 5312
Added:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.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/TestRender.java
Log:
reorg unit test for path param encoding
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-11-27
21:38:16 UTC (rev 5311)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-11-27
21:53:26 UTC (rev 5312)
@@ -104,14 +104,26 @@
return this;
}
+ /**
+ * Add a path param with the {@link EncodingMode#DEFAULT_FORM} encoding.
+ *
+ * @param name the name
+ * @param pattern the pattern
+ * @return this object
+ */
+ public RouteDescriptor addPathParam(QualifiedName name, String pattern)
+ {
+ return addPathParam(name, pattern, EncodingMode.DEFAULT_FORM);
+ }
+
public RouteDescriptor addPathParam(QualifiedName name, String pattern, EncodingMode
encodingMode)
{
- return addRequestParam(new PathParamDescriptor(name, pattern, encodingMode));
+ return addPathParam(new PathParamDescriptor(name, pattern, encodingMode));
}
- public RouteDescriptor addRequestParam(PathParamDescriptor requestParam)
+ public RouteDescriptor addPathParam(PathParamDescriptor pathParam)
{
- pathParams.put(requestParam.getName(), requestParam);
+ pathParams.put(pathParam.getName(), pathParam);
return this;
}
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-11-27
21:38:16 UTC (rev 5311)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-11-27
21:53:26 UTC (rev 5312)
@@ -104,40 +104,6 @@
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
}
- public void testWildcardPattern() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
-
- //
- assertEquals(Collections.singletonMap(QualifiedName.create("p"),
""), router.route("/"));
- assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
- assertNull(router.route("a"));
- assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a/b"), router.route("/a/b"));
- }
-
- public void testDefaultForm() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]+", EncodingMode.DEFAULT_FORM));
- Router router = new Router(routerMD);
-
- //
- assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/"), router.route("/_"));
- }
-
- public void testPreservePath() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]+", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
-
- //
- assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"_"), router.route("/_"));
- assertNull(router.route("//"));
- }
-
public void testSimplePattern() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
@@ -155,7 +121,7 @@
{
RouterDescriptor routerMD = new RouterDescriptor();
routerMD.addRoute(new RouteDescriptor("/a"));
- routerMD.addRoute(new
RouteDescriptor("/{p}/b").addPathParam(QualifiedName.parse("p"),
"a", EncodingMode.DEFAULT_FORM));
+ routerMD.addRoute(new
RouteDescriptor("/{p}/b").addPathParam(QualifiedName.parse("p"),
"a"));
Router router = new Router(routerMD);
//
Added:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java
(rev 0)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java 2010-11-27
21:53:26 UTC (rev 5312)
@@ -0,0 +1,91 @@
+/*
+ * 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.router;
+
+import org.exoplatform.web.controller.QualifiedName;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
+
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestPathParamEncoding extends AbstractTestController
+{
+
+ public void testDefaultForm() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]+", EncodingMode.DEFAULT_FORM));
+ Router router = new Router(routerMD);
+
+ // Route
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/"), router.route("/_"));
+
+ // Render
+ assertEquals("/_",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
+ }
+
+ public void testPreservePath() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]+", EncodingMode.PRESERVE_PATH));
+ Router router = new Router(routerMD);
+
+ // Route
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"_"), router.route("/_"));
+ assertNull(router.route("//"));
+
+ // Render
+ assertEquals(null,
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
+ }
+
+ public void testWildcardPathParamWithPreservePath() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.PRESERVE_PATH));
+ Router router = new Router(routerMD);
+
+ // Render
+ assertEquals("/",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"")));
+ assertEquals("//",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
+ assertEquals("/a",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a")));
+ assertEquals("/a/b",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a/b")));
+
+ // Route
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
""), router.route("/"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/"), router.route("//"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a/b"), router.route("/a/b"));
+ }
+
+ public void testWildcardParamPathWithDefaultForm() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.DEFAULT_FORM));
+ Router router = new Router(routerMD);
+
+ //
+ assertEquals("/_",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
+ }
+
+}
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-11-27
21:38:16 UTC (rev 5311)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-11-27
21:53:26 UTC (rev 5312)
@@ -76,7 +76,7 @@
public void testSimplePatternPathParam() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"a", EncodingMode.DEFAULT_FORM));
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"a"));
Router router = new Router(routerMD);
//
@@ -84,63 +84,11 @@
assertNull(router.render(Collections.singletonMap(QualifiedName.create("p"),
"ab")));
}
- public void testWildcardPathParam() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
-
- //
- assertEquals("/",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"")));
- assertEquals("/a",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a")));
- assertEquals("/a/b",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a/b")));
- }
-
- public void testFoo() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]*", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
-
- //
- assertEquals(null,
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
- }
-
- public void testBar() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]*", EncodingMode.DEFAULT_FORM));
- Router router = new Router(routerMD);
-
- //
- assertEquals("/_",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
- }
-
- public void testWildcardParamPathPreservePathEncoding() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
-
- //
- assertEquals("//",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
- }
-
- public void testWildcardParamPathDefaultFormEncoded() throws Exception
- {
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.DEFAULT_FORM));
- Router router = new Router(routerMD);
-
- //
- assertEquals("/_",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
- }
-
public void testPrecedence() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
routerMD.addRoute(new RouteDescriptor("/a"));
- routerMD.addRoute(new
RouteDescriptor("/{p}/b").addPathParam(QualifiedName.parse("p"),
"a", EncodingMode.DEFAULT_FORM));
+ routerMD.addRoute(new
RouteDescriptor("/{p}/b").addPathParam(QualifiedName.parse("p"),
"a"));
Router router = new Router(routerMD);
//