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 66191a6 RestClient tests.
66191a6 is described below
commit 66191a63981619aa2d60f8494b75840008e25c41
Author: JamesBognar <[email protected]>
AuthorDate: Thu Jun 18 10:01:24 2020 -0400
RestClient tests.
---
.../src/main/java/org/apache/juneau/Session.java | 2 +-
.../apache/juneau/rest/client2/RestClientTest.java | 35 ++-
.../apache/juneau/rest/mock2/MockRestClient.java | 21 +-
.../apache/juneau/rest/mock2/MockRestRequest.java | 330 ++++++++++++++++-----
.../juneau/rest/mock2/MockServletRequest.java | 74 +++++
5 files changed, 379 insertions(+), 83 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
index 0c2dfd1..3b3f1a1 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Session.java
@@ -331,7 +331,7 @@ public abstract class Session {
* @see Context#CONTEXT_locale
* @return The session locale.
*/
- public final Locale getLocale() {
+ public Locale getLocale() {
return locale;
}
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 b80713c..15cafef 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
@@ -49,6 +49,7 @@ import org.apache.juneau.http.header.*;
import org.apache.juneau.http.header.ContentType;
import org.apache.juneau.http.response.*;
import org.apache.juneau.httppart.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.marshall.*;
import org.apache.juneau.parser.*;
@@ -1131,7 +1132,7 @@ public class RestClientTest {
//------------------------------------------------------------------------------------------------------------------
@Test
- public void c01_interceptors() throws RestCallException {
+ public void c01_miscellaneous_interceptors() throws RestCallException {
MockRestClient
.create(A.class)
.simpleJson()
@@ -1173,7 +1174,7 @@ public class RestClientTest {
}
@Test
- public void c02_httpProcessor() throws RestCallException {
+ public void c02_miscellaneous_httpProcessor() throws RestCallException {
MockRestClient
.create(A.class)
.simpleJson()
@@ -1196,7 +1197,7 @@ public class RestClientTest {
}
@Test
- public void c03_requestExecutor() throws RestCallException {
+ public void c03_miscellaneous_requestExecutor() throws
RestCallException {
AtomicBoolean b1 = new AtomicBoolean();
MockRestClient
.create(A.class)
@@ -1216,7 +1217,7 @@ public class RestClientTest {
}
@Test
- public void c04_defaultHeaders() throws RestCallException {
+ public void c04_miscellaneous_defaultHeaders() throws RestCallException
{
MockRestClient
.create(A.class)
.simpleJson()
@@ -1228,7 +1229,7 @@ public class RestClientTest {
}
@Test
- public void c05_miscellaneous() {
+ public void c05_miscellaneous_httpClientBuilderMethods() {
RestClient.create()
.disableRedirectHandling()
.redirectStrategy(DefaultRedirectStrategy.INSTANCE)
@@ -1272,6 +1273,30 @@ public class RestClientTest {
.evictIdleConnections(1, TimeUnit.DAYS);
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void c06_miscellaneous_unusedHttpClientMethods() {
+ RestClient rc = RestClient
+ .create()
+ .build();
+
+ try {
+ assertNotNull(rc.getParams());
+ } catch (UnsupportedOperationException e) {}
+ assertNotNull(rc.getConnectionManager());
+ }
+
+ @Test
+ public void c07_miscellaneous_executeHttpUriRequest() throws Exception {
+ HttpGet x = new HttpGet("http://localhost/bean");
+ x.addHeader("Accept", "text/json+simple");
+ HttpResponse res = MockRestClient
+ .create(A.class)
+ .build()
+ .execute(x);
+ assertEquals("{f:1}",
IOUtils.read(res.getEntity().getContent()));
+ }
+
//------------------------------------------------------------------------------------------------------------------
// Pooled connections
//------------------------------------------------------------------------------------------------------------------
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 d512f23..59fada5 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
@@ -237,7 +237,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
private final RestContext restBeanCtx;
private final String contextPath, servletPath;
- private final ThreadLocal<MockRestRequest> rreq = new ThreadLocal<>();
+ private final ThreadLocal<HttpRequest> rreq = new ThreadLocal<>();
private final ThreadLocal<MockRestResponse> rres = new ThreadLocal<>();
private final ThreadLocal<MockServletRequest> sreq = new
ThreadLocal<>();
private final ThreadLocal<MockServletResponse> sres = new
ThreadLocal<>();
@@ -570,7 +570,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
*
* @return The current client-side REST request, or <jk>null</jk> if
not set.
*/
- public MockRestRequest getCurrentClientRequest() {
+ public HttpRequest getCurrentClientRequest() {
return rreq.get();
}
@@ -678,8 +678,8 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
String path = rl.getUri();
String target = findTarget(request);
- MockRestRequest mrr = findRestRequest(request);
- rreq.set(mrr);
+ HttpRequest req = findRestRequest(request);
+ rreq.set(req);
rres.remove();
sreq.remove();
sres.remove();
@@ -700,19 +700,22 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
r.header(h.getName(), h.getValue());
sreq.set(r);
-
- rreq.get().applyOverrides(sreq.get());
+ sreq.get().applyOverrides(req);
} catch (Exception e) {
throw new HttpException(e.getMessage(), e);
}
}
- private MockRestRequest findRestRequest(HttpRequest req) {
+ /**
+ * Attempts to unwrap the request to find the underlying RestRequest
object.
+ * Returns the same object if one of the low-level client methods are
used (e.g. execute(HttpUriRequest)).
+ */
+ private HttpRequest findRestRequest(HttpRequest req) {
if (req instanceof RestRequestCreated)
- return
(MockRestRequest)((RestRequestCreated)req).getRestRequest();
+ return ((RestRequestCreated)req).getRestRequest();
if (req instanceof HttpRequestWrapper)
return findRestRequest(((HttpRequestWrapper)
req).getOriginal());
- throw new RuntimeException("HttpRequest not an instance of
RestRequestCreated");
+ return req;
}
private String findTarget(HttpRequest req) {
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 1e252c9..2e259cf 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
@@ -74,74 +74,6 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
//------------------------------------------------------------------------------------------------------------------
/**
- * Applies any HTTP servlet request overrides to the specified servlet
request.
- *
- * @param req The servlet request.
- * @return This object (for method chaining).
- */
- protected MockRestRequest applyOverrides(MockServletRequest req) {
- for (Map.Entry<String,Object> a : attributeMap.entrySet())
- req.attribute(a.getKey(), a.getValue());
- for (Map.Entry<String,RequestDispatcher> a :
requestDispatcherMap.entrySet())
- req.requestDispatcher(a.getKey(), a.getValue());
- if (characterEncoding != null)
- req.characterEncoding(characterEncoding);
- if (protocol != null)
- req.protocol(protocol);
- if (scheme != null)
- req.scheme(scheme);
- if (serverName != null)
- req.serverName(serverName);
- if (remoteAddr != null)
- req.remoteAddr(remoteAddr);
- if (remoteHost != null)
- req.remoteHost(remoteHost);
- if (localName != null)
- req.localName(localName);
- if (localAddr != null)
- req.localAddr(localAddr);
- if (pathInfo != null)
- req.pathInfo(pathInfo);
- if (pathTranslated != null)
- req.pathTranslated(pathTranslated);
- if (contextPath != null)
- req.contextPath(contextPath);
- if (queryString != null)
- req.queryString(queryString);
- if (remoteUser != null)
- req.remoteUser(remoteUser);
- if (requestedSessionId != null)
- req.requestedSessionId(requestedSessionId);
- if (requestURI != null)
- req.requestURI(requestURI);
- if (servletPath != null)
- req.servletPath(servletPath);
- if (authType != null)
- req.authType(authType);
- if (serverPort != null)
- req.serverPort(serverPort);
- if (remotePort != null)
- req.remotePort(remotePort);
- if (localPort != null)
- req.localPort(localPort);
- if (locale != null)
- req.locale(locale);
- if (servletContext != null)
- req.servletContext(servletContext);
- if (dispatcherType != null)
- req.dispatcherType(dispatcherType);
- if (cookies != null)
- req.cookies(cookies);
- if (userPrincipal != null)
- req.userPrincipal(userPrincipal);
- if (httpSession != null)
- req.httpSession(httpSession);
- if (roles != null)
- req.roles(roles);
- return this;
- }
-
- /**
* Adds an attribute to the underlying {@link HttpServletRequest}
object.
*
* <p>
@@ -174,6 +106,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the attributes to add to the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The attributes to add to the underlying {@link
HttpServletRequest} object.
+ */
+ public Map<String,Object> getAttributeMap() {
+ return attributeMap;
+ }
+
+ /**
* Specifies the user roles on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -192,6 +133,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the user roles to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The user roles to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String[] getRoles() {
+ return roles;
+ }
+
+ /**
* Specifies the value for the security roles on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -228,6 +178,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the value to set for the return value on the underlying
{@link HttpServletRequest#getCharacterEncoding()} method.
+ *
+ * @return The value to set for the return value on the underlying
{@link HttpServletRequest#getCharacterEncoding()} method.
+ */
+ public String getCharacterEncoding() {
+ return characterEncoding;
+ }
+
+ /**
* Overrides the HTTP protocol value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -246,6 +205,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the HTTP protocol value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The HTTP protocol value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
* Overrides the HTTP schema value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -265,6 +233,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the HTTP schema value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The HTTP schema value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getScheme() {
+ return scheme;
+ }
+
+ /**
* Overrides the server name value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -283,6 +260,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the server name value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The server name value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getServerName() {
+ return serverName;
+ }
+
+ /**
* Overrides the server port value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -301,6 +287,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the server port value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The server port value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public Integer getServerPort() {
+ return serverPort;
+ }
+
+ /**
* Overrides the remote address value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -319,6 +314,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the remote address value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The remote address value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getRemoteAddr() {
+ return remoteAddr;
+ }
+
+ /**
* Overrides the remote host value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -337,6 +341,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the remote host value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The remote host value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getRemoteHost() {
+ return remoteHost;
+ }
+
+ /**
* Overrides the locale on the underlying {@link HttpServletRequest}
object.
*
* <p>
@@ -355,6 +368,16 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the locale to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The locale to set on the underlying {@link
HttpServletRequest} object.
+ */
+ @Override
+ public Locale getLocale() {
+ return locale;
+ }
+
+ /**
* Overrides the remote port value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -373,6 +396,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the remote port value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The remote port value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public Integer getRemotePort() {
+ return remotePort;
+ }
+
+ /**
* Overrides the local name value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -391,6 +423,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the local name value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The local name value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
* Overrides the local address value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -409,6 +450,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the local address value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The local address value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getLocalAddr() {
+ return localAddr;
+ }
+
+ /**
* Overrides the local port value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -427,6 +477,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the local port value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The local port value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public Integer getLocalPort() {
+ return localPort;
+ }
+
+ /**
* Overrides the request dispatcher on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -446,6 +505,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the request dispatcher to set on the underlying {@link
HttpServletRequest} obhject.
+ *
+ * @return The value of the <property>requestDispatcherMap</property>
property on this bean, or <jk>null</jk> if it is not set.
+ */
+ public Map<String,RequestDispatcher> getRequestDispatcherMap() {
+ return requestDispatcherMap;
+ }
+
+ /**
* Overrides the servlet context on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -464,6 +532,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the servlet context to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The servlet context to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ /**
* Overrides the dispatcher type value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -482,6 +559,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the dispatcher type value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The dispatcher type value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public DispatcherType getDispatcherType() {
+ return dispatcherType;
+ }
+
+ /**
* Overrides the authorization type value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -500,6 +586,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the authorization type value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The authorization type value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getAuthType() {
+ return authType;
+ }
+
+ /**
* Overrides the cookies on the underlying {@link HttpServletRequest}
object.
*
* <p>
@@ -518,6 +613,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the cookies to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The cookies to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public Cookie[] getCookies() {
+ return cookies;
+ }
+
+ /**
* Overrides the path-info value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -536,6 +640,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the path-info value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The path-info value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getPathInfo() {
+ return pathInfo;
+ }
+
+ /**
* Overrides the path-translated value on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -554,6 +667,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the path-translated value to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The path-translated value to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getPathTranslated() {
+ return pathTranslated;
+ }
+
+ /**
* Overrides the context path on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -572,6 +694,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the context path to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The context path to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ /**
* Overrides the query string on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -590,6 +721,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the query string to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The query string to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getQueryString() {
+ return queryString;
+ }
+
+ /**
* Overrides the remote user on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -608,6 +748,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the remote user to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The remote user to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getRemoteUser() {
+ return remoteUser;
+ }
+
+ /**
* Overrides the user principal on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -626,6 +775,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the user principal to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The user principal to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public Principal getUserPrincipal() {
+ return userPrincipal;
+ }
+
+ /**
* Overrides the requested session ID on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -644,6 +802,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the requested session ID to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The requested session ID to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getRequestedSessionId() {
+ return requestedSessionId;
+ }
+
+ /**
* Overrides the request URI on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -662,6 +829,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the request URI to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The request URI to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getRequestURI() {
+ return requestURI;
+ }
+
+ /**
* Overrides the servlet path on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -680,6 +856,15 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
}
/**
+ * Returns the servlet path to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The servlet path to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public String getServletPath() {
+ return servletPath;
+ }
+
+ /**
* Overrides the HTTP session on the underlying {@link
HttpServletRequest} object.
*
* <p>
@@ -696,4 +881,13 @@ public class MockRestRequest extends
org.apache.juneau.rest.client2.RestRequest
this.httpSession = value;
return this;
}
+
+ /**
+ * Returns the HTTP session to set on the underlying {@link
HttpServletRequest} object.
+ *
+ * @return The HTTP session to set on the underlying {@link
HttpServletRequest} object.
+ */
+ public HttpSession getHttpSession() {
+ return httpSession;
+ }
}
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockServletRequest.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockServletRequest.java
index 048ae17..6a9eb2c 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockServletRequest.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockServletRequest.java
@@ -21,6 +21,7 @@ import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
+import org.apache.http.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.rest.util.*;
@@ -948,4 +949,77 @@ public class MockServletRequest implements
HttpServletRequest {
header("X-NoTrace", true);
return this;
}
+
+ /**
+ * If the specified request is a {@link MockRestRequest}, applies any
of the override values to this servlet request.
+ *
+ * @param req The request to copy overrides from.
+ * @return This object (for method chaining).
+ */
+ public MockServletRequest applyOverrides(HttpRequest req) {
+
+ if (req instanceof MockRestRequest) {
+ MockRestRequest mreq = (MockRestRequest)req;
+ for (Map.Entry<String,Object> a :
mreq.getAttributeMap().entrySet())
+ attribute(a.getKey(), a.getValue());
+ for (Map.Entry<String,RequestDispatcher> a :
mreq.getRequestDispatcherMap().entrySet())
+ requestDispatcher(a.getKey(), a.getValue());
+ if (mreq.getCharacterEncoding() != null)
+ characterEncoding(mreq.getCharacterEncoding());
+ if (mreq.getProtocol() != null)
+ protocol(mreq.getProtocol());
+ if (mreq.getScheme() != null)
+ scheme(mreq.getScheme());
+ if (mreq.getServerName() != null)
+ serverName(mreq.getServerName());
+ if (mreq.getRemoteAddr() != null)
+ remoteAddr(mreq.getRemoteAddr());
+ if (mreq.getRemoteHost() != null)
+ remoteHost(mreq.getRemoteHost());
+ if (mreq.getLocalName() != null)
+ localName(mreq.getLocalName());
+ if (mreq.getLocalAddr() != null)
+ localAddr(mreq.getLocalAddr());
+ if (mreq.getPathInfo() != null)
+ pathInfo(mreq.getPathInfo());
+ if (mreq.getPathTranslated() != null)
+ pathTranslated(mreq.getPathTranslated());
+ if (mreq.getContextPath() != null)
+ contextPath(mreq.getContextPath());
+ if (mreq.getQueryString() != null)
+ queryString(mreq.getQueryString());
+ if (mreq.getRemoteUser() != null)
+ remoteUser(mreq.getRemoteUser());
+ if (mreq.getRequestedSessionId() != null)
+
requestedSessionId(mreq.getRequestedSessionId());
+ if (mreq.getRequestURI() != null)
+ requestURI(mreq.getRequestURI());
+ if (mreq.getServletPath() != null)
+ servletPath(mreq.getServletPath());
+ if (mreq.getAuthType() != null)
+ authType(mreq.getAuthType());
+ if (mreq.getServerPort() != null)
+ serverPort(mreq.getServerPort());
+ if (mreq.getRemotePort() != null)
+ remotePort(mreq.getRemotePort());
+ if (mreq.getLocalPort() != null)
+ localPort(mreq.getLocalPort());
+ if (mreq.getLocale() != null)
+ locale(mreq.getLocale());
+ if (mreq.getServletContext() != null)
+ servletContext(mreq.getServletContext());
+ if (mreq.getDispatcherType() != null)
+ dispatcherType(mreq.getDispatcherType());
+ if (mreq.getCookies() != null)
+ cookies(mreq.getCookies());
+ if (mreq.getUserPrincipal() != null)
+ userPrincipal(mreq.getUserPrincipal());
+ if (mreq.getHttpSession() != null)
+ httpSession(mreq.getHttpSession());
+ if (mreq.getRoles() != null)
+ roles(mreq.getRoles());
+ }
+
+ return this;
+ }
}