Clover Coverage Report - KS LUM Impl 1.1.0-SNAPSHOT
Coverage timestamp: Mon Feb 14 2011 05:53:28 EST
126   234   8   31.5
2   192   0.06   4
4     2  
1    
 
  TestCourseInfoDictionary       Line # 41 126 0% 8 13 90.2% 0.9015151
 
  (2)
 
1    package org.kuali.student.lum.course.service.impl;
2   
3    import static org.junit.Assert.assertEquals;
4    import static org.junit.Assert.assertTrue;
5    import static org.junit.Assert.fail;
6   
7    import java.util.ArrayList;
8    import java.util.Arrays;
9    import java.util.Date;
10    import java.util.HashMap;
11    import java.util.LinkedHashSet;
12    import java.util.List;
13    import java.util.Map;
14    import java.util.Set;
15   
16    import org.junit.Test;
17    import org.kuali.student.common.test.mock.MockProxyFactoryBean;
18    import org.kuali.student.common.validator.DefaultValidatorImpl;
19    import org.kuali.student.common.validator.ServerDateParser;
20    import org.kuali.student.common.validator.Validator;
21    import org.kuali.student.common.validator.ValidatorFactory;
22    import org.kuali.student.core.atp.dto.AtpInfo;
23    import org.kuali.student.core.atp.service.AtpService;
24    import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
25    import org.kuali.student.core.dictionary.service.impl.DictionaryTesterHelper;
26    import org.kuali.student.core.dto.RichTextInfo;
27    import org.kuali.student.core.exceptions.OperationFailedException;
28    import org.kuali.student.core.validation.dto.ValidationResultInfo;
29    import org.kuali.student.lum.course.dto.CourseExpenditureInfo;
30    import org.kuali.student.lum.course.dto.CourseInfo;
31    import org.kuali.student.lum.course.dto.CourseRevenueInfo;
32    import org.kuali.student.lum.course.dto.LoDisplayInfo;
33    import org.kuali.student.lum.course.service.utils.ActiveDatesValidator;
34    import org.kuali.student.lum.course.service.utils.ExpenditurePercentValidator;
35    import org.kuali.student.lum.course.service.utils.RevenuePercentValidator;
36    import org.kuali.student.lum.lo.dto.LoCategoryInfo;
37    import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo;
38    import org.springframework.context.ApplicationContext;
39    import org.springframework.context.support.ClassPathXmlApplicationContext;
40   
 
