Clover Coverage Report - Kuali Student 1.2-M6-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Sep 12 2011 05:03:53 EDT
707   1,327   87   18.13
26   1,000   0.12   19.5
39     2.23  
2    
 
  TestCourseServiceImpl       Line # 76 707 0% 87 129 83.3% 0.83290154
  TestCourseServiceImpl.ServiceMethodInvocationData       Line # 1107 0 - 0 0 - -1.0
 
  (29)
 
1    package org.kuali.student.lum.course.service.impl;
2   
3    import static org.apache.commons.collections.CollectionUtils.isEmpty;
4    import static org.junit.Assert.assertEquals;
5    import static org.junit.Assert.assertFalse;
6    import static org.junit.Assert.assertNull;
7    import static org.junit.Assert.assertNotNull;
8    import static org.junit.Assert.assertTrue;
9    import static org.junit.Assert.fail;
10   
11    import java.beans.IntrospectionException;
12    import java.lang.reflect.InvocationTargetException;
13    import java.lang.reflect.Method;
14    import java.util.ArrayList;
15    import java.util.Arrays;
16    import java.util.Calendar;
17    import java.util.Collection;
18    import java.util.Date;
19    import java.util.HashMap;
20    import java.util.List;
21    import java.util.Map;
22    import java.util.Set;
23    import java.util.TreeSet;
24   
25    import org.junit.Ignore;
26    import org.junit.Test;
27    import org.junit.runner.RunWith;
28    import org.kuali.student.common.assembly.data.Metadata;
29    import org.kuali.student.common.assembly.dictionary.MetadataServiceImpl;
30    import org.kuali.student.common.dto.CurrencyAmountInfo;
31    import org.kuali.student.common.dto.DtoConstants;
32    import org.kuali.student.common.dto.RichTextInfo;
33    import org.kuali.student.common.dto.StatusInfo;
34    import org.kuali.student.common.dto.TimeAmountInfo;
35    import org.kuali.student.common.exceptions.AlreadyExistsException;
36    import org.kuali.student.common.exceptions.CircularReferenceException;
37    import org.kuali.student.common.exceptions.CircularRelationshipException;
38    import org.kuali.student.common.exceptions.DataValidationErrorException;
39    import org.kuali.student.common.exceptions.DependentObjectsExistException;
40    import org.kuali.student.common.exceptions.DoesNotExistException;
41    import org.kuali.student.common.exceptions.IllegalVersionSequencingException;
42    import org.kuali.student.common.exceptions.InvalidParameterException;
43    import org.kuali.student.common.exceptions.MissingParameterException;
44    import org.kuali.student.common.exceptions.OperationFailedException;
45    import org.kuali.student.common.exceptions.PermissionDeniedException;
46    import org.kuali.student.common.exceptions.UnsupportedActionException;
47    import org.kuali.student.common.exceptions.VersionMismatchException;
48    import org.kuali.student.common.validation.dto.ValidationResultInfo;
49    import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo;
50    import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
51    import org.kuali.student.core.statement.dto.ReqComponentInfo;
52    import org.kuali.student.core.statement.dto.StatementOperatorTypeKey;
53    import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
54    import org.kuali.student.core.statement.service.StatementService;
55    import org.kuali.student.lum.course.dto.ActivityInfo;
56    import org.kuali.student.lum.course.dto.CourseCrossListingInfo;
57    import org.kuali.student.lum.course.dto.CourseFeeInfo;
58    import org.kuali.student.lum.course.dto.CourseInfo;
59    import org.kuali.student.lum.course.dto.FormatInfo;
60    import org.kuali.student.lum.course.dto.LoDisplayInfo;
61    import org.kuali.student.lum.course.service.CourseService;
62    import org.kuali.student.lum.course.service.CourseServiceConstants;
63    import org.kuali.student.lum.course.service.assembler.CourseAssemblerConstants;
64    import org.kuali.student.lum.lo.dto.LoCategoryInfo;
65    import org.kuali.student.lum.lo.dto.LoInfo;
66    import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
67    import org.kuali.student.lum.lu.dto.AdminOrgInfo;
68    import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo;
69    import org.kuali.student.lum.lu.dto.CluInstructorInfo;
70    import org.springframework.beans.factory.annotation.Autowired;
71    import org.springframework.test.context.ContextConfiguration;
72    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
73   
74    @RunWith(SpringJUnit4ClassRunner.class)
75    @ContextConfiguration(locations = {"classpath:course-test-context.xml"})
 
