| 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 |
|
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 |
|
|
|
|
|
| 95.9% |
Uncovered Elements: 4 (97) |
Complexity: 8 |
Complexity Density: 0.09 |
|
| 46 |
|
public class TestMetadataServiceDictionary { |
| 47 |
|
|
|
|
|
| 95.5% |
Uncovered Elements: 4 (88) |
Complexity: 5 |
Complexity Density: 0.06 |
1
PASS
|
|
| 48 |
1
|
@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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 189 |
31
|
private MetadataServiceDictionaryValidator getValidator() {... |
| 190 |
31
|
if (validator == null) { |
| 191 |
1
|
validator = new MetadataServiceDictionaryValidator(); |
| 192 |
|
} |
| 193 |
31
|
return validator; |
| 194 |
|
} |
| 195 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 196 |
31
|
private List<String> validateMetadata(Metadata md, String name, String type) {... |
| 197 |
31
|
return getValidator().validateMetadata(md, name, type); |
| 198 |
|
} |
| 199 |
|
} |