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.oapi.*;
24 import org.junit.jupiter.api.*;
25
26 class RequestAnnotation_Test extends TestBase {
27
28 private static final String CNAME = RequestAnnotation_Test.class.getName();
29
30 public static class X1 {}
31
32
33
34
35
36 Request a1 = RequestAnnotation.create()
37 .description("a")
38 .on("b")
39 .onClass(X1.class)
40 .parser(OpenApiParser.class)
41 .serializer(OpenApiSerializer.class)
42 .build();
43
44 Request a2 = RequestAnnotation.create()
45 .description("a")
46 .on("b")
47 .onClass(X1.class)
48 .parser(OpenApiParser.class)
49 .serializer(OpenApiSerializer.class)
50 .build();
51
52 @Test void a01_basic() {
53 assertBean(a1, "description,on,onClass,parser,serializer", "[a],[b],[X1],OpenApiParser,OpenApiSerializer");
54 }
55
56 @Test void a02_testEquivalency() {
57 assertEquals(a2, a1);
58 assertNotEqualsAny(a1.hashCode(), 0, -1);
59 assertEquals(a1.hashCode(), a2.hashCode());
60 }
61
62
63
64
65
66 @Test void b01_testEquivalencyInPropertyStores() {
67 var bc1 = BeanContext.create().annotations(a1).build();
68 var bc2 = BeanContext.create().annotations(a2).build();
69 assertSame(bc1, bc2);
70 }
71
72
73
74
75
76 public static class C1 {
77 public int f1;
78 public void m1() {}
79 }
80 public static class C2 {
81 public int f2;
82 public void m2() {}
83 }
84
85 @Test void c01_otherMethods() {
86 var c1 = RequestAnnotation.create(C1.class).on(C2.class).build();
87 var c2 = RequestAnnotation.create("a").on("b").build();
88
89 assertBean(c1, "on", "["+CNAME+"$C1,"+CNAME+"$C2]");
90 assertBean(c2, "on", "[a,b]");
91 }
92
93
94
95
96
97 @Request(
98 description={ "a" },
99 on="b",
100 onClass=X1.class,
101 parser=OpenApiParser.class,
102 serializer=OpenApiSerializer.class
103 )
104 public static class D1 {}
105 Request d1 = D1.class.getAnnotationsByType(Request.class)[0];
106
107 @Request(
108 description={ "a" },
109 on="b",
110 onClass=X1.class,
111 parser=OpenApiParser.class,
112 serializer=OpenApiSerializer.class
113 )
114 public static class D2 {}
115 Request d2 = D2.class.getAnnotationsByType(Request.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 }