1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.contract.model.impl;
17
18 import java.io.File;
19 import java.util.LinkedHashMap;
20 import java.util.Map;
21
22 import javax.xml.bind.annotation.XmlEnum;
23
24 import org.junit.Assert;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.BlockJUnit4ClassRunner;
29 import org.kuali.student.contract.model.util.JavaClassAnnotationUtils;
30 import org.kuali.student.model.annotation.EnumWithAnnotationValue;
31 import org.kuali.student.model.annotation.EnumWithoutAnnotationValue;
32 import org.slf4j.Logger;
33
34 import com.thoughtworks.qdox.JavaDocBuilder;
35 import com.thoughtworks.qdox.model.DefaultDocletTagFactory;
36 import com.thoughtworks.qdox.model.JavaClass;
37
38
39
40
41
42
43
44 @RunWith(BlockJUnit4ClassRunner.class)
45 public class TestAnnotationValueResolution {
46
47 private static final Logger log = org.slf4j.LoggerFactory.getLogger(TestAnnotationValueResolution.class);
48
49 private static Map<String, JavaClass> parsedJavaClassesMap;
50
51
52
53
54 public TestAnnotationValueResolution() {
55
56 }
57
58 @BeforeClass
59 public static void setup () {
60
61 DefaultDocletTagFactory dtf = new DefaultDocletTagFactory();
62 JavaDocBuilder builder = new JavaDocBuilder(dtf);
63
64 builder.addSourceTree(new File("src/test/java/org/kuali/student/model/annotation"));
65
66 parsedJavaClassesMap = new LinkedHashMap<String, JavaClass>();
67
68 for (JavaClass javaClass : builder.getClasses()) {
69
70 parsedJavaClassesMap.put(javaClass.getName(), javaClass);
71
72 }
73
74 }
75
76
77
78 @Test
79 public void checkExistence() {
80
81 JavaClass withValue = parsedJavaClassesMap.get(EnumWithAnnotationValue.class.getSimpleName());
82
83 Assert.assertNotNull(withValue);
84
85 JavaClass withOutValue = parsedJavaClassesMap.get(EnumWithAnnotationValue.class.getSimpleName());
86
87 Assert.assertNotNull(withOutValue);
88
89 }
90
91 @Test
92 public void extractAnnotationValue() {
93
94 JavaClass withValue = parsedJavaClassesMap.get(EnumWithAnnotationValue.class.getSimpleName());
95
96 Assert.assertTrue(JavaClassAnnotationUtils.doesAnnotationExist(XmlEnum.class.getSimpleName(), withValue));
97
98 Class<?>withValueClass = JavaClassAnnotationUtils.extractXmlEnumValue(withValue);
99
100 Assert.assertEquals(Integer.class, withValueClass);
101
102 JavaClass withoutValue = parsedJavaClassesMap.get(EnumWithoutAnnotationValue.class.getSimpleName());
103
104 Assert.assertTrue(JavaClassAnnotationUtils.doesAnnotationExist(XmlEnum.class.getSimpleName(), withValue));
105
106 Class<?>withoutValueClass = JavaClassAnnotationUtils.extractXmlEnumValue(withoutValue);
107
108 Assert.assertEquals(String.class, withoutValueClass);
109
110
111
112 }
113 }