Clover Coverage Report - Kuali Student 1.2-M3-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Jun 6 2011 05:02:46 EDT
../../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
59   167   11   11.8
10   147   0.19   5
5     2.2  
1    
 
  DictionaryTesterHelper       Line # 21 59 0% 11 5 93.2% 0.9324324
 
  (14)
 
1    package org.kuali.student.common.dictionary.service.impl;
2   
3    import java.io.File;
4    import java.io.FileNotFoundException;
5    import java.io.FileOutputStream;
6    import java.io.OutputStream;
7    import java.io.PrintStream;
8    import java.util.ArrayList;
9    import java.util.Date;
10    import java.util.HashMap;
11    import java.util.HashSet;
12    import java.util.LinkedHashSet;
13    import java.util.List;
14    import java.util.Map;
15    import java.util.Set;
16   
17    import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
18    import org.springframework.context.ApplicationContext;
19    import org.springframework.context.support.ClassPathXmlApplicationContext;
20   
 
21    public class DictionaryTesterHelper
22    {
23   
24    private String outputFileName;
25    private File file;
26    private OutputStream outputStream;
27    private PrintStream out;
28    private Set<String> startingClasses;
29    private String dictFileName;
30    private boolean processSubstructures = false;
31   
 
32  14 toggle public DictionaryTesterHelper (String outputFileName,
33    Set<String> startingClasses,
34    String dictFileName,
35    boolean processSubstructures)
36    {
37  14 this.outputFileName = outputFileName;
38  14 this.startingClasses = startingClasses;
39  14 this.dictFileName = dictFileName;
40  14 this.processSubstructures = processSubstructures;
41    // get printstream from file
42  14 this.file = new File (this.outputFileName);
43  14 try
44    {
45  14 outputStream = new FileOutputStream (file, false);
46    }
47    catch (FileNotFoundException ex)
48    {
49  0 throw new IllegalArgumentException (ex);
50    }
51  14 this.out = new PrintStream (outputStream);
52    }
53   
54    private transient Map<String, ObjectStructureDefinition> objectStructures;
55   
 
56  14 toggle public List<String> doTest ()
57    {
58  14 ApplicationContext ac = new ClassPathXmlApplicationContext (
59    "classpath:" + dictFileName);
60  14 objectStructures = new HashMap ();
61  14 Map<String, ObjectStructureDefinition> beansOfType =
62    (Map<String, ObjectStructureDefinition>) ac.
63    getBeansOfType (ObjectStructureDefinition.class);
64  14 for (ObjectStructureDefinition objStr: beansOfType.values ())
65    {
66  220 objectStructures.put (objStr.getName (), objStr);
67  220 System.out.println ("Loading object structure: " + objStr.getName ());
68    }
69    // First validate all the starting classes
70  14 for (String className: startingClasses)
71    {
72  33 ObjectStructureDefinition os = null;
73  33 os = objectStructures.get (className);
74  33 if (os == null)
75    {
76  0 throw new RuntimeException ("className is not defined in dictionary: " + className);
77    }
78  33 DictionaryValidator validator = new DictionaryValidator (os,
79    new HashSet (),
80    false);
81  33 List<String> errors = validator.validate ();
82  33 if (errors.size () > 0)
83    {
84  0 return errors;
85    }
86    }
87   
88   
89  14 Set<String> allStructures = new LinkedHashSet ();
90  14 for (String className: startingClasses)
91    {
92  33 allStructures.addAll (getComplexSubStructures (className));
93    }
94  14 Set<String> classesToProcess = null;
95  14 if (this.processSubstructures)
96    {
97  4 classesToProcess = startingClasses;
98    // System.out.println ("Processing just the starting classes but then processing their substructures in-line");
99    }
100    else
101    {
102  10 classesToProcess = allStructures;
103    // System.out.println ("Processing all substructures as separate entitiies");
104    }
105   
106  14 out.println ("(!) This page was automatically generated on " + new Date ());
107  14 out.println ("DO NOT UPDATE MANUALLY!");
108  14 out.println ("");
109  14 out.print ("This page represents a formatted view of [" + dictFileName
110    + "|https://test.kuali.org/svn/student/trunk/ks-lum/ks-lum-impl/src/main/resources/"
111    + dictFileName + "]");
112  14 out.println (
113    " and is compared to the following java classes (and their sub-classes) for discrepancies:");
114  14 for (String className: startingClasses)
115    {
116  33 out.println ("# " + className);
117    }
118  14 out.println ("");
119  14 out.println ("----");
120  14 out.println ("{toc}");
121  14 out.println ("----");
122  14 for (String className: classesToProcess)
123    {
124    // System.out.println ("processing class " + clazz.getSimpleName ());
125  61 doTestOnClass (className, ac);
126    }
127  14 out.close ();
128  14 return new ArrayList ();
129    }
130   
 
131  33 toggle private Set<String> getComplexSubStructures (String className)
132    {
133  33 return new ComplexSubstructuresHelper ().getComplexStructures (className);
134    }
135   
 
136  61 toggle private void doTestOnClass (String className, ApplicationContext ac)
137    {
138  61 ObjectStructureDefinition os = os = objectStructures.get (className);
139  61 String simpleName = calcSimpleName (className);
140  61 if (os == null)
141    {
142   
143  2 out.println ("h1. " + simpleName);
144  2 out.println ("{anchor:" + simpleName + "}");
145  2 out.println ("h2. Error could not find a corresponding dictionary definition");
146  2 return;
147    }
148  59 DictionaryFormatter formatter =
149    new DictionaryFormatter (className,
150    className,
151    os,
152    new HashSet (),
153    1, // header level to start at
154    this.processSubstructures);
155  59 out.println (formatter.formatForWiki ());
156    }
157   
 
158  61 toggle private String calcSimpleName (String name)
159    {
160  61 if (name.lastIndexOf (".") != -1)
161    {
162  55 name = name.substring (name.lastIndexOf (".") + 1);
163    }
164  61 return name;
165    }
166   
167    }