41    public class TestCourseInfoDictionary {
42   
 
43  1 toggle @Test
44    public void testLoadCourseInfoDictionary() {
45  1 Set<String> startingClasses = new LinkedHashSet<String>();
46  1 startingClasses.add(CourseInfo.class.getName ());
47    // startingClasses.add (StatementTreeViewInfo.class);
48  1 String contextFile = "ks-courseInfo-dictionary-context";
49  1 String outFile = "target/" + contextFile + ".txt";
50  1 DictionaryTesterHelper helper = new DictionaryTesterHelper(outFile,
51    startingClasses, contextFile + ".xml", true);
52  1 List<String> errors = helper.doTest ();
53  1 if (errors.size () > 0)
54    {
55  0 fail ("failed dictionary validation:\n" + formatAsString (errors));
56    }
57    }
58   
 
59  0 toggle private String formatAsString (List<String> errors)
60    {
61  0 int i = 0;
62  0 StringBuilder builder = new StringBuilder ();
63  0 for (String error : errors)
64    {
65  0 i ++;
66  0 builder.append (i + ". " + error + "\n");
67    }
68  0 return builder.toString ();
69    }
70   
 
71  1 toggle @Test
72    public void testCourseInfoValidation() throws OperationFailedException {
73  1 ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:ks-courseInfo-dictionary-context.xml");
74  1 System.out.println("h1. Test Validation");
75  1 DefaultValidatorImpl val = new DefaultValidatorImpl();
76  1 ValidatorFactory vf = new ValidatorFactory();
77  1 List<Validator> vList = new ArrayList<Validator>();
78   
79  1 vList.add(new RevenuePercentValidator() );
80  1 vList.add(new ExpenditurePercentValidator());
81  1 vList.add(getActiveDatesValidator());
82  1 vf.setValidatorList(vList);
83   
84  1 val.setValidatorFactory(vf);
85  1 val.setDateParser(new ServerDateParser());
86  1 val.setSearchDispatcher(new MockSearchDispatcher());
87  1 CourseInfo info = new CourseInfo();
88  1 ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean(info.getClass().getName());
89  1 List<ValidationResultInfo> validationResults = val.validateObject(info, os);
90  1 System.out.println("h3. With just a blank Course");
91  1 for (ValidationResultInfo vr : validationResults) {
92  3 System.out.println(vr.getElement() + " " + vr.getMessage());
93    }
94  1 assertEquals(3, validationResults.size());
95   
96  1 try {
97  1 info = new CourseDataGenerator().getCourseTestData();
98    } catch (Exception ex) {
99  0 throw new RuntimeException(ex);
100    }
101   
102    // Clean up revenues because of custom validation
103  1 info.setRevenues(new ArrayList<CourseRevenueInfo>());
104  1 info.setExpenditure(null);
105   
106  1 validationResults = val.validateObject(info, os);
107  1 System.out.println("h3. With generated data");
108  1 for (ValidationResultInfo vr : validationResults) {
109  0 System.out.println(vr.getElement() + " " + vr.getMessage());
110    }
111  1 assertEquals(0, validationResults.size());
112   
113  1 System.out.println("testCourseDescrRequiredBasedOnState");
114  1 info.setState("DRAFT");
115  1 info.setDescr(null);
116  1 validationResults = val.validateObject(info, os);
117  1 assertEquals(0, validationResults.size());
118   
119  1 info.setState("ACTIVE");
120  1 info.setDescr(null);
121  1 validationResults = val.validateObject(info, os);
122  1 for (ValidationResultInfo vr : validationResults) {
123  2 System.out.println(vr.getElement() + " " + vr.getMessage());
124    }
125  1 assertEquals(2, validationResults.size());
126   
127  1 System.out.println("test validation on dynamic attributes");
128  1 info.getAttributes().put("finalExamStatus", "123");
129  1 validationResults = val.validateObject(info, os);
130  1 for (ValidationResultInfo vr : validationResults) {
131  3 System.out.println(vr.getElement() + " " + vr.getMessage());
132    }
133  1 assertEquals(3, validationResults.size());
134   
135  1 LoDisplayInfo loInfo = new LoDisplayInfo();
136  1 LoCategoryInfo loCatInfo = new LoCategoryInfo();
137  1 loInfo.setLoCategoryInfoList(Arrays.asList(loCatInfo));
138  1 RichTextInfo rtInfo = new RichTextInfo();
139  1 rtInfo.setPlain("The ability to use sensory cues to guide motor activity. This ranges from sensory stimulation, through cue selection, to translation.");
140  1 rtInfo.setFormatted(rtInfo.getPlain());
141  1 loCatInfo.setDesc(rtInfo);
142  1 info.setCourseSpecificLOs(Arrays.asList(loInfo));
143  1 info.setRevenues(new ArrayList<CourseRevenueInfo>());
144  1 validationResults = val.validateObject(info, os);
145  1 for (ValidationResultInfo vr : validationResults) {
146  3 System.out.println(vr.getElement() + " " + vr.getMessage());
147    }
148  1 assertTrue(rtInfo.getPlain().matches("[A-Za-z0-9.\\\\\\-;:&#34;,'&amp;%$#@!\t\n\r ]*"));
149  1 assertEquals(3, validationResults.size());
150   
151   
152    // Test custom validation
153  1 try {
154  1 info = new CourseDataGenerator().getCourseTestData();
155    } catch (Exception ex) {
156  0 throw new RuntimeException(ex);
157    }
158   
159  1 AffiliatedOrgInfo af1 = new AffiliatedOrgInfo();
160  1 af1.setOrgId("orgId");
161  1 af1.setPercentage(15l);
162   
163  1 AffiliatedOrgInfo af2 = new AffiliatedOrgInfo();
164  1 af2.setOrgId("orgId");
165  1 af2.setPercentage(15l);
166   
167  1 List<AffiliatedOrgInfo> afList = new ArrayList<AffiliatedOrgInfo>();
168  1 afList.add(af1);
169  1 afList.add(af2);
170   
171  1 CourseRevenueInfo cr = new CourseRevenueInfo();
172  1 cr.setFeeType("REVENUE");
173  1 cr.setAffiliatedOrgs(afList);
174   
175   
176  1 AffiliatedOrgInfo af3 = new AffiliatedOrgInfo();
177  1 af3.setOrgId("orgId");
178  1 af3.setPercentage(55l);
179   
180  1 AffiliatedOrgInfo af4 = new AffiliatedOrgInfo();
181  1 af4.setOrgId("orgId");
182  1 af4.setPercentage(45l);
183   
184  1 List<AffiliatedOrgInfo> afList2 = new ArrayList<AffiliatedOrgInfo>();
185  1 afList2.add(af3);
186  1 afList2.add(af4);
187   
188  1 CourseRevenueInfo cr2 = new CourseRevenueInfo();
189  1 cr2.setFeeType("REVENUE");
190  1 cr2.setAffiliatedOrgs(afList2);
191   
192  1 List<CourseRevenueInfo> revenues = new ArrayList<CourseRevenueInfo>();
193  1 revenues.add(cr);
194  1 revenues.add(cr2);
195   
196  1 info.setRevenues(revenues);
197   
198   
199  1 CourseExpenditureInfo cei = new CourseExpenditureInfo();
200  1 cei.setAffiliatedOrgs(afList);
201   
202  1 List<ValidationResultInfo> validationResults1 = val.validateObject(info, os);
203  1 System.out.println("h3. With just a custom validations");
204   
205  1 assertEquals(2, validationResults1.size());
206   
207  1 for(ValidationResultInfo vr : validationResults1) {
208  2 System.out.println(vr.getElement());
209  2 assertTrue("/revenues".equals(vr.getElement()) || "/expenditure/affiliatedOrgs".equals(vr.getElement()));
210    }
211   
212    }
213   
 
214  1 toggle private Validator getActiveDatesValidator() {
215  1 ActiveDatesValidator adv = new ActiveDatesValidator();
216  1 MockProxyFactoryBean b = new MockProxyFactoryBean();
217  1 Map<String,Object> methodReturnMap = new HashMap<String,Object>();
218  1 AtpInfo atpInfo = new AtpInfo();
219  1 atpInfo.setStartDate(new Date());
220  1 atpInfo.setEndDate(new Date());
221  1 methodReturnMap.put("getAtp", atpInfo);
222  1 b.setMethodReturnMap(methodReturnMap);
223   
224  1 b.setInterfaceClass(AtpService.class);
225  1 try {
226  1 adv.setAtpService((AtpService) b.getObject());
227    } catch (Exception e) {
228  0 throw new RuntimeException(e);
229    }
230   
231  1 return adv;
232    }
233   
234    }