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