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.apache.juneau.junit.bct.BctAssertions.*;
21 import static org.junit.jupiter.api.Assertions.*;
22
23 import org.apache.juneau.*;
24 import org.apache.juneau.oapi.*;
25 import org.junit.jupiter.api.*;
26
27 class FormDataAnnotation_Test extends TestBase {
28
29 private static final String CNAME = FormDataAnnotation_Test.class.getName();
30
31 public static class X1 {}
32
33
34
35
36
37 FormData a1 = FormDataAnnotation.create()
38 .def("a")
39 .description("b")
40 .name("c")
41 .on("d")
42 .onClass(X1.class)
43 .parser(OpenApiParser.class)
44 .serializer(OpenApiSerializer.class)
45 .value("e")
46 .build();
47
48 FormData a2 = FormDataAnnotation.create()
49 .def("a")
50 .description("b")
51 .name("c")
52 .on("d")
53 .onClass(X1.class)
54 .parser(OpenApiParser.class)
55 .serializer(OpenApiSerializer.class)
56 .value("e")
57 .build();
58
59 @Test void a01_basic() {
60 assertBean(
61 a1,
62 "def,description,name,on,onClass{#{simpleName}},parser{simpleName},schema{description},serializer{simpleName},value",
63 "a,[b],c,[d],{[{X1}]},{OpenApiParser},{[]},{OpenApiSerializer},e"
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 = FormDataAnnotation.create(C1.class).on(C2.class).build();
98 var c2 = FormDataAnnotation.create("a").on("b").build();
99 var c3 = FormDataAnnotation.create().on(C1.class.getField("f1")).on(C2.class.getField("f2")).build();
100 var c4 = FormDataAnnotation.create().on(C1.class.getMethod("m1")).on(C2.class.getMethod("m2")).build();
101
102 assertBean(c1, "on", "["+CNAME+"$C1,"+CNAME+"$C2]");
103 assertBean(c2, "on", "[a,b]");
104 assertBean(c3, "on", "["+CNAME+"$C1.f1,"+CNAME+"$C2.f2]");
105 assertBean(c4, "on", "["+CNAME+"$C1.m1(),"+CNAME+"$C2.m2()]");
106 }
107
108
109
110
111
112 @FormData(
113 def="a",
114 description={ "b" },
115 name="c",
116 on="d",
117 onClass=X1.class,
118 parser=OpenApiParser.class,
119 serializer=OpenApiSerializer.class,
120 value="e"
121 )
122 public static class D1 {}
123 FormData d1 = D1.class.getAnnotationsByType(FormData.class)[0];
124
125 @FormData(
126 def="a",
127 description={ "b" },
128 name="c",
129 on="d",
130 onClass=X1.class,
131 parser=OpenApiParser.class,
132 serializer=OpenApiSerializer.class,
133 value="e"
134 )
135 public static class D2 {}
136 FormData d2 = D2.class.getAnnotationsByType(FormData.class)[0];
137
138 @Test void d01_comparisonWithDeclarativeAnnotations() {
139 assertEqualsAll(a1, d1, d2);
140 assertNotEqualsAny(a1.hashCode(), 0, -1);
141 assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
142 }
143 }