76    public class TestCourseServiceImpl {
77    @Autowired
78    CourseService courseService;
79    @Autowired
80    StatementService statementService;
81   
82    Set<String> subjectAreaSet = new TreeSet<String>(Arrays.asList(CourseDataGenerator.subjectAreas));
83   
 
84  1 toggle @Test
85    public void testCreateCourse() throws Exception {
86  1 System.out.println("testCreateCourse");
87  1 CourseDataGenerator generator = new CourseDataGenerator();
88  1 CourseInfo cInfo = null;
89  1 try {
90  1 assertNotNull(cInfo = generator.getCourseTestData());
91  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
92  1 assertNotNull(createdCourse);
93  1 assertEquals(DtoConstants.STATE_DRAFT, createdCourse.getState());
94  1 assertEquals("kuali.lu.type.CreditCourse", createdCourse.getType());
95  1 assertEquals(cInfo.getStartTerm(), createdCourse.getStartTerm());
96  1 assertEquals(cInfo.getEndTerm(), createdCourse.getEndTerm());
97    } catch (DataValidationErrorException e) {
98  0 dumpValidationErrors(cInfo);
99  0 fail("DataValidationError: " + e.getMessage());
100    } catch (Exception e) {
101  0 e.printStackTrace();
102  0 fail(e.getMessage());
103    }
104    }
105   
 
106  0 toggle private void dumpValidationErrors(CourseInfo cInfo) throws Exception {
107  0 List<ValidationResultInfo> validationResults = courseService.validateCourse("SYSTEM", cInfo);
108  0 for (ValidationResultInfo vr : validationResults) {
109  0 System.out.println(vr.getElement() + " " + vr.getMessage());
110    }
111    }
112   
 
113  1 toggle @Test
114    public void testGetCourse() {
115  1 System.out.println("testGetCourse");
116  1 try {
117  1 CourseDataGenerator generator = new CourseDataGenerator();
118  1 CourseInfo cInfo = generator.getCourseTestData();
119  1 assertNotNull(cInfo);
120  1 cInfo.setSpecialTopicsCourse(true);
121  1 cInfo.setPilotCourse(true);
122  1 cInfo.setCode("");
123  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
124  1 assertNotNull(createdCourse);
125   
126    // get it fresh from database
127  1 CourseInfo retrievedCourse = courseService.getCourse(createdCourse.getId());
128  1 assertNotNull(retrievedCourse);
129   
130    // confirm it has the right contents
131  1 assertEquals("323", retrievedCourse.getCourseNumberSuffix());
132   
133  1 assertEquals("level-36", retrievedCourse.getLevel());
134   
135  1 assertEquals("courseTitle-12", retrievedCourse.getCourseTitle());
136  1 assertEquals("transcriptTitle-50", retrievedCourse.getTranscriptTitle());
137   
138  1 assertEquals("plain-18", retrievedCourse.getDescr().getPlain());
139  1 assertEquals("formatted-17", retrievedCourse.getDescr().getFormatted());
140   
141  1 assertEquals(2, retrievedCourse.getFormats().size());
142  1 FormatInfo info = retrievedCourse.getFormats().get(0);
143  1 assertEquals("kuali.lu.type.CreditCourseFormatShell", info.getType());
144  1 assertEquals(2, info.getActivities().size());
145  1 assertTrue(info.getActivities().get(1).getActivityType().startsWith("kuali.lu.type.activity."));
146   
147  1 assertEquals(2, retrievedCourse.getTermsOffered().size());
148  1 String termOffered = retrievedCourse.getTermsOffered().get(0);
149   
150  1 assertTrue("termsOffered-48".equals(termOffered) || "termsOffered-49".equals(termOffered));
151   
152  1 assertEquals(2, retrievedCourse.getUnitsContentOwner().size());
153  1 String orgId = retrievedCourse.getUnitsContentOwner().get(0);
154  1 assertTrue("unitsContentOwner-53".equals(orgId) || "unitsContentOwner-54".equals(orgId));
155   
156  1 assertEquals(4, retrievedCourse.getAttributes().size());
157  1 String[] attrKeys = {"attributes-3", "attributes-4"};
158  1 for (String key : attrKeys) {
159  2 String value = retrievedCourse.getAttributes().get(key);
160  2 assertNotNull(value);
161  2 assertEquals(key, value);
162    }
163   
164  1 assertEquals(2, retrievedCourse.getCampusLocations().size());
165  1 String campus = retrievedCourse.getCampusLocations().get(1);
166  1 assertTrue(CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_SOUTH.equals(campus) || CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_NORTH.equals(campus));
167   
168    /*
169    * Test LO assertEquals(2, retrievedCourse.getCourseSpecificLOs().size()); LoDisplayInfo info =
170    * retrievedCourse.getCourseSpecificLOs().get(0); // TODO - check its contents
171    */
172   
173    /*
174    * assertEquals(2, retrievedCourse.getCrossListings().size()); CourseCrossListingInfo info =
175    * retrievedCourse.getCrossListings().get(0); // TODO - check its contents
176    */
177   
178  1 assertEquals("unitsDeployment-57", retrievedCourse.getUnitsDeployment().get(0));
179   
180  1 TimeAmountInfo timeInfo = retrievedCourse.getDuration();
181  1 assertEquals("kuali.atp.duration.Semester", timeInfo.getAtpDurationTypeKey());
182  1 assertEquals(19, timeInfo.getTimeQuantity().intValue());
183   
184    // TODO - check effective/expiration dates
185   
186    // TODO - check feeInfo
187   
188    // TODO - check joints
189    // TODO - check metaInfo
190   
191  1 assertEquals(2, retrievedCourse.getTermsOffered().size());
192   
193  1 String atpType = retrievedCourse.getTermsOffered().get(0);
194  1 CluInstructorInfo instructor = retrievedCourse.getPrimaryInstructor();
195   
196  1 assertTrue("termsOffered-48".equals(atpType) || "termsOffered-49".equals(atpType));
197   
198  1 assertEquals("orgId-43", instructor.getOrgId());
199  1 assertEquals("personId-44", instructor.getPersonId());
200   
201  1 assertEquals(DtoConstants.STATE_DRAFT, retrievedCourse.getState());
202  1 assertTrue(subjectAreaSet.contains(retrievedCourse.getSubjectArea()));
203   
204  1 assertEquals("kuali.lu.type.CreditCourse", retrievedCourse.getType());
205   
206  1 assertEquals(2, retrievedCourse.getCreditOptions().size());
207  1 assertEquals("kuali.creditType.credit.degree.11.0", retrievedCourse.getCreditOptions().get(0).getId());
208  1 assertEquals("kuali.creditType.credit.degree.11.0", retrievedCourse.getCreditOptions().get(1).getId());
209   
210  1 assertEquals(2, retrievedCourse.getGradingOptions().size());
211   
212  1 assertTrue(retrievedCourse.getGradingOptions().contains("gradingOptions-31"));
213  1 assertTrue(retrievedCourse.getGradingOptions().contains("gradingOptions-32"));
214  1 assertEquals(createdCourse.isPilotCourse(), cInfo.isPilotCourse());
215  1 assertEquals(createdCourse.isSpecialTopicsCourse(), cInfo.isSpecialTopicsCourse());
216   
217    // TODO - check variotions
218    } catch (Exception e) {
219  0 e.printStackTrace();
220  0 fail(e.getMessage());
221    }
222    }
223   
 
224  1 toggle @Test
225    public void testUpdateCourse() throws Exception {
226  1 System.out.println("testUpdateCourse");
227   
228  1 CourseDataGenerator generator = new CourseDataGenerator();
229  1 CourseInfo cInfo = null;
230  1 CourseInfo retrievedCourse = null;
231  1 CourseInfo updatedCourse = null;
232  1 CourseInfo createdCourse = null;
233  1 try {
234  1 System.out.println("Getting test data...");
235  1 cInfo = generator.getCourseTestData();
236    } catch (Exception ex) {
237  0 ex.printStackTrace();
238  0 fail("Got exception getting test data:" + ex.getMessage());
239    }
240   
241  1 assertNotNull(cInfo);
242  1 cInfo.setSpecialTopicsCourse(true);
243  1 cInfo.setPilotCourse(true);
244  1 try {
245  1 System.out.println("creating course...");
246  1 createdCourse = courseService.createCourse(cInfo);
247    } catch (DataValidationErrorException e) {
248  0 dumpValidationErrors(cInfo);
249  0 fail("DataValidationError: " + e.getMessage());
250    } catch (Exception ex) {
251  0 ex.printStackTrace();
252  0 fail("failed creating course" + ":" + ex.getMessage());
253    }
254  1 int initialFormatCount = createdCourse.getFormats().size();
255   
256    // minimal sanity check
257  1 assertNotNull(createdCourse);
258  1 assertEquals("kuali.lu.type.CreditCourse", createdCourse.getType());
259  1 assertEquals("courseTitle-12", createdCourse.getCourseTitle());
260  1 assertEquals(2, createdCourse.getUnitsContentOwner().size());
261  1 assertEquals(4, createdCourse.getAttributes().size());
262   
263    // update some fields
264  1 createdCourse.getUnitsContentOwner().clear();
265  1 AdminOrgInfo testCurrOrg = new AdminOrgInfo();
266  1 testCurrOrg.setOrgId("testOrgId");
267  1 testCurrOrg.setType(CourseAssemblerConstants.SUBJECT_ORG);
268  1 createdCourse.getUnitsContentOwner().add("testOrgId");
269   
270    // Delete One Format
271  1 createdCourse.getFormats().remove(0);
272   
273    // Delete One Activity from Existing Format
274  1 assertEquals(2, createdCourse.getFormats().get(0).getActivities().size());
275  1 createdCourse.getFormats().get(0).getActivities().remove(0);
276  1 String updActFrmtId = createdCourse.getFormats().get(0).getId();
277   
278    // Add two New formats
279  1 FormatInfo newFormat = new FormatInfo();
280  1 newFormat.setType(CourseAssemblerConstants.COURSE_FORMAT_TYPE);
281  1 newFormat.setState(DtoConstants.STATE_DRAFT);
282   
283  1 TimeAmountInfo timeInfo = new TimeAmountInfo();
284  1 timeInfo.setAtpDurationTypeKey("kuali.atp.duration.Semester");
285  1 timeInfo.setTimeQuantity(12);
286  1 newFormat.setDuration(timeInfo);
287   
288  1 List<String> termsOfferedList = new ArrayList<String>();
289  1 termsOfferedList.add("FALL2010");
290  1 newFormat.setTermsOffered(termsOfferedList);
291   
292  1 Map<String, String> attrMap = new HashMap<String, String>();
293  1 attrMap.put("FRMT", "value");
294  1 newFormat.setAttributes(attrMap);
295   
296    // Add two new activities to new formats
297  1 ActivityInfo newActivity1 = new ActivityInfo();
298  1 newActivity1.setActivityType(CourseAssemblerConstants.COURSE_ACTIVITY_DIRECTED_TYPE);
299  1 newActivity1.setState(DtoConstants.STATE_DRAFT);
300  1 newFormat.getActivities().add(newActivity1);
301   
302  1 ActivityInfo newActivity2 = new ActivityInfo();
303  1 newActivity2.setActivityType(CourseAssemblerConstants.COURSE_ACTIVITY_LAB_TYPE);
304  1 newActivity2.setState(DtoConstants.STATE_DRAFT);
305  1 newFormat.getActivities().add(newActivity2);
306   
307  1 createdCourse.getFormats().add(newFormat);
308   
309  1 FormatInfo newFormat2 = new FormatInfo();
310  1 newFormat2.setType(CourseAssemblerConstants.COURSE_FORMAT_TYPE);
311  1 newFormat2.setState(DtoConstants.STATE_DRAFT);
312  1 createdCourse.getFormats().add(newFormat2);
313   
314  1 Map<String, String> attributes = createdCourse.getAttributes();
315  1 attributes.put("testKey", "testValue");
316  1 createdCourse.setAttributes(attributes);
317   
318  1 createdCourse.getCreditOptions().remove(1);
319  1 ResultComponentInfo rsltComp = new ResultComponentInfo();
320  1 rsltComp.setType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE);
321  1 rsltComp.getResultValues().add("1");
322  1 rsltComp.getResultValues().add("3");
323  1 createdCourse.getCreditOptions().add(rsltComp);
324  1 createdCourse.getGradingOptions().remove(1);
325  1 createdCourse.getGradingOptions().add("NewGradingOption");
326   
327  1 createdCourse.setSpecialTopicsCourse(false);
328  1 createdCourse.setPilotCourse(false);
329   
330  1 createdCourse.getCourseSpecificLOs().get(0).getLoInfo().getDesc().setPlain("UPDATED!!!");
331  1 createdCourse.getCourseSpecificLOs().remove(1);
332  1 LoDisplayInfo displayInfo = new LoDisplayInfo();
333  1 displayInfo.setLoInfo(new LoInfo());
334  1 displayInfo.getLoInfo().setDesc(new RichTextInfo());
335  1 createdCourse.getCourseSpecificLOs().add(displayInfo);
336  1 createdCourse.getCourseSpecificLOs().get(1).getLoInfo().getDesc().setPlain("BrandNew!!!");
337  1 createdCourse.getCourseSpecificLOs().get(1).getLoCategoryInfoList().add(new LoCategoryInfo());
338  1 createdCourse.getCourseSpecificLOs().get(1).getLoCategoryInfoList().get(0).setId("category-3");
339   
340  1 createdCourse.getFeeJustification().setFormatted("NEWJUSTIFICATION");
341  1 createdCourse.getFees().clear();
342  1 createdCourse.getFees().add(new CourseFeeInfo());
343  1 createdCourse.getFees().get(0).setFeeType("UpdatedFeeType");
344  1 createdCourse.getFees().get(0).getFeeAmounts().clear();
345  1 createdCourse.getFees().get(0).getFeeAmounts().add(new CurrencyAmountInfo());
346  1 createdCourse.getFees().get(0).getFeeAmounts().get(0).setCurrencyQuantity(10);
347  1 createdCourse.getFees().get(0).getFeeAmounts().get(0).setCurrencyTypeKey("PESOS");
348  1 createdCourse.getRevenues().get(0).getAffiliatedOrgs().clear();
349  1 createdCourse.getRevenues().get(0).getAffiliatedOrgs().add(new AffiliatedOrgInfo());
350  1 createdCourse.getRevenues().get(0).getAffiliatedOrgs().get(0).setOrgId("NEWORG");
351  1 createdCourse.getRevenues().get(0).getAffiliatedOrgs().get(0).setPercentage(Long.valueOf(99));
352   
353  1 createdCourse.setSubjectArea(null);
354  1 createdCourse.setCode("UpdatedCode100");
355  1 createdCourse.setLevel("Level100");
356   
357    // Perform the update
358  1 try {
359  1 System.out.println("updating course...");
360  1 updatedCourse = courseService.updateCourse(createdCourse);
361    } catch (DataValidationErrorException e) {
362  0 dumpValidationErrors(createdCourse);
363  0 fail("DataValidationError: " + e.getMessage());
364    } catch (Exception ex) {
365  0 ex.printStackTrace();
366  0 fail("failed updating course: " + ex.getMessage());
367    }
368  1 assertEquals(initialFormatCount + 1, updatedCourse.getFormats().size());
369   
370  1 for (FormatInfo uFrmt : updatedCourse.getFormats()) {
371    // Check to see if activities are added to a new format
372  3 if (uFrmt.getAttributes().containsKey("FRMT")) {
373  1 assertEquals(2, uFrmt.getActivities().size());
374  1 String actType = uFrmt.getActivities().get(0).getActivityType();
375  1 assertTrue(CourseAssemblerConstants.COURSE_ACTIVITY_DIRECTED_TYPE.equals(actType) || CourseAssemblerConstants.COURSE_ACTIVITY_LAB_TYPE.equals(actType));
376   
377  1 assertEquals(1, uFrmt.getTermsOffered().size());
378  1 assertEquals("FALL2010", uFrmt.getTermsOffered().get(0));
379   
380  1 TimeAmountInfo tIfo = uFrmt.getDuration();
381  1 assertNotNull(tIfo);
382  1 assertEquals((int)12, (int) tIfo.getTimeQuantity());
383    }
384   
385    // Check to see if activity is deleted from an existing format
386  3 if (updActFrmtId.equals(uFrmt.getId())) {
387  1 assertEquals(1, uFrmt.getActivities().size());
388    }
389    }
390    // Test what was returned by updateCourse
391  1 verifyUpdate(updatedCourse);
392   
393    // Now explicitly get it
394  1 try {
395  1 System.out.println("Getting course again...");
396  1 retrievedCourse = courseService.getCourse(createdCourse.getId());
397    } catch (Exception ex) {
398  0 ex.printStackTrace();
399  0 fail("failed getting course again:" + ex.getMessage());
400    }
401  1 verifyUpdate(retrievedCourse);
402   
403    // and test for optimistic lock exception
404    // NOTE: CourseService.updateCourse(CourseInfo courseInfo) modifies its parameter,
405    // as the 'results' BusinessDTORef (our CourseInfo) is simply updated to reflect
406    // the new contents of the updated Clu (see the
407    // results.getAssembler().assemble(updatedClu, results.getBusinessDTORef(), true);
408    // line in CourseServiceMethodInvoker.invokeServiceCalls()
409  1 int currVersion = Integer.parseInt(retrievedCourse.getMetaInfo().getVersionInd());
410  1 if (currVersion > 0) {
411  1 retrievedCourse.getMetaInfo().setVersionInd(Integer.toString(--currVersion));
412    }
413  1 try {
414  1 System.out.println("Updating course again trying to get a version mismatch...");
415  1 courseService.updateCourse(retrievedCourse);
416  0 fail("Failed to throw VersionMismatchException");
417    } catch (VersionMismatchException e) {
418  1 System.out.println("Correctly received " + e.getMessage());
419    } catch (DataValidationErrorException e) {
420  0 dumpValidationErrors(retrievedCourse);
421  0 fail("DataValidationError: " + e.getMessage());
422    } catch (Exception e) {
423  0 e.printStackTrace();
424  0 fail(e.getMessage());
425    }
426    }
427   
 
