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 27d2497  RestClient tests
27d2497 is described below

commit 27d2497772822e269b3181b1654918d4a540074d
Author: JamesBognar <[email protected]>
AuthorDate: Mon Jun 8 19:54:23 2020 -0400

    RestClient tests
---
 .../apache/juneau/rest/client2/RestClientMarshallsTest.java   |  3 +--
 .../java/org/apache/juneau/rest/mock2/MockRestClient.java     |  8 ++++++--
 .../src/main/java/org/apache/juneau/rest/RestServlet.java     | 11 ++++++++++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientMarshallsTest.java
 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientMarshallsTest.java
index 38327ea..9e91c3b 100644
--- 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientMarshallsTest.java
+++ 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientMarshallsTest.java
@@ -76,7 +76,7 @@ public class RestClientMarshallsTest {
        private static RestClient a1h = 
MockRestClient.create(A.class).urlEnc().build();
        private static RestClient a1i = 
MockRestClient.create(A.class).openApi().build();
        private static RestClient a1j = 
MockRestClient.create(A.class).htmlDoc().build();
-       private static RestClient a1k = 
MockRestClient.create(A.class).htmlStrippedDoc().debug().build();
+       private static RestClient a1k = 
MockRestClient.create(A.class).htmlStrippedDoc().build();
 
        @Test
        public void a01_singleLanguages() throws Exception {
@@ -141,7 +141,6 @@ public class RestClientMarshallsTest {
                        .assertStatus().is(200)
                        .getBody().as(Bean.class).check();
                a1k.post("/a01", bean)
-                       .debug()
                        .header("X-Accept", "text/html")
                        .header("X-Content-Type", "text/html+stripped")
                        .run()
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 5275092..c9fd966 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
@@ -268,7 +268,8 @@ public class MockRestClient extends RestClient implements 
HttpClientConnection {
                        Class<?> c = restBean instanceof Class ? 
(Class<?>)restBean : restBean.getClass();
                        Map<Class<?>,RestContext> contexts = isDebug ? 
CONTEXTS_DEBUG : CONTEXTS_NORMAL;
                        if (! contexts.containsKey(c)) {
-                               Object o = restBean instanceof Class ? 
((Class<?>)restBean).newInstance() : restBean;
+                               boolean isClass = restBean instanceof Class;
+                               Object o = isClass ? 
((Class<?>)restBean).newInstance() : restBean;
                                RestContextBuilder rcb = RestContext.create(o);
                                if (isDebug) {
                                        rcb.debug(Enablement.TRUE);
@@ -276,7 +277,10 @@ public class MockRestClient extends RestClient implements 
HttpClientConnection {
                                }
                                RestContext rc = rcb.build();
                                if (o instanceof RestServlet) {
-                                       ((RestServlet)o).setContext(rc);
+                                       RestServlet rs = (RestServlet)o;
+                                       if (! rs.isInitialized())
+                                               rs.setContext(rc);
+                                       rc = rs.getContext();
                                } else {
                                        rc.postInit();
                                }
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
index 9c9f401..1004d8f 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestServlet.java
@@ -106,6 +106,15 @@ public abstract class RestServlet extends HttpServlet 
implements RestCallHandler
        }
 
        /**
+        * Returns <jk>true</jk> if this servlet has been initialized and 
{@link #getContext()} returns a value.
+        *
+        * @return <jk>true</jk> if this servlet has been initialized and 
{@link #getContext()} returns a value.
+        */
+       public synchronized boolean isInitialized() {
+               return isInitialized;
+       }
+
+       /**
         * Sets the resource resolver to use for this servlet and all child 
servlets.
         * <p>
         * This method can be called immediately following object construction, 
but must be called before {@link #init(ServletConfig)} is called.
@@ -166,7 +175,7 @@ public abstract class RestServlet extends HttpServlet 
implements RestCallHandler
         *
         * @return The context information on this servlet.
         */
-       protected synchronized RestContext getContext() {
+       public synchronized RestContext getContext() {
                if (context == null)
                        throw new InternalServerError("RestContext object not 
set on resource.");
                return context;

Reply via email to