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