428  2 toggle private void verifyUpdate(CourseInfo updatedCourse) {
429  2 assertNotNull(updatedCourse);
430   
431  2 assertEquals(1, updatedCourse.getUnitsContentOwner().size());
432  2 assertEquals("testOrgId", updatedCourse.getUnitsContentOwner().get(0));
433   
434  2 assertEquals(5, updatedCourse.getAttributes().size());
435  2 assertNotNull(updatedCourse.getAttributes().get("testKey"));
436  2 assertEquals("testValue", updatedCourse.getAttributes().get("testKey"));
437   
438  2 assertEquals(2, updatedCourse.getCreditOptions().size());
439    // assertTrue(updatedCourse.getCreditOptions().contains("creditOptions-18"));
440    // assertTrue(updatedCourse.getCreditOptions().contains("NewCreditOption"));
441   
442  2 assertEquals(2, updatedCourse.getGradingOptions().size());
443   
444  2 assertTrue(updatedCourse.getGradingOptions().contains("gradingOptions-31"));
445  2 assertTrue(updatedCourse.getGradingOptions().contains("NewGradingOption"));
446   
447  2 assertFalse(updatedCourse.isSpecialTopicsCourse());
448  2 assertFalse(updatedCourse.isPilotCourse());
449   
450  2 assertNull(updatedCourse.getSubjectArea());
451  2 assertEquals("UpdatedCode100", updatedCourse.getCode());
452  2 assertEquals("Level100", updatedCourse.getLevel());
453  2 assertEquals("NEWJUSTIFICATION", updatedCourse.getFeeJustification().getFormatted());
454  2 assertEquals("UpdatedFeeType", updatedCourse.getFees().get(0).getFeeType());
455  2 assertEquals(Integer.valueOf(10), updatedCourse.getFees().get(0).getFeeAmounts().get(0).getCurrencyQuantity());
456  2 assertEquals("PESOS", updatedCourse.getFees().get(0).getFeeAmounts().get(0).getCurrencyTypeKey());
457  2 assertEquals("NEWORG", updatedCourse.getRevenues().get(0).getAffiliatedOrgs().get(0).getOrgId());
458  2 assertEquals(Long.valueOf(99), updatedCourse.getRevenues().get(0).getAffiliatedOrgs().get(0).getPercentage());
459    }
460   
 
