Clover Coverage Report - KS LUM 1.1-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Mar 3 2011 05:27:45 EST
86   199   8   28.67
8   146   0.09   3
3     2.67  
1    
 
  TestMetadataServiceDictionary       Line # 46 86 0% 8 4 95.9% 0.9587629
 
  (1)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15    package org.kuali.student.lum.ui;
16   
17    import java.io.File;
18    import java.io.FileNotFoundException;
19    import java.io.FileOutputStream;
20    import java.io.OutputStream;
21    import java.io.PrintStream;
22    import java.util.ArrayList;
23    import java.util.Date;
24    import java.util.HashSet;
25    import java.util.LinkedHashMap;
26    import java.util.LinkedHashSet;
27    import java.util.List;
28    import java.util.Map;
29    import java.util.Set;
30   
31    import org.junit.Test;
32    import static org.junit.Assert.*;
33    import org.kuali.student.core.assembly.data.Metadata;
34    import org.kuali.student.core.assembly.dictionary.MetadataFormatter;
35    import org.kuali.student.core.assembly.dictionary.MetadataServiceImpl;
36    import org.kuali.student.core.dictionary.service.DictionaryService;
37    import org.kuali.student.core.dictionary.service.impl.DictionaryServiceImpl;
38    import org.kuali.student.core.proposal.dto.ProposalInfo;
39    import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
40    import org.kuali.student.core.statement.dto.ReqComponentInfo;
41    import org.kuali.student.core.statement.dto.StatementInfo;
42    import org.kuali.student.lum.course.dto.CourseInfo;
43    import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
44    import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
45   
 
