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