461  1 toggle @Test
462    public void testDeleteCourse() {
463  1 System.out.println("testDeleteCourse");
464  1 try {
465  1 CourseDataGenerator generator = new CourseDataGenerator();
466  1 CourseInfo cInfo = generator.getCourseTestData();
467  1 assertNotNull(cInfo);
468  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
469  1 assertNotNull(createdCourse);
470  1 assertEquals(DtoConstants.STATE_DRAFT, createdCourse.getState());
471  1 assertEquals("kuali.lu.type.CreditCourse", createdCourse.getType());
472  1 String courseId = createdCourse.getId();
473  1 CourseInfo retrievedCourse = courseService.getCourse(courseId);
474  1 assertNotNull(retrievedCourse);
475   
476  1 courseService.deleteCourse(courseId);
477  1 try {
478  1 retrievedCourse = courseService.getCourse(courseId);
479  0 fail("Retrieval of deleted course should have thrown exception");
480    } catch (DoesNotExistException e) {}
481    } catch (Exception e) {
482  0 fail(e.getMessage());
483    }
484    }
485   
486    /**
487    *
488    * This method tests setting code, attributes in course cross listing
489    *
490    */
 
491  1 toggle @Test
492    public void testCourseCrossListing() {
493  1 CourseDataGenerator generator = new CourseDataGenerator();
494  1 try {
495  1 CourseInfo cInfo = generator.getCourseTestData();
496  1 assertNotNull(cInfo);
497   
498   
499  1 CourseCrossListingInfo ccInfo = new CourseCrossListingInfo();
500  1 ccInfo.setCourseNumberSuffix("100");
501  1 ccInfo.setSubjectArea("CHEM");
502   
503  1 Map<String, String> da = new HashMap<String, String>();
504  1 da.put("KEY1", "VALUE1");
505   
506  1 ccInfo.setAttributes(da);
507   
508  1 CourseCrossListingInfo ccInfo1 = new CourseCrossListingInfo();
509  1 ccInfo1.setCourseNumberSuffix("200");
510  1 ccInfo1.setSubjectArea("MATH");
511  1 ccInfo1.setCode("LIFE042");
512   
513  1 List<CourseCrossListingInfo> ccList = new ArrayList<CourseCrossListingInfo>();
514  1 ccList.add(ccInfo);
515  1 ccList.add(ccInfo1);
516   
517  1 cInfo.setCrossListings(ccList);
518   
519  1 try {
520  1 cInfo = courseService.createCourse(cInfo);
521    } catch (DataValidationErrorException e) {
522  0 dumpValidationErrors(cInfo);
523  0 fail("DataValidationError: " + e.getMessage());
524    } catch (Exception e) {
525  0 e.printStackTrace();
526  0 fail("failed creating course:" + e.getMessage());
527    }
528   
529  1 CourseInfo rcInfo = courseService.getCourse(cInfo.getId());
530   
531  1 assertEquals(2,rcInfo.getCrossListings().size());
532   
533  1 for(CourseCrossListingInfo rcc : rcInfo.getCrossListings()) {
534   
535  2 if("100".equals(rcc.getCourseNumberSuffix())) {
536  1 assertEquals("VALUE1", rcc.getAttributes().get("KEY1"));
537    } else {
538  1 assertEquals("LIFE042", rcc.getCode());
539    }
540    }
541   
542    } catch (Exception e) {
543  0 System.out.println("caught exception: " + e.getClass().getName());
544  0 System.out.println("message: " + e.getMessage());
545  0 e.printStackTrace(System.out);
546  0 e.printStackTrace();
547  0 fail(e.getMessage());
548    }
549   
550    }
551   
 
552  1 toggle @Test
553    public void testCreditOptions() {
554  1 CourseDataGenerator generator = new CourseDataGenerator();
555  1 try {
556  1 CourseInfo cInfo = generator.getCourseTestData();
557  1 assertNotNull(cInfo);
558   
559    // Check to see if variable credit with float increment works
560  1 ResultComponentInfo rc1 = new ResultComponentInfo();
561  1 rc1.setType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE);
562  1 HashMap<String, String> attributes = new HashMap<String,String>();
563  1 attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MIN_CREDIT_VALUE, "1.0");
564  1 attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MAX_CREDIT_VALUE, "5.0");
565  1 attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_CREDIT_VALUE_INCR, "0.5");
566  1 rc1.setAttributes(attributes);
567   
568    // Check to see if variable credit with no increments
569  1 ResultComponentInfo rc2 = new ResultComponentInfo();
570  1 rc2.setType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE);
571  1 HashMap<String, String> attributes2 = new HashMap<String,String>();
572  1 attributes2.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MIN_CREDIT_VALUE, "1.0");
573  1 attributes2.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MAX_CREDIT_VALUE, "5.0");
574  1 rc2.setAttributes(attributes2);
575   
576    // Check to see floating point multiple is accepted
577  1 ResultComponentInfo rc3 = new ResultComponentInfo();
578  1 rc3.setType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE);
579  1 List<String> rv = new ArrayList<String>();
580  1 rv.add("1.0");
581  1 rv.add("1.5");
582  1 rv.add("2.0");
583  1 rc3.setResultValues(rv);
584   
585   
586  1 List<ResultComponentInfo> creditOptions = new ArrayList<ResultComponentInfo>();
587  1 creditOptions.add(rc1);
588  1 creditOptions.add(rc2);
589  1 creditOptions.add(rc3);
590   
591  1 cInfo.setCreditOptions(creditOptions);
592   
593  1 try {
594  1 cInfo = courseService.createCourse(cInfo);
595    } catch (DataValidationErrorException e) {
596  0 dumpValidationErrors(cInfo);
597  0 fail("DataValidationError: " + e.getMessage());
598    } catch (Exception e) {
599  0 e.printStackTrace();
600  0 fail("failed creating course:" + e.getMessage());
601    }
602   
603  1 CourseInfo rcInfo = courseService.getCourse(cInfo.getId());
604   
605  1 List<ResultComponentInfo> co = rcInfo.getCreditOptions();
606   
607  1 assertEquals(3, co.size());
608   
609    // Check to see if multiple was set properly
610  1 for(ResultComponentInfo rc : co) {
611  3 if(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE.equals(rc.getType())){
612  1 assertEquals(3, rc.getResultValues().size());
613  1 assertTrue(rc.getResultValues().contains("1.0"));
614  1 assertTrue(rc.getResultValues().contains("1.5"));
615  1 assertTrue(rc.getResultValues().contains("2.0"));
616    }
617   
618  3 if(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE.equals(rc.getType())){
619  2 if(3 == rc.getAttributes().size()) {
620  2 assertEquals(9, rc.getResultValues().size());
621  2 assertTrue(rc.getResultValues().contains("1.5"));
622    } else {
623  0 assertEquals(5, rc.getResultValues().size());
624  0 assertTrue(rc.getResultValues().contains("3.0"));
625    }
626    }
627    }
628   
629   
630    } catch (Exception e) {
631  0 System.out.println("caught exception: " + e.getClass().getName());
632  0 System.out.println("message: " + e.getMessage());
633  0 e.printStackTrace(System.out);
634  0 e.printStackTrace();
635  0 fail(e.getMessage());
636    }
637    }
638   
 
