abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r711278 - in /incubator/abdera/java/trunk: dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
Date Tue, 04 Nov 2008 15:54:02 GMT
Author: calavera
Date: Tue Nov  4 07:54:01 2008
New Revision: 711278

URL: http://svn.apache.org/viewvc?rev=711278&view=rev
Log:
[ABDERA-139]: routes requirements are never used

now they can be used to check parameter formats  with regular expressions, you can take a
look at the test case.

Modified:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java?rev=711278&r1=711277&r2=711278&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
Tue Nov  4 07:54:01 2008
@@ -124,7 +124,7 @@
    * Returns true if the given uri matches the route pattern
    */
   public boolean match(String uri) {
-    return regexMatch.matcher(uri).matches();
+    return regexMatch.matcher(uri).matches() && matchRequirements(uri);
   }
   
   /**
@@ -308,5 +308,19 @@
       throw new IllegalArgumentException("No Route provided");
     }
   }
+  
+  private boolean matchRequirements(String uri) {
+	  if (requirements != null && !requirements.isEmpty()) {
+		  Map<String, String> parsedUri = parse(uri);
+		  for (Map.Entry<String, String> requirement : requirements.entrySet()) {
+			Pattern patt = Pattern.compile(requirement.getValue());
+			if (parsedUri.containsKey(requirement.getKey()) && 
+					!patt.matcher(parsedUri.get(requirement.getKey())).matches()) {
+				return false;
+			}
+		  }
+	  }
+	  return true;
+  }
 
 }

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=711278&r1=711277&r2=711278&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 Nov  4 07:54:01 2008
@@ -225,4 +225,24 @@
 	    RouteTarget target = (RouteTarget) manager.resolve(request);
 	    assertEquals("/openSearch.xml", target.getRoute().getPattern());
 	}
+	
+	@Test	
+	public void testRouteRequirementsMatches() {		
+		Route route = getRouteWithRequirements();
+		assertTrue(route.match("/base/collection/1234"));
+	}
+		
+	@Test	
+	public void testRouteRequirementsNotMatch() throws Exception {
+		Route route = getRouteWithRequirements();
+		assertFalse(route.match("/base/collection/entry"));
+	}
+		
+	@SuppressWarnings("serial")
+	private Route getRouteWithRequirements() {
+		Map<String, String> requirements = new HashMap<String, String>() {{
+			put("entry", "\\d+");
+		}};
+		return new Route("entry", "/base/:collection/:entry", null, requirements);
+	}
 }



Mime
View raw message