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.junit.jupiter.api.*;
26  
27  class OpSwaggerAnnotation_Test extends TestBase {
28  
29  	//------------------------------------------------------------------------------------------------------------------
30  	// Basic tests
31  	//------------------------------------------------------------------------------------------------------------------
32  
33  	OpSwagger a1 = OpSwaggerAnnotation.create()
34  		.consumes("a")
35  		.deprecated("b")
36  		.description("c")
37  		.externalDocs(ExternalDocsAnnotation.DEFAULT)
38  		.operationId("d")
39  		.parameters("e")
40  		.produces("f")
41  		.responses("g")
42  		.schemes("h")
43  		.summary("i")
44  		.tags("j")
45  		.value("k")
46  		.build();
47  
48  	OpSwagger a2 = OpSwaggerAnnotation.create()
49  		.consumes("a")
50  		.deprecated("b")
51  		.description("c")
52  		.externalDocs(ExternalDocsAnnotation.DEFAULT)
53  		.operationId("d")
54  		.parameters("e")
55  		.produces("f")
56  		.responses("g")
57  		.schemes("h")
58  		.summary("i")
59  		.tags("j")
60  		.value("k")
61  		.build();
62  
63  	@Test void a01_basic() {
64  		assertBean(a1,
65  			"consumes,deprecated,description,externalDocs{description,url},operationId,parameters,produces,responses,schemes,summary,tags,value",
66  			"[a],b,[c],{[],},d,[e],[f],[g],[h],[i],[j],[k]");
67  	}
68  
69  	@Test void a02_testEquivalency() {
70  		assertEquals(a2, a1);
71  		assertNotEqualsAny(a1.hashCode(), 0, -1);
72  		assertEquals(a1.hashCode(), a2.hashCode());
73  	}
74  
75  	//------------------------------------------------------------------------------------------------------------------
76  	// PropertyStore equivalency.
77  	//------------------------------------------------------------------------------------------------------------------
78  
79  	@Test void b01_testEquivalencyInPropertyStores() {
80  		var bc1 = BeanContext.create().annotations(a1).build();
81  		var bc2 = BeanContext.create().annotations(a2).build();
82  		assertSame(bc1, bc2);
83  	}
84  
85  	//------------------------------------------------------------------------------------------------------------------
86  	// Other methods.
87  	//------------------------------------------------------------------------------------------------------------------
88  
89  	//------------------------------------------------------------------------------------------------------------------
90  	// Comparison with declared annotations.
91  	//------------------------------------------------------------------------------------------------------------------
92  
93  	@OpSwagger(
94  		consumes="a",
95  		deprecated="b",
96  		description="c",
97  		externalDocs=@ExternalDocs,
98  		operationId="d",
99  		parameters="e",
100 		produces="f",
101 		responses="g",
102 		schemes="h",
103 		summary="i",
104 		tags="j",
105 		value="k"
106 	)
107 	public static class D1 {}
108 	OpSwagger d1 = D1.class.getAnnotationsByType(OpSwagger.class)[0];
109 
110 	@OpSwagger(
111 		consumes="a",
112 		deprecated="b",
113 		description="c",
114 		externalDocs=@ExternalDocs,
115 		operationId="d",
116 		parameters="e",
117 		produces="f",
118 		responses="g",
119 		schemes="h",
120 		summary="i",
121 		tags="j",
122 		value="k"
123 	)
124 	public static class D2 {}
125 	OpSwagger d2 = D2.class.getAnnotationsByType(OpSwagger.class)[0];
126 
127 	@Test void d01_comparisonWithDeclarativeAnnotations() {
128 		assertEqualsAll(a1, d1, d2);
129 		assertNotEqualsAny(a1.hashCode(), 0, -1);
130 		assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
131 	}
132 }