cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r983419 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/model/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/impl/ test/java/org/apache/cxf/jaxrs/model/
Date Sun, 08 Aug 2010 14:53:26 GMT
Author: sergeyb
Date: Sun Aug  8 14:53:25 2010
New Revision: 983419

URL: http://svn.apache.org/viewvc?rev=983419&view=rev
Log:
Enabling some of disabled UriBuilderImpl tests

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=983419&r1=983418&r2=983419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Sun Aug  8 14:53:25 2010
@@ -45,7 +45,7 @@ public class UriBuilderImpl extends UriB
 
     private String scheme;
     private String userInfo;
-    private int port;
+    private int port = -1;
     private String host;
     private List<PathSegment> paths = new ArrayList<PathSegment>();
     private boolean leadingSlash;
@@ -89,7 +89,6 @@ public class UriBuilderImpl extends UriB
                     theQuery = substituteVarargs(queryTempl, values, values.length - lengthDiff);
                 }
             }
-            
             return buildURI(fromEncoded, thePath, theQuery);
         } catch (URISyntaxException ex) {
             throw new UriBuilderException("URI can not be built", ex);
@@ -327,6 +326,13 @@ public class UriBuilderImpl extends UriB
         if (path == null) {
             throw new IllegalArgumentException("path is null");
         }
+        // this is the cheapest way to figure out if a given path is a full-fledged 
+        // URI with the http(s) scheme but a more formal approach may be needed 
+        if (path.startsWith("http")) {
+            uri(URI.create(path));
+            return this;
+        }
+        
         if (paths.isEmpty()) {
             leadingSlash = path.startsWith("/");
         }
@@ -345,7 +351,7 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder port(int thePort) throws IllegalArgumentException {
-        if (thePort < 0) {
+        if (thePort < 0 && thePort != -1) {
             throw new IllegalArgumentException("Port cannot be negative");
         }
         this.port = thePort;
@@ -506,7 +512,7 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder replaceQuery(String queryValue) throws IllegalArgumentException {
-        query = JAXRSUtils.getStructuredParams(queryValue, "&", true);
+        query = JAXRSUtils.getStructuredParams(queryValue, "&", false);
         return this;
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=983419&r1=983418&r2=983419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Sun Aug  8 14:53:25 2010
@@ -255,7 +255,8 @@ public final class URITemplate {
                     }
                     sb.append(value);
                 } else {
-                    sb.append(var);
+                    throw new IllegalArgumentException("Template variable " + var.getName()

+                        + " has no matching value"); 
                 }
             } else {
                 sb.append(chunk);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=983419&r1=983418&r2=983419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Sun
Aug  8 14:53:25 2010
@@ -60,7 +60,9 @@ public final class HttpUtils {
     private static final String LOCAL_HOST = "localhost";
     private static final Pattern ENCODE_PATTERN = Pattern.compile("%[0-9a-fA-F][0-9a-fA-F]");
     private static final String CHARSET_PARAMETER = "charset";
-        
+    // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
+    private static final String PATH_RESERVED_DELIMETERS = "=";
+    
     private HttpUtils() {
     }
     
@@ -84,7 +86,9 @@ public final class HttpUtils {
     }
     
     public static String pathEncode(String value) {
-        
+        if (isReservedPathSequence(value)) {
+            return value;
+        }
         String result = urlEncode(value);
         // URLEncoder will encode '+' to %2B but will turn ' ' into '+'
         // We need to retain '+' and encode ' ' as %20
@@ -98,6 +102,11 @@ public final class HttpUtils {
         return result;
     }
     
+    private static boolean isReservedPathSequence(String sequence) {
+        // realistically, we'd probably need to check every character
+        return PATH_RESERVED_DELIMETERS.equals(sequence);
+    }
+    
     /**
      * Encodes partially encoded string. Encode all values but those matching pattern 
      * "percent char followed by two hexadecimal digits".

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=983419&r1=983418&r2=983419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Sun Aug  8 14:53:25 2010
@@ -808,6 +808,7 @@ public class UriBuilderImplTest extends 
             //expected
         }
     }
+    
     @Test
     public void testNullQueryParam() {
         try {
@@ -819,7 +820,6 @@ public class UriBuilderImplTest extends 
     }
 
     @Test
-    @Ignore
     public void testReplaceQuery4() {
         String expected = "http://localhost:8080";
 
@@ -827,25 +827,8 @@ public class UriBuilderImplTest extends 
             .queryParam("name", "x=", "y?", "x y", "&").replaceQuery(null).build();
         assertEquals(expected, uri.toString());        
     }
-    @Test
-    @Ignore
-    public void testReplaceQuery5() {
-        String expected = "http://localhost:8080?name1=x&name2=%20&name3=x+y&name4=23&name5=x%20y";
-
-        URI uri = UriBuilder.fromPath("http://localhost:8080")
-            .queryParam("name", "x=", "y?", "x y", "&")
-            .replaceQuery("name1=x&name2=%20&name3=x+y&name4=23&name5=x y").build();
-        assertEquals(expected, uri.toString());        
-    }
-    @Test
-    @Ignore
-    public void testQueryParam() {
-        String expected = "http://localhost:8080?name=x%3D&name=y?&name=x+y&name=%26";
-
-        URI uri =  UriBuilder.fromPath("http://localhost:8080")
-            .queryParam("name", "x=", "y?", "x y", "&").build();
-        assertEquals(expected, uri.toString());        
-    }
+    
+    
     @Test
     public void testInvalidPort() {
         try {
@@ -855,6 +838,13 @@ public class UriBuilderImplTest extends 
             //expected
         }
     }
+    
+    @Test
+    public void testResetPort() {
+        URI uri = UriBuilder.fromUri("http://localhost:8080/some/path").port(-1).build();
+        assertEquals("http://localhost/some/path", uri.toString());
+    }
+    
     @Test
     public void testInvalidHost() {
         try {
@@ -864,24 +854,18 @@ public class UriBuilderImplTest extends 
             //expected
         }
     }
+    
+    
     @Test
-    @Ignore
-    public void testFromEncoded() {
-        String expected = "http://localhost:8080/a/%25/=/%25G0/%25/=";
-
+    public void testFromEncodedDuplicateVar2() {
+        String expected = "http://localhost:8080/xy/%20/%25/xy";
         URI uri = UriBuilder.fromPath("http://localhost:8080")
-            .path("/{v}/{w}/{x}/{y}/{z}/{x}")
-            .buildFromEncoded("a", "%25", "=", "%G0", "%", "23"); 
-        assertEquals(expected, uri.toString());        
-
-        expected = "http://localhost:8080/xy/%20/%25/xy";
-        uri = UriBuilder.fromPath("http://localhost:8080")
             .path("/{x}/{y}/{z}/{x}")
             .buildFromEncoded("xy", " ", "%");
         assertEquals(expected, uri.toString());        
     }
+
     @Test
-    @Ignore
     public void testNullMapValue() {
         try {
             Map<String, String> maps = new HashMap<String, String>();
@@ -900,8 +884,8 @@ public class UriBuilderImplTest extends 
             //expected
         }
     }
+
     @Test
-    @Ignore
     public void testMissingMapValue() {
         try {
             Map<String, String> maps = new HashMap<String, String>();
@@ -920,4 +904,36 @@ public class UriBuilderImplTest extends 
             //expected
         }
     }
+    
+    @Test
+    @Ignore("This may need to be challenged, '23' overrides '=' for the 2nd occurence of
x")
+    public void testFromEncodedDuplicateVar() {
+        String expected = "http://localhost:8080/a/%25/=/%25G0/%25/=";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .path("/{v}/{w}/{x}/{y}/{z}/{x}")
+            .buildFromEncoded("a", "%25", "=", "%G0", "%", "23"); 
+        assertEquals(expected, uri.toString());        
+    }
+    
+    @Test
+    @Ignore("name2=%20 is double encoded after the replacement -> name2=%2520")
+    public void testReplaceQuery5() {
+        String expected = "http://localhost:8080?name1=x&name2=%20&name3=x+y&name4=23&name5=x%20y";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&")
+            .replaceQuery("name1=x&name2=%20&name3=x+y&name4=23&name5=x y").build();
+        assertEquals(expected, uri.toString());        
+    }
+    
+    @Test
+    @Ignore("query parameters are not encoded due to build() being called")
+    public void testQueryParam() {
+        String expected = "http://localhost:8080?name=x%3D&name=y?&name=x+y&name=%26";
+
+        URI uri =  UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&").build();
+        assertEquals(expected, uri.toString());        
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=983419&r1=983418&r2=983419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Sun Aug  8 14:53:25 2010
@@ -367,12 +367,12 @@ public class URITemplateTest extends Ass
         assertEquals("Wrong substitution", "/foo/bar/bar/bar", ut.substitute(map));
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testSubstituteMapIncomplete() throws Exception {
         URITemplate ut = new URITemplate("/foo/{a}/{b}/{a:\\d}");
         Map<String, String> map = new HashMap<String, String>();
         map.put("b", "bar");
-        assertEquals("Wrong substitution", "/foo/{a}/bar/{a:\\d}", ut.substitute(map));
+        ut.substitute(map);
     }
 
     @Test



Mime
View raw message