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.rest.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.apache.juneau.http.annotation.*;
26  import org.apache.juneau.http.annotation.Tag;
27  import org.junit.jupiter.api.*;
28  
29  class SwaggerAnnotation_Test extends TestBase {
30  
31  	//------------------------------------------------------------------------------------------------------------------
32  	// Basic tests
33  	//------------------------------------------------------------------------------------------------------------------
34  
35  	Swagger a1 = SwaggerAnnotation.create()
36  		.contact(ContactAnnotation.DEFAULT)
37  		.description("a")
38  		.externalDocs(ExternalDocsAnnotation.DEFAULT)
39  		.license(LicenseAnnotation.DEFAULT)
40  		.tags(TagAnnotation.DEFAULT)
41  		.termsOfService("b")
42  		.title("c")
43  		.value("d")
44  		.version("e")
45  		.build();
46  
47  	Swagger a2 = SwaggerAnnotation.create()
48  		.contact(ContactAnnotation.DEFAULT)
49  		.description("a")
50  		.externalDocs(ExternalDocsAnnotation.DEFAULT)
51  		.license(LicenseAnnotation.DEFAULT)
52  		.tags(TagAnnotation.DEFAULT)
53  		.termsOfService("b")
54  		.title("c")
55  		.value("d")
56  		.version("e")
57  		.build();
58  
59  	@Test void a01_basic() {
60  		assertBean(a1,
61  			"contact{description,email,name,url},description,externalDocs{description,url},license{description,name,url},tags{#{description,externalDocs{description,url},name}},termsOfService,title,value,version",
62  			"{[],,,},[a],{[],},{[],,},{[{[],{[],},}]},[b],[c],[d],e");
63  	}
64  
65  	@Test void a02_testEquivalency() {
66  		assertEquals(a2, a1);
67  		assertNotEqualsAny(a1.hashCode(), 0, -1);
68  		assertEquals(a1.hashCode(), a2.hashCode());
69  	}
70  
71  	//------------------------------------------------------------------------------------------------------------------
72  	// PropertyStore equivalency.
73  	//------------------------------------------------------------------------------------------------------------------
74  
75  	@Test void b01_testEquivalencyInPropertyStores() {
76  		var bc1 = BeanContext.create().annotations(a1).build();
77  		var bc2 = BeanContext.create().annotations(a2).build();
78  		assertSame(bc1, bc2);
79  	}
80  
81  	//------------------------------------------------------------------------------------------------------------------
82  	// Other methods.
83  	//------------------------------------------------------------------------------------------------------------------
84  
85  	//------------------------------------------------------------------------------------------------------------------
86  	// Comparison with declared annotations.
87  	//------------------------------------------------------------------------------------------------------------------
88  
89  	@Swagger(
90  		contact=@Contact,
91  		description="a",
92  		externalDocs=@ExternalDocs,
93  		license=@License,
94  		tags=@Tag,
95  		termsOfService="b",
96  		title="c",
97  		value="d",
98  		version="e"
99  	)
100 	public static class D1 {}
101 	Swagger d1 = D1.class.getAnnotationsByType(Swagger.class)[0];
102 
103 	@Swagger(
104 		contact=@Contact,
105 		description="a",
106 		externalDocs=@ExternalDocs,
107 		license=@License,
108 		tags=@Tag,
109 		termsOfService="b",
110 		title="c",
111 		value="d",
112 		version="e"
113 	)
114 	public static class D2 {}
115 	Swagger d2 = D2.class.getAnnotationsByType(Swagger.class)[0];
116 
117 	@Test void d01_comparisonWithDeclarativeAnnotations() {
118 		assertEqualsAll(a1, d1, d2);
119 		assertNotEqualsAny(a1.hashCode(), 0, -1);
120 		assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
121 	}
122 }