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.internal.*; 019import org.apache.juneau.serializer.*; 020 021/** 022 * Used for assertion calls against Java beans. 023 * 024 * <h5 class='section'>Example:</h5> 025 * <p class='bjava'> 026 * <jc>// Validates the specified POJO is the specified type and serializes to the specified value.</jc> 027 * <jsm>assertBean</jsm>(<jv>myBean</jv>) 028 * .isType(MyBean.<jk>class</jk>) 029 * .asProperties(<js>"foo,bar"</js>).asJson().is(<js>"{foo:1,bar:2}"</js>); 030 * </p> 031 * 032 * 033 * <h5 class='section'>Test Methods:</h5> 034 * <p> 035 * <ul class='javatree'> 036 * <li class='jc'>{@link FluentObjectAssertion} 037 * <ul class='javatreec'> 038 * <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()} 039 * <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)} 040 * <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)} 041 * <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)} 042 * <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)} 043 * <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)} 044 * <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()} 045 * <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()} 046 * <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)} 047 * <li class='jm'>{@link FluentObjectAssertion#isJson(String) isJson(String)} 048 * <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)} 049 * <li class='jm'>{@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)} 050 * <li class='jm'>{@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)} 051 * <li class='jm'>{@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)} 052 * <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)} 053 * <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)} 054 * </ul> 055 * </ul> 056 * 057 * <h5 class='section'>Transform Methods:</h5> 058 * <p> 059 * <ul class='javatree'> 060 * <li class='jc'>{@link FluentBeanAssertion} 061 * <ul class='javatreec'> 062 * <li class='jm'>{@link FluentBeanAssertion#asPropertyMap(String...) asPropertyMap(String...)} 063 * <li class='jm'>{@link FluentBeanAssertion#asProperty(String) asProperty(String)} 064 * <li class='jm'>{@link FluentBeanAssertion#asProperties(String...) asProperties(String...)} 065 * </ul> 066 * <li class='jc'>{@link FluentObjectAssertion} 067 * <ul class='javatreec'> 068 * <li class='jm'>{@link FluentObjectAssertion#asString() asString()} 069 * <li class='jm'>{@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)} 070 * <li class='jm'>{@link FluentObjectAssertion#asString(Function) asString(Function)} 071 * <li class='jm'>{@link FluentObjectAssertion#asJson() asJson()} 072 * <li class='jm'>{@link FluentObjectAssertion#asJsonSorted() asJsonSorted()} 073 * <li class='jm'>{@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)} 074 * <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()} 075 * </ul> 076 * </ul> 077 * 078 * <h5 class='section'>Configuration Methods:</h5> 079 * <p> 080 * <ul class='javatree'> 081 * <li class='jc'>{@link Assertion} 082 * <ul class='javatreec'> 083 * <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} 084 * <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)} 085 * <li class='jm'>{@link Assertion#setSilent() setSilent()} 086 * <li class='jm'>{@link Assertion#setStdOut() setStdOut()} 087 * <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)} 088 * </ul> 089 * </ul> 090 * 091 * <h5 class='section'>See Also:</h5><ul> 092 * <li class='link'><a class="doclink" href="../../../../index.html#ja.Overview">Overview > juneau-assertions > Overview</a> 093 * </ul> 094 * 095 * @param <T> The bean type. 096 */ 097@FluentSetters(returns="BeanAssertion<T>") 098public class BeanAssertion<T> extends FluentBeanAssertion<T,BeanAssertion<T>> { 099 100 //----------------------------------------------------------------------------------------------------------------- 101 // Static 102 //----------------------------------------------------------------------------------------------------------------- 103 104 /** 105 * Static creator. 106 * 107 * @param <T> The value type. 108 * @param value 109 * The object being tested. 110 * <br>Can be <jk>null</jk>. 111 * @return A new assertion object. 112 */ 113 public static <T> BeanAssertion<T> create(T value) { 114 return new BeanAssertion<>(value); 115 } 116 117 //----------------------------------------------------------------------------------------------------------------- 118 // Instance 119 //----------------------------------------------------------------------------------------------------------------- 120 121 /** 122 * Constructor. 123 * 124 * @param value 125 * The object being tested. 126 * <br>Can be <jk>null</jk>. 127 */ 128 public BeanAssertion(T value) { 129 super(value, null); 130 } 131 132 //----------------------------------------------------------------------------------------------------------------- 133 // Fluent setters 134 //----------------------------------------------------------------------------------------------------------------- 135 136 // <FluentSetters> 137 138 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 139 public BeanAssertion<T> setMsg(String msg, Object...args) { 140 super.setMsg(msg, args); 141 return this; 142 } 143 144 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 145 public BeanAssertion<T> setOut(PrintStream value) { 146 super.setOut(value); 147 return this; 148 } 149 150 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 151 public BeanAssertion<T> setSilent() { 152 super.setSilent(); 153 return this; 154 } 155 156 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 157 public BeanAssertion<T> setStdOut() { 158 super.setStdOut(); 159 return this; 160 } 161 162 @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ 163 public BeanAssertion<T> setThrowable(Class<? extends java.lang.RuntimeException> value) { 164 super.setThrowable(value); 165 return this; 166 } 167 168 // </FluentSetters> 169}