cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6474] Minor update to UriTemplate
Date Wed, 24 Jun 2015 10:41:02 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 9c5f2a657 -> c1387810b


[CXF-6474] Minor update to UriTemplate


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c1387810
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c1387810
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c1387810

Branch: refs/heads/master
Commit: c1387810b05a79a219a3fe89adac5e23fb8ef87f
Parents: 9c5f2a6
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Jun 24 11:40:43 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Jun 24 11:40:43 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/model/URITemplate.java |  3 +-
 .../apache/cxf/jaxrs/model/URITemplateTest.java | 35 +++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c1387810/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
index 637beb1..47ed9a6 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
@@ -188,7 +188,8 @@ public final class URITemplate {
         for (String name : variables) {
             while (i <= groupCount) {
                 String value = m.group(i++);
-                if (value == null || value.length() == 0 && i < groupCount) {
+                if ((value == null || value.length() == 0 && i < groupCount) 
+                    && variables.size() + 1 < groupCount) {
                     continue;
                 }
                 templateVariableToValue.add(name, value);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1387810/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
index 47bb62c..acfd7da 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
@@ -65,7 +65,7 @@ public class URITemplateTest extends Assert {
         String value = values.getFirst("id");
         assertEquals("123", value);
     }
-
+    
     @Test
     public void testMatchWithMatrixAndTemplate() throws Exception {
         URITemplate uriTemplate = new URITemplate("/customers/{id}");
@@ -439,6 +439,39 @@ public class URITemplateTest extends Assert {
         assertEquals("/", finalPath);
     }
     
+    @Test
+    public void testExpressionWithTwoVars() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/{tenant : [^/]*}/resource/{id}");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+        boolean match = uriTemplate.match("/t1/resource/1", values);
+        assertTrue(match);
+        String tenant = values.getFirst("tenant");
+        assertEquals("t1", tenant);
+        String id = values.getFirst("id");
+        assertEquals("1", id);
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+        
+        values.clear();
+        match = uriTemplate.match("//resource/1", values);
+        assertTrue(match);
+        tenant = values.getFirst("tenant");
+        assertEquals("", tenant);
+        id = values.getFirst("id");
+        assertEquals("1", id);
+        finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+        
+        values.clear();
+        match = uriTemplate.match("/t1/resource/1/sub", values);
+        assertTrue(match);
+        tenant = values.getFirst("tenant");
+        assertEquals("t1", tenant);
+        id = values.getFirst("id");
+        assertEquals("1", id);
+        finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/sub", finalPath);
+    }
     
     @Test
     public void testExpressionWithNestedGroupAndManySegments() throws Exception {


Mime
View raw message