1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.xml.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.junit.jupiter.api.*;
25
26 class XmlAnnotation_Test extends TestBase {
27
28 private static final String CNAME = XmlAnnotation_Test.class.getName();
29
30
31
32
33
34 Xml a1 = XmlAnnotation.create()
35 .childName("a")
36 .description("b")
37 .format(XmlFormat.ATTR)
38 .namespace("c")
39 .on("d")
40 .prefix("e")
41 .build();
42
43 Xml a2 = XmlAnnotation.create()
44 .childName("a")
45 .description("b")
46 .format(XmlFormat.ATTR)
47 .namespace("c")
48 .on("d")
49 .prefix("e")
50 .build();
51
52 @Test void a01_basic() {
53 assertBean(a1, "childName,description,format,namespace,on,onClass,prefix", "a,[b],ATTR,c,[d],[],e");
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() throws Exception {
86 var c1 = XmlAnnotation.create(C1.class).on(C2.class).build();
87 var c2 = XmlAnnotation.create("a").on("b").build();
88 var c3 = XmlAnnotation.create().on(C1.class.getField("f1")).on(C2.class.getField("f2")).build();
89 var c4 = XmlAnnotation.create().on(C1.class.getMethod("m1")).on(C2.class.getMethod("m2")).build();
90
91 assertBean(c1, "on", "["+CNAME+"$C1,"+CNAME+"$C2]");
92 assertBean(c2, "on", "[a,b]");
93 assertBean(c3, "on", "["+CNAME+"$C1.f1,"+CNAME+"$C2.f2]");
94 assertBean(c4, "on", "["+CNAME+"$C1.m1(),"+CNAME+"$C2.m2()]");
95 }
96
97
98
99
100
101 @Xml(
102 childName="a",
103 description={ "b" },
104 format=XmlFormat.ATTR,
105 namespace="c",
106 on="d",
107 prefix="e"
108 )
109 public static class D1 {}
110 Xml d1 = D1.class.getAnnotationsByType(Xml.class)[0];
111
112 @Xml(
113 childName="a",
114 description={ "b" },
115 format=XmlFormat.ATTR,
116 namespace="c",
117 on="d",
118 prefix="e"
119 )
120 public static class D2 {}
121 Xml d2 = D2.class.getAnnotationsByType(Xml.class)[0];
122
123 @Test void d01_comparisonWithDeclarativeAnnotations() {
124 assertEqualsAll(a1, d1, d2);
125 assertNotEqualsAny(a1.hashCode(), 0, -1);
126 assertEqualsAll(a1.hashCode(), d1.hashCode(), d2.hashCode());
127 }
128 }