46    public class TestMetadataServiceDictionary {
47   
 
48  1 toggle @Test
49    public void testMetadataService() {
50  1 Set<String> startingClasses = new LinkedHashSet<String>();
51  1 Map<String, Set<String>> types = new LinkedHashMap<String, Set<String>>();
52  1 startingClasses.add(CourseInfo.class.getName());
53  1 startingClasses.add(MajorDisciplineInfo.class.getName());
54  1 startingClasses.add(ProgramRequirementInfo.class.getName());
55  1 startingClasses.add(ProposalInfo.class.getName());
56  1 startingClasses.add(StatementInfo.class.getName());
57  1 startingClasses.add(ReqComponentInfo.class.getName());
58  1 startingClasses.add(ReqCompFieldInfo.class.getName());
59  1 startingClasses.add("cluset");
60  1 startingClasses.add("courseSet");
61  1 startingClasses.add("programSet");
62  1 startingClasses.add("testSet");
63  1 startingClasses.add("search");
64  1 startingClasses.add("browse");
65   
66    // startingClasses.add (StatementTreeViewInfo.class);
67   
68  1 Set<String> typesForClass = new LinkedHashSet<String>();
69  1 types.put(ReqCompFieldInfo.class.getName(), typesForClass);
70  1 typesForClass.add("kuali.reqComponent.field.type.gpa");
71  1 typesForClass.add("kuali.reqComponent.field.type.operator");
72  1 typesForClass.add("kuali.reqComponent.field.type.clu.id");
73  1 typesForClass.add("kuali.reqComponent.field.type.course.clu.id");
74  1 typesForClass.add("kuali.reqComponent.field.type.program.clu.id");
75  1 typesForClass.add("kuali.reqComponent.field.type.test.clu.id");
76  1 typesForClass.add("kuali.reqComponent.field.type.test.score");
77  1 typesForClass.add("kuali.reqComponent.field.type.cluSet.id");
78  1 typesForClass.add("kuali.reqComponent.field.type.course.cluSet.id");
79  1 typesForClass.add("kuali.reqComponent.field.type.program.cluSet.id");
80  1 typesForClass.add("kuali.reqComponent.field.type.test.cluSet.id");
81  1 typesForClass.add("kuali.reqComponent.field.type.person.id");
82  1 typesForClass.add("kuali.reqComponent.field.type.org.id");
83  1 typesForClass
84    .add("kuali.reqComponent.field.type.value.positive.integer");
85  1 typesForClass.add("kuali.reqComponent.field.type.gradeType.id");
86  1 typesForClass.add("kuali.reqComponent.field.type.grade.id");
87  1 typesForClass.add("kuali.reqComponent.field.type.durationType.id");
88  1 typesForClass.add("kuali.reqComponent.field.type.duration");
89   
90  1 DictionaryService courseDictService = new DictionaryServiceImpl(
91    "classpath:ks-courseInfo-dictionary-context.xml");
92  1 DictionaryService progDictService = new DictionaryServiceImpl(
93    "classpath:ks-programInfo-dictionary-context.xml");
94  1 DictionaryService cluSetDictService = new DictionaryServiceImpl(
95    "classpath:ks-cluSetInfo-dictionary-context.xml");
96   
97  1 for (String objType : cluSetDictService.getObjectTypes()) {
98  5 System.out.println("Cluset has object type=" + objType);
99    }
100   
101  1 DictionaryService proposalDictService = new DictionaryServiceImpl(
102    "classpath:ks-proposalInfo-dictionary-context.xml");
103  1 DictionaryService statementDictService = new DictionaryServiceImpl(
104    "classpath:ks-statement-dictionary-context.xml");
105  1 MetadataServiceImpl metadataService = new MetadataServiceImpl(
106    courseDictService, progDictService, cluSetDictService,
107    proposalDictService, statementDictService);
108  1 metadataService
109    .setUiLookupContext("classpath:lum-ui-lookup-context.xml");
110   
111  1 List<String> errors = new ArrayList<String>();
112  1 for (String className : startingClasses) {
113  13 String outFile = "target/metadata-for-" + className + ".txt";
114  13 File file = new File(outFile);
115  13 OutputStream outputStream = null;
116  13 try {
117  13 outputStream = new FileOutputStream(file, false);
118    } catch (FileNotFoundException ex) {
119  0 throw new RuntimeException(ex);
120    }
121  13 PrintStream out = new PrintStream(outputStream);
122  13 out.println("(!) This page was automatically generated on " + new Date());
123  13 out.println("DO NOT UPDATE MANUALLY!");
124  13 out.println("");
125  13 out.println("This page represents a formatted view of the lum ui dictionary for " + className);
126  13 out.println("");
127  13 out.println("----");
128  13 out.println("{toc}");
129  13 out.println("----");
130    // out.println ("getting meta data for " + className);
131  13 Metadata metadata = metadataService.getMetadata(className);
132  13 assertNotNull(metadata);
133  13 errors.addAll(this.validateMetadata(metadata, className, null));
134  13 MetadataFormatter formatter = new MetadataFormatter(className,
135    metadata, null, null, new HashSet<Metadata>(), 1);
136  13 out.println(formatter.formatForWiki());
137  13 if (types.get(className) == null) {
138  12 continue;
139    }
140  1 for (String type : types.get(className)) {
141  18 System.out.println("*** Generating formatted version for " + type);
142  18 metadata = metadataService.getMetadata(className, type,
143    (String) null);
144  18 assertNotNull(metadata);
145  18 errors.addAll(this.validateMetadata(metadata, className, type));
146  18 formatter = new MetadataFormatter(className, metadata, type,
147    null, new HashSet<Metadata>(), 1);
148  18 out.println(formatter.formatForWiki());
149    }
150  1 out.close();
151    }
152  1 if (errors.size() > 0) {
153  1 for (String error : errors) {
154  30 System.out.println("error: " + error);
155    }
156  1 System.out.println(errors.size() + " errors found when validating metadata");
157   
158    // These first 6 are because the recursion stops but the final field still is flagged as DATA even though it cannot have sub fields
159   
160    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loDisplayInfoList.*.loDisplayInfoList.*.loDisplayInfoList.* is of type DATA but it has no properties
161    //error: org.kuali.student.lum.program.dto.MajorDisciplineInfo.variations.*.learningObjectives.*.loDisplayInfoList.*.loDisplayInfoList.*.loDisplayInfoList.* is of type DATA but it has no properties
162    //error: org.kuali.student.lum.program.dto.MajorDisciplineInfo.orgCoreProgram.learningObjectives.*.loDisplayInfoList.*.loDisplayInfoList.*.loDisplayInfoList.* is of type DATA but it has no properties
163    //error: org.kuali.student.lum.program.dto.MajorDisciplineInfo.learningObjectives.*.loDisplayInfoList.*.loDisplayInfoList.*.loDisplayInfoList.* is of type DATA but it has no properties
164    //error: org.kuali.student.lum.program.dto.ProgramRequirementInfo.statement.statements.*.statements.*.statements.* is of type DATA but it has no properties
165    //error: org.kuali.student.lum.program.dto.ProgramRequirementInfo.learningObjectives.*.loDisplayInfoList.*.loDisplayInfoList.*.loDisplayInfoList.* is of type DATA but it has no properties
166   
167    // These 8 are caused by reusing search params external to the search config file in cross searches.
168    // Need to update dictionary to allow for reuse of external params
169   
170    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byCourse that has a parameter lu.queryParam.luOptionalCode that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
171    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byCourse that has a parameter lu.queryParam.luOptionalDivision that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
172    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byCourse that has a parameter lu.queryParam.luOptionalLevel that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
173    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byCourse that has a parameter lu.queryParam.luOptionalState that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
174    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byCourse that has a parameter lu.queryParam.luOptionalType that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
175    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byProgram that has a parameter lu.queryParam.luOptionalLongName that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
176    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byProgram that has a parameter lu.queryParam.luOptionalState that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
177    //error: org.kuali.student.lum.course.dto.CourseInfo.courseSpecificLOs.*.loInfo.desc has an additional lookup : kuali.lu.lookup.advanced.learningObjectives.byProgram that has a parameter lu.queryParam.luOptionalType that does not exist in the underlying search lo.search.loByCategoryCluCrossSearch
178    //Also 16 similar ones for major discipline and variation lo search.
179   
180    // 30 errors found when validating metadata
181  1 if (errors.size() != 30) {
182  0 fail(errors.size() + " errors found when validating metadata");
183    }
184    }
185    }
186   
187    private MetadataServiceDictionaryValidator validator = null;
188   
 
189  31 toggle private MetadataServiceDictionaryValidator getValidator() {
190  31 if (validator == null) {
191  1 validator = new MetadataServiceDictionaryValidator();
192    }
193  31 return validator;
194    }
195   
 
196  31 toggle private List<String> validateMetadata(Metadata md, String name, String type) {
197  31 return getValidator().validateMetadata(md, name, type);
198    }
199    }