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 2abc948  MockRestClient improvements.
2abc948 is described below

commit 2abc948eb1e5cf5affb91c186ff9fc479f45a924
Author: JamesBognar <james.bog...@salesforce.com>
AuthorDate: Sun May 31 19:20:40 2020 -0400

    MockRestClient improvements.
---
 .../apache/juneau/rest/client2/RestRequest.java    | 50 ++++++++++++++++------
 .../juneau/rest/client2/RestRequestCreated.java    | 31 ++++++++++++++
 .../apache/juneau/rest/mock2/MockRestRequest.java  |  1 +
 3 files changed, 70 insertions(+), 12 deletions(-)

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 2207124..49d19ba 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
@@ -97,19 +97,9 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                super(client, BeanSessionArgs.DEFAULT);
                this.client = client;
                if (hasBody) {
-                       this.request = new HttpEntityEnclosingRequestBase() {
-                               @Override /* HttpRequest */
-                               public String getMethod() {
-                                       return method;
-                               }
-                       };
+                       this.request = new EntityRequest(method);
                } else {
-                       this.request = new HttpRequestBase() {
-                               @Override /* HttpRequest */
-                               public String getMethod() {
-                                       return method;
-                               }
-                       };
+                       this.request = new Request(method);
                }
                this.request.setURI(uri);
                this.errorCodes = client.errorCodes;
@@ -118,6 +108,42 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                this.ignoreErrors = client.ignoreErrors;
        }
 
+       private class Request extends HttpRequestBase implements 
RestRequestCreated {
+               private final String method;
+
+               Request(String method) {
+                       this.method = method;
+               }
+
+               @Override /* RestRequestCreated */
+               public RestRequest getRestRequest() {
+                       return RestRequest.this;
+               }
+
+               @Override /* HttpRequestBase */
+               public String getMethod() {
+                       return method;
+               }
+       }
+
+       private class EntityRequest extends HttpEntityEnclosingRequestBase 
implements RestRequestCreated {
+               private final String method;
+
+               EntityRequest(String method) {
+                       this.method = method;
+               }
+
+               @Override /* RestRequestCreated */
+               public RestRequest getRestRequest() {
+                       return RestRequest.this;
+               }
+
+               @Override /* HttpRequestBase */
+               public String getMethod() {
+                       return method;
+               }
+       }
+
        
//------------------------------------------------------------------------------------------------------------------
        // Configuration
        
//------------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequestCreated.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequestCreated.java
new file mode 100644
index 0000000..c89b805
--- /dev/null
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequestCreated.java
@@ -0,0 +1,31 @@
+// 
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file *
+// * distributed with this work for additional information regarding copyright 
ownership.  The ASF licenses this file        *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance            *
+// * with the License.  You may obtain a copy of the License at                
                                              *
+// *                                                                           
                                              *
+// *  http://www.apache.org/licenses/LICENSE-2.0                               
                                              *
+// *                                                                           
                                              *
+// * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an  *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.  See the License for the        *
+// * specific language governing permissions and limitations under the 
License.                                              *
+// 
***************************************************************************************************************************
+package org.apache.juneau.rest.client2;
+
+import org.apache.http.*;
+
+/**
+ * Identify an {@link HttpRequest} that was created by a {@link RestRequest}.
+ * 
+ * <p>
+ * Allows HTTP client code to get access to the underlying {@link RestRequest} 
if needed.
+ */
+public interface RestRequestCreated {
+
+       /**
+        * Returns the {@link RestRequest} object that created the {@link 
HttpRequest}.
+        * 
+        * @return The {@link RestRequest} object that created the {@link 
HttpRequest}.
+        */
+       RestRequest getRestRequest();
+}
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 35d6c07..f7b9f87 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
@@ -41,6 +41,7 @@ public class MockRestRequest extends 
org.apache.juneau.rest.client2.RestRequest
        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