Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
34   92   9   6.8
8   66   0.26   5
5     1.8  
1    
 
  DictionaryTesterHelper       Line # 27 34 0% 9 47 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.kuali.student.datadictionary.util;
17   
18    import java.util.ArrayList;
19    import java.util.HashSet;
20    import java.util.List;
21    import java.util.Map;
22    import java.util.Set;
23    import org.kuali.rice.krad.datadictionary.DataObjectEntry;
24    import org.springframework.context.ApplicationContext;
25    import org.springframework.context.support.ClassPathXmlApplicationContext;
26   
 
27    public class DictionaryTesterHelper {
28   
29    private String outputDir;
30    private Set<String> configFiles;
31    private ApplicationContext ac = null;
32   
 
33  0 toggle public DictionaryTesterHelper(String outputDir,
34    Set<String> configFiles) {
35  0 this.outputDir = outputDir;
36  0 this.configFiles = configFiles;
37    }
38   
 
39  0 toggle public void loadApplicationContext() {
40  0 System.out.println ("DictionaryTesterHelper: begin loading application context");
41  0 List<String> configLocations = new ArrayList(configFiles);
42    // System.out.println ("DictionaryTesterHelper: adding " + supportFiles.size() + " support files");
43    // configLocations.add("classpath:" + dictFileName);
44  0 String[] configLocs = configLocations.toArray(new String[0]);
45  0 ac = new ClassPathXmlApplicationContext(configLocs);
46  0 System.out.println ("DictionaryTesterHelper: end loading application context");
47    }
48   
 
49  0 toggle public Map<String, DataObjectEntry> getDataObjectEntryBeans () {
50  0 return (Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class);
51    }
52   
 
53  0 toggle public List<String> doTest() {
54  0 List<String> outputFileNames = new ArrayList();
55  0 if (ac == null) {
56  0 loadApplicationContext ();
57    }
58  0 Map<String, DataObjectEntry> beansOfType = this.getDataObjectEntryBeans();
59   
60  0 for (String beanId : beansOfType.keySet()) {
61  0 DataObjectEntry doe = beansOfType.get(beanId);
62  0 if ("org.kuali.rice.krad.bo.AttributeReferenceDummy".equals(doe.getFullClassName())) {
63  0 continue;
64    }
65  0 System.out.println("Processing data object entry: " + doe.getDataObjectClass().getName());
66  0 DictionaryValidator validator = new DictionaryValidator(doe, new HashSet());
67  0 List<String> errors = validator.validate();
68  0 if (errors != null) {
69  0 if (!errors.isEmpty()) {
70  0 throw new IllegalArgumentException("Errors validating bean "
71    + beanId + "\n" + this.formatAsString(errors));
72    }
73    }
74  0 String outputFileName = beanId + ".html";
75  0 outputFileNames.add(outputFileName);
76  0 String fullOutputFileName = this.outputDir + "/" + outputFileName;
77  0 DictionaryFormatter formatter = new DictionaryFormatter(doe, beansOfType, beanId, fullOutputFileName);
78  0 formatter.formatForHtml();
79    }
80  0 return outputFileNames;
81    }
82   
 
83  0 toggle private String formatAsString(List<String> errors) {
84  0 int i = 0;
85  0 StringBuilder builder = new StringBuilder();
86  0 for (String error : errors) {
87  0 i++;
88  0 builder.append(i).append(". ").append(error).append("\n");
89    }
90  0 return builder.toString();
91    }
92    }