abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r657158 - in /incubator/abdera/java/trunk/server/src: main/java/org/apache/abdera/protocol/server/impl/RouteManager.java test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
Date Fri, 16 May 2008 18:36:13 GMT
Author: jmsnell
Date: Fri May 16 11:36:13 2008
New Revision: 657158

URL: http://svn.apache.org/viewvc?rev=657158&view=rev
Log:
https://issues.apache.org/jira/browse/ABDERA-161 - Route context doesn't support params that
start with ":"

Technically speaking, this is not a bug since the : in the route is not part of the parameter
name.  However, in the spirit of "be liberal in what you accept", this is fine.

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java?rev=657158&r1=657157&r2=657158&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
Fri May 16 11:36:13 2008
@@ -166,7 +166,7 @@
     Context context = null;
     if (param != null) {
       if (param instanceof Map) {
-        context = new HashMapContext((Map<String,Object>)param, true);
+        context = new HashMapContext(cleanMapCtx(param), true);
       } else if (param instanceof Context) {
         context = (Context)param;
       } else {
@@ -175,6 +175,17 @@
     } else context = new EmptyContext();
     return context;
   }
+  
+  @SuppressWarnings("unchecked")
+  private Map<String, Object> cleanMapCtx(Object param) {
+	  Map<String, Object> map = new HashMap<String, Object>();
+	  for (Map.Entry<String, Object> entry : ((Map<String,Object>) param).entrySet())
{
+		  map.put(entry.getKey().replaceFirst("^:", ""), entry.getValue());		  
+	  }
+	  ((Map<String,Object>) param).clear();
+	  ((Map<String,Object>) param).putAll(map);
+	  return (Map<String,Object>) param;
+  }
 
   private static class EmptyContext 
     extends CachingContext {

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java?rev=657158&r1=657157&r2=657158&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
Fri May 16 11:36:13 2008
@@ -17,9 +17,9 @@
  */
 package org.apache.abdera.protocol.server.test.route;
 
+import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.createMock;
-import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.EasyMock.replay;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -30,7 +30,6 @@
 import org.apache.abdera.i18n.templates.Route;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.Target;
-import org.apache.abdera.protocol.server.context.RequestContextWrapper;
 import org.apache.abdera.protocol.server.impl.RouteManager;
 import org.junit.Test;
 
@@ -185,11 +184,30 @@
     expect(targetMock.getParameter("collection")).andReturn("entries");
     expect(targetMock.getParameter("entry")).andReturn("123");
     replay(targetMock);
-    RequestContext contextMock = createMock(RequestContextWrapper.class);
-    expect(contextMock.getContextPath()).andReturn("/appBase");
+    RequestContext contextMock = createMock(RequestContext.class);
+    expect(contextMock.getContextPath()).andReturn("/app");
     expect(contextMock.getTarget()).andReturn(targetMock).times(2);
     replay(contextMock);
 
-    assertEquals(manager.urlFor(contextMock, "entry", null), "/appBase/base/entries/123");
+    assertEquals("/app/base/entries/123", manager.urlFor(contextMock, "entry", null));
+  }
+  
+  @Test
+  @SuppressWarnings("serial")
+  public void testUrlForNotAddQueryParams() throws Exception {
+    RouteManager manager = new RouteManager().addRoute("entry", "/base/:entry");
+
+    Target targetMock = createMock(Target.class);    
+    expect(targetMock.getParameter("entry")).andReturn(null);    
+    replay(targetMock);
+    RequestContext contextMock = createMock(RequestContext.class);
+    expect(contextMock.getContextPath()).andReturn("/app");
+    expect(contextMock.getTarget()).andReturn(targetMock).times(2);    
+    replay(contextMock);
+
+    Map<String, String> context = new HashMap<String, String>() {{
+    	put(":entry", null);
+    }};
+    assertEquals("/app/base/", manager.urlFor(contextMock, "entry", context));
   }
 }



Mime
View raw message