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.assertions;
014
015import java.io.*;
016import java.lang.reflect.*;
017import java.util.*;
018import java.util.function.*;
019import java.util.regex.*;
020
021import org.apache.juneau.assertions.*;
022import org.apache.juneau.http.response.*;
023import org.apache.juneau.internal.*;
024import org.apache.juneau.rest.httppart.*;
025import org.apache.juneau.serializer.*;
026
027/**
028 * Used for fluent assertion calls against {@link RequestQueryParam} objects.
029 *
030 * <h5 class='topic'>Test Methods</h5>
031 * <p>
032 * <ul class='javatree'>
033 *    <li class='jc'>{@link FluentStringAssertion}
034 *    <ul class='javatreec'>
035 *       <li class='jm'>{@link FluentStringAssertion#is(String) is(String)}
036 *       <li class='jm'>{@link FluentStringAssertion#isNot(String) isNot(String)}
037 *       <li class='jm'>{@link FluentStringAssertion#isLines(String...) isLines(String...)}
038 *       <li class='jm'>{@link FluentStringAssertion#isSortedLines(String...) isSortedLines(String...)}
039 *       <li class='jm'>{@link FluentStringAssertion#isIc(String) isIc(String)}
040 *       <li class='jm'>{@link FluentStringAssertion#isNotIc(String) isNotIc(String)}
041 *       <li class='jm'>{@link FluentStringAssertion#isContains(String...) isContains(String...)}
042 *       <li class='jm'>{@link FluentStringAssertion#isNotContains(String...) isNotContains(String...)}
043 *       <li class='jm'>{@link FluentStringAssertion#isEmpty() isEmpty()}
044 *       <li class='jm'>{@link FluentStringAssertion#isNotEmpty() isNotEmpty()}
045 *       <li class='jm'>{@link FluentStringAssertion#isString(Object) isString(Object)}
046 *       <li class='jm'>{@link FluentStringAssertion#isMatches(String) isMatches(String)}
047 *       <li class='jm'>{@link FluentStringAssertion#isPattern(String) isPattern(String)}
048 *       <li class='jm'>{@link FluentStringAssertion#isPattern(String,int) isPattern(String,int)}
049 *       <li class='jm'>{@link FluentStringAssertion#isPattern(Pattern) isPattern(Pattern)}
050 *       <li class='jm'>{@link FluentStringAssertion#isStartsWith(String) isStartsWith(String)}
051 *       <li class='jm'>{@link FluentStringAssertion#isEndsWith(String) isEndsWith(String)}
052 *    </ul>
053 *    <li class='jc'>{@link FluentObjectAssertion}
054 *    <ul class='javatreec'>
055 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
056 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
057 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
058 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
059 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
060 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
061 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
062 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
063 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
064 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
065 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
066 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
067 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
068 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
069 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
070 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
071 *    </ul>
072 * </ul>
073 *
074 * <h5 class='topic'>Transform Methods</h5>
075 * <p>
076 * <ul class='javatree'>
077 *    <li class='jc'>{@link FluentRequestQueryParamAssertion}
078 *    <ul class='javatreec'>
079 *       <li class='jm'>{@link FluentRequestQueryParamAssertion#asBoolean() asBoolean()}
080 *       <li class='jm'>{@link FluentRequestQueryParamAssertion#asInteger() asInteger()}
081 *       <li class='jm'>{@link FluentRequestQueryParamAssertion#asLong() asLong()}
082 *       <li class='jm'>{@link FluentRequestQueryParamAssertion#asZonedDateTime() asZonedDateTime()}
083 *       <li class='jm'>{@link FluentRequestQueryParamAssertion#as(Class) as(Class)}
084 *    </ul>
085 *    <li class='jc'>{@link FluentStringAssertion}
086 *    <ul class='javatreec'>
087 *       <li class='jm'>{@link FluentStringAssertion#asReplaceAll(String,String) asReplaceAll(String,String)}
088 *       <li class='jm'>{@link FluentStringAssertion#asReplace(String,String) asReplace(String,String)}
089 *       <li class='jm'>{@link FluentStringAssertion#asUrlDecode() asUrlDecode()}
090 *       <li class='jm'>{@link FluentStringAssertion#asLc() asLc()}
091 *       <li class='jm'>{@link FluentStringAssertion#asUc() asUc()}
092 *       <li class='jm'>{@link FluentStringAssertion#asLines() asLines()}
093 *       <li class='jm'>{@link FluentStringAssertion#asSplit(String) asSplit(String)}
094 *       <li class='jm'>{@link FluentStringAssertion#asLength() asLength()}
095 *       <li class='jm'>{@link FluentStringAssertion#asOneLine() asOneLine()}
096 *    </ul>
097 *    <li class='jc'>{@link FluentObjectAssertion}
098 *    <ul class='javatreec'>
099 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
100 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
101 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
102 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
103 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
104 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
105 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
106 * </ul>
107 * </ul>
108 *
109 * <h5 class='topic'>Configuration Methods</h5>
110 * <p>
111 * <ul class='javatree'>
112 *    <li class='jc'>{@link Assertion}
113 *    <ul class='javatreec'>
114 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
115 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
116 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
117 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
118 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
119 *    </ul>
120 * </ul>
121 *    </ul>
122 *
123 * <h5 class='section'>See Also:</h5><ul>
124 *    <li class='link'><a class="doclink" href="../../../../../index.html#ja.Overview">juneau-assertions</a>
125 * </ul>
126 *
127 * @param <R> The return type.
128 */
129@FluentSetters(returns="FluentRequestQueryParamAssertion<R>")
130public class FluentRequestQueryParamAssertion<R> extends FluentStringAssertion<R> {
131
132   private final RequestQueryParam value;
133
134   //-----------------------------------------------------------------------------------------------------------------
135   // Constructors
136   //-----------------------------------------------------------------------------------------------------------------
137
138   /**
139    * Constructor.
140    *
141    * @param value
142    *    The object being tested.
143    *    <br>Can be <jk>null</jk>.
144    * @param returns
145    *    The object to return after a test method is called.
146    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
147    * used on the same assertion.
148    */
149   public FluentRequestQueryParamAssertion(RequestQueryParam value, R returns) {
150      this(null, value, returns);
151   }
152
153   /**
154    * Chained constructor.
155    *
156    * <p>
157    * Used when transforming one assertion into another so that the assertion config can be used by the new assertion.
158    *
159    * @param creator
160    *    The assertion that created this assertion.
161    *    <br>Should be <jk>null</jk> if this is the top-level assertion.
162    * @param value
163    *    The object being tested.
164    *    <br>Can be <jk>null</jk>.
165    * @param returns
166    *    The object to return after a test method is called.
167    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
168    * used on the same assertion.
169    */
170   public FluentRequestQueryParamAssertion(Assertion creator, RequestQueryParam value, R returns) {
171      super(creator, value.asString().orElse(null), returns);
172      this.value = value;
173      setThrowable(BadRequest.class);
174   }
175
176   //-----------------------------------------------------------------------------------------------------------------
177   // Transform methods
178   //-----------------------------------------------------------------------------------------------------------------
179
180   /**
181    * Converts this object assertion into a boolean assertion.
182    *
183    * @return A new assertion.
184    * @throws AssertionError If object is not a boolean.
185    */
186   public FluentBooleanAssertion<R> asBoolean() {
187      return new FluentBooleanAssertion<>(this, value.asBoolean().orElse(null), returns());
188   }
189
190   /**
191    * Converts this object assertion into an integer assertion.
192    *
193    * @return A new assertion.
194    * @throws AssertionError If object is not an integer.
195    */
196   public FluentIntegerAssertion<R> asInteger() {
197      return new FluentIntegerAssertion<>(this, value.asInteger().orElse(null), returns());
198   }
199
200   /**
201    * Converts this object assertion into a long assertion.
202    *
203    * @return A new assertion.
204    * @throws AssertionError If object is not a long.
205    */
206   public FluentLongAssertion<R> asLong() {
207      return new FluentLongAssertion<>(this, value.asLong().orElse(null), returns());
208   }
209
210   /**
211    * Converts this object assertion into a zoned-datetime assertion.
212    *
213    * @return A new assertion.
214    * @throws AssertionError If object is not a zoned-datetime.
215    */
216   public FluentZonedDateTimeAssertion<R> asZonedDateTime() {
217      return new FluentZonedDateTimeAssertion<>(this, value.asDatePart().asZonedDateTime().orElse(null), returns());
218   }
219
220   /**
221    * Converts the parameter value to a type using {@link RequestQueryParam#as(Class)} and then returns the value as an any-object assertion.
222    *
223    * @param <T> The object type to create.
224    * @param type The object type to create.
225    * @return A new fluent assertion object.
226    */
227   public <T> FluentAnyAssertion<T,R> as(Class<T> type) {
228      return new FluentAnyAssertion<>(value.as(type).orElse(null), returns());
229   }
230
231   /**
232    * Converts the parameter value to a type using {@link RequestQueryParam#as(Type,Type...)} and then returns the value as an any-object assertion.
233    *
234    * <p>
235    * See <a class="doclink" href="../../../../../index.html#jm.ComplexDataTypes">Complex Data Types</a> for information on defining complex generic types of {@link Map Maps} and {@link Collection Collections}.
236    *
237    * @param type The object type to create.
238    * @param args Optional type arguments.
239    * @return A new fluent assertion object.
240    */
241   public FluentAnyAssertion<Object,R> as(Type type, Type...args) {
242      return new FluentAnyAssertion<>(value.as(type, args).orElse(null), returns());
243   }
244
245   //-----------------------------------------------------------------------------------------------------------------
246   // Fluent setters
247   //-----------------------------------------------------------------------------------------------------------------
248
249   // <FluentSetters>
250
251   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
252   public FluentRequestQueryParamAssertion<R> setMsg(String msg, Object...args) {
253      super.setMsg(msg, args);
254      return this;
255   }
256
257   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
258   public FluentRequestQueryParamAssertion<R> setOut(PrintStream value) {
259      super.setOut(value);
260      return this;
261   }
262
263   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
264   public FluentRequestQueryParamAssertion<R> setSilent() {
265      super.setSilent();
266      return this;
267   }
268
269   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
270   public FluentRequestQueryParamAssertion<R> setStdOut() {
271      super.setStdOut();
272      return this;
273   }
274
275   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
276   public FluentRequestQueryParamAssertion<R> setThrowable(Class<? extends java.lang.RuntimeException> value) {
277      super.setThrowable(value);
278      return this;
279   }
280
281   @Override /* GENERATED - org.apache.juneau.assertions.FluentStringAssertion */
282   public FluentRequestQueryParamAssertion<R> asJavaStrings() {
283      super.asJavaStrings();
284      return this;
285   }
286
287   // </FluentSetters>
288}