cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1095025 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Date Tue, 19 Apr 2011 10:54:21 GMT
Author: sergeyb
Date: Tue Apr 19 10:54:21 2011
New Revision: 1095025

URL: http://svn.apache.org/viewvc?rev=1095025&view=rev
Log:
Merged revisions 1094992 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1094992 | sergeyb | 2011-04-19 11:14:37 +0100 (Tue, 19 Apr 2011) | 1 line
  
  [CXF-3460] Updating WebClient with methods simplifying the replacement of query and path
values
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Apr 19 10:54:21 2011
@@ -1 +1 @@
-/cxf/trunk:1094926
+/cxf/trunk:1094926,1094992

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1095025&r1=1095024&r2=1095025&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Tue Apr 19 10:54:21 2011
@@ -499,11 +499,48 @@ public class WebClient extends AbstractC
     }
     
     /**
+     * Replaces the current path with the new value.
+     * @param path new path value. If it starts from "/" then all the current
+     * path starting from the base URI will be replaced, otherwise only the 
+     * last path segment will be replaced. Providing a null value is equivalent
+     * to calling back(true)  
+     * @return updated WebClient
+     */
+    public WebClient replacePath(String path) {
+        if (path == null) {
+            return back(true);
+        }
+        back(path.startsWith("/") ? true : false);
+        return path(path);
+    }
+    
+    /**
      * Resets the current query
      * @return updated WebClient
      */
     public WebClient resetQuery() {
-        getCurrentBuilder().replaceQuery(null);
+        return replaceQuery(null);
+    }
+    
+    /**
+     * Replaces the current query with the new value.
+     * @param queryString the new value, providing a null is
+     *        equivalent to calling resetQuery().  
+     * @return updated WebClient
+     */
+    public WebClient replaceQuery(String queryString) {
+        getCurrentBuilder().replaceQuery(queryString);
+        return this;
+    }
+    
+    /**
+     * Replaces the current query with the new value.
+     * @param queryString the new value, providing a null is
+     *        equivalent to calling resetQuery().  
+     * @return updated WebClient
+     */
+    public WebClient replaceQueryParam(String queryParam, Object... value) {
+        getCurrentBuilder().replaceQueryParam(queryParam, value);
         return this;
     }
     

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=1095025&r1=1095024&r2=1095025&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Tue Apr 19 10:54:21 2011
@@ -164,6 +164,45 @@ public class WebClientTest extends Asser
     }
     
     @Test
+    public void testReplaceQuery() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        wc.path("bar").path("baz").query("foo", "bar");
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo/bar/baz?foo=bar"), wc.getCurrentURI());
+        wc.replaceQuery("foo1=bar1");
+        assertEquals(URI.create("http://foo/bar/baz?foo1=bar1"), wc.getCurrentURI());
+    }
+    
+    @Test
+    public void testReplaceQueryParam() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        wc.path("bar").path("baz").query("foo", "bar").query("foo1", "bar1");
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo/bar/baz?foo=bar&foo1=bar1"), wc.getCurrentURI());
+        wc.replaceQueryParam("foo1", "baz");
+        assertEquals(URI.create("http://foo/bar/baz?foo=bar&foo1=baz"), wc.getCurrentURI());
+    }
+    
+    @Test
+    public void testReplacePathAll() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        wc.path("bar").path("baz");
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo/bar/baz"), wc.getCurrentURI());
+        wc.replacePath("/new");
+        assertEquals(URI.create("http://foo/new"), wc.getCurrentURI());
+    }
+    @Test
+    public void testReplacePathLastSegment() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        wc.path("bar").path("baz");
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo/bar/baz"), wc.getCurrentURI());
+        wc.replacePath("new");
+        assertEquals(URI.create("http://foo/bar/new"), wc.getCurrentURI());
+    }
+    
+    @Test
     public void testFragment() {
         WebClient wc = WebClient.create(URI.create("http://foo"));
         wc.path("bar").path("baz").query("foo", "bar").fragment("1");



Mime
View raw message