001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.mock.classic;
018
019import static org.apache.juneau.commons.utils.CollectionUtils.*;
020import static org.apache.juneau.commons.utils.Shorts.*;
021
022import java.net.*;
023import java.security.*;
024import java.util.*;
025import java.util.function.*;
026
027import org.apache.http.*;
028import org.apache.http.client.config.*;
029import org.apache.http.concurrent.*;
030import org.apache.http.protocol.*;
031import org.apache.juneau.marshall.httppart.*;
032import org.apache.juneau.marshall.parser.*;
033import org.apache.juneau.marshall.serializer.*;
034import org.apache.juneau.rest.client.classic.*;
035
036import jakarta.servlet.*;
037import jakarta.servlet.http.*;
038
039/**
040 * A subclass of {@link RestRequest} with additional features for mocked testing.
041 *
042 * <p>
043 * Instances of this class are instantiated through methods on {@link MockRestClient} such as {@link MockRestClient#post(Object,Object)}
044 *
045 * <h5 class='section'>Notes:</h5><ul>
046 *    <li class='warn'>This class is not thread safe.
047 * </ul>
048 *
049 * <h5 class='section'>See Also:</h5><ul>
050 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestMock">juneau-rest-mock</a>
051 * </ul>
052 */
053@SuppressWarnings({
054   "resource" // MockRestRequest manages Closeable resources
055})
056public class MockRestRequest extends RestRequest {
057   private final Map<String,Object> attributeMap = map();
058   private final Map<String,RequestDispatcher> requestDispatcherMap = map();
059   private String characterEncoding;
060   private String protocol;
061   private String scheme;
062   private String serverName;
063   private String remoteAddr;
064   private String remoteHost;
065   private String localName;
066   private String localAddr;
067   private String pathInfo;
068   private String pathTranslated;
069   private String contextPath;
070   private String queryString;
071   private String remoteUser;
072   private String requestedSessionId;
073   private String requestURI;
074   private String servletPath;
075   private String authType;
076   private Integer serverPort;
077   private Integer remotePort;
078   private Integer localPort;
079   private Locale locale;
080   private ServletContext servletContext;
081   private DispatcherType dispatcherType;
082   private Cookie[] cookies;
083   private Principal userPrincipal;
084   private HttpSession httpSession;
085   private String[] roles;
086
087   /**
088    * Constructs a REST call with the specified method name.
089    *
090    * @param client The client that created this request.
091    * @param uri The target URI.
092    * @param method The HTTP method name (uppercase).
093    * @param hasBody Whether this method has a body.
094    * @throws RestCallException If an exception or non-200 response code occurred during the connection attempt.
095    */
096   protected MockRestRequest(RestClient client, URI uri, String method, boolean hasBody) throws RestCallException {
097      super(client, uri, method, hasBody);
098   }
099
100   @Override /* Overridden from RestRequest */
101   public MockRestRequest accept(String value) throws RestCallException {
102      super.accept(value);
103      return this;
104   }
105
106   @Override /* Overridden from RestRequest */
107   public MockRestRequest acceptCharset(String value) throws RestCallException {
108      super.acceptCharset(value);
109      return this;
110   }
111
112   /**
113    * Adds an attribute to the underlying {@link HttpServletRequest} object.
114    *
115    * <p>
116    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
117    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
118    *
119    * @param name The servlet request attribute name.
120    * @param value The servlet request attribute value.
121    * @return This object.
122    */
123   public MockRestRequest attribute(String name, Object value) {
124      this.attributeMap.put(name, value);
125      return this;
126   }
127
128   /**
129    * Replaces the attributes on the underlying {@link HttpServletRequest} object.
130    *
131    * <p>
132    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
133    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
134    *
135    * @param value The new servlet attribute values.
136    * @return This object.
137    */
138   public MockRestRequest attributes(Map<String,Object> value) {
139      this.attributeMap.clear();
140      this.attributeMap.putAll(value);
141      return this;
142   }
143
144   /**
145    * Overrides the authorization type value on the underlying {@link HttpServletRequest} object.
146    *
147    * <p>
148    * Affects the results of calling {@link HttpServletRequest#getAuthType()}.
149    *
150    * <p>
151    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
152    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
153    *
154    * @param value The new value for this setting.
155    * @return This object.
156    */
157   public MockRestRequest authType(String value) {
158      authType = value;
159      return this;
160   }
161
162   @Override /* Overridden from RestRequest */
163   public MockRestRequest cancellable(Cancellable cancellable) {
164      super.cancellable(cancellable);
165      return this;
166   }
167
168   /**
169    * Overrides the character encoding value on the underlying {@link HttpServletRequest} object.
170    *
171    * <p>
172    * Affects the results of calling {@link HttpServletRequest#getCharacterEncoding()}.
173    *
174    * <p>
175    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
176    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
177    *
178    * @param value The new value for this setting.
179    * @return This object.
180    */
181   public MockRestRequest characterEncoding(String value) {
182      characterEncoding = value;
183      return this;
184   }
185
186   @Override /* Overridden from RestRequest */
187   public MockRestRequest config(RequestConfig value) {
188      super.config(value);
189      return this;
190   }
191
192   @Override /* Overridden from RestRequest */
193   public MockRestRequest content(Object value) {
194      super.content(value);
195      return this;
196   }
197
198   @Override /* Overridden from RestRequest */
199   public MockRestRequest content(Object input, HttpPartSchema schema) {
200      super.content(input, schema);
201      return this;
202   }
203
204   @Override /* Overridden from RestRequest */
205   public MockRestRequest contentString(Object input) throws RestCallException {
206      super.contentString(input);
207      return this;
208   }
209
210   @Override /* Overridden from RestRequest */
211   public MockRestRequest contentType(String value) throws RestCallException {
212      super.contentType(value);
213      return this;
214   }
215
216   @Override /* Overridden from RestRequest */
217   public MockRestRequest context(HttpContext context) {
218      super.context(context);
219      return this;
220   }
221
222   /**
223    * Overrides the context path on the underlying {@link HttpServletRequest} object.
224    *
225    * <p>
226    * Affects the results of calling {@link HttpServletRequest#getContextPath()}.
227    *
228    * <p>
229    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
230    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
231    *
232    * @param value The new value for this setting.
233    * @return This object.
234    */
235   public MockRestRequest contextPath(String value) {
236      contextPath = value;
237      return this;
238   }
239
240   /**
241    * Overrides the cookies on the underlying {@link HttpServletRequest} object.
242    *
243    * <p>
244    * Affects the results of calling {@link HttpServletRequest#getCookies()}.
245    *
246    * <p>
247    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
248    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
249    *
250    * @param value The new value for this setting.
251    * @return This object.
252    */
253   public MockRestRequest cookies(Cookie[] value) {
254      cookies = value;
255      return this;
256   }
257
258   @Override /* Overridden from RestRequest */
259   public MockRestRequest debug() throws RestCallException {
260      super.debug();
261      return this;
262   }
263
264   /**
265    * Overrides the dispatcher type value on the underlying {@link HttpServletRequest} object.
266    *
267    * <p>
268    * Affects the results of calling {@link HttpServletRequest#getDispatcherType()}.
269    *
270    * <p>
271    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
272    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
273    *
274    * @param value The new value for this setting.
275    * @return This object.
276    */
277   public MockRestRequest dispatcherType(DispatcherType value) {
278      dispatcherType = value;
279      return this;
280   }
281
282   @Override /* Overridden from RestRequest */
283   public MockRestRequest errorCodes(Predicate<Integer> value) {
284      super.errorCodes(value);
285      return this;
286   }
287
288   @Override /* Overridden from RestRequest */
289   public MockRestRequest formData(NameValuePair...parts) {
290      super.formData(parts);
291      return this;
292   }
293
294   @Override /* Overridden from RestRequest */
295   public MockRestRequest formData(String name, Object value) {
296      super.formData(name, value);
297      return this;
298   }
299
300   @Override /* Overridden from RestRequest */
301   public MockRestRequest formDataBean(Object value) {
302      super.formDataBean(value);
303      return this;
304   }
305
306   @Override /* Overridden from RestRequest */
307   public MockRestRequest formDataCustom(Object value) {
308      super.formDataCustom(value);
309      return this;
310   }
311
312   @Override /* Overridden from RestRequest */
313   public MockRestRequest formDataPairs(String...pairs) throws RestCallException {
314      super.formDataPairs(pairs);
315      return this;
316   }
317
318   /**
319    * Returns the attributes to add to the underlying {@link HttpServletRequest} object.
320    *
321    * @return The attributes to add to the underlying {@link HttpServletRequest} object.
322    */
323   public Map<String,Object> getAttributeMap() { return attributeMap; }
324
325   /**
326    * Returns the authorization type value to set on the underlying {@link HttpServletRequest} object.
327    *
328    * @return The authorization type value to set on the underlying {@link HttpServletRequest} object.
329    */
330   public String getAuthType() { return authType; }
331
332   /**
333    * Returns the value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method.
334    *
335    * @return The value to set for the return value on the underlying {@link HttpServletRequest#getCharacterEncoding()} method.
336    */
337   public String getCharacterEncoding() { return characterEncoding; }
338
339   /**
340    * Returns the context path to set on the underlying {@link HttpServletRequest} object.
341    *
342    * @return The context path to set on the underlying {@link HttpServletRequest} object.
343    */
344   public String getContextPath() { return contextPath; }
345
346   /**
347    * Returns the cookies to set on the underlying {@link HttpServletRequest} object.
348    *
349    * @return The cookies to set on the underlying {@link HttpServletRequest} object.
350    */
351   public Cookie[] getCookies() { return cookies; }
352
353   /**
354    * Returns the dispatcher type value to set on the underlying {@link HttpServletRequest} object.
355    *
356    * @return The dispatcher type value to set on the underlying {@link HttpServletRequest} object.
357    */
358   public DispatcherType getDispatcherType() { return dispatcherType; }
359
360   /**
361    * Returns the HTTP session to set on the underlying {@link HttpServletRequest} object.
362    *
363    * @return The HTTP session to set on the underlying {@link HttpServletRequest} object.
364    */
365   public HttpSession getHttpSession() { return httpSession; }
366
367   /**
368    * Returns the local address value to set on the underlying {@link HttpServletRequest} object.
369    *
370    * @return The local address value to set on the underlying {@link HttpServletRequest} object.
371    */
372   public String getLocalAddr() { return localAddr; }
373
374   /**
375    * Returns the locale to set on the underlying {@link HttpServletRequest} object.
376    *
377    * @return The locale to set on the underlying {@link HttpServletRequest} object.
378    */
379   @Override
380   public Locale getLocale() { return locale; }
381
382   /**
383    * Returns the local name value to set on the underlying {@link HttpServletRequest} object.
384    *
385    * @return The local name value to set on the underlying {@link HttpServletRequest} object.
386    */
387   public String getLocalName() { return localName; }
388
389   /**
390    * Returns the local port value to set on the underlying {@link HttpServletRequest} object.
391    *
392    * @return The local port value to set on the underlying {@link HttpServletRequest} object.
393    */
394   public Integer getLocalPort() { return localPort; }
395
396   /**
397    * Returns the path-info value to set on the underlying {@link HttpServletRequest} object.
398    *
399    * @return The path-info value to set on the underlying {@link HttpServletRequest} object.
400    */
401   public String getPathInfo() { return pathInfo; }
402
403   /**
404    * Returns the path-translated value to set on the underlying {@link HttpServletRequest} object.
405    *
406    * @return The path-translated value to set on the underlying {@link HttpServletRequest} object.
407    */
408   public String getPathTranslated() { return pathTranslated; }
409
410   /**
411    * Returns the HTTP protocol value to set on the underlying {@link HttpServletRequest} object.
412    *
413    * @return The HTTP protocol value to set on the underlying {@link HttpServletRequest} object.
414    */
415   public String getProtocol() { return protocol; }
416
417   /**
418    * Returns the query string to set on the underlying {@link HttpServletRequest} object.
419    *
420    * @return The query string to set on the underlying {@link HttpServletRequest} object.
421    */
422   public String getQueryString() { return queryString; }
423
424   /**
425    * Returns the remote address value to set on the underlying {@link HttpServletRequest} object.
426    *
427    * @return The remote address value to set on the underlying {@link HttpServletRequest} object.
428    */
429   public String getRemoteAddr() { return remoteAddr; }
430
431   /**
432    * Returns the remote host value to set on the underlying {@link HttpServletRequest} object.
433    *
434    * @return The remote host value to set on the underlying {@link HttpServletRequest} object.
435    */
436   public String getRemoteHost() { return remoteHost; }
437
438   /**
439    * Returns the remote port value to set on the underlying {@link HttpServletRequest} object.
440    *
441    * @return The remote port value to set on the underlying {@link HttpServletRequest} object.
442    */
443   public Integer getRemotePort() { return remotePort; }
444
445   /**
446    * Returns the remote user to set on the underlying {@link HttpServletRequest} object.
447    *
448    * @return The remote user to set on the underlying {@link HttpServletRequest} object.
449    */
450   public String getRemoteUser() { return remoteUser; }
451
452   /**
453    * Returns the request dispatcher to set on the underlying {@link HttpServletRequest} object.
454    *
455    * @return The request dispatcher map. Never <jk>null</jk>.
456    */
457   public Map<String,RequestDispatcher> getRequestDispatcherMap() { return requestDispatcherMap; }
458
459   /**
460    * Returns the requested session ID to set on the underlying {@link HttpServletRequest} object.
461    *
462    * @return The requested session ID to set on the underlying {@link HttpServletRequest} object.
463    */
464   public String getRequestedSessionId() { return requestedSessionId; }
465
466   /**
467    * Returns the request URI to set on the underlying {@link HttpServletRequest} object.
468    *
469    * @return The request URI to set on the underlying {@link HttpServletRequest} object.
470    */
471   public String getRequestURI() { return requestURI; }
472
473   /**
474    * Returns the user roles to set on the underlying {@link HttpServletRequest} object.
475    *
476    * @return The user roles to set on the underlying {@link HttpServletRequest} object.
477    */
478   public String[] getRoles() { return roles; }
479
480   /**
481    * Returns the HTTP schema value to set on the underlying {@link HttpServletRequest} object.
482    *
483    * @return The HTTP schema value to set on the underlying {@link HttpServletRequest} object.
484    */
485   public String getScheme() { return scheme; }
486
487   /**
488    * Returns the server name value to set on the underlying {@link HttpServletRequest} object.
489    *
490    * @return The server name value to set on the underlying {@link HttpServletRequest} object.
491    */
492   public String getServerName() { return serverName; }
493
494   /**
495    * Returns the server port value to set on the underlying {@link HttpServletRequest} object.
496    *
497    * @return The server port value to set on the underlying {@link HttpServletRequest} object.
498    */
499   public Integer getServerPort() { return serverPort; }
500
501   /**
502    * Returns the servlet context to set on the underlying {@link HttpServletRequest} object.
503    *
504    * @return The servlet context to set on the underlying {@link HttpServletRequest} object.
505    */
506   public ServletContext getServletContext() { return servletContext; }
507
508   /**
509    * Returns the servlet path to set on the underlying {@link HttpServletRequest} object.
510    *
511    * @return The servlet path to set on the underlying {@link HttpServletRequest} object.
512    */
513   public String getServletPath() { return servletPath; }
514
515   /**
516    * Returns the user principal to set on the underlying {@link HttpServletRequest} object.
517    *
518    * @return The user principal to set on the underlying {@link HttpServletRequest} object.
519    */
520   public Principal getUserPrincipal() { return userPrincipal; }
521
522   @Override /* Overridden from RestRequest */
523   public MockRestRequest header(Header part) {
524      super.header(part);
525      return this;
526   }
527
528   @Override /* Overridden from RestRequest */
529   public MockRestRequest header(String name, Object value) {
530      super.header(name, value);
531      return this;
532   }
533
534   @Override /* Overridden from RestRequest */
535   public MockRestRequest headerPairs(String...pairs) {
536      super.headerPairs(pairs);
537      return this;
538   }
539
540   @Override /* Overridden from RestRequest */
541   public MockRestRequest headers(Header...parts) {
542      super.headers(parts);
543      return this;
544   }
545
546   @Override /* Overridden from RestRequest */
547   public MockRestRequest headersBean(Object value) {
548      super.headersBean(value);
549      return this;
550   }
551
552   @Override /* Overridden from RestRequest */
553   public MockRestRequest html() {
554      super.html();
555      return this;
556   }
557
558   @Override /* Overridden from RestRequest */
559   public MockRestRequest htmlDoc() {
560      super.htmlDoc();
561      return this;
562   }
563
564   @Override /* Overridden from RestRequest */
565   public MockRestRequest htmlStrippedDoc() {
566      super.htmlStrippedDoc();
567      return this;
568   }
569
570   /**
571    * Overrides the HTTP session on the underlying {@link HttpServletRequest} object.
572    *
573    * <p>
574    * Affects the results of calling {@link HttpServletRequest#getSession()}.
575    *
576    * <p>
577    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
578    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
579    *
580    * @param value The new value for this setting.
581    * @return This object.
582    */
583   public MockRestRequest httpSession(HttpSession value) {
584      httpSession = value;
585      return this;
586   }
587
588   @Override /* Overridden from RestRequest */
589   public MockRestRequest ignoreErrors() {
590      super.ignoreErrors();
591      return this;
592   }
593
594   @Override /* Overridden from RestRequest */
595   public MockRestRequest interceptors(RestCallInterceptor...interceptors) throws RestCallException {
596      super.interceptors(interceptors);
597      return this;
598   }
599
600   @Override /* Overridden from RestRequest */
601   public MockRestRequest json() {
602      super.json();
603      return this;
604   }
605
606   @Override /* Overridden from RestRequest */
607   public MockRestRequest json5() {
608      super.json5();
609      return this;
610   }
611
612   /**
613    * Overrides the local address value on the underlying {@link HttpServletRequest} object.
614    *
615    * <p>
616    * Affects the results of calling {@link HttpServletRequest#getLocalAddr()}.
617    *
618    * <p>
619    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
620    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
621    *
622    * @param value The new value for this setting.
623    * @return This object.
624    */
625   public MockRestRequest localAddr(String value) {
626      localAddr = value;
627      return this;
628   }
629
630   /**
631    * Overrides the locale on the underlying {@link HttpServletRequest} object.
632    *
633    * <p>
634    * Affects the results of calling {@link HttpServletRequest#getLocale()}.
635    *
636    * <p>
637    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
638    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
639    *
640    * @param value The new value for this setting.
641    * @return This object.
642    */
643   public MockRestRequest locale(Locale value) {
644      locale = value;
645      return this;
646   }
647
648   /**
649    * Overrides the local name value on the underlying {@link HttpServletRequest} object.
650    *
651    * <p>
652    * Affects the results of calling {@link HttpServletRequest#getLocalName()}.
653    *
654    * <p>
655    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
656    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
657    *
658    * @param value The new value for this setting.
659    * @return This object.
660    */
661   public MockRestRequest localName(String value) {
662      localName = value;
663      return this;
664   }
665
666   /**
667    * Overrides the local port value on the underlying {@link HttpServletRequest} object.
668    *
669    * <p>
670    * Affects the results of calling {@link HttpServletRequest#getLocalPort()}.
671    *
672    * <p>
673    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
674    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
675    *
676    * @param value The new value for this setting.
677    * @return This object.
678    */
679   public MockRestRequest localPort(int value) {
680      localPort = value;
681      return this;
682   }
683
684   @Override /* Overridden from RestRequest */
685   public MockRestRequest mediaType(String value) throws RestCallException {
686      super.mediaType(value);
687      return this;
688   }
689
690   @Override /* Overridden from RestRequest */
691   public MockRestRequest bson() {
692      super.bson();
693      return this;
694   }
695
696   @Override /* Overridden from RestRequest */
697   public MockRestRequest msgPack() {
698      super.msgPack();
699      return this;
700   }
701
702   @Override /* Overridden from RestRequest */
703   public MockRestRequest noTrace() throws RestCallException {
704      super.noTrace();
705      return this;
706   }
707
708   @Override /* Overridden from RestRequest */
709   public MockRestRequest openApi() {
710      super.openApi();
711      return this;
712   }
713
714   @Override /* Overridden from RestRequest */
715   public MockRestRequest parser(Class<? extends Parser> parser) {
716      super.parser(parser);
717      return this;
718   }
719
720   @Override /* Overridden from RestRequest */
721   public MockRestRequest parser(Parser parser) {
722      super.parser(parser);
723      return this;
724   }
725
726   @Override /* Overridden from RestRequest */
727   public MockRestRequest pathData(NameValuePair...parts) {
728      super.pathData(parts);
729      return this;
730   }
731
732   @Override /* Overridden from RestRequest */
733   public MockRestRequest pathData(String name, Object value) {
734      super.pathData(name, value);
735      return this;
736   }
737
738   @Override /* Overridden from RestRequest */
739   public MockRestRequest pathDataBean(Object value) {
740      super.pathDataBean(value);
741      return this;
742   }
743
744   @Override /* Overridden from RestRequest */
745   public MockRestRequest pathDataPairs(String...pairs) {
746      super.pathDataPairs(pairs);
747      return this;
748   }
749
750   /**
751    * Overrides the path-info value on the underlying {@link HttpServletRequest} object.
752    *
753    * <p>
754    * Affects the results of calling {@link HttpServletRequest#getPathInfo()}.
755    *
756    * <p>
757    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
758    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
759    *
760    * @param value The new value for this setting.
761    * @return This object.
762    */
763   public MockRestRequest pathInfo(String value) {
764      pathInfo = value;
765      return this;
766   }
767
768   /**
769    * Overrides the path-translated value on the underlying {@link HttpServletRequest} object.
770    *
771    * <p>
772    * Affects the results of calling {@link HttpServletRequest#getPathTranslated()}.
773    *
774    * <p>
775    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
776    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
777    *
778    * @param value The new value for this setting.
779    * @return This object.
780    */
781   public MockRestRequest pathTranslated(String value) {
782      pathTranslated = value;
783      return this;
784   }
785
786   @Override /* Overridden from RestRequest */
787   public MockRestRequest plainText() {
788      super.plainText();
789      return this;
790   }
791
792   /**
793    * Overrides the HTTP protocol value on the underlying {@link HttpServletRequest} object.
794    *
795    * <p>
796    * Affects the results of calling {@link HttpServletRequest#getProtocol()}.
797    *
798    * <p>
799    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
800    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
801    *
802    * @param value The new value for this setting.
803    * @return This object.
804    */
805   public MockRestRequest protocol(String value) {
806      protocol = value;
807      return this;
808   }
809
810   @Override /* Overridden from RestRequest */
811   public MockRestRequest serializerSessionOptionsHeader(String json5) {
812      super.serializerSessionOptionsHeader(json5);
813      return this;
814   }
815
816   @Override /* Overridden from RestRequest */
817   public MockRestRequest serializerSessionOptionsHeader(Map<String,?> properties) {
818      super.serializerSessionOptionsHeader(properties);
819      return this;
820   }
821
822   @Override /* Overridden from RestRequest */
823   public MockRestRequest serializerSessionOptionsQuery(String uon) {
824      super.serializerSessionOptionsQuery(uon);
825      return this;
826   }
827
828   @Override /* Overridden from RestRequest */
829   public MockRestRequest serializerSessionOptionsQuery(Map<String,?> properties) {
830      super.serializerSessionOptionsQuery(properties);
831      return this;
832   }
833
834   @Override /* Overridden from RestRequest */
835   public MockRestRequest parserSessionOptionsHeader(String json5) {
836      super.parserSessionOptionsHeader(json5);
837      return this;
838   }
839
840   @Override /* Overridden from RestRequest */
841   public MockRestRequest parserSessionOptionsHeader(Map<String,?> properties) {
842      super.parserSessionOptionsHeader(properties);
843      return this;
844   }
845
846   @Override /* Overridden from RestRequest */
847   public MockRestRequest parserSessionOptionsQuery(String uon) {
848      super.parserSessionOptionsQuery(uon);
849      return this;
850   }
851
852   @Override /* Overridden from RestRequest */
853   public MockRestRequest parserSessionOptionsQuery(Map<String,?> properties) {
854      super.parserSessionOptionsQuery(properties);
855      return this;
856   }
857
858   @Override /* Overridden from RestRequest */
859   public MockRestRequest protocolVersion(ProtocolVersion version) {
860      super.protocolVersion(version);
861      return this;
862   }
863
864   @Override /* Overridden from RestRequest */
865   public MockRestRequest queryCustom(Object value) {
866      super.queryCustom(value);
867      return this;
868   }
869
870   @Override /* Overridden from RestRequest */
871   public MockRestRequest queryData(NameValuePair...parts) {
872      super.queryData(parts);
873      return this;
874   }
875
876   @Override /* Overridden from RestRequest */
877   public MockRestRequest queryData(String name, Object value) {
878      super.queryData(name, value);
879      return this;
880   }
881
882   @Override /* Overridden from RestRequest */
883   public MockRestRequest queryDataBean(Object value) {
884      super.queryDataBean(value);
885      return this;
886   }
887
888   @Override /* Overridden from RestRequest */
889   public MockRestRequest queryDataPairs(String...pairs) throws RestCallException {
890      super.queryDataPairs(pairs);
891      return this;
892   }
893
894   /**
895    * Overrides the query string on the underlying {@link HttpServletRequest} object.
896    *
897    * <p>
898    * Affects the results of calling {@link HttpServletRequest#getQueryString()}.
899    *
900    * <p>
901    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
902    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
903    *
904    * @param value The new value for this setting.
905    * @return This object.
906    */
907   public MockRestRequest queryString(String value) {
908      queryString = value;
909      return this;
910   }
911
912   /**
913    * Overrides the remote address value on the underlying {@link HttpServletRequest} object.
914    *
915    * <p>
916    * Affects the results of calling {@link HttpServletRequest#getRemoteAddr()}.
917    *
918    * <p>
919    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
920    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
921    *
922    * @param value The new value for this setting.
923    * @return This object.
924    */
925   public MockRestRequest remoteAddr(String value) {
926      remoteAddr = value;
927      return this;
928   }
929
930   /**
931    * Overrides the remote host value on the underlying {@link HttpServletRequest} object.
932    *
933    * <p>
934    * Affects the results of calling {@link HttpServletRequest#getRemoteHost()}.
935    *
936    * <p>
937    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
938    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
939    *
940    * @param value The new value for this setting.
941    * @return This object.
942    */
943   public MockRestRequest remoteHost(String value) {
944      remoteHost = value;
945      return this;
946   }
947
948   /**
949    * Overrides the remote port value on the underlying {@link HttpServletRequest} object.
950    *
951    * <p>
952    * Affects the results of calling {@link HttpServletRequest#getRemotePort()}.
953    *
954    * <p>
955    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
956    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
957    *
958    * @param value The new value for this setting.
959    * @return This object.
960    */
961   public MockRestRequest remotePort(int value) {
962      remotePort = value;
963      return this;
964   }
965
966   /**
967    * Overrides the remote user on the underlying {@link HttpServletRequest} object.
968    *
969    * <p>
970    * Affects the results of calling {@link HttpServletRequest#getRemoteUser()}.
971    *
972    * <p>
973    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
974    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
975    *
976    * @param value The new value for this setting.
977    * @return This object.
978    */
979   public MockRestRequest remoteUser(String value) {
980      remoteUser = value;
981      return this;
982   }
983
984   /**
985    * Overrides the request dispatcher on the underlying {@link HttpServletRequest} object.
986    *
987    * <p>
988    * Affects the results of calling {@link HttpServletRequest#getRequestDispatcher(String)}.
989    *
990    * <p>
991    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
992    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
993    *
994    * @param path The path to the resource being resolved.
995    * @param value The new value for this setting.
996    * @return This object.
997    */
998   public MockRestRequest requestDispatcher(String path, RequestDispatcher value) {
999      this.requestDispatcherMap.put(path, value);
1000      return this;
1001   }
1002
1003   /**
1004    * Overrides the requested session ID on the underlying {@link HttpServletRequest} object.
1005    *
1006    * <p>
1007    * Affects the results of calling {@link HttpServletRequest#getRequestedSessionId()}.
1008    *
1009    * <p>
1010    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1011    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1012    *
1013    * @param value The new value for this setting.
1014    * @return This object.
1015    */
1016   public MockRestRequest requestedSessionId(String value) {
1017      requestedSessionId = value;
1018      return this;
1019   }
1020
1021   /**
1022    * Overrides the request URI on the underlying {@link HttpServletRequest} object.
1023    *
1024    * <p>
1025    * Affects the results of calling {@link HttpServletRequest#getRequestURI()}.
1026    *
1027    * <p>
1028    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1029    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1030    *
1031    * @param value The new value for this setting.
1032    * @return This object.
1033    */
1034   public MockRestRequest requestURI(String value) {
1035      requestURI = value;
1036      return this;
1037   }
1038
1039   @Override /* Overridden from RestRequest */
1040   public MockRestRequest rethrow(Class<?>...values) {
1041      super.rethrow(values);
1042      return this;
1043   }
1044
1045   /**
1046    * Specifies the value for the security roles on the underlying {@link HttpServletRequest} object.
1047    *
1048    * <p>
1049    * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}.
1050    *
1051    * <p>
1052    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1053    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1054    *
1055    * @param role The role to add to this request (e.g. <js>"ROLE_ADMIN"</js>).
1056    * @return This object.
1057    */
1058   public MockRestRequest role(String role) {
1059      this.roles = a(role);
1060      return this;
1061   }
1062
1063   /**
1064    * Specifies the user roles on the underlying {@link HttpServletRequest} object.
1065    *
1066    * <p>
1067    * Affects the results of calling {@link HttpServletRequest#isUserInRole(String)}.
1068    *
1069    * <p>
1070    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1071    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1072    *
1073    * @param roles The roles to add to this request (e.g. <js>"ROLE_ADMIN"</js>).
1074    * @return This object.
1075    */
1076   public MockRestRequest roles(String...roles) {
1077      this.roles = roles;
1078      return this;
1079   }
1080
1081   @Override /* Overridden from RestRequest */
1082   public MockRestRequest serializer(Class<? extends Serializer> serializer) {
1083      super.serializer(serializer);
1084      return this;
1085   }
1086
1087   @Override /* Overridden from RestRequest */
1088   public MockRestRequest serializer(Serializer serializer) {
1089      super.serializer(serializer);
1090      return this;
1091   }
1092
1093   /**
1094    * Overrides the server name value on the underlying {@link HttpServletRequest} object.
1095    *
1096    * <p>
1097    * Affects the results of calling {@link HttpServletRequest#getServerName()}.
1098    *
1099    * <p>
1100    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1101    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1102    *
1103    * @param value The new value for this setting.
1104    * @return This object.
1105    */
1106   public MockRestRequest serverName(String value) {
1107      serverName = value;
1108      return this;
1109   }
1110
1111   /**
1112    * Overrides the server port value on the underlying {@link HttpServletRequest} object.
1113    *
1114    * <p>
1115    * Affects the results of calling {@link HttpServletRequest#getServerPort()}.
1116    *
1117    * <p>
1118    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1119    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1120    *
1121    * @param value The new value for this setting.
1122    * @return This object.
1123    */
1124   public MockRestRequest serverPort(int value) {
1125      serverPort = value;
1126      return this;
1127   }
1128
1129   /**
1130    * Overrides the servlet context on the underlying {@link HttpServletRequest} object.
1131    *
1132    * <p>
1133    * Affects the results of calling {@link HttpServletRequest#getServletContext()}.
1134    *
1135    * <p>
1136    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1137    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1138    *
1139    * @param value The new value for this setting.
1140    * @return This object.
1141    */
1142   public MockRestRequest servletContext(ServletContext value) {
1143      servletContext = value;
1144      return this;
1145   }
1146
1147   /**
1148    * Overrides the servlet path on the underlying {@link HttpServletRequest} object.
1149    *
1150    * <p>
1151    * Affects the results of calling {@link HttpServletRequest#getServletPath()}.
1152    *
1153    * <p>
1154    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1155    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1156    *
1157    * @param value The new value for this setting.
1158    * @return This object.
1159    */
1160   public MockRestRequest servletPath(String value) {
1161      servletPath = value;
1162      return this;
1163   }
1164
1165   @Override /* Overridden from RestRequest */
1166   public MockRestRequest suppressLogging() {
1167      super.suppressLogging();
1168      return this;
1169   }
1170
1171   @Override /* Overridden from RestRequest */
1172   public MockRestRequest target(HttpHost target) {
1173      super.target(target);
1174      return this;
1175   }
1176
1177   @Override /* Overridden from RestRequest */
1178   public MockRestRequest uon() {
1179      super.uon();
1180      return this;
1181   }
1182
1183   @Override /* Overridden from RestRequest */
1184   public MockRestRequest uri(Object uri) throws RestCallException {
1185      super.uri(uri);
1186      return this;
1187   }
1188
1189   @Override /* Overridden from RestRequest */
1190   public MockRestRequest uriFragment(String fragment) {
1191      super.uriFragment(fragment);
1192      return this;
1193   }
1194
1195   @Override /* Overridden from RestRequest */
1196   public MockRestRequest uriHost(String host) {
1197      super.uriHost(host);
1198      return this;
1199   }
1200
1201   @Override /* Overridden from RestRequest */
1202   public MockRestRequest uriPort(int port) {
1203      super.uriPort(port);
1204      return this;
1205   }
1206
1207   /**
1208    * Overrides the HTTP schema value on the underlying {@link HttpServletRequest} object.
1209    *
1210    * <p>
1211    * Affects the results of calling {@link HttpServletRequest#getScheme()}.
1212    *
1213    * <p>
1214    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1215    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1216    *
1217    * @param value The new value for this setting.
1218    * @return This object.
1219    */
1220   @Override
1221   public MockRestRequest uriScheme(String value) {
1222      super.uriScheme(value);
1223      scheme = value;
1224      return this;
1225   }
1226
1227   @Override /* Overridden from RestRequest */
1228   public MockRestRequest uriUserInfo(String userInfo) {
1229      super.uriUserInfo(userInfo);
1230      return this;
1231   }
1232
1233   @Override /* Overridden from RestRequest */
1234   public MockRestRequest uriUserInfo(String username, String password) {
1235      super.uriUserInfo(username, password);
1236      return this;
1237   }
1238
1239   @Override /* Overridden from RestRequest */
1240   public MockRestRequest urlEnc() {
1241      super.urlEnc();
1242      return this;
1243   }
1244
1245   /**
1246    * Overrides the user principal on the underlying {@link HttpServletRequest} object.
1247    *
1248    * <p>
1249    * Affects the results of calling {@link HttpServletRequest#getUserPrincipal()}.
1250    *
1251    * <p>
1252    * This value gets copied to the servlet request after the call to {@link HttpClientConnection#sendRequestHeader(HttpRequest)}
1253    * and right before {@link HttpClientConnection#sendRequestEntity(HttpEntityEnclosingRequest)}.
1254    *
1255    * @param value The new value for this setting.
1256    * @return This object.
1257    */
1258   public MockRestRequest userPrincipal(Principal value) {
1259      userPrincipal = value;
1260      return this;
1261   }
1262
1263   @Override /* Overridden from RestRequest */
1264   public MockRestRequest xml() {
1265      super.xml();
1266      return this;
1267   }
1268}