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.junit.jupiter.api.Assertions.*;
21  
22  import org.apache.juneau.*;
23  import org.apache.juneau.annotation.*;
24  import org.junit.jupiter.api.*;
25  
26  class ItemsAnnotation_Test extends TestBase {
27  
28  	//------------------------------------------------------------------------------------------------------------------
29  	// Basic tests
30  	//------------------------------------------------------------------------------------------------------------------
31  
32  	Items a1 = ItemsAnnotation.create()
33  		.$ref("a")
34  		._default("b")
35  		._enum("c")
36  		.cf("d")
37  		.collectionFormat("e")
38  		.description("f")
39  		.df("g")
40  		.e("h")
41  		.emax(true)
42  		.emin(true)
43  		.exclusiveMaximum(true)
44  		.exclusiveMinimum(true)
45  		.f("i")
46  		.format("j")
47  		.max("k")
48  		.maxi(1)
49  		.maximum("l")
50  		.maxItems(2)
51  		.maxl(3)
52  		.maxLength(4)
53  		.min("m")
54  		.mini(5)
55  		.minimum("n")
56  		.minItems(6)
57  		.minl(7)
58  		.minLength(8)
59  		.mo("o")
60  		.multipleOf("p")
61  		.p("q")
62  		.pattern("r")
63  		.t("s")
64  		.type("t")
65  		.ui(true)
66  		.uniqueItems(true)
67  		.build();
68  
69  	Items a2 = ItemsAnnotation.create()
70  		.$ref("a")
71  		._default("b")
72  		._enum("c")
73  		.cf("d")
74  		.collectionFormat("e")
75  		.description("f")
76  		.df("g")
77  		.e("h")
78  		.emax(true)
79  		.emin(true)
80  		.exclusiveMaximum(true)
81  		.exclusiveMinimum(true)
82  		.f("i")
83  		.format("j")
84  		.max("k")
85  		.maxi(1)
86  		.maximum("l")
87  		.maxItems(2)
88  		.maxl(3)
89  		.maxLength(4)
90  		.min("m")
91  		.mini(5)
92  		.minimum("n")
93  		.minItems(6)
94  		.minl(7)
95  		.minLength(8)
96  		.mo("o")
97  		.multipleOf("p")
98  		.p("q")
99  		.pattern("r")
100 		.t("s")
101 		.type("t")
102 		.ui(true)
103 		.uniqueItems(true)
104 		.build();
105 
106 	@Test void a01_basic() {
107 		assertBean(a1,
108 			"$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",
109 			"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");
110 	}
111 
112 	@Test void a02_testEquivalency() {
113 		assertEquals(a2, a1);
114 		assertNotEqualsAny(a1.hashCode(), 0, -1);
115 		assertEquals(a1.hashCode(), a2.hashCode());
116 	}
117 
118 	//------------------------------------------------------------------------------------------------------------------
119 	// PropertyStore equivalency.
120 	//------------------------------------------------------------------------------------------------------------------
121 
122 	@Test void b01_testEquivalencyInPropertyStores() {
123 		var bc1 = BeanContext.create().annotations(a1).build();
124 		var bc2 = BeanContext.create().annotations(a2).build();
125 		assertSame(bc1, bc2);
126 	}
127 
128 	//------------------------------------------------------------------------------------------------------------------
129 	// Other methods.
130 	//------------------------------------------------------------------------------------------------------------------
131 
132 	//------------------------------------------------------------------------------------------------------------------
133 	// Comparison with declared annotations.
134 	//------------------------------------------------------------------------------------------------------------------
135 
136 	@Items(
137 		$ref="a",
138 		_default="b",
139 		_enum="c",
140 		cf="d",
141 		collectionFormat="e",
142 		description={ "f" },
143 		df="g",
144 		e="h",
145 		emax=true,
146 		emin=true,
147 		exclusiveMaximum=true,
148 		exclusiveMinimum=true,
149 		f="i",
150 		format="j",
151 		max="k",
152 		maxi=1,
153 		maximum="l",
154 		maxItems=2,
155 		maxl=3,
156 		maxLength=4,
157 		min="m",
158 		mini=5,
159 		minimum="n",
160 		minItems=6,
161 		minl=7,
162 		minLength=8,
163 		mo="o",
164 		multipleOf="p",
165 		p="q",
166 		pattern="r",
167 		t="s",
168 		type="t",
169 		ui=true,
170 		uniqueItems=true
171 	)
172 	public static class D1 {}
173 	Items d1 = D1.class.getAnnotationsByType(Items.class)[0];
174 
175 	@Items(
176 		$ref="a",
177 		_default="b",
178 		_enum="c",
179 		cf="d",
180 		collectionFormat="e",
181 		description={ "f" },
182 		df="g",
183 		e="h",
184 		emax=true,
185 		emin=true,
186 		exclusiveMaximum=true,
187 		exclusiveMinimum=true,
188 		f="i",
189 		format="j",
190 		max="k",
191 		maxi=1,
192 		maximum="l",
193 		maxItems=2,
194 		maxl=3,
195 		maxLength=4,
196 		min="m",
197 		mini=5,
198 		minimum="n",
199 		minItems=6,
200 		minl=7,
201 		minLength=8,
202 		mo="o",
203 		multipleOf="p",
204 		p="q",
205 		pattern="r",
206 		t="s",
207 		type="t",
208 		ui=true,
209 		uniqueItems=true
210 	)
211 	public static class D2 {}
212 	Items d2 = D2.class.getAnnotationsByType(Items.class)[0];
213 
214 	@Test void d01_comparisonWithDeclarativeAnnotations() {
215 		assertEqualsAll(a1, d1, d2);
216 		assertNotEqualsAny(a1.hashCode(), 0, -1);
217 		assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
218 	}
219 }