Clover Coverage Report - KS LUM Impl 1.2-M4-SNAPSHOT
Coverage timestamp: Wed Jul 20 2011 13:49:35 EDT
39   130   4   13
2   81   0.1   3
3     1.33  
1    
 
  TestCluInfoDictionary       Line # 21 39 0% 4 9 79.5% 0.79545456
 
  (2)
 
1    package org.kuali.student.lum.course.service.impl;
2   
3    import java.util.LinkedHashSet;
4    import java.util.List;
5    import java.util.Set;
6    import org.junit.Test;
7    import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
8    import org.kuali.student.common.dictionary.service.impl.DictionaryTesterHelper;
9    import org.kuali.student.common.dto.AmountInfo;
10    import org.kuali.student.common.dto.TimeAmountInfo;
11    import org.kuali.student.common.exceptions.OperationFailedException;
12    import org.kuali.student.common.validation.dto.ValidationResultInfo;
13    import org.kuali.student.common.validator.DefaultValidatorImpl;
14    import org.kuali.student.common.validator.ServerDateParser;
15    import org.kuali.student.lum.lu.dto.CluIdentifierInfo;
16    import org.kuali.student.lum.lu.dto.CluInfo;
17    import org.springframework.context.ApplicationContext;
18    import org.springframework.context.support.ClassPathXmlApplicationContext;
19    import static org.junit.Assert.*;
20   
 
21    public class TestCluInfoDictionary
22    {
23   
 
24  1 toggle @Test
25    public void testLoadCluInfoDictionary ()
26    {
27  1 Set<String> startingClasses = new LinkedHashSet ();
28  1 startingClasses.add (CluInfo.class.getName ());
29    // startingClasses.add (CluCluRelationInfo.class.getName ());
30  1 String contextFile = "ks-cluInfo-dictionary-context";
31  1 String outFile = "target/" + contextFile + ".txt";
32  1 DictionaryTesterHelper helper = new DictionaryTesterHelper (outFile,
33    startingClasses,
34    contextFile
35    + ".xml",
36    false);
37  1 List<String> errors = helper.doTest ();
38  1 if (errors.size () > 0)
39    {
40  0 fail ("failed dictionary validation:\n" + formatAsString (errors));
41    }
42    }
43   
 
44  0 toggle private String formatAsString (List<String> errors)
45    {
46  0 int i = 0;
47  0 StringBuilder builder = new StringBuilder ();
48  0 for (String error : errors)
49    {
50  0 i ++;
51  0 builder.append (i + ". " + error + "\n");
52    }
53  0 return builder.toString ();
54    }
55   
56   
 
57  1 toggle @Test
58    public void testCluInfoValidation () throws OperationFailedException
59    {
60  1 ApplicationContext ac = new ClassPathXmlApplicationContext (
61    "classpath:ks-cluInfo-dictionary-context.xml");
62  1 System.out.println ("h2. Validation Test");
63  1 DefaultValidatorImpl val = new DefaultValidatorImpl ();
64  1 val.setDateParser (new ServerDateParser ());
65  1 val.setSearchDispatcher (new MockSearchDispatcher ());
66  1 CluInfo info = new CluInfo ();
67  1 ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean (
68    info.getClass ().getName ());
69  1 List<ValidationResultInfo> validationResults = val.validateObject (info, os);
70  1 System.out.println ("h3. With just a blank CluInfo");
71    // for (ValidationResultInfo vr : validationResults)
72    // {
73    // System.out.println (vr.getElement () + " " + vr.getMessage ());
74    // }
75  1 assertEquals (2, validationResults.size ());
76   
77    // test that we validate substructures
78  1 info.setOfficialIdentifier (new CluIdentifierInfo ());
79  1 validationResults = val.validateObject (info, os);
80    // for (ValidationResultInfo vr : validationResults)
81    // {
82    // System.out.println (vr.getElement () + " " + vr.getMessage ());
83    // }
84    // should now require type and state of the identifier structure too
85  1 assertEquals (4, validationResults.size ());
86   
87   
88    // test that we can put completely blank timeAmountInfo structures
89  1 info.setStdDuration (new TimeAmountInfo ());
90  1 validationResults = val.validateObject (info, os);
91    // for (ValidationResultInfo vr : validationResults)
92    // {
93    // System.out.println (vr.getElement () + " " + vr.getMessage ());
94    // }
95  1 assertEquals (4, validationResults.size ());
96   
97    // test the requires constraint
98    // that requires a durationType if we have a timeQuantity
99  1 info.getStdDuration ().setTimeQuantity (1);
100  1 validationResults = val.validateObject (info, os);
101    // for (ValidationResultInfo vr : validationResults)
102    // {
103    // System.out.println (vr.getElement () + " " + vr.getMessage ());
104    // }
105  1 assertEquals (6, validationResults.size ());
106   
107    // test that we can put completely blank timeAmountInfo structures
108  1 info.setIntensity (new AmountInfo ());
109  1 validationResults = val.validateObject (info, os);
110    // System.out.println ("validation results adding a blank CluIdentifierInfo");
111    // for (ValidationResultInfo vr : validationResults)
112    // {
113    // System.out.println (vr.getElement () + " " + vr.getMessage ());
114    // }
115  1 assertEquals (6, validationResults.size ());
116   
117    // test the requires constraint
118    // that requires a unity if we have a unitQuantity
119  1 info.getIntensity ().setUnitQuantity ("1");
120  1 validationResults = val.validateObject (info, os);
121    // System.out.println ("validation results adding a blank CluIdentifierInfo");
122    // for (ValidationResultInfo vr : validationResults)
123    // {
124    // System.out.println (vr.getElement () + " " + vr.getMessage ());
125    // }
126  1 assertEquals (8, validationResults.size ());
127   
128   
129    }
130    }