1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.test.lifecycles;
17
18 import org.kuali.rice.core.api.lifecycle.Lifecycle;
19 import org.kuali.rice.core.api.lifecycle.Lifecycle;
20 import org.kuali.rice.test.data.PerTestUnitTestData;
21 import org.kuali.rice.test.data.UnitTestData;
22 import org.kuali.rice.test.data.UnitTestDataUtils;
23
24 import java.lang.reflect.Method;
25
26
27
28
29
30
31
32
33 public class PerTestDataLoaderLifecycle implements Lifecycle {
34 private boolean started;
35 private Method method;
36
37 public PerTestDataLoaderLifecycle(Method method) {
38 this.method = method;
39 }
40
41 public boolean isStarted() {
42 return started;
43 }
44
45 public void start() throws Exception {
46 if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) {
47 UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).value();
48 UnitTestDataUtils.executeDataLoader(data);
49 }
50 if (method.isAnnotationPresent(UnitTestData.class)) {
51 UnitTestData data = method.getAnnotation(UnitTestData.class);
52 UnitTestDataUtils.executeDataLoader(data);
53 }
54 started = true;
55 }
56
57 public void stop() throws Exception {
58 if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) {
59 UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).tearDown();
60 UnitTestDataUtils.executeDataLoader(data);
61 }
62 started = false;
63 }
64 }