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