abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r660609 - in /incubator/abdera/java/trunk/server/src: main/java/org/apache/abdera/protocol/server/impl/ test/java/org/apache/abdera/protocol/server/test/customer/ test/java/org/apache/abdera/protocol/server/test/route/
Date Tue, 27 May 2008 17:07:53 GMT
Author: jmsnell
Date: Tue May 27 10:07:47 2008
New Revision: 660609

URL: http://svn.apache.org/viewvc?rev=660609&view=rev
Log:
https://issues.apache.org/jira/browse/ABDERA-162 - "RouteManager.urlFor shouldn't read params
from request"

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/customer/CustomerAdapterTest.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=660609&r1=660608&r2=660609&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
Tue May 27 10:07:47 2008
@@ -143,27 +143,13 @@
     Object key, 
     Object param) {
     Route route = routes.get(key);
-    if (route != null) {
-      Map<String, Object> map = new HashMap<String,Object>();
-      Context ctx = getContext(param);
-      for (String var : ctx) {
-        map.put(var, ctx.resolve(var));
-      }
-      for (String var : route.getVariables()) {
-        Object value = context.getTarget().getParameter(var);
-        if (!map.containsKey(var) && value != null) {
-          map.put(var, value);
-        }
-      }            
-      return context.getContextPath() + route.expand(getContext(map));
-    } else {
-      return null;
-    }
+		return route != null?
+    	context.getContextPath() + route.expand(getContext(param)) : null;
   }
   
   @SuppressWarnings("unchecked")
   private Context getContext(Object param) {
-    Context context = null;
+    Context context = new EmptyContext();
     if (param != null) {
       if (param instanceof Map) {
         context = new HashMapContext(cleanMapCtx(param), true);
@@ -172,7 +158,7 @@
       } else {
         context = new ObjectContext(param,true);
       }
-    } else context = new EmptyContext();
+    }
     return context;
   }
   

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java?rev=660609&r1=660608&r2=660609&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
Tue May 27 10:07:47 2008
@@ -86,22 +86,6 @@
     runTests("/foo/");
   }
 
-  @Test
-  public void testCustomerProviderWithNonRootBase() throws Exception {
-    setupAbdera("/:base/");
-    initializeJetty("/");
-
-    runTests("/base/");
-  }
-
-  @Test
-  public void testCustomerProviderWithNonRootContextBaseAndBase() throws Exception {
-    setupAbdera("/:base/");
-    initializeJetty("/foo");
-
-    runTests("/foo/base/");
-  }
-
   private void runTests(String base) throws IOException {
     Abdera abdera = new Abdera();
     Factory factory = abdera.getFactory();
@@ -158,7 +142,7 @@
     res = client.post(colUri.toString() + "?test=foo", entry, opts);
     assertEquals(201, res.getStatus());
 
-    prettyPrint(abdera, res.getDocument());
+    //prettyPrint(abdera, res.getDocument());
 
     IRI location = res.getLocation();
     assertEquals(base + "customers/1001-Dan_Diephouse", location.toString());
@@ -170,7 +154,7 @@
 
     // prettyPrint(abdera, res.getDocument());
     org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
-    prettyPrint(abdera, entry_doc);
+    //prettyPrint(abdera, entry_doc);
     entry = entry_doc.getRoot();
     assertEquals(uri + "customers/1001-Dan_Diephouse", entry_doc.getRoot().getEditLinkResolvedHref().toString());
 

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=660609&r1=660608&r2=660609&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
Tue May 27 10:07:47 2008
@@ -177,37 +177,36 @@
   }
     
   @Test
+	@SuppressWarnings("serial")
   public void testUrlFor() throws Exception {
-    RouteManager manager = new RouteManager().addRoute(new Route("entry", "/base/:collection/:entry"));
-
-    Target targetMock = createMock(Target.class);
-    expect(targetMock.getParameter("collection")).andReturn("entries");
-    expect(targetMock.getParameter("entry")).andReturn("123");
-    replay(targetMock);
-    RequestContext contextMock = createMock(RequestContext.class);
-    expect(contextMock.getContextPath()).andReturn("/app");
-    expect(contextMock.getTarget()).andReturn(targetMock).times(2);
-    replay(contextMock);
-
-    assertEquals("/app/base/entries/123", manager.urlFor(contextMock, "entry", null));
+		Map<String, String> context = new HashMap<String, String>() {{
+			put("entry", "123");
+		}};
+    runTestUrlFor("/app/base/123", context);
   }
   
   @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);
-
+  public void testUrlForSupportsParamsWithColon() throws Exception {
     Map<String, String> context = new HashMap<String, String>() {{
     	put(":entry", null);
     }};
-    assertEquals("/app/base/", manager.urlFor(contextMock, "entry", context));
+    runTestUrlFor("/app/base/", context);
   }
+
+	@Test
+	@SuppressWarnings("serial")
+	public void testUrlForEmptyContext() throws Exception {
+		runTestUrlFor("/app/base/", null);
+	}
+	
+	private void runTestUrlFor(String expected, Map<String, String> context) {
+		RouteManager manager = new RouteManager().addRoute(new Route("entry", "/base/:entry"));
+
+    RequestContext request = createMock(RequestContext.class);
+    expect(request.getContextPath()).andReturn("/app");
+    replay(request);
+
+		assertEquals(expected, manager.urlFor(request, "entry", context));
+	}
 }



Mime
View raw message