1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.test.mock.data;
17
18 import java.util.Date;
19 import java.util.Map;
20
21 import org.kuali.student.common.mock.MockService;
22 import org.kuali.student.common.test.TestAwareDataLoader;
23 import org.kuali.student.r2.common.dto.ContextInfo;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.BeansException;
27 import org.springframework.context.ApplicationContext;
28 import org.springframework.context.ApplicationContextAware;
29
30
31
32
33
34
35
36
37
38
39
40
41 public abstract class AbstractMockServicesAwareDataLoader implements ApplicationContextAware, TestAwareDataLoader {
42
43 private static final Logger log = LoggerFactory
44 .getLogger(AbstractMockServicesAwareDataLoader.class);
45
46 protected ApplicationContext applicationContext;
47
48 protected boolean initialized;
49
50 protected final ContextInfo context;
51
52 public AbstractMockServicesAwareDataLoader() {
53
54 context = new ContextInfo();
55
56 context.setPrincipalId("123");
57 context.setCurrentDate(new Date());
58 }
59
60 @Override
61 public final void setApplicationContext(ApplicationContext applicationContext)
62 throws BeansException {
63 this.applicationContext = applicationContext;
64
65 }
66
67 @Override
68 public final void beforeTest() throws Exception {
69
70 initializeData();
71
72 initialized = true;
73
74 }
75
76
77
78
79 protected abstract void initializeData() throws Exception;
80
81
82
83
84
85
86 public final boolean isInitialized() {
87 return initialized;
88 }
89
90 @Override
91 public final void afterTest() throws Exception {
92
93 Map<String, MockService> map = applicationContext.getBeansOfType(MockService.class);
94
95 for (MockService mock : map.values()) {
96
97
98 mock.clear();
99 }
100
101 }
102
103
104
105
106 }