639  1 toggle @Test
640    public void testDynamicAttributes() {
641  1 System.out.println("testDynamicAttributes");
642  1 CourseDataGenerator generator = new CourseDataGenerator();
643  1 try {
644  1 CourseInfo cInfo = generator.getCourseTestData();
645   
646  1 assertNotNull(cInfo);
647   
648  1 Map<String, String> attrMap = new HashMap<String, String>();
649  1 attrMap.put("finalExamStatus", "GRD");
650  1 attrMap.put("altFinalExamStatusDescr", "Some123description");
651  1 attrMap.put("proposalTitle", "proposalTitle-1");
652  1 attrMap.put("proposalRationale", "proposalRationale");
653   
654  1 cInfo.setAttributes(attrMap);
655   
656  1 FormatInfo fInfo = new FormatInfo();
657  1 fInfo.setType(CourseAssemblerConstants.COURSE_FORMAT_TYPE);
658  1 ActivityInfo aInfo = new ActivityInfo();
659  1 aInfo.setActivityType(CourseAssemblerConstants.COURSE_ACTIVITY_DIRECTED_TYPE);
660  1 Map<String, String> activityAttrs = new HashMap<String, String>();
661  1 activityAttrs.put("ACTIVITY_KEY", "ACTIVITY_VALUE");
662  1 aInfo.setAttributes(activityAttrs);
663   
664  1 List<ActivityInfo> activities = new ArrayList<ActivityInfo>();
665  1 activities.add(aInfo);
666  1 fInfo.setActivities(activities);
667   
668  1 List<FormatInfo> formats = new ArrayList<FormatInfo>();
669  1 formats.add(fInfo);
670   
671  1 cInfo.setFormats(formats);
672   
673  1 try {
674  1 cInfo = courseService.createCourse(cInfo);
675    } catch (DataValidationErrorException e) {
676  0 dumpValidationErrors(cInfo);
677  0 fail("DataValidationError: " + e.getMessage());
678    } catch (Exception e) {
679  0 e.printStackTrace();
680  0 fail("failed creating course:" + e.getMessage());
681    }
682    // Check in LuService if the attributes are mapped properly
683   
684    // CourseInfo rInfo = courseService.getCourse(cInfo.getId());
685   
686  1 assertEquals("GRD", cInfo.getAttributes().get("finalExamStatus"));
687  1 assertEquals("Some123description", cInfo.getAttributes().get("altFinalExamStatusDescr"));
688   
689   
690    // Check if the attributes are being set in the activity
691  1 assertEquals("ACTIVITY_VALUE", cInfo.getFormats().get(0).getActivities().get(0).getAttributes().get("ACTIVITY_KEY"));
692   
693    } catch (Exception e) {
694  0 System.out.println("caught exception: " + e.getClass().getName());
695  0 System.out.println("message: " + e.getMessage());
696  0 e.printStackTrace(System.out);
697  0 e.printStackTrace();
698  0 fail(e.getMessage());
699    }
700   
701    }
702   
 
703  1 toggle @Test
704    public void testCluIsUpdated() {
705   
706    }
707   
 
708  1 toggle @Test
709    public void testGetMetadata() {
710  1 System.out.println("testGetMetadata");
711  1 MetadataServiceImpl metadataService = new MetadataServiceImpl(courseService);
712  1 metadataService.setUiLookupContext("classpath:lum-ui-test-lookup-context.xml");
713  1 Metadata metadata = metadataService.getMetadata("org.kuali.student.lum.course.dto.CourseInfo");
714   
715  1 Map<String, Metadata> properties = metadata.getProperties();
716  1 assertTrue(properties.size() > 0);
717   
718  1 assertTrue(properties.containsKey("state"));
719  1 assertTrue(properties.containsKey("campusLocations"));
720   
721  1 assertTrue(properties.containsKey("formats"));
722  1 metadata = properties.get("formats");
723   
724  1 properties = metadata.getProperties();
725  1 assertTrue(properties.containsKey("*"));
726  1 metadata = properties.get("*");
727   
728  1 properties = metadata.getProperties();
729  1 assertTrue(properties.containsKey("activities"));
730  1 metadata = properties.get("activities");
731   
732  1 properties = metadata.getProperties();
733  1 assertTrue(properties.containsKey("*"));
734  1 metadata = properties.get("*");
735   
736  1 properties = metadata.getProperties();
737  1 assertFalse(properties.containsKey("foo"));
738   
739  1 return;
740    }
741   
 
742  1 toggle @Test
743    public void testCourseVersioning() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, IllegalVersionSequencingException {
744  1 CourseDataGenerator generator = new CourseDataGenerator();
745  1 CourseInfo cInfo = generator.getCourseTestData();
746  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
747   
748  1 CourseInfo newCourse = null;
749  1 try {
750  1 newCourse = courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test make a new version");
751  1 assertTrue(true);
752    } catch (Exception e) {
753  0 assertTrue(false);
754    }
755   
756  1 assertNotNull(newCourse);
757   
758   
759    // test that creating a new course version copies over statements
760  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
761  1 StatementTreeViewInfo createdTree = courseService.createCourseStatement(createdCourse.getId(), statementTreeViewInfo);
762  1 assertNotNull(createdTree);
763   
764  1 CourseInfo newVersion = null;
765   
766  1 try {
767  1 newVersion = courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test make a new version for statements");
768  1 assertTrue(true);
769    } catch (Exception e) {
770  0 e.printStackTrace();
771  0 assertTrue(false);
772    }
773   
774  1 assertNotNull(newVersion);
775   
776   
777    }
778   
 
779  1 toggle @Test
780    public void testGetCourseStatement() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
781   
782  1 String courseId = "COURSE-STMT-1";
783  1 List<StatementTreeViewInfo> courseStatements = courseService.getCourseStatements(courseId, null, null);
784  1 assertEquals(2, courseStatements.size());
785  1 for (StatementTreeViewInfo tree : courseStatements) {
786  2 checkTreeView(tree, false);
787    }
788   
789    // test that the proper error message occurs if an invalid Clu id is attempted
790  1 String credentialProgramId = "d02dbbd3-20e2-410d-ab52-1bd6d362748b";
791   
792  1 try {
793  1 courseService.getCourseStatements(credentialProgramId, null, null);
794  0 assertTrue(false);
795    }
796    catch(DoesNotExistException e) {
797    // we should reach here, since the exception should trigger
798  1 assertTrue(true);
799    }
800    }
801   
 
802  0 toggle @Test
803    @Ignore
804    // FIXME
805    public void testGetCourseStatement_nl() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
806   
807  0 String courseId = "COURSE-STMT-1";
808  0 String nlUsageTypeKey = "KUALI.RULE";
809  0 String language = "en";
810  0 List<StatementTreeViewInfo> courseStatements = courseService.getCourseStatements(courseId, nlUsageTypeKey, language);
811  0 assertEquals(2, courseStatements.size());
812  0 for (StatementTreeViewInfo tree : courseStatements) {
813  0 checkTreeView(tree, true);
814    }
815    }
816   
 
817  1 toggle @Test
818    public void testCreateCourseStatement() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException {
819  1 final String courseId = "COURSE-STMT-1";
820   
821  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
822  1 StatementTreeViewInfo createdTree = courseService.createCourseStatement(courseId, statementTreeViewInfo);
823  1 assertNotNull(createdTree);
824  1 assertEquals(2, createdTree.getStatements().size());
825    }
826   
 
827  1 toggle @Test(expected = InvalidParameterException.class)
828    public void testCreateCourseStatement_duplicateTree() throws Exception {
829  1 String courseId = "COURSE-STMT-1";
830  1 String nlUsageTypeKey = "KUALI.RULE";
831  1 String language = "en";
832  1 List<StatementTreeViewInfo> courseStatements = courseService.getCourseStatements(courseId, nlUsageTypeKey, language);
833  1 courseService.createCourseStatement(courseId, courseStatements.get(0));
834    }
835   
 
836  1 toggle @Test(expected = MissingParameterException.class)
837    public void testCreateCourseStatement_nullCourseId() throws Exception {
838   
839  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
840  1 @SuppressWarnings("unused")
841    StatementTreeViewInfo createdTree = courseService.createCourseStatement(null, statementTreeViewInfo);
842    }
843   
 
