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 | 0 | public PerTestDataLoaderLifecycle(Method method) { |
38 | 0 | this.method = method; |
39 | 0 | } |
40 | |
|
41 | |
public boolean isStarted() { |
42 | 0 | return started; |
43 | |
} |
44 | |
|
45 | |
public void start() throws Exception { |
46 | 0 | if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) { |
47 | 0 | UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).value(); |
48 | 0 | UnitTestDataUtils.executeDataLoader(data); |
49 | |
} |
50 | 0 | if (method.isAnnotationPresent(UnitTestData.class)) { |
51 | 0 | UnitTestData data = method.getAnnotation(UnitTestData.class); |
52 | 0 | UnitTestDataUtils.executeDataLoader(data); |
53 | |
} |
54 | 0 | started = true; |
55 | 0 | } |
56 | |
|
57 | |
public void stop() throws Exception { |
58 | 0 | if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) { |
59 | 0 | UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).tearDown(); |
60 | 0 | UnitTestDataUtils.executeDataLoader(data); |
61 | |
} |
62 | 0 | started = false; |
63 | 0 | } |
64 | |
} |