Clover Coverage Report - KS LUM Impl 1.1.0-M10
Coverage timestamp: Fri Dec 17 2010 21:51:54 EST
178   342   40   25.43
0   283   0.22   7
7     5.71  
1    
 
  TestLrcServiceImpl       Line # 53 178 0% 40 45 75.7% 0.7567568
 
  (6)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
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" /*, testDataFile = "classpath:test-beans.xml"*/) })
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  1 toggle @Test
58    public void testResultComponentCrud() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
59  1 ResultComponentInfo rci = new ResultComponentInfo();
60  1 rci.setName("New Result Component");
61  1 RichTextInfo richText = new RichTextInfo();
62  1 richText.setFormatted("<p>New ResultComponent</p>");
63  1 richText.setPlain("New ResultComponent");
64  1 rci.setDesc(richText);
65  1 List<String> resultValueIds = new ArrayList<String>();
66  1 resultValueIds.add("LRC-RESULT_VALUE-GRADE-1");
67  1 rci.setResultValues(resultValueIds);
68  1 Date date = new Date();
69  1 rci.setEffectiveDate(date);
70  1 rci.setExpirationDate(date);
71  1 Map<String, String> attributes = new HashMap<String, String>();
72  1 attributes.put("attrKey", "attrValue");
73  1 rci.setAttributes(attributes);
74  1 MetaInfo metaInfo = new MetaInfo();
75  1 metaInfo.setCreateId("1");
76  1 metaInfo.setCreateTime(date);
77  1 metaInfo.setUpdateId("2");
78  1 metaInfo.setUpdateTime(date);
79  1 rci.setMetaInfo(metaInfo);
80  1 rci.setType("resultComponentType.grade");
81  1 rci.setState("Active");
82  1 try {
83  1 ResultComponentInfo newRci = client.createResultComponent("resultComponentType.grade", rci);
84  1 assertNotNull(newRci);
85  1 String id = newRci.getId();
86  1 assertNotNull(id);
87   
88  1 RichTextInfo rti = newRci.getDesc();
89  1 assertNotNull(rti);
90  1 assertEquals("<p>New ResultComponent</p>", rti.getFormatted());
91  1 assertEquals("New ResultComponent", rti.getPlain());
92  1 List<String> ids = newRci.getResultValues();
93  1 java.util.Collections.sort(ids);
94  1 assertNotNull(ids);
95  1 assertEquals(1, ids.size());
96  1 assertEquals("LRC-RESULT_VALUE-GRADE-1", ids.get(0));
97  1 assertEquals(date.toString(), newRci.getEffectiveDate().toString());
98  1 assertEquals(date.toString(), newRci.getExpirationDate().toString());
99  1 Map<String, String> newAttributes = newRci.getAttributes();
100  1 assertNotNull(newAttributes);
101  1 assertEquals("attrValue", newAttributes.get("attrKey"));
102  1 assertEquals("resultComponentType.grade", newRci.getType());
103  1 assertEquals("Active", newRci.getState());
104   
105  1 rci = client.getResultComponent(id);
106  1 rci.getResultValues().add("LRC-RESULT_VALUE-GRADE-2");
107  1 try {
108   
109  1 client.updateResultComponent(id, rci);
110  1 newRci = client.getResultComponent(newRci.getId());
111  1 assertNotNull(newRci);
112  1 assertNotNull(newRci.getId());
113  1 rti = newRci.getDesc();
114  1 assertNotNull(rti);
115  1 assertEquals("<p>New ResultComponent</p>", rti.getFormatted());
116  1 assertEquals("New ResultComponent", rti.getPlain());
117  1 ids = newRci.getResultValues();
118  1 java.util.Collections.sort(ids);
119  1 assertNotNull(ids);
120  1 assertEquals(2, ids.size());
121  1 assertEquals("LRC-RESULT_VALUE-GRADE-1", ids.get(0));
122  1 assertEquals("LRC-RESULT_VALUE-GRADE-2", ids.get(1));
123  1 assertEquals(date.toString(), newRci.getEffectiveDate().toString());
124  1 assertEquals(date.toString(), newRci.getExpirationDate().toString());
125  1 newAttributes = newRci.getAttributes();
126  1 assertNotNull(newAttributes);
127  1 assertEquals("attrValue", newAttributes.get("attrKey"));
128  1 assertEquals("resultComponentType.grade", newRci.getType());
129  1 assertEquals("Active", newRci.getState());
130    } catch (VersionMismatchException e) {
131  0 assertTrue(false);
132    }
133   
134    //Updateing an out of date version should throw an exception
135  1 try{
136  1 client.updateResultComponent(id, rci);
137  0 assertTrue(false);
138    }catch(VersionMismatchException e){
139  1 assertTrue(true);
140    }
141   
142  1 rci = client.getResultComponent(id);
143  1 rci.getResultValues().add("LRC-RESULT_VALUE-CREDIT-1");
144  1 try {
145  1 client.updateResultComponent(id, rci);
146    //assertTrue(false);
147    } catch (DataValidationErrorException e) {
148  0 assertTrue(false);
149    } catch (VersionMismatchException e) {
150  0 assertTrue(false);
151    }
152   
153   
154   
155   
156  1 StatusInfo statusInfo = client.deleteResultComponent(id);
157  1 assertTrue(statusInfo.getSuccess());
158   
159    } catch (AlreadyExistsException e) {
160  0 assertTrue(false);
161    } catch (DataValidationErrorException e) {
162  0 assertTrue(false);
163    } catch (PermissionDeniedException e) {
164  0 assertTrue(false);
165    }
166   
167  1 ResultComponentInfo resultComponentInfo = new ResultComponentInfo();
168  1 try {
169  1 client.createResultComponent(null, resultComponentInfo);
170  0 assertTrue(false);
171    } catch (MissingParameterException e) {
172  1 assertTrue(true);
173    } catch (AlreadyExistsException e) {
174  0 assertTrue(false);
175    } catch (DataValidationErrorException e) {
176  0 assertTrue(false);
177    } catch (PermissionDeniedException e) {
178  0 assertTrue(false);
179    }
180   
181  1 try {
182  1 client.createResultComponent("a", null);
183  0 assertTrue(false);
184    } catch (MissingParameterException e) {
185  1 assertTrue(true);
186    } catch (AlreadyExistsException e) {
187  0 assertTrue(false);
188    } catch (DataValidationErrorException e) {
189  0 assertTrue(false);
190    } catch (PermissionDeniedException e) {
191  0 assertTrue(false);
192    }
193   
194  1 try {
195  1 client.updateResultComponent(null, resultComponentInfo);
196  0 assertTrue(false);
197    } catch (MissingParameterException e) {
198  1 assertTrue(true);
199    } catch (VersionMismatchException e) {
200  0 assertTrue(false);
201    } catch (DataValidationErrorException e) {
202  0 assertTrue(false);
203    } catch (PermissionDeniedException e) {
204  0 assertTrue(false);
205    }
206   
207  1 try {
208  1 client.updateResultComponent("a", null);
209  0 assertTrue(false);
210    } catch (MissingParameterException e) {
211  1 assertTrue(true);
212    } catch (VersionMismatchException e) {
213  0 assertTrue(false);
214    } catch (DataValidationErrorException e) {
215  0 assertTrue(false);
216    } catch (PermissionDeniedException e) {
217  0 assertTrue(false);
218    }
219   
220  1 try {
221  1 client.deleteResultComponent("xx1");
222  0 assertTrue(false);
223    } catch (DoesNotExistException e) {
224  1 assertTrue(true);
225    } catch (PermissionDeniedException e) {
226  0 assertTrue(false);
227    }
228  1 try {
229  1 client.deleteResultComponent(null);
230  0 assertTrue(false);
231    } catch (MissingParameterException e) {
232  1 assertTrue(true);
233    } catch (PermissionDeniedException e) {
234  0 assertTrue(false);
235    }
236    }
237   
 