844  1 toggle @Test(expected = MissingParameterException.class)
845    public void testCreateCourseStatement_nullTree() throws Exception {
846  1 String courseId = "COURSE-STMT-1";
847   
848  1 @SuppressWarnings("unused")
849    StatementTreeViewInfo createdTree = courseService.createCourseStatement(courseId, null);
850    }
851   
 
852  1 toggle @Test(expected = DoesNotExistException.class)
853    public void testDeleteCourseStatement() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, CircularReferenceException, VersionMismatchException {
854  1 final String courseId = "COURSE-STMT-1";
855   
856  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
857  1 StatementTreeViewInfo createdTree = courseService.createCourseStatement(courseId, statementTreeViewInfo);
858  1 StatusInfo status = courseService.deleteCourseStatement(courseId, createdTree);
859  1 assertTrue(status.getSuccess());
860  1 List<StatementTreeViewInfo> statements = courseService.getCourseStatements(courseId, null, null);
861  1 for (StatementTreeViewInfo statement : statements) {
862  3 if (statement.getId().equals(createdTree.getId())) {
863  0 fail("StatementTree not deleted from course");
864    }
865    }
866  1 statementService.getStatementTreeView(createdTree.getId());
867    }
868   
 
869  1 toggle @Test(expected = DoesNotExistException.class)
870    public void testDeleteCourseStatement_badTree() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
871  1 final String courseId = "COURSE-STMT-1";
872   
873  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
874  1 courseService.deleteCourseStatement(courseId, statementTreeViewInfo);
875    }
876   
 
877  1 toggle @Test(expected = DoesNotExistException.class)
878    public void testDeleteCourseStatement_badCourse() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
879  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
880  1 courseService.deleteCourseStatement("xxx", statementTreeViewInfo);
881    }
882   
 
883  1 toggle @Test(expected = MissingParameterException.class)
884    public void testDeleteCourseStatement_nullCourseId() throws Exception {
885  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
886  1 courseService.deleteCourseStatement(null, statementTreeViewInfo);
887    }
888   
 
889  1 toggle @Test(expected = MissingParameterException.class)
890    public void testDeleteCourseStatement_nullTreeId() throws Exception {
891  1 courseService.deleteCourseStatement("xxx", null);
892    }
893   
 
894  1 toggle @Test
895    public void testUpdateCourseStatement() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, CircularReferenceException, VersionMismatchException {
896  1 final String courseId = "COURSE-STMT-1";
897   
898  1 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
899  1 StatementTreeViewInfo createdTree = courseService.createCourseStatement(courseId, statementTreeViewInfo);
900   
901  1 List<ReqComponentInfo> reqCompList1 = new ArrayList<ReqComponentInfo>(3);
902  1 ReqComponentInfo rc1 = new ReqComponentInfo();
903  1 rc1.setDesc(toRichText("REQCOMP-1"));
904  1 rc1.setType("kuali.reqComponent.type.course.courseset.completed.all");
905  1 ReqComponentInfo rc2 = new ReqComponentInfo();
906  1 rc2.setDesc(toRichText("REQCOMP-2"));
907  1 rc2.setType("kuali.reqComponent.type.course.courseset.gpa.min");
908  1 StatementTreeViewInfo subTree1 = new StatementTreeViewInfo();
909  1 subTree1.setDesc(toRichText("STMT-5"));
910  1 subTree1.setOperator(StatementOperatorTypeKey.AND);
911  1 subTree1.setType("kuali.statement.type.program.entrance");
912  1 reqCompList1.add(rc1);
913  1 reqCompList1.add(rc2);
914  1 subTree1.setReqComponents(reqCompList1);
915   
916  1 StatementTreeViewInfo oldSubTree1 = createdTree.getStatements().get(0);
917  1 createdTree.getStatements().set(0, subTree1);
918  1 StatementTreeViewInfo updatedTree = courseService.updateCourseStatement(courseId, statementTreeViewInfo);
919  1 assertEquals(createdTree.getStatements().get(0).getDesc().getPlain(), updatedTree.getStatements().get(0).getDesc().getPlain());
920   
921    }
922   
 
923  0 toggle @Test
924    @Ignore
925    // FIXME need a dictionary that defines StatamentTreeViewInfo
926    public void testValidataCourseStatement() throws Exception {
927  0 final String courseId = "COURSE-STMT-1";
928   
929  0 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
930  0 courseService.validateCourseStatement(courseId, statementTreeViewInfo);
931  0 List<ValidationResultInfo> validations = courseService.validateCourseStatement(courseId, statementTreeViewInfo);
932  0 assertTrue(isEmpty(validations));
933    }
934   
 
935  0 toggle @Test
936    @Ignore
937    // FIXME need a dictionary that defines StatamentTreeViewInfo
938    public void testValidataCourseStatement_invalidStatement() throws InvalidParameterException, MissingParameterException, OperationFailedException {
939  0 final String courseId = "COURSE-STMT-1";
940   
941  0 StatementTreeViewInfo statementTreeViewInfo = createStatementTree();
942  0 statementTreeViewInfo.setType("an.example.of.a.bad.statementType");
943  0 statementTreeViewInfo.getStatements().get(0).setType("fictional.program");
944  0 statementTreeViewInfo.getStatements().get(0).getReqComponents().set(0, createBadReqComponent());
945  0 List<ValidationResultInfo> validations = courseService.validateCourseStatement(courseId, statementTreeViewInfo);
946  0 assertFalse(isEmpty(validations));
947    }
948   
 
949  0 toggle private static ReqComponentInfo createBadReqComponent() {
950  0 ReqComponentInfo reqCompInfo = new ReqComponentInfo();
951    // reqCompInfo.setId("REQCOMP-NL-X");
952  0 reqCompInfo.setId("1234567890123456789012345678901234567890");
953  0 reqCompInfo.setType("kuali.reqComponent.type.courseList.nof");
954  0 reqCompInfo.setState("Active");
955   
956  0 List<ReqCompFieldInfo> fieldList = new ArrayList<ReqCompFieldInfo>();
957   
958  0 ReqCompFieldInfo field1 = new ReqCompFieldInfo();
959  0 field1.setId("1234567890123456789012345678901234567890");
960  0 field1.setType("kuali.reqComponent.field.type.operator");
961  0 field1.setValue("-1");
962  0 fieldList.add(field1);
963   
964  0 ReqCompFieldInfo field2 = new ReqCompFieldInfo();
965  0 field2.setId("2");
966  0 field2.setType("kuali.reqComponent.field.type.operator");
967  0 field2.setValue("greater_than_or_equal_to42");
968  0 fieldList.add(field2);
969   
970  0 ReqCompFieldInfo field3 = new ReqCompFieldInfo();
971  0 field3.setId("3");
972  0 field3.setType("kuali.reqComponent.field.type.cluSet.id");
973  0 field3.setValue("CLUSET-NL-Y");
974  0 fieldList.add(field3);
975   
976  0 reqCompInfo.setReqCompFields(fieldList);
977  0 return reqCompInfo;
978    }
979   
 
