1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.server.applicationstate.dao.impl; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import org.junit.Assert; |
24 |
|
import org.junit.Test; |
25 |
|
import org.kuali.student.common.exceptions.AlreadyExistsException; |
26 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
27 |
|
import org.kuali.student.common.test.spring.AbstractTransactionalDaoTest; |
28 |
|
import org.kuali.student.common.test.spring.Dao; |
29 |
|
import org.kuali.student.common.test.spring.PersistenceFileLocation; |
30 |
|
import org.kuali.student.common.ui.server.applicationstate.dao.ApplicationStateDao; |
31 |
|
import org.kuali.student.common.ui.server.applicationstate.entity.ApplicationState; |
32 |
|
import org.kuali.student.common.ui.server.applicationstate.entity.KeyValuePair; |
33 |
|
|
34 |
|
@PersistenceFileLocation("classpath:META-INF/application-state-persistence.xml") |
|
|
| 95.4% |
Uncovered Elements: 7 (152) |
Complexity: 19 |
Complexity Density: 0.14 |
|
35 |
|
public class ApplicationStateDaoImplTest extends AbstractTransactionalDaoTest { |
36 |
|
|
37 |
|
@Dao(value = "org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImpl") |
38 |
|
public ApplicationStateDao dao; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
40 |
5
|
private Map<String, String> getMap(List<KeyValuePair> list) {... |
41 |
5
|
Map<String, String> map = new HashMap<String, String>(); |
42 |
5
|
for(KeyValuePair pair : list) { |
43 |
11
|
map.put(pair.getKey(), pair.getValue()); |
44 |
|
} |
45 |
5
|
return map; |
46 |
|
} |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
48 |
8
|
private List<KeyValuePair> getKeyValuePairList(int startIndex, int n) {... |
49 |
8
|
List<KeyValuePair> list = new ArrayList<KeyValuePair>(); |
50 |
28
|
for(int i=startIndex; i<(startIndex+n); i++) { |
51 |
20
|
list.add(new KeyValuePair("key-"+i, "value-"+i)); |
52 |
|
} |
53 |
8
|
return list; |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
56 |
10
|
private ApplicationState getApplicationState(String appId, String refKey, String refType, String userId, List<KeyValuePair> list) {... |
57 |
10
|
ApplicationState appState = new ApplicationState(); |
58 |
10
|
appState.setApplicationId(appId); |
59 |
10
|
appState.setKeyValueList(list); |
60 |
10
|
appState.setReferenceKey(refKey); |
61 |
10
|
appState.setReferenceType(refType); |
62 |
10
|
appState.setUserId(userId); |
63 |
10
|
return appState; |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
66 |
1
|
@Test... |
67 |
|
public void testUpdateApplicationState1() throws Exception { |
68 |
1
|
List<KeyValuePair> list = getKeyValuePairList(1,3); |
69 |
1
|
ApplicationState appState = getApplicationState("1", "2", "course", null, list); |
70 |
1
|
ApplicationState newAppState = dao.createApplicationState(appState); |
71 |
|
|
72 |
1
|
ApplicationState getAppState = dao.getApplicationState("1", "2", "course"); |
73 |
|
|
74 |
1
|
list = new ArrayList<KeyValuePair>(); |
75 |
1
|
list.add(new KeyValuePair("k1", "v1")); |
76 |
1
|
list.add(new KeyValuePair("k2", "v2")); |
77 |
1
|
getAppState.setKeyValueList(list); |
78 |
|
|
79 |
1
|
dao.update(getAppState); |
80 |
|
|
81 |
1
|
getAppState = dao.getApplicationState("1", "2", "course"); |
82 |
1
|
Assert.assertNotNull(getAppState); |
83 |
1
|
Assert.assertEquals(newAppState.toString(), getAppState.toString()); |
84 |
1
|
Assert.assertEquals(newAppState.getKeyValueList().toString(), getAppState.getKeyValueList().toString()); |
85 |
|
|
86 |
1
|
ApplicationState getAppState2 = dao.fetch(ApplicationState.class, newAppState.getId()); |
87 |
1
|
Assert.assertEquals(getAppState.toString(), getAppState2.toString()); |
88 |
1
|
Assert.assertEquals(getAppState.getKeyValueList().toString(), getAppState2.getKeyValueList().toString()); |
89 |
|
|
90 |
1
|
dao.delete(ApplicationState.class, newAppState.getId()); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1
PASS
|
|
93 |
1
|
@Test... |
94 |
|
public void testUpdateApplicationState2() throws Exception { |
95 |
1
|
List<KeyValuePair> list = getKeyValuePairList(1,3); |
96 |
1
|
ApplicationState appState = getApplicationState("1", "2", "course", null, list); |
97 |
1
|
ApplicationState newAppState = dao.createApplicationState(appState); |
98 |
|
|
99 |
1
|
ApplicationState getAppState = dao.getApplicationState("1", "2", "course"); |
100 |
|
|
101 |
1
|
getAppState.setApplicationId("A"); |
102 |
1
|
getAppState.setReferenceKey("B"); |
103 |
1
|
getAppState.setReferenceType("program"); |
104 |
1
|
list = new ArrayList<KeyValuePair>(); |
105 |
1
|
list.add(new KeyValuePair("k1", "v1")); |
106 |
1
|
list.add(new KeyValuePair("k2", "v2")); |
107 |
1
|
getAppState.setKeyValueList(list); |
108 |
|
|
109 |
1
|
dao.update(getAppState); |
110 |
|
|
111 |
1
|
getAppState = dao.getApplicationState("A", "B", "program"); |
112 |
|
|
113 |
1
|
Assert.assertNotNull(getAppState); |
114 |
1
|
Assert.assertEquals(newAppState.toString(), getAppState.toString()); |
115 |
1
|
Assert.assertEquals(newAppState.getKeyValueList().toString(), getAppState.getKeyValueList().toString()); |
116 |
|
|
117 |
1
|
ApplicationState getAppState2 = dao.fetch(ApplicationState.class, newAppState.getId()); |
118 |
1
|
Assert.assertEquals(getAppState.toString(), getAppState2.toString()); |
119 |
1
|
Assert.assertEquals(getAppState.getKeyValueList().toString(), getAppState2.getKeyValueList().toString()); |
120 |
|
|
121 |
1
|
dao.delete(ApplicationState.class, newAppState.getId()); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
124 |
1
|
@Test... |
125 |
|
public void testCreateGetApplicationState1() throws Exception { |
126 |
1
|
List<KeyValuePair> list = getKeyValuePairList(1,3); |
127 |
1
|
ApplicationState appState = getApplicationState("1", "2", "course", null, list); |
128 |
1
|
ApplicationState newAppState = dao.createApplicationState(appState); |
129 |
|
|
130 |
1
|
ApplicationState getAppState = dao.getApplicationState("1", "2", "course"); |
131 |
|
|
132 |
1
|
Assert.assertNotNull(getAppState); |
133 |
1
|
Map<String, String> map2 = getMap(getAppState.getKeyValueList()); |
134 |
|
|
135 |
1
|
Assert.assertEquals(3, map2.size()); |
136 |
1
|
Assert.assertEquals("value-1", map2.get("key-1")); |
137 |
1
|
Assert.assertEquals("value-2", map2.get("key-2")); |
138 |
1
|
Assert.assertEquals("value-3", map2.get("key-3")); |
139 |
|
|
140 |
1
|
dao.delete(ApplicationState.class, newAppState.getId()); |
141 |
|
} |
142 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1
PASS
|
|
143 |
1
|
@Test... |
144 |
|
public void testGetApplicationState_NoApplicationState() throws Exception { |
145 |
1
|
try { |
146 |
1
|
dao.getApplicationState("1", "2", "course"); |
147 |
0
|
Assert.fail("Should have thrown an exception for no application state"); |
148 |
|
} catch(DoesNotExistException e) { |
149 |
1
|
Assert.assertNotNull(e); |
150 |
|
} |
151 |
|
} |
152 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1
PASS
|
|
153 |
1
|
@Test... |
154 |
|
public void testGetApplicationState_NoApplicationStateforUserId() throws Exception { |
155 |
1
|
try { |
156 |
1
|
dao.getApplicationState("1", "2", "course", "wil"); |
157 |
0
|
Assert.fail("Should have thrown an exception for no application state"); |
158 |
|
} catch(DoesNotExistException e) { |
159 |
1
|
Assert.assertNotNull(e); |
160 |
|
} |
161 |
|
} |
162 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1
PASS
|
|
163 |
1
|
@Test... |
164 |
|
public void testCreateApplicationState_NullParameters() throws Exception { |
165 |
1
|
try { |
166 |
1
|
ApplicationState appState = getApplicationState(null, null, null, null, null); |
167 |
1
|
dao.createApplicationState(appState); |
168 |
0
|
Assert.fail("Should have thrown a persistence exception for null parameters"); |
169 |
|
} catch(javax.persistence.PersistenceException e) { |
170 |
1
|
Assert.assertNotNull(e); |
171 |
|
} |
172 |
|
} |
173 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
174 |
1
|
@Test... |
175 |
|
public void testCreateApplicationState1_Error_DuplicateKey() throws Exception { |
176 |
1
|
List<KeyValuePair> list = new ArrayList<KeyValuePair>(); |
177 |
1
|
list.add(new KeyValuePair("key-1", "value-1")); |
178 |
1
|
ApplicationState appState = getApplicationState("1", "2", "course", null, list); |
179 |
|
|
180 |
1
|
ApplicationState newAppState1 = null; |
181 |
|
|
182 |
1
|
try { |
183 |
1
|
newAppState1 = dao.createApplicationState(appState); |
184 |
1
|
dao.createApplicationState(appState); |
185 |
0
|
dao.getApplicationState("1", "2", "course"); |
186 |
0
|
Assert.fail("Should have thrown a duplicate key persistence exception"); |
187 |
|
} catch(AlreadyExistsException e ) { |
188 |
1
|
Assert.assertTrue(true); |
189 |
1
|
Assert.assertTrue(e.getMessage() != null); |
190 |
|
} finally { |
191 |
1
|
dao.delete(ApplicationState.class, newAppState1.getId()); |
192 |
|
} |
193 |
|
} |
194 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
195 |
1
|
@Test... |
196 |
|
public void testCreateApplicationState1_Error_DuplicateKeyUserId() throws Exception { |
197 |
1
|
ApplicationState newAppState = null; |
198 |
1
|
List<KeyValuePair> list = getKeyValuePairList(1,3); |
199 |
1
|
ApplicationState appState = getApplicationState("1", "2", "course", "tom", list); |
200 |
|
|
201 |
1
|
try { |
202 |
1
|
newAppState = dao.createApplicationState(appState); |
203 |
1
|
dao.createApplicationState(appState); |
204 |
0
|
dao.getApplicationState("1", "2", "course"); |
205 |
0
|
Assert.fail("Should have thrown a duplicate key persistence exception"); |
206 |
|
} catch(AlreadyExistsException e ) { |
207 |
1
|
Assert.assertTrue(true); |
208 |
1
|
Assert.assertTrue(e.getMessage() != null); |
209 |
|
} finally { |
210 |
1
|
dao.delete(newAppState); |
211 |
|
} |
212 |
|
} |
213 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1
PASS
|
|
214 |
1
|
@Test... |
215 |
|
public void testCreateGetApplicationState3() throws Exception { |
216 |
1
|
List<KeyValuePair> list1 = getKeyValuePairList(1,2); |
217 |
1
|
ApplicationState appState1 = getApplicationState("1", "2", "course1", null, list1); |
218 |
1
|
ApplicationState newAppState1 = dao.createApplicationState(appState1); |
219 |
|
|
220 |
1
|
List<KeyValuePair> list2 = getKeyValuePairList(3,2); |
221 |
1
|
ApplicationState appState2 = getApplicationState("11", "22", "course2", null, list2); |
222 |
1
|
ApplicationState newAppState2 = dao.createApplicationState(appState2); |
223 |
|
|
224 |
1
|
ApplicationState getAppState1 = dao.getApplicationState("1", "2", "course1"); |
225 |
1
|
Assert.assertNotNull(getAppState1); |
226 |
1
|
Map<String, String> returnedMap1 = getMap(getAppState1.getKeyValueList()); |
227 |
1
|
Assert.assertEquals(2, returnedMap1.size()); |
228 |
1
|
Assert.assertEquals("value-1", returnedMap1.get("key-1")); |
229 |
1
|
Assert.assertEquals("value-2", returnedMap1.get("key-2")); |
230 |
|
|
231 |
1
|
ApplicationState getAppState2 = dao.getApplicationState("11", "22", "course2"); |
232 |
1
|
Assert.assertNotNull(getAppState2); |
233 |
1
|
Map<String, String> returnedMap2 = getMap(getAppState2.getKeyValueList()); |
234 |
1
|
Assert.assertEquals(2, returnedMap2.size()); |
235 |
1
|
Assert.assertEquals("value-3", returnedMap2.get("key-3")); |
236 |
1
|
Assert.assertEquals("value-4", returnedMap2.get("key-4")); |
237 |
|
|
238 |
1
|
dao.delete(newAppState1); |
239 |
1
|
dao.delete(newAppState2); |
240 |
|
} |
241 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
242 |
1
|
@Test... |
243 |
|
public void testGetApplicationStateByAppIdRefIdRefTypeUserId() throws Exception { |
244 |
1
|
List<KeyValuePair> list1 = getKeyValuePairList(1,2); |
245 |
1
|
ApplicationState appState1 = getApplicationState("1", "2", "course1", "tom", list1); |
246 |
1
|
ApplicationState newAppState1 = dao.createApplicationState(appState1); |
247 |
|
|
248 |
1
|
List<KeyValuePair> list2 = getKeyValuePairList(3,2); |
249 |
1
|
ApplicationState appState2 = getApplicationState("11", "22", "course2", "jim", list2); |
250 |
1
|
ApplicationState newAppState2 = dao.createApplicationState(appState2); |
251 |
|
|
252 |
1
|
ApplicationState as1 = dao.getApplicationState("1", "2", "course1", "tom"); |
253 |
1
|
Map<String, String> returnedMap1 = getMap(as1.getKeyValueList()); |
254 |
1
|
Assert.assertEquals(2, returnedMap1.size()); |
255 |
1
|
Assert.assertEquals("value-1", returnedMap1.get("key-1")); |
256 |
1
|
Assert.assertEquals("value-2", returnedMap1.get("key-2")); |
257 |
|
|
258 |
1
|
ApplicationState as2 = dao.getApplicationState("11", "22", "course2", "jim"); |
259 |
1
|
Map<String, String> returnedMap2 = getMap(as2.getKeyValueList()); |
260 |
1
|
Assert.assertEquals(2, returnedMap2.size()); |
261 |
1
|
Assert.assertEquals("value-3", returnedMap2.get("key-3")); |
262 |
1
|
Assert.assertEquals("value-4", returnedMap2.get("key-4")); |
263 |
|
|
264 |
1
|
dao.delete(newAppState1); |
265 |
1
|
dao.delete(newAppState2); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
} |