1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.bo.DocumentAttachment;
20 import org.kuali.rice.krad.document.DocumentBase;
21 import org.kuali.rice.krad.maintenance.MaintenanceLock;
22 import org.kuali.rice.krad.messages.Message;
23 import org.reflections.Reflections;
24
25 import javax.persistence.Embeddable;
26 import javax.persistence.Entity;
27 import javax.persistence.MappedSuperclass;
28 import java.lang.reflect.Method;
29 import java.util.Set;
30
31 import static org.junit.Assert.fail;
32
33
34
35
36
37
38
39
40
41
42
43 public class StaticWeavingTest {
44
45
46
47 private static final String TEST_PACKAGE_PREFIX = "org.kuali.rice.krad.sampleapp";
48
49 @Test
50 public void testStaticWeaving() {
51
52 Reflections reflections = new Reflections(
53 DocumentAttachment.class.getPackage().getName(),
54 DocumentBase.class.getPackage().getName(),
55 MaintenanceLock.class.getPackage().getName(),
56 Message.class.getPackage().getName());
57 Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class);
58 Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class);
59 Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class);
60
61
62 assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
63 }
64
65 private void assertStaticWeaved(Set<Class<?>>... types) {
66 for (Set<Class<?>> typeSet : types) {
67 for (Class<?> type : typeSet) {
68 if (type.getName().startsWith(TEST_PACKAGE_PREFIX)) {
69 continue;
70 }
71 boolean foundWeaved = false;
72 Method[] methods = type.getDeclaredMethods();
73 for (Method method : methods) {
74 if (method.getName().startsWith("_persistence")) {
75 foundWeaved = true;
76 break;
77 }
78 }
79 if (!foundWeaved) {
80 fail("(NOTE: it is expected this test may fail if executed from the IDE instead of command line "
81 + "since the IDE will not execute the static weaving automatically). Found a class which is "
82 + "not bytecode weaved (contains no methods starting with '_persistence'): " + type + " "
83 + "In order to resolve this, please ensure that this type is included in "
84 + "META-INF/persistence-weaving.xml");
85 }
86 }
87 }
88 }
89
90 }