1 |
|
package org.kuali.student.lum.program.service.impl; |
2 |
|
|
3 |
|
import static org.junit.Assert.assertEquals; |
4 |
|
import static org.junit.Assert.fail; |
5 |
|
|
6 |
|
import java.util.LinkedHashSet; |
7 |
|
import java.util.List; |
8 |
|
import java.util.Set; |
9 |
|
|
10 |
|
import org.junit.Test; |
11 |
|
import org.kuali.student.common.validator.DefaultValidatorImpl; |
12 |
|
import org.kuali.student.common.validator.ServerDateParser; |
13 |
|
import org.kuali.student.common.validator.ValidatorFactory; |
14 |
|
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
15 |
|
import org.kuali.student.core.dictionary.service.impl.DictionaryTesterHelper; |
16 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
17 |
|
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
18 |
|
import org.kuali.student.lum.course.service.impl.MockSearchDispatcher; |
19 |
|
import org.kuali.student.lum.program.dto.CoreProgramInfo; |
20 |
|
import org.kuali.student.lum.program.dto.CredentialProgramInfo; |
21 |
|
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
22 |
|
import org.kuali.student.lum.program.dto.MinorDisciplineInfo; |
23 |
|
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
24 |
|
import org.kuali.student.lum.program.service.assembler.MajorDisciplineDataGenerator; |
25 |
|
import org.springframework.context.ApplicationContext; |
26 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
27 |
|
|
|
|
| 76.7% |
Uncovered Elements: 10 (43) |
Complexity: 5 |
Complexity Density: 0.13 |
|
28 |
|
public class TestProgramInfoDictionary { |
29 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
30 |
1
|
@Test... |
31 |
|
public void testLoadProgramInfoDictionary() { |
32 |
1
|
Set<String> startingClasses = new LinkedHashSet(); |
33 |
1
|
startingClasses.add(MajorDisciplineInfo.class.getName ()); |
34 |
1
|
startingClasses.add(CoreProgramInfo.class.getName ()); |
35 |
1
|
startingClasses.add(MinorDisciplineInfo.class.getName ()); |
36 |
1
|
startingClasses.add(CredentialProgramInfo.class.getName ()); |
37 |
1
|
startingClasses.add(ProgramRequirementInfo.class.getName ()); |
38 |
1
|
String contextFile = "ks-programInfo-dictionary-context"; |
39 |
1
|
String outFile = "target/" + contextFile + ".txt"; |
40 |
1
|
DictionaryTesterHelper helper = new DictionaryTesterHelper(outFile, |
41 |
|
startingClasses, |
42 |
|
contextFile |
43 |
|
+ ".xml", |
44 |
|
true); |
45 |
1
|
List<String> errors = helper.doTest (); |
46 |
1
|
if (errors.size () > 0) |
47 |
|
{ |
48 |
0
|
fail ("failed dictionary validation:\n" + formatAsString (errors)); |
49 |
|
} |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
52 |
0
|
private String formatAsString (List<String> errors)... |
53 |
|
{ |
54 |
0
|
int i = 0; |
55 |
0
|
StringBuilder builder = new StringBuilder (); |
56 |
0
|
for (String error : errors) |
57 |
|
{ |
58 |
0
|
i ++; |
59 |
0
|
builder.append (i + ". " + error + "\n"); |
60 |
|
} |
61 |
0
|
return builder.toString (); |
62 |
|
} |
63 |
|
|
64 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 2 |
Complexity Density: 0.1 |
1
PASS
|
|
65 |
1
|
@Test... |
66 |
|
public void testMajorDisciplineInfoValidation() throws |
67 |
|
OperationFailedException { |
68 |
1
|
System.out.println("h1. Validation results"); |
69 |
1
|
ApplicationContext ac = new ClassPathXmlApplicationContext( |
70 |
|
"classpath:ks-programInfo-dictionary-context.xml"); |
71 |
1
|
DefaultValidatorImpl val = new DefaultValidatorImpl(); |
72 |
1
|
val.setValidatorFactory(new ValidatorFactory()); |
73 |
1
|
val.setDateParser(new ServerDateParser()); |
74 |
1
|
val.setSearchDispatcher(new MockSearchDispatcher()); |
75 |
1
|
MajorDisciplineInfo info = new MajorDisciplineInfo(); |
76 |
1
|
ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean( |
77 |
|
info.getClass().getName()); |
78 |
1
|
List<ValidationResultInfo> validationResults = val.validateObject(info, os); |
79 |
1
|
System.out.println("h2. with just a blank record"); |
80 |
1
|
for (ValidationResultInfo vr : validationResults) { |
81 |
5
|
System.out.println(vr.getElement() + " " + vr.getMessage()); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
1
|
assertEquals(5, validationResults.size()); |
89 |
|
|
90 |
1
|
try { |
91 |
1
|
info = |
92 |
|
new MajorDisciplineDataGenerator().getMajorDisciplineInfoTestData(); |
93 |
|
} |
94 |
|
catch (Exception ex) { |
95 |
0
|
throw new RuntimeException(ex); |
96 |
|
} |
97 |
1
|
validationResults = val.validateObject(info, os); |
98 |
1
|
System.out.println("h2. with generated data"); |
99 |
1
|
for (ValidationResultInfo vr : validationResults) { |
100 |
18
|
System.out.println(vr.getElement() + " " + vr.getMessage()); |
101 |
|
} |
102 |
|
|
103 |
|
} |
104 |
|
} |