1
2
3
4
5
6
7
8
9
10
11
12
13
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
34 import org.kuali.student.common.assembly.data.Metadata;
35 import org.kuali.student.common.assembly.dictionary.MetadataFormatter;
36 import org.kuali.student.common.assembly.dictionary.MetadataServiceImpl;
37 import org.kuali.student.common.dictionary.service.DictionaryService;
38 import org.kuali.student.common.dictionary.service.impl.DictionaryServiceImpl;
39 import org.kuali.student.core.proposal.dto.ProposalInfo;
40 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
41 import org.kuali.student.core.statement.dto.ReqComponentInfo;
42 import org.kuali.student.core.statement.dto.StatementInfo;
43 import org.kuali.student.lum.course.dto.CourseInfo;
44 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
45 import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
46
47 public class TestMetadataServiceDictionary {
48
49 @Test
50 public void testMetadataService() {
51 Set<String> startingClasses = new LinkedHashSet<String>();
52 Map<String, Set<String>> types = new LinkedHashMap<String, Set<String>>();
53 startingClasses.add(CourseInfo.class.getName());
54 startingClasses.add(MajorDisciplineInfo.class.getName());
55 startingClasses.add(ProgramRequirementInfo.class.getName());
56 startingClasses.add(ProposalInfo.class.getName());
57 startingClasses.add(StatementInfo.class.getName());
58 startingClasses.add(ReqComponentInfo.class.getName());
59 startingClasses.add(ReqCompFieldInfo.class.getName());
60 startingClasses.add("cluset");
61 startingClasses.add("courseSet");
62 startingClasses.add("programSet");
63 startingClasses.add("testSet");
64 startingClasses.add("search");
65 startingClasses.add("browse");
66
67
68
69 Set<String> typesForClass = new LinkedHashSet<String>();
70 types.put(ReqCompFieldInfo.class.getName(), typesForClass);
71 typesForClass.add("kuali.reqComponent.field.type.gpa");
72 typesForClass.add("kuali.reqComponent.field.type.operator");
73 typesForClass.add("kuali.reqComponent.field.type.clu.id");
74 typesForClass.add("kuali.reqComponent.field.type.course.clu.id");
75 typesForClass.add("kuali.reqComponent.field.type.program.clu.id");
76 typesForClass.add("kuali.reqComponent.field.type.test.clu.id");
77 typesForClass.add("kuali.reqComponent.field.type.test.score");
78 typesForClass.add("kuali.reqComponent.field.type.cluSet.id");
79 typesForClass.add("kuali.reqComponent.field.type.course.cluSet.id");
80 typesForClass.add("kuali.reqComponent.field.type.program.cluSet.id");
81 typesForClass.add("kuali.reqComponent.field.type.test.cluSet.id");
82 typesForClass.add("kuali.reqComponent.field.type.person.id");
83 typesForClass.add("kuali.reqComponent.field.type.org.id");
84 typesForClass
85 .add("kuali.reqComponent.field.type.value.positive.integer");
86 typesForClass.add("kuali.reqComponent.field.type.gradeType.id");
87 typesForClass.add("kuali.reqComponent.field.type.grade.id");
88 typesForClass.add("kuali.reqComponent.field.type.durationType.id");
89 typesForClass.add("kuali.reqComponent.field.type.duration");
90
91 DictionaryService courseDictService = new DictionaryServiceImpl(
92 "classpath:ks-courseInfo-dictionary-context.xml");
93 DictionaryService progDictService = new DictionaryServiceImpl(
94 "classpath:ks-programInfo-dictionary-context.xml");
95 DictionaryService cluSetDictService = new DictionaryServiceImpl(
96 "classpath:ks-cluSetInfo-dictionary-context.xml");
97
98 for (String objType : cluSetDictService.getObjectTypes()) {
99 System.out.println("Cluset has object type=" + objType);
100 }
101
102 DictionaryService proposalDictService = new DictionaryServiceImpl(
103 "classpath:ks-proposalInfo-dictionary-context.xml");
104 DictionaryService statementDictService = new DictionaryServiceImpl(
105 "classpath:ks-statement-dictionary-context.xml");
106 MetadataServiceImpl metadataService = new MetadataServiceImpl(
107 courseDictService, progDictService, cluSetDictService,
108 proposalDictService, statementDictService);
109 metadataService
110 .setUiLookupContext("classpath:lum-ui-lookup-context.xml");
111
112 List<String> errors = new ArrayList<String>();
113 for (String className : startingClasses) {
114 String outFile = "target/metadata-for-" + className + ".txt";
115 File file = new File(outFile);
116 OutputStream outputStream = null;
117 try {
118 outputStream = new FileOutputStream(file, false);
119 } catch (FileNotFoundException ex) {
120 throw new RuntimeException(ex);
121 }
122 PrintStream out = new PrintStream(outputStream);
123 out.println("(!) This page was automatically generated on " + new Date());
124 out.println("DO NOT UPDATE MANUALLY!");
125 out.println("");
126 out.println("This page represents a formatted view of the lum ui dictionary for " + className);
127 out.println("");
128 out.println("----");
129 out.println("{toc}");
130 out.println("----");
131
132 Metadata metadata = metadataService.getMetadata(className);
133 assertNotNull(metadata);
134 errors.addAll(this.validateMetadata(metadata, className, null));
135 MetadataFormatter formatter = new MetadataFormatter(className,
136 metadata, null, null, new HashSet<Metadata>(), 1);
137 out.println(formatter.formatForWiki());
138 if (types.get(className) == null) {
139 continue;
140 }
141 for (String type : types.get(className)) {
142 System.out.println("*** Generating formatted version for " + type);
143 metadata = metadataService.getMetadata(className, type,
144 (String) null);
145 assertNotNull(metadata);
146 errors.addAll(this.validateMetadata(metadata, className, type));
147 formatter = new MetadataFormatter(className, metadata, type,
148 null, new HashSet<Metadata>(), 1);
149 out.println(formatter.formatForWiki());
150 }
151 out.close();
152 }
153 if (errors.size() > 0) {
154 for (String error : errors) {
155 System.out.println("error: " + error);
156 }
157 System.out.println(errors.size() + " errors found when validating metadata");
158
159
160
161
162
163
164
165
166
167
168
169
170 if (errors.size() != 29) {
171 fail(errors.size() + " errors found when validating metadata");
172 }
173 }
174 }
175
176 private MetadataServiceDictionaryValidator validator = null;
177
178 private MetadataServiceDictionaryValidator getValidator() {
179 if (validator == null) {
180 validator = new MetadataServiceDictionaryValidator();
181 }
182 return validator;
183 }
184
185 private List<String> validateMetadata(Metadata md, String name, String type) {
186 return getValidator().validateMetadata(md, name, type);
187 }
188 }