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.ArrayList; |
7 |
|
import java.util.LinkedHashSet; |
8 |
|
import java.util.List; |
9 |
|
import java.util.Set; |
10 |
|
|
11 |
|
import org.apache.cxf.service.model.MessageInfo; |
12 |
|
import org.junit.Test; |
13 |
|
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
14 |
|
import org.kuali.student.common.dictionary.service.impl.DictionaryTesterHelper; |
15 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
16 |
|
import org.kuali.student.common.messages.dto.LocaleKeyList; |
17 |
|
import org.kuali.student.common.messages.dto.Message; |
18 |
|
import org.kuali.student.common.messages.dto.MessageGroupKeyList; |
19 |
|
import org.kuali.student.common.messages.dto.MessageList; |
20 |
|
import org.kuali.student.common.messages.service.MessageService; |
21 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
22 |
|
import org.kuali.student.common.validator.DefaultValidatorImpl; |
23 |
|
import org.kuali.student.common.validator.ServerDateParser; |
24 |
|
import org.kuali.student.common.validator.Validator; |
25 |
|
import org.kuali.student.common.validator.ValidatorFactory; |
26 |
|
import org.kuali.student.core.messages.service.impl.MessageServiceMock; |
27 |
|
import org.kuali.student.lum.course.service.impl.MockSearchDispatcher; |
28 |
|
import org.kuali.student.lum.program.dto.CoreProgramInfo; |
29 |
|
import org.kuali.student.lum.program.dto.CredentialProgramInfo; |
30 |
|
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
31 |
|
import org.kuali.student.lum.program.dto.MinorDisciplineInfo; |
32 |
|
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
33 |
|
import org.kuali.student.lum.program.service.assembler.MajorDisciplineDataGenerator; |
34 |
|
import org.kuali.student.lum.program.service.validation.ProgramManagingBodiesValidator; |
35 |
|
import org.springframework.context.ApplicationContext; |
36 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
37 |
|
|
|
|
| 82.1% |
Uncovered Elements: 10 (56) |
Complexity: 5 |
Complexity Density: 0.1 |
|
38 |
|
public class TestProgramInfoDictionary { |
39 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
40 |
1
|
@Test... |
41 |
|
public void testLoadProgramInfoDictionary() { |
42 |
1
|
Set<String> startingClasses = new LinkedHashSet(); |
43 |
1
|
startingClasses.add(MajorDisciplineInfo.class.getName ()); |
44 |
1
|
startingClasses.add(CoreProgramInfo.class.getName ()); |
45 |
1
|
startingClasses.add(MinorDisciplineInfo.class.getName ()); |
46 |
1
|
startingClasses.add(CredentialProgramInfo.class.getName ()); |
47 |
1
|
startingClasses.add(ProgramRequirementInfo.class.getName ()); |
48 |
1
|
String contextFile = "ks-programInfo-dictionary-context"; |
49 |
1
|
String outFile = "target/" + contextFile + ".txt"; |
50 |
1
|
DictionaryTesterHelper helper = new DictionaryTesterHelper(outFile, |
51 |
|
startingClasses, |
52 |
|
contextFile |
53 |
|
+ ".xml", |
54 |
|
true); |
55 |
1
|
List<String> errors = helper.doTest (); |
56 |
1
|
if (errors.size () > 0) |
57 |
|
{ |
58 |
0
|
fail ("failed dictionary validation:\n" + formatAsString (errors)); |
59 |
|
} |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
62 |
0
|
private String formatAsString (List<String> errors)... |
63 |
|
{ |
64 |
0
|
int i = 0; |
65 |
0
|
StringBuilder builder = new StringBuilder (); |
66 |
0
|
for (String error : errors) |
67 |
|
{ |
68 |
0
|
i ++; |
69 |
0
|
builder.append (i + ". " + error + "\n"); |
70 |
|
} |
71 |
0
|
return builder.toString (); |
72 |
|
} |
73 |
|
|
74 |
|
|
|
|
| 97% |
Uncovered Elements: 1 (33) |
Complexity: 2 |
Complexity Density: 0.06 |
1
PASS
|
|
75 |
1
|
@Test... |
76 |
|
public void testMajorDisciplineInfoValidation() throws |
77 |
|
OperationFailedException { |
78 |
1
|
System.out.println("h1. Validation results"); |
79 |
1
|
ApplicationContext ac = new ClassPathXmlApplicationContext( |
80 |
|
"classpath:ks-programInfo-dictionary-context.xml"); |
81 |
1
|
DefaultValidatorImpl val = new DefaultValidatorImpl(); |
82 |
1
|
val.setValidatorFactory(new ValidatorFactory()); |
83 |
1
|
ProgramManagingBodiesValidator programManagingBodiesValidator = new ProgramManagingBodiesValidator(); |
84 |
1
|
MessageServiceMock messageServiceMock = new MessageServiceMock(); |
85 |
1
|
Message message = new Message(); |
86 |
1
|
message.setGroupName("validation"); |
87 |
1
|
message.setLocale("en"); |
88 |
1
|
message.setId("validation.programManagingBodiesMatch"); |
89 |
1
|
message.setValue("validation.programManagingBodiesMatch"); |
90 |
1
|
messageServiceMock.addMessage(message); |
91 |
1
|
programManagingBodiesValidator.setMessageService(messageServiceMock); |
92 |
1
|
programManagingBodiesValidator.setSearchDispatcher(new MockSearchDispatcher()); |
93 |
1
|
List<Validator> validatorList = new ArrayList<Validator>(); |
94 |
1
|
validatorList.add(programManagingBodiesValidator); |
95 |
1
|
val.getValidatorFactory().setValidatorList(validatorList); |
96 |
1
|
val.setDateParser(new ServerDateParser()); |
97 |
1
|
val.setSearchDispatcher(new MockSearchDispatcher()); |
98 |
1
|
MajorDisciplineInfo info = new MajorDisciplineInfo(); |
99 |
1
|
ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean( |
100 |
|
info.getClass().getName()); |
101 |
1
|
List<ValidationResultInfo> validationResults = val.validateObject(info, os); |
102 |
1
|
System.out.println("h2. with just a blank record"); |
103 |
1
|
for (ValidationResultInfo vr : validationResults) { |
104 |
5
|
System.out.println(vr.getElement() + " " + vr.getMessage()); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
1
|
assertEquals(5, validationResults.size()); |
112 |
|
|
113 |
1
|
try { |
114 |
1
|
info = |
115 |
|
new MajorDisciplineDataGenerator().getMajorDisciplineInfoTestData(); |
116 |
|
} |
117 |
|
catch (Exception ex) { |
118 |
0
|
throw new RuntimeException(ex); |
119 |
|
} |
120 |
1
|
validationResults = val.validateObject(info, os); |
121 |
1
|
System.out.println("h2. with generated data"); |
122 |
1
|
for (ValidationResultInfo vr : validationResults) { |
123 |
18
|
System.out.println(vr.getElement() + " " + vr.getMessage()); |
124 |
|
} |
125 |
|
|
126 |
|
} |
127 |
|
} |