This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new b12a571  MockRestClient improvements.
b12a571 is described below

commit b12a571a8ebf0173f667e14cf84ef92f687b0b05
Author: JamesBognar <james.bog...@salesforce.com>
AuthorDate: Sun May 31 19:00:33 2020 -0400

    MockRestClient improvements.
---
 .../org/apache/juneau/rest/client2/RestClient.java | 55 +++++++---------------
 .../apache/juneau/rest/client2/RestRequest.java    | 23 +++++++--
 .../apache/juneau/rest/mock2/MockRestClient.java   | 11 +++--
 .../apache/juneau/rest/mock2/MockRestRequest.java  | 11 +++--
 4 files changed, 52 insertions(+), 48 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
index 27da129..fae2f36 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
@@ -2802,46 +2802,25 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable {
                        throw new RestCallException("RestClient.close() has 
already been called.  This client cannot be reused.  Closed location stack 
trace can be displayed by setting the system property 
'org.apache.juneau.rest.client2.RestClient.trackCreation' to true.");
                }
 
-               RestRequest req = null;
-               final String methodUC = method.toUpperCase(Locale.ENGLISH);
                try {
-                       HttpRequestBase reqb = null;
-                       final URI uri = toURI(url);
-                       if (hasBody) {
-                               reqb = new HttpEntityEnclosingRequestBase() {
-                                       @Override /* HttpRequest */
-                                       public String getMethod() {
-                                               return methodUC;
-                                       }
-                               };
-                               reqb.setURI(uri);
-                               req = createRequest(reqb);
-                       } else {
-                               reqb = new HttpRequestBase() {
-                                       @Override /* HttpRequest */
-                                       public String getMethod() {
-                                               return methodUC;
-                                       }
-                               };
-                               reqb.setURI(uri);
-                               req = createRequest(reqb);
-                       }
-               } catch (URISyntaxException e1) {
-                       throw new RestCallException(e1);
-               }
+                       RestRequest req = createRequest(toURI(url), 
method.toUpperCase(Locale.ENGLISH), hasBody);
+
+                       for (Object o : headers)
+                               req.header(toHeader(o));
 
-               for (Object o : headers)
-                       req.header(toHeader(o));
+                       for (Object o : query)
+                               req.query(toQuery(o));
 
-               for (Object o : query)
-                       req.query(toQuery(o));
+                       for (Object o : formData)
+                               req.formData(toFormData(o));
 
-               for (Object o : formData)
-                       req.formData(toFormData(o));
+                       req.interceptors(interceptors);
 
-               req.interceptors(interceptors);
+                       return req;
 
-               return req;
+               } catch (URISyntaxException e1) {
+                       throw new RestCallException(e1);
+               }
        }
 
        /**
@@ -2850,12 +2829,14 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable {
         * <p>
         * Subclasses can override this method to provide their own specialized 
{@link RestRequest} objects.
         *
-        * @param httpRequest The request object to wrap.
+        * @param uri The target.
+        * @param method The HTTP method (uppercase).
+        * @param hasBody Whether this method has a request entity.
         * @return A new {@link RestRequest} object.
         * @throws RestCallException If an exception or non-200 response code 
occurred during the connection attempt.
         */
-       protected RestRequest createRequest(HttpRequestBase httpRequest) throws 
RestCallException {
-               return new RestRequest(this, httpRequest);
+       protected RestRequest createRequest(URI uri, String method, boolean 
hasBody) throws RestCallException {
+               return new RestRequest(this, uri, method, hasBody);
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
index 02962e9..2207124 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
@@ -88,13 +88,30 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
         * Constructs a REST call with the specified method name.
         *
         * @param client The client that created this request.
-        * @param request The wrapped Apache HTTP client request object.
+        * @param uri The target URI.
+        * @param method The HTTP method name (uppercase).
+        * @param hasBody Whether this method has a body.
         * @throws RestCallException If an exception or non-200 response code 
occurred during the connection attempt.
         */
-       protected RestRequest(RestClient client, HttpRequestBase request) 
throws RestCallException {
+       protected RestRequest(RestClient client, URI uri, String method, 
boolean hasBody) throws RestCallException {
                super(client, BeanSessionArgs.DEFAULT);
                this.client = client;
-               this.request = request;
+               if (hasBody) {
+                       this.request = new HttpEntityEnclosingRequestBase() {
+                               @Override /* HttpRequest */
+                               public String getMethod() {
+                                       return method;
+                               }
+                       };
+               } else {
+                       this.request = new HttpRequestBase() {
+                               @Override /* HttpRequest */
+                               public String getMethod() {
+                                       return method;
+                               }
+                       };
+               }
+               this.request.setURI(uri);
                this.errorCodes = client.errorCodes;
                this.partSerializer = client.getPartSerializerSession();
                this.uriBuilder = new URIBuilder(request.getURI());
diff --git 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
index a6813af..d4a4b34 100644
--- 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
+++ 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
@@ -12,8 +12,9 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest.mock2;
 
+import java.net.*;
+
 import org.apache.http.*;
-import org.apache.http.client.methods.*;
 import org.apache.juneau.*;
 import org.apache.juneau.rest.annotation.*;
 import org.apache.juneau.rest.client2.*;
@@ -110,13 +111,15 @@ public class MockRestClient extends RestClient {
         * <p>
         * Subclasses can override this method to provide their own specialized 
{@link RestRequest} objects.
         *
-        * @param httpRequest The request object to wrap.
+        * @param uri The target.
+        * @param method The HTTP method (uppercase).
+        * @param hasBody Whether this method has a request entity.
         * @return A new {@link RestRequest} object.
         * @throws RestCallException If an exception or non-200 response code 
occurred during the connection attempt.
         */
        @Override
-       protected MockRestRequest createRequest(HttpRequestBase httpRequest) 
throws RestCallException {
-               return new MockRestRequest(this, httpRequest);
+       protected MockRestRequest createRequest(URI uri, String method, boolean 
hasBody) throws RestCallException {
+               return new MockRestRequest(this, uri, method, hasBody);
        }
 
        // <CONFIGURATION-PROPERTIES>
diff --git 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestRequest.java
 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestRequest.java
index c1ec765..35d6c07 100644
--- 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestRequest.java
+++ 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestRequest.java
@@ -12,10 +12,11 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest.mock2;
 
+import java.net.*;
+
 import javax.servlet.http.*;
 
 import org.apache.http.*;
-import org.apache.http.client.methods.*;
 import org.apache.juneau.parser.*;
 import org.apache.juneau.rest.client2.*;
 
@@ -32,11 +33,13 @@ public class MockRestRequest extends 
org.apache.juneau.rest.client2.RestRequest
         * Constructs a REST call with the specified method name.
         *
         * @param client The client that created this request.
-        * @param request The wrapped Apache HTTP client request object.
+        * @param uri The target URI.
+        * @param method The HTTP method name (uppercase).
+        * @param hasBody Whether this method has a body.
         * @throws RestCallException If an exception or non-200 response code 
occurred during the connection attempt.
         */
-       protected MockRestRequest(RestClient client, HttpRequestBase request) 
throws RestCallException {
-               super(client, request);
+       protected MockRestRequest(RestClient client, URI uri, String method, 
boolean hasBody) throws RestCallException {
+               super(client, uri, method, hasBody);
        }
        /**
         * Creates a {@link RestResponse} object from the specified {@link 
HttpResponse} object.

Reply via email to