238  1 toggle @Test
239    public void testGetResultComponent() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
240  1 ResultComponentInfo rci = client.getResultComponent("LRC-RESCOMP-1");
241  1 assertNotNull(rci);
242  1 assertEquals(4, rci.getResultValues().size());
243   
244  1 try {
245  1 rci = client.getResultComponent("LRC-RESCOMP-1x");
246  0 assertTrue(false);
247    } catch (DoesNotExistException e) {
248  1 assertTrue(true);
249    }
250   
251  1 try {
252  1 rci = client.getResultComponent(null);
253  0 assertTrue(false);
254    } catch (MissingParameterException e) {
255  1 assertTrue(true);
256    }
257    }
258   
 
259  1 toggle @Test
260    public void testGetResultComponentIdsByResult() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
261  1 List<String> rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1", "resultComponentType.credential");
262  1 assertNotNull(rcis);
263  1 assertEquals(1, rcis.size());
264   
265  1 rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1x", "resultComponentType.credential");
266  1 assertEquals(0,rcis.size());
267   
268  1 rcis = client.getResultComponentIdsByResult("LRC-RESULT_VALUE-CREDIT-1", "resultComponentType.credentialx");
269  1 assertEquals(0,rcis.size());
270   
271  1 try {
272  1 rcis = client.getResultComponentIdsByResult(null, "resultComponentType.credentialx");
273  0 assertTrue(false);
274    } catch (MissingParameterException e) {
275  1 assertTrue(true);
276    }
277  1 try {
278  1 rcis = client.getResultComponentIdsByResult("a", null);
279  0 assertTrue(false);
280    } catch (MissingParameterException e) {
281  1 assertTrue(true);
282    }
283    }
284   
 
