View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.jsonschema.annotation;
18  
19  import static org.apache.juneau.TestUtils.*;
20  import static org.apache.juneau.junit.bct.BctAssertions.*;
21  import static org.junit.jupiter.api.Assertions.*;
22  
23  import org.apache.juneau.*;
24  import org.apache.juneau.annotation.*;
25  import org.junit.jupiter.api.*;
26  
27  class ItemsAnnotation_Test extends TestBase {
28  
29  	//------------------------------------------------------------------------------------------------------------------
30  	// Basic tests
31  	//------------------------------------------------------------------------------------------------------------------
32  
33  	Items a1 = ItemsAnnotation.create()
34  		.$ref("a")
35  		.default_("b")
36  		.enum_("c")
37  		.cf("d")
38  		.collectionFormat("e")
39  		.description("f")
40  		.df("g")
41  		.e("h")
42  		.emax(true)
43  		.emin(true)
44  		.exclusiveMaximum(true)
45  		.exclusiveMinimum(true)
46  		.f("i")
47  		.format("j")
48  		.max("k")
49  		.maxi(1)
50  		.maximum("l")
51  		.maxItems(2)
52  		.maxl(3)
53  		.maxLength(4)
54  		.min("m")
55  		.mini(5)
56  		.minimum("n")
57  		.minItems(6)
58  		.minl(7)
59  		.minLength(8)
60  		.mo("o")
61  		.multipleOf("p")
62  		.p("q")
63  		.pattern("r")
64  		.t("s")
65  		.type("t")
66  		.ui(true)
67  		.uniqueItems(true)
68  		.build();
69  
70  	Items a2 = ItemsAnnotation.create()
71  		.$ref("a")
72  		.default_("b")
73  		.enum_("c")
74  		.cf("d")
75  		.collectionFormat("e")
76  		.description("f")
77  		.df("g")
78  		.e("h")
79  		.emax(true)
80  		.emin(true)
81  		.exclusiveMaximum(true)
82  		.exclusiveMinimum(true)
83  		.f("i")
84  		.format("j")
85  		.max("k")
86  		.maxi(1)
87  		.maximum("l")
88  		.maxItems(2)
89  		.maxl(3)
90  		.maxLength(4)
91  		.min("m")
92  		.mini(5)
93  		.minimum("n")
94  		.minItems(6)
95  		.minl(7)
96  		.minLength(8)
97  		.mo("o")
98  		.multipleOf("p")
99  		.p("q")
100 		.pattern("r")
101 		.t("s")
102 		.type("t")
103 		.ui(true)
104 		.uniqueItems(true)
105 		.build();
106 
107 	@Test void a01_basic() {
108 		assertBean(a1,
109 			"$ref,default_,enum_,cf,collectionFormat,description,df,e,emax,emin,exclusiveMaximum,exclusiveMinimum,f,format,items{$ref,default_,enum_,cf,collectionFormat,description,df,e,emax,emin,exclusiveMaximum,exclusiveMinimum,f,format,items,max,maxItems,maxLength,maxi,maximum,maxl,min,minItems,minLength,mini,minimum,minl,mo,multipleOf,p,pattern,t,type,ui,uniqueItems},max,maxItems,maxLength,maxi,maximum,maxl,min,minItems,minLength,mini,minimum,minl,mo,multipleOf,p,pattern,t,type,ui,uniqueItems",
110 			"a,[b],[c],d,e,[f],[g],[h],true,true,true,true,i,j,{,[],[],,,[],[],[],false,false,false,false,,,[],,-1,-1,-1,,-1,,-1,-1,-1,,-1,,,,,,,false,false},k,2,4,1,l,3,m,6,8,5,n,7,o,p,q,r,s,t,true,true");
111 	}
112 
113 	@Test void a02_testEquivalency() {
114 		assertEquals(a2, a1);
115 		assertNotEqualsAny(a1.hashCode(), 0, -1);
116 		assertEquals(a1.hashCode(), a2.hashCode());
117 	}
118 
119 	//------------------------------------------------------------------------------------------------------------------
120 	// PropertyStore equivalency.
121 	//------------------------------------------------------------------------------------------------------------------
122 
123 	@Test void b01_testEquivalencyInPropertyStores() {
124 		var bc1 = BeanContext.create().annotations(a1).build();
125 		var bc2 = BeanContext.create().annotations(a2).build();
126 		assertSame(bc1, bc2);
127 	}
128 
129 	//------------------------------------------------------------------------------------------------------------------
130 	// Other methods.
131 	//------------------------------------------------------------------------------------------------------------------
132 
133 	//------------------------------------------------------------------------------------------------------------------
134 	// Comparison with declared annotations.
135 	//------------------------------------------------------------------------------------------------------------------
136 
137 	@Items(
138 		$ref="a",
139 		default_="b",
140 		enum_="c",
141 		cf="d",
142 		collectionFormat="e",
143 		description={ "f" },
144 		df="g",
145 		e="h",
146 		emax=true,
147 		emin=true,
148 		exclusiveMaximum=true,
149 		exclusiveMinimum=true,
150 		f="i",
151 		format="j",
152 		max="k",
153 		maxi=1,
154 		maximum="l",
155 		maxItems=2,
156 		maxl=3,
157 		maxLength=4,
158 		min="m",
159 		mini=5,
160 		minimum="n",
161 		minItems=6,
162 		minl=7,
163 		minLength=8,
164 		mo="o",
165 		multipleOf="p",
166 		p="q",
167 		pattern="r",
168 		t="s",
169 		type="t",
170 		ui=true,
171 		uniqueItems=true
172 	)
173 	public static class D1 {}
174 	Items d1 = D1.class.getAnnotationsByType(Items.class)[0];
175 
176 	@Items(
177 		$ref="a",
178 		default_="b",
179 		enum_="c",
180 		cf="d",
181 		collectionFormat="e",
182 		description={ "f" },
183 		df="g",
184 		e="h",
185 		emax=true,
186 		emin=true,
187 		exclusiveMaximum=true,
188 		exclusiveMinimum=true,
189 		f="i",
190 		format="j",
191 		max="k",
192 		maxi=1,
193 		maximum="l",
194 		maxItems=2,
195 		maxl=3,
196 		maxLength=4,
197 		min="m",
198 		mini=5,
199 		minimum="n",
200 		minItems=6,
201 		minl=7,
202 		minLength=8,
203 		mo="o",
204 		multipleOf="p",
205 		p="q",
206 		pattern="r",
207 		t="s",
208 		type="t",
209 		ui=true,
210 		uniqueItems=true
211 	)
212 	public static class D2 {}
213 	Items d2 = D2.class.getAnnotationsByType(Items.class)[0];
214 
215 	@Test void d01_comparisonWithDeclarativeAnnotations() {
216 		assertEqualsAll(a1, d1, d2);
217 		assertNotEqualsAny(a1.hashCode(), 0, -1);
218 		assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
219 	}
220 }