| 1 |
|
package org.kuali.student.core.dictionary.service; |
| 2 |
|
|
| 3 |
|
import java.util.LinkedHashSet; |
| 4 |
|
import java.util.List; |
| 5 |
|
import java.util.Set; |
| 6 |
|
import org.junit.Test; |
| 7 |
|
import org.kuali.student.common.validator.DefaultValidatorImpl; |
| 8 |
|
import org.kuali.student.common.validator.ServerDateParser; |
| 9 |
|
import org.kuali.student.core.atp.dto.AtpInfo; |
| 10 |
|
import org.kuali.student.core.atp.dto.DateRangeInfo; |
| 11 |
|
import org.kuali.student.core.atp.dto.MilestoneInfo; |
| 12 |
|
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
| 13 |
|
import org.kuali.student.core.dictionary.service.impl.DictionaryTesterHelper; |
| 14 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
| 15 |
|
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
| 16 |
|
import org.springframework.context.ApplicationContext; |
| 17 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 18 |
|
import static org.junit.Assert.*; |
| 19 |
|
|
|
|
|
| 73.5% |
Uncovered Elements: 9 (34) |
Complexity: 4 |
Complexity Density: 0.14 |
|
| 20 |
|
public class TestAtpDictionary { |
| 21 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
| 22 |
1
|
@Test... |
| 23 |
|
public void testLoadAtpDictionary() { |
| 24 |
1
|
System.out.println ("testing atp dictionary"); |
| 25 |
1
|
Set<String> startingClasses = new LinkedHashSet(); |
| 26 |
1
|
startingClasses.add(AtpInfo.class.getName ()); |
| 27 |
1
|
startingClasses.add(MilestoneInfo.class.getName ()); |
| 28 |
1
|
startingClasses.add(DateRangeInfo.class.getName ()); |
| 29 |
1
|
String contextFile = "ks-atp-dictionary-context"; |
| 30 |
1
|
String outFile = "target/" + contextFile + ".txt"; |
| 31 |
1
|
DictionaryTesterHelper helper = new DictionaryTesterHelper(outFile, |
| 32 |
|
startingClasses, contextFile + ".xml", false); |
| 33 |
1
|
List<String> errors = helper.doTest (); |
| 34 |
1
|
if (errors.size () > 0) |
| 35 |
|
{ |
| 36 |
0
|
fail ("failed dictionary validation:\n" + formatAsString (errors)); |
| 37 |
|
} |
| 38 |
|
} |
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 40 |
0
|
private String formatAsString (List<String> errors)... |
| 41 |
|
{ |
| 42 |
0
|
int i = 0; |
| 43 |
0
|
StringBuilder builder = new StringBuilder (); |
| 44 |
0
|
for (String error : errors) |
| 45 |
|
{ |
| 46 |
0
|
i ++; |
| 47 |
0
|
builder.append (i + ". " + error + "\n"); |
| 48 |
|
} |
| 49 |
0
|
return builder.toString (); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
| 53 |
1
|
@Test... |
| 54 |
|
public void testAtpInfoValidation() throws OperationFailedException { |
| 55 |
1
|
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:ks-atp-dictionary-context.xml"); |
| 56 |
1
|
System.out.println("h2. Validation Test"); |
| 57 |
1
|
DefaultValidatorImpl val = new DefaultValidatorImpl(); |
| 58 |
1
|
val.setDateParser(new ServerDateParser()); |
| 59 |
1
|
val.setSearchDispatcher(new MockSearchDispatcher()); |
| 60 |
1
|
AtpInfo info = new AtpInfo (); |
| 61 |
1
|
ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean(info.getClass().getName()); |
| 62 |
1
|
List<ValidationResultInfo> validationResults = val.validateObject(info, os); |
| 63 |
1
|
System.out.println("h3. With just a blank StatementInfo"); |
| 64 |
1
|
for (ValidationResultInfo vr : validationResults) |
| 65 |
|
{ |
| 66 |
3
|
System.out.println (vr.getElement () + " " + vr.getMessage ()); |
| 67 |
|
} |
| 68 |
1
|
assertEquals(3, validationResults.size()); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
} |