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.assertions;
014
015import java.io.*;
016import java.util.function.*;
017
018import org.apache.juneau.*;
019import org.apache.juneau.internal.*;
020import org.apache.juneau.serializer.*;
021
022/**
023 * Used for fluent assertion calls against {@link Version} objects.
024 *
025 * <h5 class='section'>Example:</h5>
026 * <p class='bjava'>
027 *    <jc>// Validates the response expiration is after the current date.</jc>
028 *    <jv>client</jv>
029 *       .get(<jsf>URL</jsf>)
030 *       .run()
031 *       .getHeader(ClientVersion.<jk>class</jk>).assertVersion().asMajor().isGreaterThanOrEqual(2);
032 * </p>
033 *
034 *
035 * <h5 class='section'>Test Methods:</h5>
036 * <p>
037 * <ul class='javatree'>
038 *    <li class='jc'>{@link FluentComparableAssertion}
039 *    <ul class='javatreec'>
040 *       <li class='jm'>{@link FluentComparableAssertion#isGt(Comparable) isGt(Comparable)}
041 *       <li class='jm'>{@link FluentComparableAssertion#isGte(Comparable) isGte(Comparable)}
042 *       <li class='jm'>{@link FluentComparableAssertion#isLt(Comparable) isLt(Comparable)}
043 *       <li class='jm'>{@link FluentComparableAssertion#isLte(Comparable) isLte(Comparable)}
044 *       <li class='jm'>{@link FluentComparableAssertion#isBetween(Comparable,Comparable) isBetween(Comparable,Comparable)}
045  *   </ul>
046 *    <li class='jc'>{@link FluentObjectAssertion}
047 *    <ul class='javatreec'>
048 *       <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()}
049 *       <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)}
050 *       <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)}
051 *       <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)}
052 *       <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)}
053 *       <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)}
054 *       <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()}
055 *       <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()}
056 *       <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)}
057 *       <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)}
058 *       <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)}
059 *       <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)}
060 *       <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)}
061 *       <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)}
062 *       <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)}
063 *       <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)}
064 *    </ul>
065 * </ul>
066 *
067 * <h5 class='section'>Transform Methods:</h5>
068 * <p>
069 * <ul class='javatree'>
070 *    <li class='jc'>{@link FluentVersionAssertion}
071 *    <ul class='javatreec'>
072 *       <li class='jm'>{@link FluentVersionAssertion#asPart(int) asPart(int)}
073 *       <li class='jm'>{@link FluentVersionAssertion#asMajor() asMajor()}
074 *       <li class='jm'>{@link FluentVersionAssertion#asMinor() asMinor()}
075 *       <li class='jm'>{@link FluentVersionAssertion#asMaintenance() asMaintenance()}
076 *    </ul>
077 *    <li class='jc'>{@link FluentObjectAssertion}
078 *    <ul class='javatreec'>
079 *       <li class='jm'>{@link FluentObjectAssertion#asString() asString()}
080 *       <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)}
081 *       <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)}
082 *       <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()}
083 *       <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()}
084 *       <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)}
085 *       <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()}
086 * </ul>
087 * </ul>
088 *
089 * <h5 class='section'>Configuration Methods:</h5>
090 * <p>
091 * <ul class='javatree'>
092 *    <li class='jc'>{@link Assertion}
093 *    <ul class='javatreec'>
094 *       <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)}
095 *       <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)}
096 *       <li class='jm'>{@link Assertion#setSilent() setSilent()}
097 *       <li class='jm'>{@link Assertion#setStdOut() setStdOut()}
098 *       <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)}
099 *    </ul>
100 * </ul>
101 *
102 * <h5 class='section'>See Also:</h5><ul>
103 *    <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview &gt; juneau-assertions &gt; Overview</a>
104 * </ul>
105 *
106 * @param <R> The return type.
107 */
108@FluentSetters(returns="FluentVersionAssertion<R>")
109public class FluentVersionAssertion<R> extends FluentComparableAssertion<Version,R> {
110
111   //-----------------------------------------------------------------------------------------------------------------
112   // Instance
113   //-----------------------------------------------------------------------------------------------------------------
114
115   /**
116    * Constructor.
117    *
118    * @param value
119    *    The object being tested.
120    *    <br>Can be <jk>null</jk>.
121    * @param returns
122    *    The object to return after a test method is called.
123    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
124    * used on the same assertion.
125    */
126   public FluentVersionAssertion(Version value, R returns) {
127      this(null, value, returns);
128   }
129
130   /**
131    * Chained constructor.
132    *
133    * <p>
134    * Used when transforming one assertion into another so that the assertion config can be used by the new assertion.
135    *
136    * @param creator
137    *    The assertion that created this assertion.
138    *    <br>Should be <jk>null</jk> if this is the top-level assertion.
139    * @param value
140    *    The object being tested.
141    *    <br>Can be <jk>null</jk>.
142    * @param returns
143    *    The object to return after a test method is called.
144    *    <br>If <jk>null</jk>, the test method returns this object allowing multiple test method calls to be
145    * used on the same assertion.
146    */
147   public FluentVersionAssertion(Assertion creator, Version value, R returns) {
148      super(creator, value, returns);
149   }
150
151   //-----------------------------------------------------------------------------------------------------------------
152   // Transform methods
153   //-----------------------------------------------------------------------------------------------------------------
154
155   /**
156    * Extracts the specified version part (zero-indexed position).
157    *
158    * @param index The index of the version part to extract.
159    * @return This object.
160    */
161   public FluentIntegerAssertion<R> asPart(int index) {
162      return new FluentIntegerAssertion<>(this, valueIsNull() ? null : value().getPart(index).orElse(null), returns());
163   }
164
165   /**
166    * Extracts the major part of the version string (index position 0).
167    *
168    * @return This object.
169    */
170   public FluentIntegerAssertion<R> asMajor() {
171      return asPart(0);
172   }
173
174   /**
175    * Extracts the minor part of the version string (index position 1).
176    *
177    * @return This object.
178    */
179   public FluentIntegerAssertion<R> asMinor() {
180      return asPart(1);
181   }
182
183   /**
184    * Extracts the maintenance part of the version string (index position 2).
185    *
186    * @return This object.
187    */
188   public FluentIntegerAssertion<R> asMaintenance() {
189      return asPart(2);
190   }
191
192   //-----------------------------------------------------------------------------------------------------------------
193   // Fluent setters
194   //-----------------------------------------------------------------------------------------------------------------
195
196   // <FluentSetters>
197
198   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
199   public FluentVersionAssertion<R> setMsg(String msg, Object...args) {
200      super.setMsg(msg, args);
201      return this;
202   }
203
204   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
205   public FluentVersionAssertion<R> setOut(PrintStream value) {
206      super.setOut(value);
207      return this;
208   }
209
210   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
211   public FluentVersionAssertion<R> setSilent() {
212      super.setSilent();
213      return this;
214   }
215
216   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
217   public FluentVersionAssertion<R> setStdOut() {
218      super.setStdOut();
219      return this;
220   }
221
222   @Override /* GENERATED - org.apache.juneau.assertions.Assertion */
223   public FluentVersionAssertion<R> setThrowable(Class<? extends java.lang.RuntimeException> value) {
224      super.setThrowable(value);
225      return this;
226   }
227
228   // </FluentSetters>
229}