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