980  8 toggle private static StatementTreeViewInfo createStatementTree() {
981    // Statement Tree
982    // --------- STMT-1:OR ---------
983    // | |
984    // STMT-2:AND STMT-3:AND
985    // | | | |
986    // REQCOMP-1 REQCOMP-2 REQCOMP-3 REQCOMP-4
987   
988  8 List<StatementTreeViewInfo> subStatements = new ArrayList<StatementTreeViewInfo>(3);
989  8 List<ReqComponentInfo> reqCompList1 = new ArrayList<ReqComponentInfo>(3);
990  8 List<ReqComponentInfo> reqCompList2 = new ArrayList<ReqComponentInfo>(3);
991   
992    // req components
993  8 ReqComponentInfo rc1 = new ReqComponentInfo();
994  8 rc1.setDesc(toRichText("REQCOMP-1"));
995  8 rc1.setType("kuali.reqComponent.type.course.courseset.completed.all");
996  8 ReqComponentInfo rc2 = new ReqComponentInfo();
997  8 rc2.setDesc(toRichText("REQCOMP-2"));
998  8 rc2.setType("kuali.reqComponent.type.course.courseset.gpa.min");
999  8 ReqComponentInfo rc3 = new ReqComponentInfo();
1000  8 rc3.setDesc(toRichText("REQCOMP-3"));
1001  8 rc3.setType("kuali.reqComponent.type.course.courseset.completed.nof");
1002  8 ReqComponentInfo rc4 = new ReqComponentInfo();
1003  8 rc4.setDesc(toRichText("REQCOMP-4"));
1004  8 rc4.setType("kuali.reqComponent.type.course.permission.instructor.required");
1005   
1006    // statement tree views
1007  8 StatementTreeViewInfo statementTree = new StatementTreeViewInfo();
1008  8 statementTree.setDesc(toRichText("STMT-1"));
1009  8 statementTree.setOperator(StatementOperatorTypeKey.OR);
1010    // statementTree.setType("kuali.statement.type.program.entrance");
1011  8 statementTree.setType("kuali.statement.type.course.academicReadiness.coreq");
1012   
1013  8 StatementTreeViewInfo subTree1 = new StatementTreeViewInfo();
1014  8 subTree1.setDesc(toRichText("STMT-2"));
1015  8 subTree1.setOperator(StatementOperatorTypeKey.AND);
1016    // subTree1.setType("kuali.statement.type.program.entrance");
1017  8 subTree1.setType("kuali.statement.type.course.recommendedPreparation");
1018   
1019  8 StatementTreeViewInfo subTree2 = new StatementTreeViewInfo();
1020  8 subTree2.setDesc(toRichText("STMT-3"));
1021  8 subTree2.setOperator(StatementOperatorTypeKey.AND);
1022    // subTree2.setType("kuali.statement.type.program.entrance");
1023  8 subTree2.setType("kuali.statement.type.course.academicReadiness.antireq");
1024   
1025    // construct tree with statements and req components
1026  8 reqCompList1.add(rc1);
1027  8 reqCompList1.add(rc2);
1028  8 subTree1.setReqComponents(reqCompList1);
1029  8 reqCompList2.add(rc3);
1030  8 reqCompList2.add(rc4);
1031  8 subTree2.setReqComponents(reqCompList2);
1032  8 subStatements.add(subTree1);
1033  8 subStatements.add(subTree2);
1034  8 statementTree.setStatements(subStatements);
1035   
1036  8 return statementTree;
1037    }
1038   
 
1039  59 toggle private static RichTextInfo toRichText(String text) {
1040  59 RichTextInfo richTextInfo = new RichTextInfo();
1041  59 if (text == null) {
1042  0 return null;
1043    }
1044  59 richTextInfo.setPlain(text);
1045  59 richTextInfo.setFormatted("<p>" + text + "</p>");
1046  59 return richTextInfo;
1047    }
1048   
 
1049  2 toggle private static void checkTreeView(final StatementTreeViewInfo rootTree, final boolean checkNaturalLanguage) {
1050  2 assertNotNull(rootTree);
1051  2 List<StatementTreeViewInfo> subTreeView = rootTree.getStatements();
1052  2 assertNotNull(subTreeView);
1053  2 assertEquals(2, subTreeView.size());
1054  2 StatementTreeViewInfo subTree1 = subTreeView.get(0);
1055  2 StatementTreeViewInfo subTree2 = subTreeView.get(1);
1056   
1057    // Check root tree
1058  2 assertNotNull(rootTree);
1059  2 assertEquals(2, subTreeView.size());
1060  2 assertNotNull(subTree1);
1061  2 assertNotNull(subTree2);
1062   
1063    // Check reqComps of sub-tree 1
1064  2 assertEquals("STMT-TV-2", subTree1.getId());
1065  2 assertEquals(2, subTree1.getReqComponents().size());
1066  2 assertEquals("REQCOMP-TV-1", subTree1.getReqComponents().get(0).getId());
1067  2 assertEquals("REQCOMP-TV-2", subTree1.getReqComponents().get(1).getId());
1068  2 if (checkNaturalLanguage) {
1069  0 assertEquals("Student must have completed all of MATH 152, MATH 180", subTree1.getReqComponents().get(0).getNaturalLanguageTranslation());
1070  0 assertEquals("Student needs a minimum GPA of 3.5 in MATH 152, MATH 180", subTree1.getReqComponents().get(1).getNaturalLanguageTranslation());
1071    }
1072   
1073    // Check reqComps of sub-tree 2
1074  2 assertEquals("STMT-TV-3", subTree2.getId());
1075  2 assertEquals(2, subTree2.getReqComponents().size());
1076  2 assertEquals("REQCOMP-TV-3", subTree2.getReqComponents().get(0).getId());
1077  2 assertEquals("REQCOMP-TV-4", subTree2.getReqComponents().get(1).getId());
1078  2 if (checkNaturalLanguage) {
1079  0 assertEquals("Student must have completed 1 of MATH 152, MATH 180", subTree2.getReqComponents().get(0).getNaturalLanguageTranslation());
1080  0 assertEquals("Student needs a minimum GPA of 4.0 in MATH 152, MATH 180", subTree2.getReqComponents().get(1).getNaturalLanguageTranslation());
1081    }
1082    }
1083   
1084    /**
1085    *
1086    * This method checks for an UnsupportedOperationException to be thrown from the methods in the created list.
1087    *
1088    */
 
1089  1 toggle @Test
1090    public void testExpectedUnsupported() throws Exception {
1091  1 String[] unsupportedOperations = {"getCourseActivities", "getCourseFormats", "getCourseLos"};
1092   
1093  1 Collection<ServiceMethodInvocationData> methods = new ArrayList<ServiceMethodInvocationData>(unsupportedOperations.length);
1094  1 for(String s : unsupportedOperations) {
1095  3 ServiceMethodInvocationData invocationData = new ServiceMethodInvocationData();
1096  3 invocationData.methodName = s;
1097  3 invocationData.parameters = new Object[1];
1098   
1099    // all the parameter types for these methods are the same
1100  3 invocationData.paramterTypes = new Class<?>[] {String.class};
1101  3 methods.add(invocationData);
1102    }
1103   
1104  1 invokeForExpectedException(methods, UnsupportedOperationException.class);
1105    }
1106   
 
1107    private class ServiceMethodInvocationData {
1108    String methodName;
1109    Object[] parameters;
1110    Class<?>[] paramterTypes;
1111    }
1112   
 
1113  2 toggle private void invokeForExpectedException(Collection<ServiceMethodInvocationData> methods, Class<? extends Exception> expectedExceptionClass) throws Exception {
1114  2 for(ServiceMethodInvocationData methodData : methods) {
1115  9 Method method = courseService.getClass().getMethod(methodData.methodName, methodData.paramterTypes);
1116  9 Throwable expected = null;
1117  9 Exception unexpected = null;
1118  9 try {
1119  9 method.invoke(courseService, methodData.parameters);
1120    }
1121    catch(InvocationTargetException ex) {
1122  9 if(ex.getCause() != null && ex.getCause().getClass().equals(expectedExceptionClass)) {
1123  9 expected = ex.getCause();
1124    }
1125    else {
1126  0 unexpected = ex;
1127  0 unexpected.printStackTrace();
1128    }
1129    }
1130    catch(Exception other) {
1131  0 unexpected = other;
1132    }
1133    finally {
1134  9 assertNotNull("An exception of class: " + expectedExceptionClass.toString() + " was expected, but the method: " + methodData.methodName + " threw this exception: " + unexpected, expected);
1135    }
1136    }
1137    }
1138   
 
