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 3608a7e  RestClient tests.
3608a7e is described below

commit 3608a7e3dd13f9d1395c3ad259bb38b6460de047
Author: JamesBognar <[email protected]>
AuthorDate: Thu Jun 11 18:16:02 2020 -0400

    RestClient tests.
---
 .../apache/juneau/rest/client2/RestClientTest.java | 67 +++++++++++++++-
 .../org/apache/juneau/rest/client2/RestClient.java | 90 ++++++----------------
 .../apache/juneau/rest/client2/RestRequest.java    | 81 ++++++++++++++-----
 .../apache/juneau/rest/client2/RestResponse.java   | 34 ++++++++
 .../org/apache/juneau/rest/mock2/MockLogger.java   | 44 ++++++++---
 .../apache/juneau/rest/mock2/MockRestClient.java   |  5 --
 6 files changed, 216 insertions(+), 105 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
index 9b55f60..59f9a89 100644
--- 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
+++ 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
@@ -22,6 +22,7 @@ import java.net.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
+import java.util.function.*;
 import java.util.logging.*;
 
 import org.apache.http.*;
@@ -572,6 +573,9 @@ public class RestClientTest {
 
        @Test
        public void a23_basicCalls_formPost_exhaustiveBodyTypes() throws 
Exception {
+               Supplier<Object>
+                       s1 = () -> new StringReader("f=1"),
+                       s2 = () -> new ByteArrayInputStream("f=1".getBytes());
 
                List<Object> bodies = AList.of(
                        /*[ 0]*/ bean,
@@ -587,7 +591,9 @@ public class RestClientTest {
                        /*[10]*/ 
StreamResource.create().contents("f=1").build(),
                        /*[11]*/ StreamResource.create().contents("f=1"),
                        /*[12]*/ 
StreamResource.create().contents("f=1").mediaType("application/x-www-form-urlencoded").build(),
-                       /*[13]*/ 
StreamResource.create().contents("f=1").mediaType("application/x-www-form-urlencoded")
+                       /*[13]*/ 
StreamResource.create().contents("f=1").mediaType("application/x-www-form-urlencoded"),
+                       /*[14]*/ s1,
+                       /*[15]*/ s2
                );
 
                for (int i = 0; i < bodies.size(); i++) {
@@ -841,6 +847,7 @@ public class RestClientTest {
                MockRestClient
                        .create(A.class)
                        .simpleJson()
+                       .logRequests(DetailLevel.SIMPLE, Level.SEVERE)
                        .logToConsole()
                        .build()
                        .post("/bean", bean)
@@ -879,6 +886,56 @@ public class RestClientTest {
                );
        }
 
+       public static class B02a extends BasicRestCallInterceptor {
+               @Override /* RestCallInterceptor */
+               public void onConnect(RestRequest req, RestResponse res) throws 
Exception {
+                       req.log(Level.WARNING, "Foo");
+                       req.log(Level.WARNING, new RuntimeException(), "Foo");
+                       res.log(Level.WARNING, "Foo");
+                       res.log(Level.WARNING, new RuntimeException(), "Foo");
+               }
+       }
+
+       @SuppressWarnings("unchecked")
+       @Test
+       public void b02a_loggingOther() throws Exception {
+               MockLogger ml = new MockLogger();
+
+               MockRestClient
+                       .create(A.class)
+                       .simpleJson()
+                       .logger(ml)
+                       .interceptors(B02a.class)
+                       .build()
+                       .post("/bean", bean)
+                       .complete();
+
+               ml.assertCount(4);
+       }
+
+       public static class B03 extends RestClient {
+               private static boolean METHOD_CALLED;
+               public B03(PropertyStore ps) {
+                       super(ps);
+               }
+
+               @Override
+               protected RestRequest createRequest(java.net.URI uri, String 
method, boolean hasBody) throws RestCallException {
+                       METHOD_CALLED = true;
+                       return super.createRequest(uri, method, hasBody);
+               }
+       }
+
+       @Test
+       public void b03_overrideCreateRequest() throws Exception {
+               RestClient
+                       .create()
+                       .simpleJson()
+                       .build(B03.class)
+                       .get("foo");
+               assertTrue(B03.METHOD_CALLED);
+       }
+
        
//------------------------------------------------------------------------------------------------------------------
        // Passthrough methods for HttpClientBuilder.
        
//------------------------------------------------------------------------------------------------------------------
@@ -5707,4 +5764,12 @@ public class RestClientTest {
                        .assertBody().is("{foo:1}")
                ;
        }
+
+       
//-----------------------------------------------------------------------------------------------------------------
+       // Remote proxies
+       
//-----------------------------------------------------------------------------------------------------------------
+
+       
//-----------------------------------------------------------------------------------------------------------------
+       // Other methods
+       
//-----------------------------------------------------------------------------------------------------------------
 }
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 7b31585..27d2dbd 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
@@ -174,7 +174,6 @@ import org.apache.http.client.CookieStore;
  *             <li class='jm'>{@link RestClient#options(Object) options(Object 
url)}
  *             <li class='jm'>{@link RestClient#formPost(Object,Object) 
formPost(Object url, Object body)}
  *             <li class='jm'>{@link RestClient#formPost(Object) 
formPost(Object url)}
- *             <li class='jm'>{@link 
RestClient#formPost(Object,NameValuePair...) formPost(Object url, 
NameValuePair...parameters)}
  *             <li class='jm'>{@link 
RestClient#formPostPairs(Object,Object...) formPost(Object url, 
Object...parameters)}
  *             <li class='jm'>{@link 
RestClient#request(HttpMethod,Object,Object) request(HttpMethod method, Object 
url, Object body)}
  *     </ul>
