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 SubItemsAnnotation_Test extends TestBase {
28  
29  	//------------------------------------------------------------------------------------------------------------------
30  	// Basic tests
31  	//------------------------------------------------------------------------------------------------------------------
32  
33  	SubItems a1 = SubItemsAnnotation.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  	SubItems a2 = SubItemsAnnotation.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, "$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", "a,[b],[c],d,e,[f],[g],[h],true,true,true,true,i,j,[],k,2,4,1,l,3,m,6,8,5,n,7,o,p,q,r,s,t,true,true");
109 	}
110 
111 	@Test void a02_testEquivalency() {
112 		assertEquals(a2, a1);
113 		assertNotEqualsAny(a1.hashCode(), 0, -1);
114 		assertEquals(a1.hashCode(), a2.hashCode());
115 	}
116 
117 	//------------------------------------------------------------------------------------------------------------------
118 	// PropertyStore equivalency.
119 	//------------------------------------------------------------------------------------------------------------------
120 
121 	@Test void b01_testEquivalencyInPropertyStores() {
122 		var bc1 = BeanContext.create().annotations(a1).build();
123 		var bc2 = BeanContext.create().annotations(a2).build();
124 		assertSame(bc1, bc2);
125 	}
126 
127 	//------------------------------------------------------------------------------------------------------------------
128 	// Other methods.
129 	//------------------------------------------------------------------------------------------------------------------
130 
131 	//------------------------------------------------------------------------------------------------------------------
132 	// Comparison with declared annotations.
133 	//------------------------------------------------------------------------------------------------------------------
134 
135 	@SubItems(
136 		$ref="a",
137 		default_="b",
138 		enum_="c",
139 		cf="d",
140 		collectionFormat="e",
141 		description={ "f" },
142 		df="g",
143 		e="h",
144 		emax=true,
145 		emin=true,
146 		exclusiveMaximum=true,
147 		exclusiveMinimum=true,
148 		f="i",
149 		format="j",
150 		max="k",
151 		maxi=1,
152 		maximum="l",
153 		maxItems=2,
154 		maxl=3,
155 		maxLength=4,
156 		min="m",
157 		mini=5,
158 		minimum="n",
159 		minItems=6,
160 		minl=7,
161 		minLength=8,
162 		mo="o",
163 		multipleOf="p",
164 		p="q",
165 		pattern="r",
166 		t="s",
167 		type="t",
168 		ui=true,
169 		uniqueItems=true
170 	)
171 	public static class D1 {}
172 	SubItems d1 = D1.class.getAnnotationsByType(SubItems.class)[0];
173 
174 	@SubItems(
175 		$ref="a",
176 		default_="b",
177 		enum_="c",
178 		cf="d",
179 		collectionFormat="e",
180 		description={ "f" },
181 		df="g",
182 		e="h",
183 		emax=true,
184 		emin=true,
185 		exclusiveMaximum=true,
186 		exclusiveMinimum=true,
187 		f="i",
188 		format="j",
189 		max="k",
190 		maxi=1,
191 		maximum="l",
192 		maxItems=2,
193 		maxl=3,
194 		maxLength=4,
195 		min="m",
196 		mini=5,
197 		minimum="n",
198 		minItems=6,
199 		minl=7,
200 		minLength=8,
201 		mo="o",
202 		multipleOf="p",
203 		p="q",
204 		pattern="r",
205 		t="s",
206 		type="t",
207 		ui=true,
208 		uniqueItems=true
209 	)
210 	public static class D2 {}
211 	SubItems d2 = D2.class.getAnnotationsByType(SubItems.class)[0];
212 
213 	@Test void d01_comparisonWithDeclarativeAnnotations() {
214 		assertEqualsAll(a1, d1, d2);
215 		assertNotEqualsAny(a1.hashCode(), 0, -1);
216 		assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
217 	}
218 }