1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.lum.lrc.service.impl;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.junit.Test;
29 import org.kuali.student.common.test.spring.AbstractServiceTest;
30 import org.kuali.student.common.test.spring.Client;
31 import org.kuali.student.common.test.spring.Dao;
32 import org.kuali.student.common.test.spring.Daos;
33 import org.kuali.student.common.test.spring.PersistenceFileLocation;
34 import org.kuali.student.core.dto.MetaInfo;
35 import org.kuali.student.core.dto.RichTextInfo;
36 import org.kuali.student.core.dto.StatusInfo;
37 import org.kuali.student.core.exceptions.AlreadyExistsException;
38 import org.kuali.student.core.exceptions.DataValidationErrorException;
39 import org.kuali.student.core.exceptions.DoesNotExistException;
40 import org.kuali.student.core.exceptions.InvalidParameterException;
41 import org.kuali.student.core.exceptions.MissingParameterException;
42 import org.kuali.student.core.exceptions.OperationFailedException;
43 import org.kuali.student.core.exceptions.PermissionDeniedException;
44 import org.kuali.student.core.exceptions.VersionMismatchException;
45 import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
46 import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo;
47 import org.kuali.student.lum.lrc.service.LrcService;
48
49 import edu.emory.mathcs.backport.java.util.Arrays;
50
51 @Daos( { @Dao(value = "org.kuali.student.lum.lrc.dao.impl.LrcDaoImpl",testSqlFile="classpath:ks-lrc.sql"
52 @PersistenceFileLocation("classpath:META-INF/lrc-persistence.xml")
53 public class TestLrcServiceImpl extends AbstractServiceTest {
54 @Client(value = "org.kuali.student.lum.lrc.service.impl.LrcServiceImpl", additionalContextFile="classpath:lrc-additional-context.xml")
55 public LrcService client;
56
57 @Test
58 public void testResultComponentCrud() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
59 ResultComponentInfo rci = new ResultComponentInfo();
60 rci.setName("New Result Component");
61 RichTextInfo richText = new RichTextInfo();
62 richText.setFormatted("<p>New ResultComponent</p>");
63 richText.setPlain("New ResultComponent");
64 rci.setDesc(richText);
65 List<String> resultValueIds = new ArrayList<String>();
66 resultValueIds.add("LRC-RESULT_VALUE-GRADE-1");
67 rci.setResultValues(resultValueIds);
68 Date date = new Date();
69 rci.setEffectiveDate(date);
70 rci.setExpirationDate(date);
71 Map<String, String> attributes = new HashMap<String, String>();
72 attributes.put("attrKey", "attrValue");
73 rci.setAttributes(attributes);
74 MetaInfo metaInfo = new MetaInfo();
75 metaInfo.setCreateId("1");
76 metaInfo.setCreateTime(date);
77 metaInfo.setUpdateId("2");
78 metaInfo.setUpdateTime(date);
79 rci.setMetaInfo(metaInfo);
80 rci.setType("resultComponentType.grade");
81 rci.setState("Active");
82 try {
83 ResultComponentInfo newRci = client.createResultComponent("resultComponentType.grade", rci);
84 assertNotNull(newRci);
85 String id = newRci.getId();
86 assertNotNull(id);
87
88 RichTextInfo rti = newRci.getDesc();
89 assertNotNull(rti);
90 assertEquals("<p>New ResultComponent</p>", rti.getFormatted());
91 assertEquals("New ResultComponent", rti.getPlain());
92 List<String> ids = newRci.getResultValues();
93 java.util.Collections.sort(ids);
94 assertNotNull(ids);
95 assertEquals(1, ids.size());
96 assertEquals("LRC-RESULT_VALUE-GRADE-1", ids.get(0));
97 assertEquals(date.toString(), newRci.getEffectiveDate().toString());
98 assertEquals(date.toString(), newRci.getExpirationDate().toString());
99 Map<String, String> newAttributes = newRci.getAttributes();
100 assertNotNull(newAttributes);
101 assertEquals("attrValue", newAttributes.get("attrKey"));
102 assertEquals("resultComponentType.grade", newRci.getType());
103 assertEquals("Active", newRci.getState());
104
105 rci = client.getResultComponent(id);
106 rci.getResultValues().add("LRC-RESULT_VALUE-GRADE-2");
107 try {
108
109 client.updateResultComponent(id, rci);
110 newRci = client.getResultComponent(newRci.getId());
111 assertNotNull(newRci);
112 assertNotNull(newRci.getId());
113 rti = newRci.getDesc();
114 assertNotNull(rti);
115 assertEquals("<p>New ResultComponent</p>", rti.getFormatted());
116 assertEquals("New ResultComponent", rti.getPlain());
117 ids = newRci.getResultValues();
118 java.util.Collections.sort(ids);
119 assertNotNull(ids);
120 assertEquals(2, ids.size());
121 assertEquals("LRC-RESULT_VALUE-GRADE-1", ids.get(0));
122 assertEquals("LRC-RESULT_VALUE-GRADE-2", ids.get(1));
123 assertEquals(date.toString(), newRci.getEffectiveDate().toString());
124 assertEquals(date.toString(), newRci.getExpirationDate().toString());
125 newAttributes = newRci.getAttributes();
126 assertNotNull(newAttributes);
127 assertEquals("attrValue", newAttributes.get("attrKey"));
128 assertEquals("resultComponentType.grade", newRci.getType());
129 assertEquals("Active", newRci.getState());
130 } catch (VersionMismatchException e) {
131 assertTrue(false);
132 }
133
134
135 try{
136 client.updateResultComponent(id, rci);
137 assertTrue(false);
138 }catch(VersionMismatchException e){
139 assertTrue(true);
140 }
141
142 rci = client.getResultComponent(id);
143 rci.getResultValues().add("LRC-RESULT_VALUE-CREDIT-1");
144 try {
145 client.updateResultComponent(id, rci);
146
147 } catch (DataValidationErrorException e) {
148 assertTrue(false);
149 } catch (VersionMismatchException e) {
150 assertTrue(false);
151 }
152
153
154
155
156 StatusInfo statusInfo = client.deleteResultComponent(id);
157 assertTrue(statusInfo.getSuccess());
158
159 } catch (AlreadyExistsException e) {
160 assertTrue(false);
161 } catch (DataValidationErrorException e) {
162 assertTrue(false);
163 } catch (PermissionDeniedException e) {
164 assertTrue(false);
165 }
166
167 ResultComponentInfo resultComponentInfo = new ResultComponentInfo();
168 try {
169 client.createResultComponent(null, resultComponentInfo);
170 assertTrue(false);
171 } catch (MissingParameterException e) {
172 assertTrue(true);
173 } catch (AlreadyExistsException e) {
174 assertTrue(false);
175 } catch (DataValidationErrorException e) {
176 assertTrue(false);
177 } catch (PermissionDeniedException e) {
178 assertTrue(false);
179 }
180
181 try {
182 client.createResultComponent("a", null);
183 assertTrue(false);
184 } catch (MissingParameterException e) {
185 assertTrue(true);
186 } catch (AlreadyExistsException e) {
187 assertTrue(false);
188 } catch (DataValidationErrorException e) {
189 assertTrue(false);
190 } catch (PermissionDeniedException e) {
191 assertTrue(false);
192 }
193
194 try {
195 client.updateResultComponent(null, resultComponentInfo);
196 assertTrue(false);
197 } catch (MissingParameterException e) {
198 assertTrue(true);
199 } catch (VersionMismatchException e) {
200 assertTrue(false);
201 } catch (DataValidationErrorException e) {
202 assertTrue(false);
203 } catch (PermissionDeniedException e) {
204 assertTrue(false);
205 }
206
207 try {
208 client.updateResultComponent("a", null);
209 assertTrue(false);
210 } catch (MissingParameterException e) {
211 assertTrue(true);
212 } catch (VersionMismatchException e) {
213 assertTrue(false);
214 } catch (DataValidationErrorException e) {
215 assertTrue(false);
216 } catch (PermissionDeniedException e) {
217 assertTrue(false);
218 }
219
220 try {
221 client.deleteResultComponent("xx1");
222 assertTrue(false);
223 } catch (DoesNotExistException e) {
224 assertTrue(true);
225 } catch (PermissionDeniedException e) {
226 assertTrue(false);
227 }
228 try {
229 client.deleteResultComponent(null);
230 assertTrue(false);
231 } catch (MissingParameterException e) {
232 assertTrue(true);
233 } catch (PermissionDeniedException e) {
234 assertTrue(false);
235 }
236 }
237
238 @Test
239 public void testGetResultComponent() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
240 ResultComponentInfo rci = client.getResultComponent("LRC-RESCOMP-1");
241 assertNotNull(rci);
242 assertEquals(4, rci.getResultValues().size());
243
244 try {
245 rci = client.getResultComponent("LRC-RESCOMP-1x");
246 assertTrue(false);
247 } catch (DoesNotExistException e) {
248 assertTrue(true);
249 }
250
251 try {
252 rci = client.getResultComponent(null);
253 assertTrue(false);
254 } catch (MissingParameterException e) {
255 assertTrue(true);
256 }
257 }
258
259 @Test
260 public void testGetResultComponentIdsByResult() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
261 List<String> rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1", "resultComponentType.credential");
262 assertNotNull(rcis);
263 assertEquals(1, rcis.size());
264
265 rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1x", "resultComponentType.credential");
266 assertEquals(0,rcis.size());
267
268 rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1", "resultComponentType.credentialx");
269 assertEquals(0,rcis.size());
270
271 try {
272 rcis = client.getResultComponentIdsByResult(null, "resultComponentType.credentialx");
273 assertTrue(false);
274 } catch (MissingParameterException e) {
275 assertTrue(true);
276 }
277 try {
278 rcis = client.getResultComponentIdsByResult("a", null);
279 assertTrue(false);
280 } catch (MissingParameterException e) {
281 assertTrue(true);
282 }
283 }
284
285 @Test
286 public void testGetResultComponentIdsByResultComponentType() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
287 List<String> rcis = client.getResultComponentIdsByResultComponentType("resultComponentType.credential");
288 assertNotNull(rcis);
289 assertEquals(1, rcis.size());
290
291 rcis = client.getResultComponentIdsByResultComponentType("resultComponentType.credentialx");
292 assertEquals(0,rcis.size());
293
294 try {
295 rcis = client.getResultComponentIdsByResultComponentType(null);
296 assertTrue(false);
297 } catch (MissingParameterException e) {
298 assertTrue(true);
299 }
300
301 }
302
303 @Test
304 public void getResultComponentTypes() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
305 List<ResultComponentTypeInfo> rctis = client.getResultComponentTypes();
306 assertNotNull(rctis);
307 assertEquals(7, rctis.size());
308 }
309
310 @Test
311 public void testGetResultComponentType() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
312 ResultComponentTypeInfo rcti = client.getResultComponentType("resultComponentType.credential");
313 assertNotNull(rcti);
314
315 try {
316 rcti = client.getResultComponentType("resultComponentType.credentialYYY");
317 assertTrue(false);
318 } catch (DoesNotExistException e) {
319 assertTrue(true);
320 }
321 }
322
323
324 public void testBusinessCaseExample() throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
325 ResultComponentInfo rc = new ResultComponentInfo();
326 RichTextInfo richText = new RichTextInfo();
327 richText.setFormatted("<p>ResultComponent</p>");
328 richText.setPlain("ResultComponent");
329 rc.setDesc(richText);
330
331 String specificGradeId = "LRC-RESULT_VALUE-GRADE-1";
332
333 rc.setName("ResultComponent");
334 rc.setResultValues(Arrays.asList(new String[] {specificGradeId}));
335 rc.setState("ACTIVE");
336 rc.setType("resultComponentType.grade");
337
338 client.createResultComponent("resultComponentType.grade", rc);
339
340
341 }
342 }