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