001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.mock2;
014
015import java.net.*;
016import java.security.*;
017import java.util.*;
018
019import javax.servlet.*;
020import javax.servlet.http.*;
021
022import org.apache.http.*;
023import org.apache.juneau.rest.client2.*;
024
025/**
026 * A subclass of {@link RestRequest} with additional features for mocked testing.
027 *
028 * <p>
029 * Instances of this class are instantiated through methods on {@link MockRestClient} such as {@link MockRestClient#post(Object,Object)}
030 *
031 * <ul class='seealso'>
032 *    <li class='link'>{@doc juneau-rest-mock}
033 * </ul>
034 */
035public class MockRestRequest extends org.apache.juneau.rest.client2.RestRequest {
036
037   //------------------------------------------------------------------------------------------------------------------
038   // Servlet request override values.
039   //------------------------------------------------------------------------------------------------------------------
040   private Map<String,Object> attributeMap = new LinkedHashMap<>();
041   private Map<String,RequestDispatcher> requestDispatcherMap = new LinkedHashMap<>();
042   private String characterEncoding, protocol, scheme, serverName, remoteAddr, remoteHost, localName, localAddr,
043      pathInfo, pathTranslated, contextPath, queryString, remoteUser, requestedSessionId, requestURI, servletPath, authType;
044   private Integer serverPort, remotePort, localPort;
045   private Locale locale;
046   private ServletContext servletContext;
047   private DispatcherType dispatcherType;
048   private Cookie[] cookies;
049   private Principal userPrincipal;
050   private HttpSession httpSession;
051   private String[] roles;
052
053   /**
054    * Constructs a REST call with the specified method name.
055    *
056    * @param client The client that created this request.
057    * @param uri The target URI.
058    * @param method The HTTP method name (uppercase).
059    * @param hasBody Whether this method has a body.
060    * @throws RestCallException If an exception or non-200 response code occurred during the connection attempt.
061    */
062   protected MockRestRequest(RestClient client, URI uri, String method, boolean hasBody) throws RestCallException {
063      super(client, uri, method, hasBody);
064   }
065
066   //------------------------------------------------------------------------------------------------------------------
067   // MockServletRequest passthrough methods.
068   //------------------------------------------------------------------------------------------------------------------
069
070   /**
071    * Adds an attribute to the underlying {@link HttpServletRequest} object.
072    *
073    * <p>
074    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
075    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
076    *
077    * @param name The servlet request attribute name.
078    * @param value The servlet request attribute value.
079    * @return This object (for method chaining).
080    */
081   public MockRestRequest attribute(String name, Object value) {
082      this.attributeMap.put(name, value);
083      return this;
084   }
085
086   /**
087    * Replaces the attributes on the underlying {@link HttpServletRequest} object.
088    *
089    * <p>
090    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
091    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
092    *
093    * @param value The new servlet attribute values.
094    * @return This object (for method chaining).
095    */
096   public MockRestRequest attributes(Map<String,Object> value) {
097      this.attributeMap.clear();
098      this.attributeMap.putAll(value);
099      return this;
100   }
101
102   /**
103    * Returns the attributes to add to the underlying {@link HttpServletRequest} object.
104    *
105    * @return The attributes to add to the underlying {@link HttpServletRequest} object.
106    */
107   public Map<String,Object> getAttributeMap() {
108      return attributeMap;
109   }
110
111   /**
112    * Specifies the user roles on the underlying {@link HttpServletRequest} object.
113    *
114    * <p>
115    * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}.
116    *
117    * <p>
118    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
119    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
120    *
121    * @param roles The roles to add to this request (e.g. <js>"ROLE_ADMIN"</js>).
122    * @return This object (for method chaining).
123    */
124   public MockRestRequest roles(String...roles) {
125      this.roles = roles;
126      return this;
127   }
128
129   /**
130    * Returns the user roles to set on the underlying {@link HttpServletRequest} object.
131    *
132    * @return The user roles to set on the underlying {@link HttpServletRequest} object.
133    */
134   public String[] getRoles() {
135      return roles;
136   }
137
138   /**
139    * Specifies the value for the security roles on the underlying {@link HttpServletRequest} object.
140    *
141    * <p>
142    * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}.
143    *
144    * <p>
145    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
146    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
147    *
148    * @param role The role to add to this request (e.g. <js>"ROLE_ADMIN"</js>).
149    * @return This object (for method chaining).
150    */
151   public MockRestRequest role(String role) {
152      this.roles = new String[]{role};
153      return this;
154   }
155
156   /**
157    * Overrides the character encoding value on the underlying {@link HttpServletRequest} object.
158    *
159    * <p>
160    * Affects the results of calling {@link HttpServletRequest#getCharacterEncoding()}.
161    *
162    * <p>
163    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
164    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
165    *
166    * @param value The new value for this setting.
167    * @return This object (for method chaining).
168    */
169   public MockRestRequest characterEncoding(String value) {
170      this.characterEncoding = value;
171      return this;
172   }
173
174   /**
175    * Returns the value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method.
176    *
177    * @return The value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method.
178    */
179   public String getCharacterEncoding() {
180      return characterEncoding;
181   }
182
183   /**
184    * Overrides the HTTP protocol value on the underlying {@link HttpServletRequest} object.
185    *
186    * <p>
187    * Affects the results of calling {@link HttpServletRequest#getProtocol()}.
188    *
189    * <p>
190    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
191    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
192    *
193    * @param value The new value for this setting.
194    * @return This object (for method chaining).
195    */
196   public MockRestRequest protocol(String value) {
197      this.protocol = value;
198      return this;
199   }
200
201   /**
202    * Returns the HTTP protocol value to set on the underlying {@link HttpServletRequest} object.
203    *
204    * @return The HTTP protocol value to set on the underlying {@link HttpServletRequest} object.
205    */
206   public String getProtocol() {
207      return protocol;
208   }
209
210   /**
211    * Overrides the HTTP schema value on the underlying {@link HttpServletRequest} object.
212    *
213    * <p>
214    * Affects the results of calling {@link HttpServletRequest#getScheme()}.
215    *
216    * <p>
217    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
218    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
219    *
220    * @param value The new value for this setting.
221    * @return This object (for method chaining).
222    */
223   @Override
224   public MockRestRequest scheme(String value) {
225      super.scheme(value);
226      this.scheme = value;
227      return this;
228   }
229
230   /**
231    * Returns the HTTP schema value to set on the underlying {@link HttpServletRequest} object.
232    *
233    * @return The HTTP schema value to set on the underlying {@link HttpServletRequest} object.
234    */
235   public String getScheme() {
236      return scheme;
237   }
238
239   /**
240    * Overrides the server name value on the underlying {@link HttpServletRequest} object.
241    *
242    * <p>
243    * Affects the results of calling {@link HttpServletRequest#getServerName()}.
244    *
245    * <p>
246    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
247    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
248    *
249    * @param value The new value for this setting.
250    * @return This object (for method chaining).
251    */
252   public MockRestRequest serverName(String value) {
253      this.serverName = value;
254      return this;
255   }
256
257   /**
258    * Returns the server name value to set on the underlying {@link HttpServletRequest} object.
259    *
260    * @return The server name value to set on the underlying {@link HttpServletRequest} object.
261    */
262   public String getServerName() {
263      return serverName;
264   }
265
266   /**
267    * Overrides the server port value on the underlying {@link HttpServletRequest} object.
268    *
269    * <p>
270    * Affects the results of calling {@link HttpServletRequest#getServerPort()}.
271    *
272    * <p>
273    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
274    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
275    *
276    * @param value The new value for this setting.
277    * @return This object (for method chaining).
278    */
279   public MockRestRequest serverPort(int value) {
280      this.serverPort = value;
281      return this;
282   }
283
284   /**
285    * Returns the server port value to set on the underlying {@link HttpServletRequest} object.
286    *
287    * @return The server port value to set on the underlying {@link HttpServletRequest} object.
288    */
289   public Integer getServerPort() {
290      return serverPort;
291   }
292
293   /**
294    * Overrides the remote address value on the underlying {@link HttpServletRequest} object.
295    *
296    * <p>
297    * Affects the results of calling {@link HttpServletRequest#getRemoteAddr()}.
298    *
299    * <p>
300    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
301    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
302    *
303    * @param value The new value for this setting.
304    * @return This object (for method chaining).
305    */
306   public MockRestRequest remoteAddr(String value) {
307      this.remoteAddr = value;
308      return this;
309   }
310
311   /**
312    * Returns the remote address value to set on the underlying {@link HttpServletRequest} object.
313    *
314    * @return The remote address value to set on the underlying {@link HttpServletRequest} object.
315    */
316   public String getRemoteAddr() {
317      return remoteAddr;
318   }
319
320   /**
321    * Overrides the remote host value on the underlying {@link HttpServletRequest} object.
322    *
323    * <p>
324    * Affects the results of calling {@link HttpServletRequest#getRemoteHost()}.
325    *
326    * <p>
327    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
328    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
329    *
330    * @param value The new value for this setting.
331    * @return This object (for method chaining).
332    */
333   public MockRestRequest remoteHost(String value) {
334      this.remoteHost = value;
335      return this;
336   }
337
338   /**
339    * Returns the remote host value to set on the underlying {@link HttpServletRequest} object.
340    *
341    * @return The remote host value to set on the underlying {@link HttpServletRequest} object.
342    */
343   public String getRemoteHost() {
344      return remoteHost;
345   }
346
347   /**
348    * Overrides the locale on the underlying {@link HttpServletRequest} object.
349    *
350    * <p>
351    * Affects the results of calling {@link HttpServletRequest#getLocale()}.
352    *
353    * <p>
354    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
355    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
356    *
357    * @param value The new value for this setting.
358    * @return This object (for method chaining).
359    */
360   public MockRestRequest locale(Locale value) {
361      this.locale = value;
362      return this;
363   }
364
365   /**
366    * Returns the locale to set on the underlying {@link HttpServletRequest} object.
367    *
368    * @return The locale to set on the underlying {@link HttpServletRequest} object.
369    */
370   @Override
371   public Locale getLocale() {
372      return locale;
373   }
374
375   /**
376    * Overrides the remote port value on the underlying {@link HttpServletRequest} object.
377    *
378    * <p>
379    * Affects the results of calling {@link HttpServletRequest#getRemotePort()}.
380    *
381    * <p>
382    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
383    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
384    *
385    * @param value The new value for this setting.
386    * @return This object (for method chaining).
387    */
388   public MockRestRequest remotePort(int value) {
389      this.remotePort = value;
390      return this;
391   }
392
393   /**
394    * Returns the remote port value to set on the underlying {@link HttpServletRequest} object.
395    *
396    * @return The remote port value to set on the underlying {@link HttpServletRequest} object.
397    */
398   public Integer getRemotePort() {
399      return remotePort;
400   }
401
402   /**
403    * Overrides the local name value on the underlying {@link HttpServletRequest} object.
404    *
405    * <p>
406    * Affects the results of calling {@link HttpServletRequest#getLocalName()}.
407    *
408    * <p>
409    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
410    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
411    *
412    * @param value The new value for this setting.
413    * @return This object (for method chaining).
414    */
415   public MockRestRequest localName(String value) {
416      this.localName = value;
417      return this;
418   }
419
420   /**
421    * Returns the local name value to set on the underlying {@link HttpServletRequest} object.
422    *
423    * @return The local name value to set on the underlying {@link HttpServletRequest} object.
424    */
425   public String getLocalName() {
426      return localName;
427   }
428
429   /**
430    * Overrides the local address value on the underlying {@link HttpServletRequest} object.
431    *
432    * <p>
433    * Affects the results of calling {@link HttpServletRequest#getLocalAddr()}.
434    *
435    * <p>
436    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
437    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
438    *
439    * @param value The new value for this setting.
440    * @return This object (for method chaining).
441    */
442   public MockRestRequest localAddr(String value) {
443      this.localAddr = value;
444      return this;
445   }
446
447   /**
448    * Returns the local address value to set on the underlying {@link HttpServletRequest} object.
449    *
450    * @return The local address value to set on the underlying {@link HttpServletRequest} object.
451    */
452   public String getLocalAddr() {
453      return localAddr;
454   }
455
456   /**
457    * Overrides the local port value on the underlying {@link HttpServletRequest} object.
458    *
459    * <p>
460    * Affects the results of calling {@link HttpServletRequest#getLocalPort()}.
461    *
462    * <p>
463    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
464    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
465    *
466    * @param value The new value for this setting.
467    * @return This object (for method chaining).
468    */
469   public MockRestRequest localPort(int value) {
470      this.localPort = value;
471      return this;
472   }
473
474   /**
475    * Returns the local port value to set on the underlying {@link HttpServletRequest} object.
476    *
477    * @return The local port value to set on the underlying {@link HttpServletRequest} object.
478    */
479   public Integer getLocalPort() {
480      return localPort;
481   }
482
483   /**
484    * Overrides the request dispatcher on the underlying {@link HttpServletRequest} object.
485    *
486    * <p>
487    * Affects the results of calling {@link HttpServletRequest#getRequestDispatcher(String)}.
488    *
489    * <p>
490    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
491    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
492    *
493    * @param path The path to the resource being resolved.
494    * @param value The new value for this setting.
495    * @return This object (for method chaining).
496    */
497   public MockRestRequest requestDispatcher(String path, RequestDispatcher value) {
498      this.requestDispatcherMap.put(path, value);
499      return this;
500   }
501
502   /**
503    * Returns the request dispatcher to set on the underlying {@link HttpServletRequest} obhject.
504    *
505    * @return The value of the <property>requestDispatcherMap</property> property on this bean, or <jk>null</jk> if it is not set.
506    */
507   public Map<String,RequestDispatcher> getRequestDispatcherMap() {
508      return requestDispatcherMap;
509   }
510
511   /**
512    * Overrides the servlet context on the underlying {@link HttpServletRequest} object.
513    *
514    * <p>
515    * Affects the results of calling {@link HttpServletRequest#getServletContext()}.
516    *
517    * <p>
518    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
519    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
520    *
521    * @param value The new value for this setting.
522    * @return This object (for method chaining).
523    */
524   public MockRestRequest servletContext(ServletContext value) {
525      this.servletContext = value;
526      return this;
527   }
528
529   /**
530    * Returns the servlet context to set on the underlying {@link HttpServletRequest} object.
531    *
532    * @return The servlet context to set on the underlying {@link HttpServletRequest} object.
533    */
534   public ServletContext getServletContext() {
535      return servletContext;
536   }
537
538   /**
539    * Overrides the dispatcher type value on the underlying {@link HttpServletRequest} object.
540    *
541    * <p>
542    * Affects the results of calling {@link HttpServletRequest#getDispatcherType()}.
543    *
544    * <p>
545    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
546    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
547    *
548    * @param value The new value for this setting.
549    * @return This object (for method chaining).
550    */
551   public MockRestRequest dispatcherType(DispatcherType value) {
552      this.dispatcherType = value;
553      return this;
554   }
555
556   /**
557    * Returns the dispatcher type value to set on the underlying {@link HttpServletRequest} object.
558    *
559    * @return The dispatcher type value to set on the underlying {@link HttpServletRequest} object.
560    */
561   public DispatcherType getDispatcherType() {
562      return dispatcherType;
563   }
564
565   /**
566    * Overrides the authorization type value on the underlying {@link HttpServletRequest} object.
567    *
568    * <p>
569    * Affects the results of calling {@link HttpServletRequest#getAuthType()}.
570    *
571    * <p>
572    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
573    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
574    *
575    * @param value The new value for this setting.
576    * @return This object (for method chaining).
577    */
578   public MockRestRequest authType(String value) {
579      this.authType = value;
580      return this;
581   }
582
583   /**
584    * Returns the authorization type value to set on the underlying {@link HttpServletRequest} object.
585    *
586    * @return The authorization type value to set on the underlying {@link HttpServletRequest} object.
587    */
588   public String getAuthType() {
589      return authType;
590   }
591
592   /**
593    * Overrides the cookies on the underlying {@link HttpServletRequest} object.
594    *
595    * <p>
596    * Affects the results of calling {@link HttpServletRequest#getCookies()}.
597    *
598    * <p>
599    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
600    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
601    *
602    * @param value The new value for this setting.
603    * @return This object (for method chaining).
604    */
605   public MockRestRequest cookies(Cookie[] value) {
606      this.cookies = value;
607      return this;
608   }
609
610   /**
611    * Returns the cookies to set on the underlying {@link HttpServletRequest} object.
612    *
613    * @return The cookies to set on the underlying {@link HttpServletRequest} object.
614    */
615   public Cookie[] getCookies() {
616      return cookies;
617   }
618
619   /**
620    * Overrides the path-info value on the underlying {@link HttpServletRequest} object.
621    *
622    * <p>
623    * Affects the results of calling {@link HttpServletRequest#getPathInfo()}.
624    *
625    * <p>
626    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
627    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
628    *
629    * @param value The new value for this setting.
630    * @return This object (for method chaining).
631    */
632   public MockRestRequest pathInfo(String value) {
633      this.pathInfo = value;
634      return this;
635   }
636
637   /**
638    * Returns the path-info value to set on the underlying {@link HttpServletRequest} object.
639    *
640    * @return The path-info value to set on the underlying {@link HttpServletRequest} object.
641    */
642   public String getPathInfo() {
643      return pathInfo;
644   }
645
646   /**
647    * Overrides the path-translated value on the underlying {@link HttpServletRequest} object.
648    *
649    * <p>
650    * Affects the results of calling {@link HttpServletRequest#getPathTranslated()}.
651    *
652    * <p>
653    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
654    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
655    *
656    * @param value The new value for this setting.
657    * @return This object (for method chaining).
658    */
659   public MockRestRequest pathTranslated(String value) {
660      this.pathTranslated = value;
661      return this;
662   }
663
664   /**
665    * Returns the path-translated value to set on the underlying {@link HttpServletRequest} object.
666    *
667    * @return The path-translated value to set on the underlying {@link HttpServletRequest} object.
668    */
669   public String getPathTranslated() {
670      return pathTranslated;
671   }
672
673   /**
674    * Overrides the context path on the underlying {@link HttpServletRequest} object.
675    *
676    * <p>
677    * Affects the results of calling {@link HttpServletRequest#getContextPath()}.
678    *
679    * <p>
680    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
681    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
682    *
683    * @param value The new value for this setting.
684    * @return This object (for method chaining).
685    */
686   public MockRestRequest contextPath(String value) {
687      this.contextPath = value;
688      return this;
689   }
690
691   /**
692    * Returns the context path to set on the underlying {@link HttpServletRequest} object.
693    *
694    * @return The context path to set on the underlying {@link HttpServletRequest} object.
695    */
696   public String getContextPath() {
697      return contextPath;
698   }
699
700   /**
701    * Overrides the query string on the underlying {@link HttpServletRequest} object.
702    *
703    * <p>
704    * Affects the results of calling {@link HttpServletRequest#getQueryString()}.
705    *
706    * <p>
707    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
708    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
709    *
710    * @param value The new value for this setting.
711    * @return This object (for method chaining).
712    */
713   public MockRestRequest queryString(String value) {
714      this.queryString = value;
715      return this;
716   }
717
718   /**
719    * Returns the query string to set on the underlying {@link HttpServletRequest} object.
720    *
721    * @return The query string to set on the underlying {@link HttpServletRequest} object.
722    */
723   public String getQueryString() {
724      return queryString;
725   }
726
727   /**
728    * Overrides the remote user on the underlying {@link HttpServletRequest} object.
729    *
730    * <p>
731    * Affects the results of calling {@link HttpServletRequest#getRemoteUser()}.
732    *
733    * <p>
734    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
735    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
736    *
737    * @param value The new value for this setting.
738    * @return This object (for method chaining).
739    */
740   public MockRestRequest remoteUser(String value) {
741      this.remoteUser = value;
742      return this;
743   }
744
745   /**
746    * Returns the remote user to set on the underlying {@link HttpServletRequest} object.
747    *
748    * @return The remote user to set on the underlying {@link HttpServletRequest} object.
749    */
750   public String getRemoteUser() {
751      return remoteUser;
752   }
753
754   /**
755    * Overrides the user principal on the underlying {@link HttpServletRequest} object.
756    *
757    * <p>
758    * Affects the results of calling {@link HttpServletRequest#getUserPrincipal()}.
759    *
760    * <p>
761    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
762    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
763    *
764    * @param value The new value for this setting.
765    * @return This object (for method chaining).
766    */
767   public MockRestRequest userPrincipal(Principal value) {
768      this.userPrincipal = value;
769      return this;
770   }
771
772   /**
773    * Returns the user principal to set on the underlying {@link HttpServletRequest} object.
774    *
775    * @return The user principal to set on the underlying {@link HttpServletRequest} object.
776    */
777   public Principal getUserPrincipal() {
778      return userPrincipal;
779   }
780
781   /**
782    * Overrides the requested session ID on the underlying {@link HttpServletRequest} object.
783    *
784    * <p>
785    * Affects the results of calling {@link HttpServletRequest#getRequestedSessionId()}.
786    *
787    * <p>
788    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
789    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
790    *
791    * @param value The new value for this setting.
792    * @return This object (for method chaining).
793    */
794   public MockRestRequest requestedSessionId(String value) {
795      this.requestedSessionId = value;
796      return this;
797   }
798
799   /**
800    * Returns the requested session ID to set on the underlying {@link HttpServletRequest} object.
801    *
802    * @return The requested session ID to set on the underlying {@link HttpServletRequest} object.
803    */
804   public String getRequestedSessionId() {
805      return requestedSessionId;
806   }
807
808   /**
809    * Overrides the request URI on the underlying {@link HttpServletRequest} object.
810    *
811    * <p>
812    * Affects the results of calling {@link HttpServletRequest#getRequestURI()}.
813    *
814    * <p>
815    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
816    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
817    *
818    * @param value The new value for this setting.
819    * @return This object (for method chaining).
820    */
821   public MockRestRequest requestURI(String value) {
822      this.requestURI = value;
823      return this;
824   }
825
826   /**
827    * Returns the request URI to set on the underlying {@link HttpServletRequest} object.
828    *
829    * @return The request URI to set on the underlying {@link HttpServletRequest} object.
830    */
831   public String getRequestURI() {
832      return requestURI;
833   }
834
835   /**
836    * Overrides the servlet path on the underlying {@link HttpServletRequest} object.
837    *
838    * <p>
839    * Affects the results of calling {@link HttpServletRequest#getServletPath()}.
840    *
841    * <p>
842    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
843    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
844    *
845    * @param value The new value for this setting.
846    * @return This object (for method chaining).
847    */
848   public MockRestRequest servletPath(String value) {
849      this.servletPath = value;
850      return this;
851   }
852
853   /**
854    * Returns the servlet path to set on the underlying {@link HttpServletRequest} object.
855    *
856    * @return The servlet path to set on the underlying {@link HttpServletRequest} object.
857    */
858   public String getServletPath() {
859      return servletPath;
860   }
861
862   /**
863    * Overrides the HTTP session on the underlying {@link HttpServletRequest} object.
864    *
865    * <p>
866    * Affects the results of calling {@link HttpServletRequest#getSession()}.
867    *
868    * <p>
869    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
870    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
871    *
872    * @param value The new value for this setting.
873    * @return This object (for method chaining).
874    */
875   public MockRestRequest httpSession(HttpSession value) {
876      this.httpSession = value;
877      return this;
878   }
879
880   /**
881    * Returns the HTTP session to set on the underlying {@link HttpServletRequest} object.
882    *
883    * @return The HTTP session to set on the underlying {@link HttpServletRequest} object.
884    */
885   public HttpSession getHttpSession() {
886      return httpSession;
887   }
888}