1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.http.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.oapi.*;
25 import org.junit.jupiter.api.*;
26
27 class ResponseAnnotation_Test extends TestBase {
28
29 private static final String CNAME = ResponseAnnotation_Test.class.getName();
30
31 public static class X1 {}
32
33
34
35
36
37 Response a1 = ResponseAnnotation.create()
38 .description("a")
39 .examples("b")
40 .headers(HeaderAnnotation.DEFAULT)
41 .on("c")
42 .onClass(X1.class)
43 .parser(OpenApiParser.class)
44 .schema(SchemaAnnotation.DEFAULT)
45 .serializer(OpenApiSerializer.class)
46 .build();
47
48 Response a2 = ResponseAnnotation.create()
49 .description("a")
50 .examples("b")
51 .headers(HeaderAnnotation.DEFAULT)
52 .on("c")
53 .onClass(X1.class)
54 .parser(OpenApiParser.class)
55 .schema(SchemaAnnotation.DEFAULT)
56 .serializer(OpenApiSerializer.class)
57 .build();
58
59 @Test void a01_basic() {
60 assertBean(
61 a1,
62 "description,examples,on,onClass{#{simpleName}},parser{simpleName},serializer{simpleName}",
63 "[a],[b],[c],{[{X1}]},{OpenApiParser},{OpenApiSerializer}"
64 );
65 }
66
67 @Test void a02_testEquivalency() {
68 assertEquals(a2, a1);
69 assertNotEqualsAny(a1.hashCode(), 0, -1);
70 assertEquals(a1.hashCode(), a2.hashCode());
71 }
72
73
74
75
76
77 @Test void b01_testEquivalencyInPropertyStores() {
78 var bc1 = BeanContext.create().annotations(a1).build();
79 var bc2 = BeanContext.create().annotations(a2).build();
80 assertSame(bc1, bc2);
81 }
82
83
84
85
86
87 public static class C1 {
88 public int f1;
89 public void m1() {}
90 }
91 public static class C2 {
92 public int f2;
93 public void m2() {}
94 }
95
96 @Test void c01_otherMethods() throws Exception {
97 var c1 = ResponseAnnotation.create(C1.class).on(C2.class).build();
98 var c2 = ResponseAnnotation.create("a").on("b").build();
99 var c4 = ResponseAnnotation.create().on(C1.class.getMethod("m1")).on(C2.class.getMethod("m2")).build();
100
101 assertBean(c1, "on", "["+CNAME+"$C1,"+CNAME+"$C2]");
102 assertBean(c2, "on", "[a,b]");
103 assertBean(c4, "on", "["+CNAME+"$C1.m1(),"+CNAME+"$C2.m2()]");
104 }
105
106
107
108
109
110 @Response(
111 description={ "a" },
112 examples="b",
113 headers=@Header,
114 on="c",
115 onClass=X1.class,
116 parser=OpenApiParser.class,
117 schema=@Schema,
118 serializer=OpenApiSerializer.class
119 )
120 public static class D1 {}
121 Response d1 = D1.class.getAnnotationsByType(Response.class)[0];
122
123 @Response(
124 description={ "a" },
125 examples="b",
126 headers=@Header,
127 on="c",
128 onClass=X1.class,
129 parser=OpenApiParser.class,
130 schema=@Schema,
131 serializer=OpenApiSerializer.class
132 )
133 public static class D2 {}
134 Response d2 = D2.class.getAnnotationsByType(Response.class)[0];
135
136 @Test void d01_comparisonWithDeclarativeAnnotations() {
137 assertEqualsAll(a1, d1, d2);
138 assertNotEqualsAny(a1.hashCode(), 0, -1);
139 assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
140 }
141 }