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 FormDataAnnotation_Test extends TestBase {
27
28 private static final String CNAME = FormDataAnnotation_Test.class.getName();
29
30 public static class X1 {}
31
32
33
34
35
36 FormData a1 = FormDataAnnotation.create()
37 .def("a")
38 .description("b")
39 .name("c")
40 .on("d")
41 .onClass(X1.class)
42 .parser(OpenApiParser.class)
43 .serializer(OpenApiSerializer.class)
44 .value("e")
45 .build();
46
47 FormData a2 = FormDataAnnotation.create()
48 .def("a")
49 .description("b")
50 .name("c")
51 .on("d")
52 .onClass(X1.class)
53 .parser(OpenApiParser.class)
54 .serializer(OpenApiSerializer.class)
55 .value("e")
56 .build();
57
58 @Test void a01_basic() {
59 assertBean(
60 a1,
61 "def,description,name,on,onClass{#{simpleName}},parser{simpleName},schema{description},serializer{simpleName},value",
62 "a,[b],c,[d],{[{X1}]},{OpenApiParser},{[]},{OpenApiSerializer},e"
63 );
64 }
65
66 @Test void a02_testEquivalency() {
67 assertEquals(a2, a1);
68 assertNotEqualsAny(a1.hashCode(), 0, -1);
69 assertEquals(a1.hashCode(), a2.hashCode());
70 }
71
72
73
74
75
76 @Test void b01_testEquivalencyInPropertyStores() {
77 var bc1 = BeanContext.create().annotations(a1).build();
78 var bc2 = BeanContext.create().annotations(a2).build();
79 assertSame(bc1, bc2);
80 }
81
82
83
84
85
86 public static class C1 {
87 public int f1;
88 public void m1() {}
89 }
90 public static class C2 {
91 public int f2;
92 public void m2() {}
93 }
94
95 @Test void c01_otherMethods() throws Exception {
96 var c1 = FormDataAnnotation.create(C1.class).on(C2.class).build();
97 var c2 = FormDataAnnotation.create("a").on("b").build();
98 var c3 = FormDataAnnotation.create().on(C1.class.getField("f1")).on(C2.class.getField("f2")).build();
99 var c4 = FormDataAnnotation.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(c3, "on", "["+CNAME+"$C1.f1,"+CNAME+"$C2.f2]");
104 assertBean(c4, "on", "["+CNAME+"$C1.m1(),"+CNAME+"$C2.m2()]");
105 }
106
107
108
109
110
111 @FormData(
112 def="a",
113 description={ "b" },
114 name="c",
115 on="d",
116 onClass=X1.class,
117 parser=OpenApiParser.class,
118 serializer=OpenApiSerializer.class,
119 value="e"
120 )
121 public static class D1 {}
122 FormData d1 = D1.class.getAnnotationsByType(FormData.class)[0];
123
124 @FormData(
125 def="a",
126 description={ "b" },
127 name="c",
128 on="d",
129 onClass=X1.class,
130 parser=OpenApiParser.class,
131 serializer=OpenApiSerializer.class,
132 value="e"
133 )
134 public static class D2 {}
135 FormData d2 = D2.class.getAnnotationsByType(FormData.class)[0];
136
137 @Test void d01_comparisonWithDeclarativeAnnotations() {
138 assertEqualsAll(a1, d1, d2);
139 assertNotEqualsAny(a1.hashCode(), 0, -1);
140 assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
141 }
142 }