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