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