1139  1 toggle @Test
1140    public void testGetVersionMethodsForInvalidParameters() throws Exception {
1141  1 String[] getVersionMethods = {"getVersionBySequenceNumber", "getVersions", "getFirstVersion", "getVersionsInDateRange", "getCurrentVersion", "getCurrentVersionOnDate"};
1142   
1143    // build an object array with the appropriate number of arguments for each version method to be called
1144  1 Object[][] getVersionParams = {new Object[3], new Object[2], new Object[2], new Object[4], new Object[2], new Object[3]};
1145   
1146    // build a class array with the parameter types for each method call
1147  1 Class<?>[][] getVersionParamTypes = {{String.class, String.class, Long.class}, // for getVersionBySequenceNumber
1148    {String.class, String.class}, // for getVersions
1149    {String.class, String.class}, // for getFirstVersion
1150    {String.class, String.class, Date.class, Date.class}, // for getVersionsInDateRange
1151    {String.class, String.class}, // for getCurrentVersion
1152    {String.class, String.class, Date.class}}; // for getCurrentVersionOnDate
1153   
1154  1 String badRefObjectTypeURI = "BADBADBAD";
1155  1 Collection<ServiceMethodInvocationData> methods = new ArrayList<ServiceMethodInvocationData>(getVersionMethods.length);
1156  7 for(int i = 0; i < getVersionMethods.length; i++) {
1157  6 ServiceMethodInvocationData invocationData = new ServiceMethodInvocationData();
1158  6 invocationData.methodName = getVersionMethods[i];
1159   
1160    // set the first parameter of each invocation to the invalid data
1161  6 getVersionParams[i][0] = badRefObjectTypeURI;
1162   
1163  6 invocationData.parameters = getVersionParams[i];
1164  6 invocationData.paramterTypes = getVersionParamTypes[i];
1165   
1166  6 methods.add(invocationData);
1167    }
1168   
1169  1 invokeForExpectedException(methods, InvalidParameterException.class);
1170    }
1171   
 
1172  1 toggle @Test
1173    public void testGetCurrentVersion() throws Exception {
1174  1 CourseDataGenerator generator = new CourseDataGenerator();
1175  1 CourseInfo cInfo = generator.getCourseTestData();
1176  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1177   
1178  1 try {
1179  1 courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version");
1180  1 assertTrue(true);
1181    } catch (Exception e) {
1182  0 assertTrue(false);
1183    }
1184   
1185  1 VersionDisplayInfo versionInfo = courseService.getCurrentVersion(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId());
1186   
1187  1 assertNotNull(versionInfo);
1188  1 assertEquals(createdCourse.getVersionInfo().getSequenceNumber(),versionInfo.getSequenceNumber());
1189    }
1190   
 
1191  1 toggle @Test
1192    public void testGetCurrentVersionOnDate() throws Exception {
1193  1 CourseDataGenerator generator = new CourseDataGenerator();
1194  1 CourseInfo cInfo = generator.getCourseTestData();
1195  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1196   
1197  1 VersionDisplayInfo versionInfo = courseService.getCurrentVersionOnDate(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId(), new Date());
1198   
1199  1 assertNotNull(versionInfo);
1200  1 assertEquals(createdCourse.getVersionInfo().getSequenceNumber(),versionInfo.getSequenceNumber());
1201   
1202   
1203    // make a second version of the course, set it to be the current version a month in the future, and ensure that getting today's version gets the one that was created first
1204  1 CourseInfo cInfo2 = null;
1205  1 try {
1206  1 cInfo2 = courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version by date");
1207  1 assertTrue(true);
1208    } catch (Exception e) {
1209  0 assertTrue(false);
1210    }
1211   
1212  1 Calendar cal = Calendar.getInstance();
1213  1 cal.add(Calendar.MONTH, 1);
1214   
1215    // Make the created the current version one month from now
1216  1 courseService.setCurrentCourseVersion(cInfo2.getId(), cal.getTime());
1217   
1218    // make sure when we get the current version for today, it still returns the first one created
1219  1 versionInfo = courseService.getCurrentVersionOnDate(CourseServiceConstants.COURSE_NAMESPACE_URI, cInfo2.getVersionInfo().getVersionIndId(), new Date());
1220   
1221  1 assertNotNull(versionInfo);
1222  1 assertEquals(createdCourse.getVersionInfo().getSequenceNumber(), versionInfo.getSequenceNumber());
1223    }
1224   
 
1225  1 toggle @Test
1226    public void testGetVersions() throws Exception {
1227   
1228  1 CourseDataGenerator generator = new CourseDataGenerator();
1229  1 CourseInfo cInfo = generator.getCourseTestData();
1230  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1231   
1232  1 List<VersionDisplayInfo> versions = courseService.getVersions(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId());
1233   
1234  1 assertEquals(1, versions.size());
1235   
1236  1 try {
1237  1 courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version");
1238  1 assertTrue(true);
1239    } catch (Exception e) {
1240  0 assertTrue(false);
1241    }
1242   
1243  1 versions = courseService.getVersions(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId());
1244   
1245  1 assertEquals(2, versions.size());
1246    }
1247   
 
1248  1 toggle @Test
1249    public void testGetFirstVersion() throws Exception {
1250   
1251  1 CourseDataGenerator generator = new CourseDataGenerator();
1252  1 CourseInfo cInfo = generator.getCourseTestData();
1253  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1254   
1255  1 try {
1256  1 courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version");
1257  1 assertTrue(true);
1258    } catch (Exception e) {
1259  0 assertTrue(false);
1260    }
1261   
1262  1 VersionDisplayInfo firstVersion = courseService.getFirstVersion(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId());
1263   
1264  1 assertEquals(firstVersion.getSequenceNumber(), createdCourse.getVersionInfo().getSequenceNumber());
1265    }
1266   
 
1267  1 toggle @Test
1268    public void testGetVersionBySequenceNumber() throws Exception {
1269   
1270  1 CourseDataGenerator generator = new CourseDataGenerator();
1271  1 CourseInfo cInfo = generator.getCourseTestData();
1272  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1273   
1274  1 CourseInfo version2 = null;
1275  1 try {
1276  1 version2 = courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version");
1277  1 assertTrue(true);
1278    } catch (Exception e) {
1279  0 assertTrue(false);
1280    }
1281   
1282  1 VersionDisplayInfo secondVersion = courseService.getVersionBySequenceNumber(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId(), version2.getVersionInfo().getSequenceNumber());
1283   
1284  1 assertEquals(secondVersion.getSequenceNumber(), version2.getVersionInfo().getSequenceNumber());
1285    }
1286   
 
1287  1 toggle @Test
1288    public void testGetVersionsInDateRange() throws Exception {
1289  1 CourseDataGenerator generator = new CourseDataGenerator();
1290  1 CourseInfo cInfo = generator.getCourseTestData();
1291  1 CourseInfo createdCourse = courseService.createCourse(cInfo);
1292   
1293  1 VersionDisplayInfo versionInfo = courseService.getCurrentVersionOnDate(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId(), new Date());
1294   
1295  1 assertNotNull(versionInfo);
1296  1 assertEquals(createdCourse.getVersionInfo().getSequenceNumber(),versionInfo.getSequenceNumber());
1297   
1298   
1299    // make a second version of the course, set it to be the current version a month in the future, and ensure that getting today's version gets the one that was created first
1300  1 CourseInfo cInfo2 = null;
1301  1 try {
1302  1 cInfo2 = courseService.createNewCourseVersion(createdCourse.getVersionInfo().getVersionIndId(), "test getting version by date");
1303  1 assertTrue(true);
1304    } catch (Exception e) {
1305  0 assertTrue(false);
1306    }
1307   
1308  1 Calendar cal = Calendar.getInstance();
1309  1 cal.add(Calendar.MONTH, 1);
1310   
1311    // Make the created the current version one month from now
1312  1 courseService.setCurrentCourseVersion(cInfo2.getId(), cal.getTime());
1313   
1314    // ensure that when retrieving versions from yesterday to tomorrow, we get only the first created version
1315  1 Calendar rangeInstance = Calendar.getInstance();
1316  1 rangeInstance.add(Calendar.DATE, -1);
1317  1 Date yesterday = rangeInstance.getTime();
1318   
1319  1 rangeInstance.add(Calendar.DATE, 2);
1320  1 Date tomorrow = rangeInstance.getTime();
1321   
1322  1 List<VersionDisplayInfo> versions = courseService.getVersionsInDateRange(CourseServiceConstants.COURSE_NAMESPACE_URI, createdCourse.getVersionInfo().getVersionIndId(), yesterday, tomorrow);
1323   
1324  1 assertEquals(1, versions.size());
1325    }
1326   
1327    }