@@ -950,7 +949,7 @@ import org.apache.http.client.CookieStore;
  * </ul>
  */
 @ConfigurableContext(nocache=true)
-public class RestClient extends BeanContext implements HttpClient, Closeable, 
RestCallHandler, RestCallInterceptor {
+public class RestClient extends BeanContext implements HttpClient, Closeable, 
RestCallHandler {
 
        
//-------------------------------------------------------------------------------------------------------------------
        // Configurable properties
@@ -2162,6 +2161,8 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *                      {@link HttpEntity} - Bypass Juneau 
serialization and pass HttpEntity directly to HttpClient.
         *              <li class='jc'>
         *                      {@link NameValuePairs} - Converted to a 
URL-encoded FORM post.
+        *              <li class='jc'>
+        *                      {@link Supplier} - A supplier of anything on 
this list.
         *      </ul>
         * @return
         *      A {@link RestRequest} object that can be further tailored 
before executing the request
@@ -2259,6 +2260,8 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *                      {@link HttpEntity} - Bypass Juneau 
serialization and pass HttpEntity directly to HttpClient.
         *              <li class='jc'>
         *                      {@link NameValuePairs} - Converted to a 
URL-encoded FORM post.
+        *              <li class='jc'>
+        *                      {@link Supplier} - A supplier of anything on 
this list.
         *      </ul>
         * @return
         *      A {@link RestRequest} object that can be further tailored 
before executing the request and getting the response
@@ -2414,6 +2417,7 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *              <li class='jc'>{@link Reader}/{@link InputStream}- 
Streamed directly and <l>Content-Type</l> set to 
<js>"application/x-www-form-urlencoded"</js>
         *              <li class='jc'>{@link ReaderResource}/{@link 
ReaderResourceBuilder}/{@link StreamResource}/{@link 
StreamResourceBuilder}/{@link HttpEntity}- Streamed directly and 
<l>Content-Type</l> set to <js>"application/x-www-form-urlencoded"</js> if not 
already specified on the entity.
         *              <li class='jc'>{@link Object} - Converted to a {@link 
SerializedHttpEntity} using {@link UrlEncodingSerializer} to serialize.
+        *              <li class='jc'>{@link Supplier} - A supplier of 
anything on this list.
         *      </ul>
         * @return
         *      A {@link RestRequest} object that can be further tailored 
before executing the request and getting the response
@@ -2423,6 +2427,8 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
        public RestRequest formPost(Object url, Object body) throws 
RestCallException {
                RestRequest req = request("POST", url, true);
                try {
+                       if (body instanceof Supplier)
+                               body = ((Supplier<?>)body).get();
                        if (body instanceof NameValuePair)
                                return req.body(new 
UrlEncodedFormEntity(AList.of((NameValuePair)body)));
                        if (body instanceof NameValuePair[])
@@ -2497,31 +2503,6 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *      </ul>
         * @param parameters
         *      The parameters of the form post.
-        * @return
-        *      A {@link RestRequest} object that can be further tailored 
before executing the request and getting the response
-        *      as a parsed object.
-        * @throws RestCallException If any authentication errors occurred.
-        */
-       public RestRequest formPost(Object url, NameValuePair...parameters) 
throws RestCallException {
-               return formPost(url, new NameValuePairs(parameters));
-       }
-
-       /**
-        * Perform a <c>POST</c> request with a content type of 
<c>application/x-www-form-urlencoded</c>
-        * against the specified URL.
-        *
-        * @param url
-        *      The URL of the remote REST resource.
-        *      Can be any of the following types:
-        *      <ul class='spaced-list'>
-        *              <li class='jc'>{@link URIBuilder}
-        *              <li class='jc'>{@link URI}
-        *              <li class='jc'>{@link URL}
-        *              <li class='jc'>{@link String}
-        *              <li class='jc'>{@link Object} - Converted to 
<c>String</c> using <c>toString()</c>
-        *      </ul>
-        * @param parameters
-        *      The parameters of the form post.
         *      <br>The parameters represent name/value pairs and must be an 
even number of arguments.
         *      <br>Parameters are converted to {@link BasicNameValuePair} 
objects.
         * @return
@@ -2565,6 +2546,8 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *                      {@link HttpEntity} - Bypass Juneau 
serialization and pass HttpEntity directly to HttpClient.
         *              <li class='jc'>
         *                      {@link NameValuePairs} - Converted to a 
URL-encoded FORM post.
+        *              <li class='jc'>
+        *                      {@link Supplier} - A supplier of anything on 
this list.
         *      </ul>
         * @return
         *      A {@link RestRequest} object that can be further tailored 
before executing the request and getting the response
@@ -2749,6 +2732,8 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *                      {@link HttpEntity} - Bypass Juneau 
serialization and pass HttpEntity directly to HttpClient.
         *              <li class='jc'>
         *                      {@link NameValuePairs} - Converted to a 
URL-encoded FORM post.
+        *              <li class='jc'>
+        *                      {@link Supplier} - A supplier of anything on 
this list.
         *      </ul>
         *      This parameter is IGNORED if {@link HttpMethod#hasContent()} is 
<jk>false</jk>.
         * @return
@@ -2833,7 +2818,6 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                for (Object o : formData)
                        req.formData(toFormData(o));
 
-               req.interceptors(this);
                req.interceptors(interceptors);
 
                return req;
@@ -3287,42 +3271,6 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
        
//-----------------------------------------------------------------------------------------------------------------
 
        /**
-        * Interceptor method called before a request is sent to the server.
-        *
-        * <p>
-        * Subclasses can override this method to intercept the request and 
perform special modifications.
-        * The default behavior is a no-op.
-        *
-        * <ul class='seealso'>
-        *      <li class='jf'>{@link RestClient#RESTCLIENT_interceptors}
-        *      <li class='jm'>{@link RestClientBuilder#interceptors(Class...)}
-        *      <li class='jm'>{@link 
RestClientBuilder#interceptors(RestCallInterceptor...)}
-        * </ul>
-        */
-       @Override /* HttpRequestInterceptor */
-       public void process(HttpRequest request, HttpContext context) throws 
HttpException, IOException {
-               // Default is a no-op.
-       }
-
-       /**
-        * Interceptor method called before the message body is evaluated.
-        *
-        * <p>
-        * Subclasses can override this method to intercept the response and 
perform special modifications.
-        * The default behavior is a no-op.
-        *
-        * <ul class='seealso'>
-        *      <li class='jf'>{@link RestClient#RESTCLIENT_interceptors}
-        *      <li class='jm'>{@link RestClientBuilder#interceptors(Class...)}
-        *      <li class='jm'>{@link 
RestClientBuilder#interceptors(RestCallInterceptor...)}
-        * </ul>
-        */
-       @Override /* HttpRequestInterceptor */
-       public void process(HttpResponse response, HttpContext context) throws 
HttpException, IOException {
-               // Default is a no-op.
-       }
-
-       /**
         * Interceptor method called immediately after the RestRequest object 
is created and all headers/query/form-data has been copied from the client.
         *
         * <p>
@@ -3334,8 +3282,10 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *      <li class='jm'>{@link RestClientBuilder#interceptors(Class...)}
         *      <li class='jm'>{@link 
RestClientBuilder#interceptors(RestCallInterceptor...)}
         * </ul>
+        *
+        * @param req The HTTP request.
+        * @throws Exception Any exception can be thrown.
         */
-       @Override /* RestCallInterceptor */
        public void onInit(RestRequest req) throws Exception {
                // Default is a no-op.
        }
@@ -3352,8 +3302,11 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *      <li class='jm'>{@link RestClientBuilder#interceptors(Class...)}
         *      <li class='jm'>{@link 
RestClientBuilder#interceptors(RestCallInterceptor...)}
         * </ul>
+        *
+        * @param req The HTTP request.
+        * @param res The HTTP response.
+        * @throws Exception Any exception can be thrown.
         */
-       @Override /* RestCallInterceptor */
        public void onConnect(RestRequest req, RestResponse res) throws 
Exception {
                // Default is a no-op.
        }
@@ -3370,8 +3323,11 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
         *      <li class='jm'>{@link RestClientBuilder#interceptors(Class...)}
         *      <li class='jm'>{@link 
RestClientBuilder#interceptors(RestCallInterceptor...)}
         * </ul>
+        *
+        * @param req The HTTP request.
+        * @param res The HTTP response.
+        * @throws Exception Any exception can be thrown.
         */
-       @Override /* RestCallInterceptor */
        public void onClose(RestRequest req, RestResponse res) throws Exception 
{
                // Default is a no-op.
        }
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 8a5a13c..637f671 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
@@ -19,9 +19,11 @@ import static 
org.apache.juneau.rest.client2.RestClientUtils.*;
 
 import java.io.*;
 import java.net.*;
+import java.text.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.function.*;
+import java.util.logging.*;
 
 import org.apache.http.*;
 import org.apache.http.client.config.*;
@@ -691,6 +693,12 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                                throw RestCallException.create(e);
                        }
                }
+               try {
+                       client.onInit(this);
+               } catch (Exception e) {
+                       throw RestCallException.create(e);
+               }
+
                return this;
        }
 
@@ -3807,39 +3815,44 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                                if (request2 == null)
                                        throw new RestCallException(0, "Method 
does not support content entity.", getMethod(), getURI(), null);
 
+                               Object input2 = input;
+
+                               if (input2 instanceof Supplier)
+                                       input2 = ((Supplier<?>)input).get();
+
                                HttpEntity entity = null;
                                if (formData != null)
                                        entity = new 
UrlEncodedFormEntity(formData);
-                               else if (input instanceof NameValuePairs)
-                                       entity = new 
UrlEncodedFormEntity((NameValuePairs)input);
-                               else if (input instanceof HttpEntity)
-                                       entity = (HttpEntity)input;
-                               else if (input instanceof Reader)
-                                       entity = new 
StringEntity(IOUtils.read((Reader)input), getRequestContentType(TEXT_PLAIN));
-                               else if (input instanceof InputStream)
-                                       entity = new 
InputStreamEntity((InputStream)input, 
getRequestContentType(ContentType.APPLICATION_OCTET_STREAM));
-                               else if (input instanceof ReaderResource || 
input instanceof ReaderResourceBuilder) {
-                                       if (input instanceof 
ReaderResourceBuilder)
-                                               input = 
((ReaderResourceBuilder)input).build();
-                                       ReaderResource r = 
(ReaderResource)input;
+                               else if (input2 instanceof NameValuePairs)
+                                       entity = new 
UrlEncodedFormEntity((NameValuePairs)input2);
+                               else if (input2 instanceof HttpEntity)
+                                       entity = (HttpEntity)input2;
+                               else if (input2 instanceof Reader)
+                                       entity = new 
StringEntity(IOUtils.read((Reader)input2), getRequestContentType(TEXT_PLAIN));
+                               else if (input2 instanceof InputStream)
+                                       entity = new 
InputStreamEntity((InputStream)input2, 
getRequestContentType(ContentType.APPLICATION_OCTET_STREAM));
+                               else if (input2 instanceof ReaderResource || 
input2 instanceof ReaderResourceBuilder) {
+                                       if (input2 instanceof 
ReaderResourceBuilder)
+                                               input2 = 
((ReaderResourceBuilder)input2).build();
+                                       ReaderResource r = 
(ReaderResource)input2;
                                        contentType(r.getContentType());
                                        headers(r.getHeaders());
                                        entity = new 
StringEntity(IOUtils.read(r.getContents()), getRequestContentType(TEXT_PLAIN));
                                }
-                               else if (input instanceof StreamResource || 
input instanceof StreamResourceBuilder) {
-                                       if (input instanceof 
StreamResourceBuilder)
-                                               input = 
((StreamResourceBuilder)input).build();
-                                       StreamResource r = 
(StreamResource)input;
+                               else if (input2 instanceof StreamResource || 
input2 instanceof StreamResourceBuilder) {
+                                       if (input2 instanceof 
StreamResourceBuilder)
+                                               input2 = 
((StreamResourceBuilder)input2).build();
+                                       StreamResource r = 
(StreamResource)input2;
                                        contentType(r.getContentType());
                                        headers(r.getHeaders());
                                        entity = new 
InputStreamEntity(r.getContents(), 
getRequestContentType(ContentType.APPLICATION_OCTET_STREAM));
                                }
                                else if (serializer != null)
-                                       entity = new 
SerializedHttpEntity(input, serializer, requestBodySchema, contentType);
+                                       entity = new 
SerializedHttpEntity(input2, serializer, requestBodySchema, contentType);
                                else {
-                                       if (input == null)
-                                               input = "";
-                                       entity = new 
StringEntity(getBeanContext().getClassMetaForObject(input).toString(input), 
getRequestContentType(TEXT_PLAIN));
+                                       if (input2 == null)
+                                               input2 = "";
+                                       entity = new 
StringEntity(getBeanContext().getClassMetaForObject(input2).toString(input2), 
getRequestContentType(TEXT_PLAIN));
                                }
 
                                request2.setEntity(entity);
@@ -3859,6 +3872,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
 
                        for (RestCallInterceptor rci : interceptors)
                                rci.onConnect(this, response);
+                       client.onConnect(this, response);
 
                        if (response.getStatusCode() == 0)
                                throw new RestCallException("HttpClient 
returned a null response");
@@ -4006,6 +4020,33 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                return (request instanceof HttpEntityEnclosingRequestBase ? 
((HttpEntityEnclosingRequestBase)request).getEntity() : null);
        }
 
+       /**
+        * Logs a message.
+        *
+        * @param level The log level.
+        * @param t The throwable cause.
+        * @param msg The message with {@link MessageFormat}-style arguments.
+        * @param args The arguments.
+        * @return This object (for method chaining).
+        */
+       public RestRequest log(Level level, Throwable t, String msg, 
Object...args) {
+               client.log(level, t, msg, args);
+               return this;
+       }
+
+       /**
+        * Logs a message.
+        *
+        * @param level The log level.
+        * @param msg The message with {@link MessageFormat}-style arguments.
+        * @param args The arguments.
+        * @return This object (for method chaining).
+        */
+       public RestRequest log(Level level, String msg, Object...args) {
+               client.log(level, msg, args);
+               return this;
+       }
+
        
//-----------------------------------------------------------------------------------------------------------------
        // HttpRequestBase pass-through methods.
        
//-----------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
index 16c9f86..e2d3e4c 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
@@ -17,7 +17,9 @@ import org.apache.juneau.parser.*;
 import static org.apache.juneau.httppart.HttpPartType.*;
 
 import java.lang.reflect.*;
+import java.text.*;
 import java.util.*;
+import java.util.logging.*;
 
 import org.apache.http.*;
 import org.apache.http.message.*;
@@ -573,6 +575,33 @@ public class RestResponse implements HttpResponse {
                }
        }
 
+       /**
+        * Logs a message.
+        *
+        * @param level The log level.
+        * @param t The throwable cause.
+        * @param msg The message with {@link MessageFormat}-style arguments.
+        * @param args The arguments.
+        * @return This object (for method chaining).
+        */
+       public RestResponse log(Level level, Throwable t, String msg, 
Object...args) {
+               client.log(level, t, msg, args);
+               return this;
+       }
+
+       /**
+        * Logs a message.
+        *
+        * @param level The log level.
+        * @param msg The message with {@link MessageFormat}-style arguments.
+        * @param args The arguments.
+        * @return This object (for method chaining).
+        */
+       public RestResponse log(Level level, String msg, Object...args) {
+               client.log(level, msg, args);
+               return this;
+       }
+
        // 
-----------------------------------------------------------------------------------------------------------------
        // HttpResponse pass-through methods.
        // 
-----------------------------------------------------------------------------------------------------------------
@@ -972,6 +1001,11 @@ public class RestResponse implements HttpResponse {
                                throw RestCallException.create(e);
                        }
                }
+               try {
+                       client.onClose(request, this);
+               } catch (Exception e) {
+                       throw RestCallException.create(e);
+               }
        }
 
        
//------------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockLogger.java
 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockLogger.java
index 30c503a..ecf6868 100644
--- 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockLogger.java
+++ 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockLogger.java
@@ -12,6 +12,7 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest.mock2;
 
+import java.util.*;
 import java.util.logging.*;
 
 /**
@@ -56,7 +57,7 @@ import java.util.logging.*;
  */
 public class MockLogger extends Logger {
 
-       private volatile LogRecord logRecord;
+       private volatile List<LogRecord> logRecords = new ArrayList<>();
 
        /**
         * Constructor.
@@ -67,7 +68,7 @@ public class MockLogger extends Logger {
 
        @Override /* Logger */
        public synchronized void log(LogRecord record) {
-               this.logRecord = record;
+               logRecords.add(record);
        }
 
        /**
@@ -76,7 +77,7 @@ public class MockLogger extends Logger {
         * @return This object (for method chaining).
         */
        public synchronized MockLogger reset() {
-               this.logRecord = null;
+               logRecords.clear();
                return this;
        }
 
@@ -86,7 +87,7 @@ public class MockLogger extends Logger {
         * @return This object (for method chaining).
         */
        public synchronized MockLogger assertLogged() {
-               if (logRecord == null)
+               if (logRecords.isEmpty())
                        throw new AssertionError("Message not logged");
                return this;
        }
@@ -99,8 +100,8 @@ public class MockLogger extends Logger {
         */
        public synchronized MockLogger assertLevel(Level level) {
                assertLogged();
-               if (logRecord.getLevel() != level)
-                       throw new AssertionError("Message logged at [" + 
logRecord.getLevel() + "] instead of [" + level + "]");
+               if (last().getLevel() != level)
+                       throw new AssertionError("Message logged at [" + 
last().getLevel() + "] instead of [" + level + "]");
                return this;
        }
 
@@ -112,8 +113,8 @@ public class MockLogger extends Logger {
         */
        public synchronized MockLogger assertMessage(String message) {
                assertLogged();
-               if (! logRecord.getMessage().equals(message))
-                       throw new AssertionError("Message was not [" + message 
+ "].  Message=[" + logRecord.getMessage() + "]");
+               if (! last().getMessage().equals(message))
+                       throw new AssertionError("Message was not [" + message 
+ "].  Message=[" + last().getMessage() + "]");
                return this;
        }
 
@@ -126,8 +127,8 @@ public class MockLogger extends Logger {
        public synchronized MockLogger assertMessageContains(String...messages) 
{
                assertLogged();
                for (String m : messages)
-                       if (! logRecord.getMessage().contains(m))
-                               throw new AssertionError("Message did not 
contain [" + m + "].  Message=[" + logRecord.getMessage() + "]");
+                       if (! last().getMessage().contains(m))
+                               throw new AssertionError("Message did not 
contain [" + m + "].  Message=[" + last().getMessage() + "]");
                return this;
        }
 
@@ -140,8 +141,27 @@ public class MockLogger extends Logger {
        public synchronized MockLogger 
assertMessageNotContains(String...messages) {
                assertLogged();
                for (String m : messages)
-                       if (logRecord.getMessage().contains(m))
-                               throw new AssertionError("Message contained [" 
+ m + "].  Message=[" + logRecord.getMessage() + "]");
+                       if (last().getMessage().contains(m))
+                               throw new AssertionError("Message contained [" 
+ m + "].  Message=[" + last().getMessage() + "]");
                return this;
        }
+
+       /**
+        * Asserts that the specified number of messages have been logged.
+        *
+        * @param count Expected number of messages logged.
+        * @return This object (for method chaining).
+        */
+       public synchronized MockLogger assertCount(int count) {
+               assertLogged();
+               if (logRecords.size() != count)
+                       throw new AssertionError("Wrong number of messages.  
Expected=["+count+"], Actual=["+logRecords.size()+"]");
+               return this;
+       }
+
+       private LogRecord last() {
+               if (logRecords.isEmpty())
+                       throw new AssertionError("Message not logged");
+               return logRecords.get(logRecords.size()-1);
+       }
 }
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 e306a54..5cdc6df 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
@@ -441,11 +441,6 @@ public class MockRestClient extends RestClient implements 
HttpClientConnection {
        }
 
        @Override /* RestClient */
-       public MockRestRequest formPost(Object url, NameValuePair...parameters) 
throws RestCallException {
-               return (MockRestRequest)super.formPost(url, parameters);
-       }
-
-       @Override /* RestClient */
        public MockRestRequest formPostPairs(Object url, Object...parameters) 
throws RestCallException {
                return (MockRestRequest)super.formPostPairs(url, parameters);
        }

Reply via email to