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.assertions;
018
019import java.io.*;
020import java.util.function.*;
021
022import org.apache.http.*;
023import org.apache.juneau.assertions.*;
024import org.apache.juneau.http.response.*;
025import org.apache.juneau.internal.*;
026import org.apache.juneau.serializer.*;
027
028/**
029 * Used for fluent assertion calls against {@link RequestLine} objects.
030 *
031 * <h5 class='topic'>Test Methods</h5>
032 * <p>
033 * <ul class='javatree'>
034 *    <li class='jc'>{@link FluentObjectAssertion}
035 *    <ul class='javatreec'>
036 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
037 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
038 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
039 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
040 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
041 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
042 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
043 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
044 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
045 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
046 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
047 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
048 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
049 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
050 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
051 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
052 *    </ul>
053 * </ul>
054 *
055 * <h5 class='topic'>Transform Methods</h5>
056 * <p>
057 * <ul class='javatree'>
058 *    <li class='jc'>{@link FluentRequestLineAssertion}
059 *    <ul class='javatreec'>
060 *       <li class='jm'>{@link FluentRequestLineAssertion#asMethod() asMethod()}
061 *       <li class='jm'>{@link FluentRequestLineAssertion#asUri() asUri()}
062 *       <li class='jm'>{@link FluentRequestLineAssertion#asProtocolVersion() asProtocolVersion()}
063 *    </ul>
064 *    <li class='jc'>{@link FluentObjectAssertion}
065 *    <ul class='javatreec'>
066 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
067 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
068 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
069 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
070 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
071 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
072 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
073 * </ul>
074 * </ul>
075 *
076 * <h5 class='topic'>Configuration Methods</h5>
077 * <p>
078 * <ul class='javatree'>
079 *    <li class='jc'>{@link Assertion}
080 *    <ul class='javatreec'>
081 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
082 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
083 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
084 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
085 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
086 *    </ul>
087 * </ul>
088 *
089 * <h5 class='section'>See Also:</h5><ul>
090 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem Overview</a>
091 * </ul>
092 *
093 * @param <R> The return type.
094 */
095public class FluentRequestLineAssertion<R> extends FluentObjectAssertion<RequestLine,R> {
096
097   //-----------------------------------------------------------------------------------------------------------------
098   // Constructors
099   //-----------------------------------------------------------------------------------------------------------------
100
101   /**
102    * Constructor.
103    *
104    * @param value
105    *    The object being tested.
106    *    <br>Can be <jk>null</jk>.
107    * @param returns
108    *    The object to return after a test method is called.
109    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
110    * used on the same assertion.
111    */
112   public FluentRequestLineAssertion(RequestLine value, R returns) {
113      this(null, value, returns);
114   }
115
116   /**
117    * Chained constructor.
118    *
119    * <p>
120    * Used when transforming one assertion into another so that the assertion config can be used by the new assertion.
121    *
122    * @param creator
123    *    The assertion that created this assertion.
124    *    <br>Should be <jk>null</jk> if this is the top-level assertion.
125    * @param value
126    *    The object being tested.
127    *    <br>Can be <jk>null</jk>.
128    * @param returns
129    *    The object to return after a test method is called.
130    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
131    * used on the same assertion.
132    */
133   public FluentRequestLineAssertion(Assertion creator, RequestLine value, R returns) {
134      super(creator, value, returns);
135      setThrowable(BadRequest.class);
136   }
137
138   //-----------------------------------------------------------------------------------------------------------------
139   // Transform methods
140   //-----------------------------------------------------------------------------------------------------------------
141
142   /**
143    * Returns the request line method string as a new assertion.
144    *
145    * @return A new assertion.
146    */
147   public FluentStringAssertion<R> asMethod() {
148      return new FluentStringAssertion<>(value().getMethod(), returns());
149   }
150
151   /**
152    * Returns the request line uri string as a new assertion.
153    *
154    * @return A new assertion.
155    */
156   public FluentStringAssertion<R> asUri() {
157      return new FluentStringAssertion<>(value().getUri(), returns());
158   }
159
160   /**
161    * Returns the request line protocol version as a new assertion.
162    *
163    * @return A new assertion.
164    */
165   public FluentProtocolVersionAssertion<R> asProtocolVersion() {
166      return new FluentProtocolVersionAssertion<>(value().getProtocolVersion(), returns());
167   }
168
169   //-----------------------------------------------------------------------------------------------------------------
170   // Fluent setters
171   //-----------------------------------------------------------------------------------------------------------------
172   @Override /* Overridden from Assertion */
173   public FluentRequestLineAssertion<R> setMsg(String msg, Object...args) {
174      super.setMsg(msg, args);
175      return this;
176   }
177
178   @Override /* Overridden from Assertion */
179   public FluentRequestLineAssertion<R> setOut(PrintStream value) {
180      super.setOut(value);
181      return this;
182   }
183
184   @Override /* Overridden from Assertion */
185   public FluentRequestLineAssertion<R> setSilent() {
186      super.setSilent();
187      return this;
188   }
189
190   @Override /* Overridden from Assertion */
191   public FluentRequestLineAssertion<R> setStdOut() {
192      super.setStdOut();
193      return this;
194   }
195
196   @Override /* Overridden from Assertion */
197   public FluentRequestLineAssertion<R> setThrowable(Class<? extends java.lang.RuntimeException> value) {
198      super.setThrowable(value);
199      return this;
200   }
201}