Author: julien_viet
Date: 2010-11-29 17:35:18 -0500 (Mon, 29 Nov 2010)
New Revision: 5359
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/PathParamDescriptor.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RequestParamDescriptor.java
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/RouteParamDescriptor.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RequestParam.java
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
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.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/TestPathParamEncoding.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.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
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
Log:
simplify configuration for unit test
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -19,7 +19,6 @@
package org.exoplatform.web.controller.metadata;
-import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.controller.router.EncodingMode;
import javax.xml.namespace.QName;
@@ -35,6 +34,21 @@
public class DescriptorBuilder
{
+ public static PathParamDescriptor pathParam(String qualifiedName)
+ {
+ return new PathParamDescriptor(qualifiedName);
+ }
+
+ public static RequestParamDescriptor requestParam(String qualifiedName)
+ {
+ return new RequestParamDescriptor(qualifiedName);
+ }
+
+ public static RouteParamDescriptor routeParam(String qualifiedName)
+ {
+ return new RouteParamDescriptor(qualifiedName);
+ }
+
/** . */
private static final QName routeQN = new
QName("http://www.gatein.org/xml/ns/gatein_router_1_0", "route");
@@ -47,9 +61,19 @@
/** . */
private static final QName pathParamQN = new
QName("http://www.gatein.org/xml/ns/gatein_router_1_0",
"path-param");
+ public static RouteDescriptor route(String path)
+ {
+ return new RouteDescriptor(path);
+ }
+
+ public static RouterDescriptor router()
+ {
+ return new RouterDescriptor();
+ }
+
public RouterDescriptor build(XMLStreamReader reader) throws Exception
{
- RouterDescriptor routerDesc = new RouterDescriptor();
+ RouterDescriptor routerDesc = router();
//
while (true)
@@ -76,7 +100,7 @@
private void build(XMLStreamReader reader, List<RouteDescriptor> descriptors)
throws XMLStreamException
{
String path = reader.getAttributeValue(null, "path");
- RouteDescriptor routeDesc = new RouteDescriptor(path);
+ RouteDescriptor routeDesc = route(path);
//
while (true)
@@ -93,25 +117,25 @@
{
if (paramQN.equals(reader.getName()))
{
- String name = reader.getAttributeValue(null, "qname");
+ String qualifiedName = reader.getAttributeValue(null, "qname");
String value = reader.getAttributeValue(null, "value");
- routeDesc.addRouteParam(QualifiedName.parse(name), value);
+ routeDesc.add(new RouteParamDescriptor(qualifiedName).withValue(value));
}
else if (requestParamQN.equals(reader.getName()))
{
- String name = reader.getAttributeValue(null, "qname");
- String matchName = reader.getAttributeValue(null, "name");
- String matchValue = reader.getAttributeValue(null, "value");
+ String qualifiedName = reader.getAttributeValue(null, "qname");
+ String name = reader.getAttributeValue(null, "name");
+ String value = reader.getAttributeValue(null, "value");
String optional = reader.getAttributeValue(null, "required");
- routeDesc.addRequestParam(QualifiedName.parse(name), matchName,
matchValue, "true".equals(optional));
+ routeDesc.add(new
RequestParamDescriptor(qualifiedName).withName(name).withValue(value).required("true".equals(optional)));
}
else if (pathParamQN.equals(reader.getName()))
{
- String name = reader.getAttributeValue(null, "qname");
+ String qualifiedName = reader.getAttributeValue(null, "qname");
String pattern = reader.getAttributeValue(null, "pattern");
String encoded = reader.getAttributeValue(null, "encoding");
EncodingMode encodingMode = "preserve-path".equals(encoded) ?
EncodingMode.PRESERVE_PATH : EncodingMode.FORM;
- routeDesc.addPathParam(QualifiedName.parse(name), pattern, encodingMode);
+ routeDesc.add(new
PathParamDescriptor(qualifiedName).withPattern(pattern).withEncodingMode(encodingMode));
}
else if (routeQN.equals(reader.getName()))
{
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/PathParamDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/PathParamDescriptor.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/PathParamDescriptor.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -30,32 +30,65 @@
{
/** . */
- private final QualifiedName name;
+ private final QualifiedName qualifiedName;
/** . */
- private final String pattern;
+ private String pattern;
/** . */
- private final EncodingMode encodingMode;
+ private EncodingMode encodingMode = EncodingMode.FORM;
- public PathParamDescriptor(QualifiedName name, String pattern, EncodingMode
encodingMode)
+ public PathParamDescriptor(QualifiedName qualifiedName)
{
- if (name == null)
+ if (qualifiedName == null)
{
throw new NullPointerException("No null name accepted");
}
//
- this.name = name;
+ this.qualifiedName = qualifiedName;
+ }
+
+ public PathParamDescriptor(String qualifiedName)
+ {
+ if (qualifiedName == null)
+ {
+ throw new NullPointerException("No null name accepted");
+ }
+
+ //
+ this.qualifiedName = QualifiedName.parse(qualifiedName);
+ }
+
+ public PathParamDescriptor withPattern(String pattern)
+ {
this.pattern = pattern;
+ return this;
+ }
+
+ public PathParamDescriptor withEncodingMode(EncodingMode encodingMode)
+ {
this.encodingMode = encodingMode;
+ return this;
}
- public QualifiedName getName()
+ public PathParamDescriptor preservingPath()
{
- return name;
+ this.encodingMode = EncodingMode.PRESERVE_PATH;
+ return this;
}
+ public PathParamDescriptor form()
+ {
+ this.encodingMode = EncodingMode.FORM;
+ return this;
+ }
+
+ public QualifiedName getQualifiedName()
+ {
+ return qualifiedName;
+ }
+
public String getPattern()
{
return pattern;
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RequestParamDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RequestParamDescriptor.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RequestParamDescriptor.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -29,48 +29,78 @@
{
/** . */
- private final QualifiedName name;
+ private final QualifiedName qualifiedName;
/** . */
- private final String matchName;
+ private String name;
/** . */
- private final String matchValue;
+ private String value;
/** . */
- private final boolean required;
+ private boolean required;
- public RequestParamDescriptor(QualifiedName name, String matchName, String matchValue,
boolean required)
+ public RequestParamDescriptor(QualifiedName qualifiedName)
{
- if (name == null)
+ if (qualifiedName == null)
{
- throw new NullPointerException("No null name accepted");
+ throw new NullPointerException("No null qualified name accepted");
}
- if (matchName == null)
+
+ //
+ this.qualifiedName = qualifiedName;
+ this.value = null;
+ this.required = false;
+ }
+
+ public RequestParamDescriptor(String qualifiedName)
+ {
+ if (qualifiedName == null)
{
- throw new NullPointerException("No null match name accepted");
+ throw new NullPointerException("No null qualified name accepted");
}
//
+ this.qualifiedName = QualifiedName.parse(qualifiedName);
+ }
+
+ public RequestParamDescriptor withName(String name)
+ {
this.name = name;
- this.matchName = matchName;
- this.matchValue = matchValue;
+ return this;
+ }
+
+ public RequestParamDescriptor withValue(String value)
+ {
+ this.value = value;
+ return this;
+ }
+
+ public RequestParamDescriptor required()
+ {
+ this.required = true;
+ return this;
+ }
+
+ public RequestParamDescriptor required(boolean required)
+ {
this.required = required;
+ return this;
}
- public QualifiedName getName()
+ public QualifiedName getQualifiedName()
{
- return name;
+ return qualifiedName;
}
- public String getMatchName()
+ public String getName()
{
- return matchName;
+ return name;
}
- public String getMatchValue()
+ public String getValue()
{
- return matchValue;
+ return value;
}
public boolean isRequired()
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-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -67,17 +67,6 @@
return path;
}
- public RouteDescriptor addRouteParam(QualifiedName name, String value)
- {
- routeParams.put(name, new RouteParamDescriptor(name, value));
- return this;
- }
-
- public RouteDescriptor addRouteParam(String name, String value)
- {
- return addRouteParam(QualifiedName.parse(name), value);
- }
-
public Set<QualifiedName> getRouteParamNames()
{
return routeParams.keySet();
@@ -93,37 +82,21 @@
return routeParams.get(name);
}
- public RouteDescriptor addRequestParam(QualifiedName name, String matchName, String
matchValue, boolean required)
+ public RouteDescriptor add(RouteParamDescriptor routeParam)
{
- return addRequestParam(new RequestParamDescriptor(name, matchName, matchValue,
required));
+ routeParams.put(routeParam.getQualifiedName(), routeParam);
+ return this;
}
- public RouteDescriptor addRequestParam(RequestParamDescriptor requestParam)
+ public RouteDescriptor add(RequestParamDescriptor requestParam)
{
- requestParams.put(requestParam.getMatchName(), requestParam);
+ requestParams.put(requestParam.getName(), requestParam);
return this;
}
- /**
- * Add a path param with the {@link EncodingMode#FORM} encoding.
- *
- * @param name the name
- * @param pattern the pattern
- * @return this object
- */
- public RouteDescriptor addPathParam(QualifiedName name, String pattern)
+ public RouteDescriptor add(PathParamDescriptor pathParam)
{
- return addPathParam(name, pattern, EncodingMode.FORM);
- }
-
- public RouteDescriptor addPathParam(QualifiedName name, String pattern, EncodingMode
encodingMode)
- {
- return addPathParam(new PathParamDescriptor(name, pattern, encodingMode));
- }
-
- public RouteDescriptor addPathParam(PathParamDescriptor pathParam)
- {
- pathParams.put(pathParam.getName(), pathParam);
+ pathParams.put(pathParam.getQualifiedName(), pathParam);
return this;
}
@@ -147,7 +120,7 @@
return pathParams;
}
- public RouteDescriptor addRoute(RouteDescriptor child)
+ public RouteDescriptor add(RouteDescriptor child)
{
children.add(child);
return this;
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteParamDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteParamDescriptor.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteParamDescriptor.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -29,30 +29,30 @@
{
/** . */
- private final QualifiedName name;
+ private final QualifiedName qualifiedName;
/** . */
- private final String value;
+ private String value;
- public RouteParamDescriptor(QualifiedName name, String value)
+ public RouteParamDescriptor(QualifiedName qualifiedName)
{
- if (name == null)
- {
- throw new NullPointerException("No null name accepted");
- }
- if (value == null)
- {
- throw new NullPointerException("No null value accepted");
- }
+ this.qualifiedName = qualifiedName;
+ }
- //
- this.name = name;
+ public RouteParamDescriptor(String qualifiedName)
+ {
+ this.qualifiedName = QualifiedName.parse(qualifiedName);
+ }
+
+ public RouteParamDescriptor withValue(String value)
+ {
this.value = value;
+ return this;
}
- public QualifiedName getName()
+ public QualifiedName getQualifiedName()
{
- return name;
+ return qualifiedName;
}
public String getValue()
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -19,6 +19,8 @@
package org.exoplatform.web.controller.metadata;
+import org.exoplatform.web.controller.router.Router;
+
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +41,7 @@
this.routes = new ArrayList<RouteDescriptor>();
}
- public RouterDescriptor addRoute(RouteDescriptor controller)
+ public RouterDescriptor add(RouteDescriptor controller)
{
if (controller == null)
{
@@ -57,4 +59,9 @@
{
return routes;
}
+
+ public Router build()
+ {
+ return new Router(this);
+ }
}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RequestParam.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RequestParam.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RequestParam.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -52,12 +52,12 @@
//
Pattern matchValue = null;
- if (descriptor.getMatchValue() != null)
+ if (descriptor.getValue() != null)
{
PatternBuilder matchValueBuilder = new PatternBuilder();
matchValueBuilder.expr("^");
int level = 0;
- for (char c : descriptor.getMatchValue().toCharArray())
+ for (char c : descriptor.getValue().toCharArray())
{
switch (c)
{
@@ -91,8 +91,8 @@
}
//
- this.name = descriptor.getName();
- this.matchName = descriptor.getMatchName();
+ this.name = descriptor.getQualifiedName();
+ this.matchName = descriptor.getName();
this.matchValue = matchValue;
this.required = descriptor.isRequired();
}
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-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -529,14 +529,14 @@
Map<QualifiedName, RouteParam> routeParams = new HashMap<QualifiedName,
RouteParam>();
for (RouteParamDescriptor routeParamDesc : descriptor.getRouteParams())
{
- routeParams.put(routeParamDesc.getName(), new
RouteParam(routeParamDesc.getName(), routeParamDesc.getValue()));
+ routeParams.put(routeParamDesc.getQualifiedName(), new
RouteParam(routeParamDesc.getQualifiedName(), routeParamDesc.getValue()));
}
//
Map<String, RequestParam> requestParams = new HashMap<String,
RequestParam>();
for (RequestParamDescriptor requestParamDesc : descriptor.getRequestParams())
{
- requestParams.put(requestParamDesc.getMatchName(), new
RequestParam(requestParamDesc));
+ requestParams.put(requestParamDesc.getName(), new
RequestParam(requestParamDesc));
}
//
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-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -21,8 +21,7 @@
import junit.framework.TestCase;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteDescriptor;
-import org.exoplatform.web.controller.metadata.RouterDescriptor;
+import static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -36,9 +35,7 @@
String[] paths = {"/",""};
for (String path : paths)
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor(path));
- Router router = new Router(routerMD);
+ Router router = new Router(router().add(route(path)));
Route expectedRoute = new Route();
assertEquals(expectedRoute, router.root);
}
@@ -49,9 +46,7 @@
String[] paths = {"/a","a"};
for (String path : paths)
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor(path));
- Router router = new Router(routerMD);
+ Router router = new Router(router().add(route(path)));
Route expectedRoute = new Route();
expectedRoute.add(new SegmentRoute("a"));
assertEquals(expectedRoute, router.root);
@@ -63,9 +58,7 @@
String[] paths = {"/{a}","{a}"};
for (String path : paths)
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor(path));
- Router router = new Router(routerMD);
+ Router router = new Router(router().add(route(path)));
//
assertEquals(0, router.root.getSegmentNames().size());
@@ -87,9 +80,7 @@
String[] paths = {"/{q:a}","{q:a}"};
for (String path : paths)
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor(path));
- Router router = new Router(routerMD);
+ Router router = new Router(router().add(route(path)));
//
assertEquals(0, router.root.getSegmentNames().size());
@@ -111,9 +102,7 @@
String[] paths = {"/{a}","{a}"};
for (String path : paths)
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor(path).addPathParam(QualifiedName.parse("a"), ".*",
EncodingMode.FORM));
- Router router = new Router(routerMD);
+ Router router = new
Router(router().add(route(path).add(pathParam("a").withPattern(".*"))));
//
assertEquals(0, router.root.getSegmentNames().size());
@@ -132,12 +121,7 @@
public void testSamePrefix()
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/public/foo"));
- routerMD.addRoute(new RouteDescriptor("/public/bar"));
-
- //
- Router router = new Router(routerMD);
+ Router router =
router().add(route("/public/foo")).add(route("/public/bar")).build();
assertEquals(2, router.root.getSegmentSize("public"));
Route publicRoute1 = router.root.getSegment("public", 0);
assertEquals(1, publicRoute1.getSegmentSize("foo"));
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -55,10 +55,10 @@
RouteDescriptor route1 = i.next();
assertEquals("/public/{gtn:sitetype}/{gtn:sitename}{gtn:path}",
route1.getPath());
assertEquals(Collections.singleton(WebAppController.HANDLER_PARAM),
route1.getRouteParamNames());
- assertEquals(WebAppController.HANDLER_PARAM,
route1.getRouteParam(WebAppController.HANDLER_PARAM).getName());
+ assertEquals(WebAppController.HANDLER_PARAM,
route1.getRouteParam(WebAppController.HANDLER_PARAM).getQualifiedName());
assertEquals("portal",
route1.getRouteParam(WebAppController.HANDLER_PARAM).getValue());
assertEquals(Collections.singleton(QualifiedName.parse("gtn:path")),
route1.getPathParams().keySet());
- assertEquals(QualifiedName.parse("gtn:path"),
route1.getPathParams().get(QualifiedName.parse("gtn:path")).getName());
+ assertEquals(QualifiedName.parse("gtn:path"),
route1.getPathParams().get(QualifiedName.parse("gtn:path")).getQualifiedName());
assertEquals(".*",
route1.getPathParams().get(QualifiedName.parse("gtn:path")).getPattern());
assertEquals(EncodingMode.FORM,
route1.getPathParams().get(QualifiedName.parse("gtn:path")).getEncodingMode());
@@ -67,10 +67,10 @@
RouteDescriptor route2 = i.next();
assertEquals("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}",
route2.getPath());
assertEquals(Collections.singleton(WebAppController.HANDLER_PARAM),
route2.getRouteParamNames());
- assertEquals(WebAppController.HANDLER_PARAM,
route2.getRouteParam(WebAppController.HANDLER_PARAM).getName());
+ assertEquals(WebAppController.HANDLER_PARAM,
route2.getRouteParam(WebAppController.HANDLER_PARAM).getQualifiedName());
assertEquals("portal",
route2.getRouteParam(WebAppController.HANDLER_PARAM).getValue());
assertEquals(Collections.singleton(QualifiedName.parse("gtn:path")),
route2.getPathParams().keySet());
- assertEquals(QualifiedName.parse("gtn:path"),
route2.getPathParams().get(QualifiedName.parse("gtn:path")).getName());
+ assertEquals(QualifiedName.parse("gtn:path"),
route2.getPathParams().get(QualifiedName.parse("gtn:path")).getQualifiedName());
assertEquals(".*",
route2.getPathParams().get(QualifiedName.parse("gtn:path")).getPattern());
assertEquals(EncodingMode.PRESERVE_PATH,
route2.getPathParams().get(QualifiedName.parse("gtn:path")).getEncodingMode());
@@ -79,7 +79,7 @@
RouteDescriptor route3 = i.next();
assertEquals("/upload", route3.getPath());
assertEquals(Collections.singleton(WebAppController.HANDLER_PARAM),
route3.getRouteParamNames());
- assertEquals(WebAppController.HANDLER_PARAM,
route3.getRouteParam(WebAppController.HANDLER_PARAM).getName());
+ assertEquals(WebAppController.HANDLER_PARAM,
route3.getRouteParam(WebAppController.HANDLER_PARAM).getQualifiedName());
assertEquals("upload",
route3.getRouteParam(WebAppController.HANDLER_PARAM).getValue());
//
@@ -87,7 +87,7 @@
RouteDescriptor route4 = i.next();
assertEquals("/download", route4.getPath());
assertEquals(Collections.singleton(WebAppController.HANDLER_PARAM),
route4.getRouteParamNames());
- assertEquals(WebAppController.HANDLER_PARAM,
route4.getRouteParam(WebAppController.HANDLER_PARAM).getName());
+ assertEquals(WebAppController.HANDLER_PARAM,
route4.getRouteParam(WebAppController.HANDLER_PARAM).getQualifiedName());
assertEquals("download",
route4.getRouteParam(WebAppController.HANDLER_PARAM).getValue());
//
@@ -95,13 +95,13 @@
RouteDescriptor route5 = i.next();
assertEquals("/a", route5.getPath());
assertEquals(Collections.singleton(QualifiedName.create("a")),
route5.getRouteParamNames());
- assertEquals(QualifiedName.create("a"),
route5.getRouteParam(QualifiedName.create("a")).getName());
+ assertEquals(QualifiedName.create("a"),
route5.getRouteParam(QualifiedName.create("a")).getQualifiedName());
assertEquals("a_value",
route5.getRouteParam(QualifiedName.create("a")).getValue());
assertEquals(1, route5.getChildren().size());
RouteDescriptor route5_1 = route5.getChildren().get(0);
assertEquals("/b", route5_1.getPath());
assertEquals(Collections.singleton(QualifiedName.create("b")),
route5_1.getRouteParamNames());
- assertEquals(QualifiedName.create("b"),
route5_1.getRouteParam(QualifiedName.create("b")).getName());
+ assertEquals(QualifiedName.create("b"),
route5_1.getRouteParam(QualifiedName.create("b")).getQualifiedName());
assertEquals("b_value",
route5_1.getRouteParam(QualifiedName.create("b")).getValue());
//
@@ -109,17 +109,17 @@
RouteDescriptor route6 = i.next();
assertEquals("/b", route6.getPath());
assertEquals(new HashSet<String>(Arrays.asList("foo",
"bar", "juu")), route6.getRequestParamMatchNames());
- assertEquals(QualifiedName.parse("foo"),
route6.getRequestParam("foo").getName());
- assertEquals("foo",
route6.getRequestParam("foo").getMatchName());
- assertEquals(null, route6.getRequestParam("foo").getMatchValue());
+ assertEquals(QualifiedName.parse("foo"),
route6.getRequestParam("foo").getQualifiedName());
+ assertEquals("foo", route6.getRequestParam("foo").getName());
+ assertEquals(null, route6.getRequestParam("foo").getValue());
assertEquals(false, route6.getRequestParam("foo").isRequired());
- assertEquals(QualifiedName.parse("bar"),
route6.getRequestParam("bar").getName());
- assertEquals("bar",
route6.getRequestParam("bar").getMatchName());
- assertEquals("bar",
route6.getRequestParam("bar").getMatchValue());
+ assertEquals(QualifiedName.parse("bar"),
route6.getRequestParam("bar").getQualifiedName());
+ assertEquals("bar", route6.getRequestParam("bar").getName());
+ assertEquals("bar", route6.getRequestParam("bar").getValue());
assertEquals(false, route6.getRequestParam("bar").isRequired());
- assertEquals(QualifiedName.parse("juu"),
route6.getRequestParam("juu").getName());
- assertEquals("juu",
route6.getRequestParam("juu").getMatchName());
- assertEquals("juu",
route6.getRequestParam("juu").getMatchValue());
+ assertEquals(QualifiedName.parse("juu"),
route6.getRequestParam("juu").getQualifiedName());
+ assertEquals("juu", route6.getRequestParam("juu").getName());
+ assertEquals("juu", route6.getRequestParam("juu").getValue());
assertEquals(true, route6.getRequestParam("juu").isRequired());
//
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
import java.util.HashMap;
@@ -36,15 +35,12 @@
public void testFoo() throws Exception
{
+ Router router = router().
+
add(route("/a").add(routeParam("foo").withValue("bar")).
+
add(route("/b").add(routeParam("juu").withValue("daa")))).
+ build();
- RouteDescriptor descriptor = new RouteDescriptor("/a").
- addRouteParam("foo", "bar").
- addRoute(new RouteDescriptor("/b").addRouteParam("juu",
"daa"));
-
//
- Router router = new Router(new RouterDescriptor().addRoute(descriptor));
-
- //
assertEquals(Collections.singletonMap(QualifiedName.create("foo"),
"bar"), router.route("/a"));
//
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -21,8 +21,7 @@
import junit.framework.TestCase;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteDescriptor;
-import org.exoplatform.web.controller.metadata.RouterDescriptor;
+import static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
import java.util.HashMap;
@@ -41,27 +40,19 @@
@Override
protected void setUp() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
-
- RouteDescriptor portal = new RouteDescriptor("/").
- addRouteParam(QualifiedName.parse("gtn:handler"),
"portal").
- addRequestParam(QualifiedName.parse("gtn:componentid"),
"portal:componentId", null, false).
- addRequestParam(QualifiedName.parse("gtn:action"),
"portal:action", null, false).
- addRequestParam(QualifiedName.parse("gtn:objectid"),
"portal:objectId", null, false).
- addRoute(
- new RouteDescriptor("/public/{gtn:sitename}{gtn:path}").
- addRouteParam(QualifiedName.parse("gtn:access"),
"public")).
- addPathParam(QualifiedName.parse("gtn:path"), ".*",
EncodingMode.PRESERVE_PATH).
- addRoute(
- new RouteDescriptor("/private/{gtn:sitename}{gtn:path}").
- addPathParam(QualifiedName.parse("gtn:path"), ".*",
EncodingMode.PRESERVE_PATH).
- addRouteParam(QualifiedName.parse("gtn:access"),
"private"));
-
- //
- routerMD.addRoute(portal);
-
- //
- this.router = new Router(routerMD);
+ this.router = router().
+ add(route("/").
+ add(routeParam("gtn:handler").withValue("portal")).
+
add(requestParam("gtn:componentid").withName("portal:componentId")).
+
add(requestParam("gtn:action").withName("portal:action")).
+
add(requestParam("gtn:objectid").withName("portal:objectId")).
+ add(route("/public/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:access").withValue("public")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath())).
+ add(route("/private/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:access").withValue("private")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath()))).
+ build();
}
public void testPrivateClassicComponent() throws Exception
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-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
import java.util.HashMap;
@@ -36,9 +35,7 @@
public void testRoot() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/")).build();
//
assertNull(router.route(""));
@@ -49,9 +46,7 @@
public void testA() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/a"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/a")).build();
//
assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.route("/a"));
@@ -67,9 +62,7 @@
public void testAB() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/a/b"));
- Router router = new Router( routerMD);
+ Router router = router().add(route("/a/b")).build();
//
assertNull(router.route("a/b"));
@@ -85,9 +78,7 @@
public void testParameter() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/{p}"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/{p}")).build();
//
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
@@ -95,10 +86,9 @@
public void testParameterPropagationToDescendants() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/").addRouteParam("p",
"a"));
- routerMD.addRoute(new RouteDescriptor("/a"));
- Router router = new Router(routerMD);
+ Router router = router().
+
add(route("/").add(routeParam("p").withValue("a"))).
+ add(route("/a")).build();
//
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
@@ -106,9 +96,7 @@
public void testSimplePattern() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"a", EncodingMode.FORM));
- Router router = new Router(routerMD);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern("a"))).build();
//
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"a"), router.route("/a"));
@@ -119,10 +107,10 @@
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"));
- Router router = new Router(routerMD);
+ Router router = router().
+ add(route("/a")).
+
add(route("/{p}/b").add(pathParam("p").withPattern("a"))).
+ build();
//
assertNull(router.route("a"));
@@ -133,10 +121,10 @@
public void testTwoRules1() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/a").addRouteParam("b",
"b"));
- routerMD.addRoute(new RouteDescriptor("/a/b"));
- Router router = new Router(routerMD);
+ Router router = router().
+
add(route("/a").add(routeParam("b").withValue("b"))).
+ add(route("/a/b")).
+ build();
//
assertEquals(Collections.singletonMap(QualifiedName.create("b"),
"b"), router.route("/a"));
@@ -145,10 +133,10 @@
public void testTwoRules2() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{a}").addRouteParam("b", "b"));
- routerMD.addRoute(new RouteDescriptor("/{a}/b"));
- Router router = new Router(routerMD);
+ Router router = router().
+
add(route("/{a}").add(routeParam("b").withValue("b"))).
+ add(route("/{a}/b")).
+ build();
//
Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
@@ -160,9 +148,9 @@
public void testLang() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(([A-Za-z]{2})/)?", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
+ Router router = router().
+
add(route("/{a}b").add(pathParam("a").withPattern("(([A-Za-z]{2})/)?").preservingPath())).
+ build();
//
assertEquals(Collections.singletonMap(QualifiedName.create("a"),
"fr/"), router.route("/fr/b"));
Modified:
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 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
@@ -34,9 +33,7 @@
public void testDefaultForm() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".+", EncodingMode.FORM));
- Router router = new Router(routerMD);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern(".+"))).build();
// Route
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/"), router.route("/_"));
@@ -47,9 +44,7 @@
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);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern("[^/]+").preservingPath())).build();
// Route
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"_"), router.route("/_"));
@@ -61,10 +56,10 @@
public void testD() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/{p}").
- addPathParam(QualifiedName.parse("p"), "/[a-z]+/[a-z]+/?",
EncodingMode.FORM));
- Router router = new Router(routerMD);
+ Router router = router().
+ add(route("/{p}").
+ add(pathParam("p").withPattern("/[a-z]+/[a-z]+/?"))).
+ build();
// Route
assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/platform/administrator"),
router.route("/_platform_administrator"));
@@ -80,9 +75,7 @@
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);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern(".*").preservingPath())).build();
// Render
assertEquals("/",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"")));
@@ -99,9 +92,7 @@
public void testWildcardParamPathWithDefaultForm() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".*", EncodingMode.FORM));
- Router router = new Router(routerMD);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern(".*"))).build();
//
assertEquals("/_",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,7 +20,8 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
+
import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.util.Collections;
@@ -34,9 +35,9 @@
public void testLanguage1() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor().addRoute(
- new RouteDescriptor("/public{gtn:lang}").addPathParam(
- QualifiedName.parse("gtn:lang"), "(/[A-Za-z][A-Za-z])?",
EncodingMode.PRESERVE_PATH)
+ RouterDescriptor routerMD = router().add(
+ route("/public{gtn:lang}").add(
+
pathParam("gtn:lang").withPattern("(/[A-Za-z][A-Za-z])?").preservingPath())
);
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(QualifiedName.parse("gtn:lang"),
""), router.route("/public"));
@@ -45,9 +46,9 @@
public void testLanguage2() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor().addRoute(
- new RouteDescriptor("/{gtn:lang}public").addPathParam(
- QualifiedName.parse("gtn:lang"), "([A-Za-z]{2}/)?",
EncodingMode.PRESERVE_PATH)
+ RouterDescriptor routerMD = router().add(
+ route("/{gtn:lang}public").add(
+
pathParam("gtn:lang").withPattern("([A-Za-z]{2}/)?").preservingPath())
);
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(QualifiedName.parse("gtn:lang"),
""), router.route("/public"));
@@ -56,11 +57,10 @@
public void testLanguage3() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor().
- addRoute(new RouteDescriptor("/public")).
- addRoute(new RouteDescriptor("/{gtn:lang}/public").
- addPathParam(QualifiedName.parse("gtn:lang"),
"([A-Za-z]{2})", EncodingMode.FORM
- )
+ RouterDescriptor routerMD = router().
+ add(route("/public")).
+ add(route("/{gtn:lang}/public").
+ add(pathParam("gtn:lang").withPattern("([A-Za-z]{2})"))
);
Router router = new Router(routerMD);
assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.route("/public"));
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-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
import java.util.HashMap;
@@ -40,35 +39,22 @@
@Override
protected void setUp() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
-
- //
- RouteDescriptor portalRouteMD = new
RouteDescriptor("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}");
- portalRouteMD.addRouteParam(QualifiedName.create("gtn",
"controller"), "site");
- portalRouteMD.addRequestParam(QualifiedName.create("gtn",
"componentid"), "portal:componentId", null, false);
- portalRouteMD.addPathParam(QualifiedName.create("gtn", "path"),
".*", EncodingMode.PRESERVE_PATH);
- routerMD.addRoute(portalRouteMD);
-
- //
- RouteDescriptor portalRouteMD2 = new
RouteDescriptor("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}");
- portalRouteMD2.addRouteParam(QualifiedName.create("gtn",
"controller"), "site");
- portalRouteMD2.addPathParam(QualifiedName.create("gtn",
"path"), ".*", EncodingMode.PRESERVE_PATH);
- routerMD.addRoute(portalRouteMD2);
-
- //
- RouteDescriptor groupRouteMD = new
RouteDescriptor("/groups/{gtn:sitetype}/{gtn:sitename}{gtn:path}");
- groupRouteMD.addRouteParam(QualifiedName.create("gtn",
"controller"), "site");
- groupRouteMD.addPathParam(QualifiedName.create("gtn", "path"),
".*", EncodingMode.PRESERVE_PATH);
- routerMD.addRoute(groupRouteMD);
-
- //
- RouteDescriptor userRouteMD = new
RouteDescriptor("/users/{gtn:sitetype}/{gtn:sitename}{gtn:path}");
- userRouteMD.addRouteParam(QualifiedName.create("gtn",
"controller"), "site");
- userRouteMD.addPathParam(QualifiedName.create("gtn", "path"),
".*", EncodingMode.PRESERVE_PATH);
- routerMD.addRoute(userRouteMD);
-
- //
- this.router = new Router(routerMD);
+ this.router = router().
+ add(route("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:controller").withValue("site")).
+ add(routeParam("gtn:controller").withValue("site")).
+
add(requestParam("gtn:componentid").withName("portal:componentId")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath())).
+ add(route("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:controller").withValue("site")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath())).
+ add(route("/groups/{gtn:sitetype}/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:controller").withValue("site")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath())).
+ add(route("/users/{gtn:sitetype}/{gtn:sitename}{gtn:path}").
+ add(routeParam("gtn:controller").withValue("site")).
+
add(pathParam("gtn:path").withPattern(".*").preservingPath())).
+ build();
}
public void testComponent() throws Exception
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-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
@@ -34,9 +33,7 @@
public void testRoot() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/")).build();
//
assertEquals("/", router.render(Collections.<QualifiedName,
String>emptyMap()));
@@ -44,9 +41,7 @@
public void testA() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/a"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/a")).build();
//
assertEquals("/a", router.render(Collections.<QualifiedName,
String>emptyMap()));
@@ -54,9 +49,7 @@
public void testAB() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/a/b"));
- Router router = new Router( routerMD);
+ Router router = router().add(route("/a/b")).build();
//
assertEquals("/a/b", router.render(Collections.<QualifiedName,
String>emptyMap()));
@@ -64,9 +57,7 @@
public void testPathParam() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new RouteDescriptor("/{p}"));
- Router router = new Router(routerMD);
+ Router router = router().add(route("/{p}")).build();
//
assertEquals("/a",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a")));
@@ -75,9 +66,7 @@
public void testSimplePatternPathParam() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"a"));
- Router router = new Router(routerMD);
+ Router router =
router().add(route("/{p}").add(pathParam("p").withPattern("a"))).build();
//
assertEquals("/a",
router.render(Collections.singletonMap(QualifiedName.create("p"),
"a")));
@@ -86,10 +75,11 @@
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"));
- Router router = new Router(routerMD);
+ Router router = router().
+ add(route("/a")).
+ add(route("/{p}/b").
+ add(pathParam("p").withPattern("a"))).
+ build();
//
assertEquals("/a", router.render(Collections.<QualifiedName,
String>emptyMap()));
@@ -100,9 +90,10 @@
public void testLang() throws Exception
{
- RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(([A-Za-z]{2})/)?", EncodingMode.PRESERVE_PATH));
- Router router = new Router(routerMD);
+ Router router = router().
+ add(route("/{a}b").
+
add(pathParam("a").withPattern("(([A-Za-z]{2})/)?").preservingPath())).
+ build();
//
assertEquals("/fr/b",
router.render(Collections.singletonMap(QualifiedName.parse("a"),
"fr/")));
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-11-29
21:08:43 UTC (rev 5358)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-11-29
22:35:18 UTC (rev 5359)
@@ -20,8 +20,7 @@
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 static org.exoplatform.web.controller.metadata.DescriptorBuilder.*;
import java.util.Collections;
import java.util.HashMap;
@@ -36,9 +35,7 @@
public void testRoot() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true));
- Router router = new Router(descriptor);
+ Router router =
router().add(route("/").add(requestParam("foo").withName("a").withValue("a").required())).build();
//
assertNull(router.route("/"));
@@ -54,9 +51,7 @@
public void testSegment() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true));
- Router router = new Router(descriptor);
+ Router router =
router().add(route("/a").add(requestParam("foo").withName("a").withValue("a").required())).build();
//
assertNull(router.route("/a"));
@@ -72,9 +67,7 @@
public void testValuePattern() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "{[0-9]+}", true));
- Router router = new Router(descriptor);
+ Router router =
router().add(route("/a").add(requestParam("foo").withName("a").withValue("{[0-9]+}").required())).build();
//
assertNull(router.route("/a"));
@@ -92,10 +85,10 @@
public void testPrecedence() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true));
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("bar"),
"b", "b", true));
- Router router = new Router(descriptor);
+ Router router = router().
+
add(route("/a").add(requestParam("foo").withName("a").withValue("a").required())).
+
add(route("/a").add(requestParam("bar").withName("b").withValue("b").required())).
+ build();
//
assertNull(router.route("/a"));
@@ -116,9 +109,11 @@
public void testInheritance() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true).addRoute(new
RouteDescriptor("/b").addRequestParam(QualifiedName.parse("bar"),
"b", "b", true)));
- Router router = new Router(descriptor);
+ Router router = router().add(route("/a").
+
add(requestParam("foo").withName("a").withValue("a").required()).
+ add(route("/b").
+
add(requestParam("bar").withName("b").withValue("b").required()))).
+ build();
//
assertNull(router.route("/a"));
@@ -149,9 +144,8 @@
public void testOptional() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/").addRequestParam(QualifiedName.parse("foo"),
"a", "a", false));
- Router router = new Router(descriptor);
+ Router router = router().add(route("/").
+
add(requestParam("foo").withName("a").withValue("a"))).build();
//
assertEquals(Collections.<QualifiedName, String>emptyMap(),
router.route("/", Collections.<String, String[]>emptyMap()));
@@ -170,14 +164,12 @@
public void testMatchDescendantOfRootParameters() throws Exception
{
- RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.
- addRoute(new RouteDescriptor("/").
- addRequestParam(QualifiedName.parse("foo"), "a",
"a", false).
- addRoute(new RouteDescriptor("/a").
- addRequestParam(QualifiedName.parse("bar"), "b",
"b", false))
- );
- Router router = new Router(descriptor);
+ Router router = router().
+ add(route("/").
+
add(requestParam("foo").withName("a").withValue("a")).
+ add(route("/a").
+
add(requestParam("bar").withName("b").withValue("b")))
+ ).build();
//
SimpleRenderContext renderContext = new SimpleRenderContext();