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