285  1 toggle @Test
286    public void testGetResultComponentIdsByResultComponentType() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
287  1 List<String> rcis = client.getResultComponentIdsByResultComponentType("resultComponentType.credential");
288  1 assertNotNull(rcis);
289  1 assertEquals(1, rcis.size());
290   
291  1 rcis = client.getResultComponentIdsByResultComponentType("resultComponentType.credentialx");
292  1 assertEquals(0,rcis.size());
293   
294  1 try {
295  1 rcis = client.getResultComponentIdsByResultComponentType(null);
296  0 assertTrue(false);
297    } catch (MissingParameterException e) {
298  1 assertTrue(true);
299    }
300   
301    }
302   
 
303  1 toggle @Test
304    public void getResultComponentTypes() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
305  1 List<ResultComponentTypeInfo> rctis = client.getResultComponentTypes();
306  1 assertNotNull(rctis);
307  1 assertEquals(7, rctis.size());
308    }
309   
 
310  1 toggle @Test
311    public void testGetResultComponentType() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
312  1 ResultComponentTypeInfo rcti = client.getResultComponentType("resultComponentType.credential");
313  1 assertNotNull(rcti);
314   
315  1 try {
316  1 rcti = client.getResultComponentType("resultComponentType.credentialYYY");
317  0 assertTrue(false);
318    } catch (DoesNotExistException e) {
319  1 assertTrue(true);
320    }
321    }
322   
323   
 
324  0 toggle public void testBusinessCaseExample() throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
325  0 ResultComponentInfo rc = new ResultComponentInfo();
326  0 RichTextInfo richText = new RichTextInfo();
327  0 richText.setFormatted("<p>ResultComponent</p>");
328  0 richText.setPlain("ResultComponent");
329  0 rc.setDesc(richText);
330   
331  0 String specificGradeId = "LRC-RESULT_VALUE-GRADE-1";
332   
333  0 rc.setName("ResultComponent");
334  0 rc.setResultValues(Arrays.asList(new String[] {specificGradeId}));
335  0 rc.setState("ACTIVE");
336  0 rc.setType("resultComponentType.grade");
337   
338  0 client.createResultComponent("resultComponentType.grade", rc);
339   
340   
341    }
342    }