| 1 |
|
package org.kuali.student.lum.course.service.impl; |
| 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.dictionary.dto.ObjectStructureDefinition; |
| 8 |
|
import org.kuali.student.common.dictionary.service.impl.DictionaryTesterHelper; |
| 9 |
|
import org.kuali.student.common.dto.AmountInfo; |
| 10 |
|
import org.kuali.student.common.dto.TimeAmountInfo; |
| 11 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
| 12 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 13 |
|
import org.kuali.student.common.validator.DefaultValidatorImpl; |
| 14 |
|
import org.kuali.student.common.validator.ServerDateParser; |
| 15 |
|
import org.kuali.student.lum.lu.dto.CluIdentifierInfo; |
| 16 |
|
import org.kuali.student.lum.lu.dto.CluInfo; |
| 17 |
|
import org.springframework.context.ApplicationContext; |
| 18 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 19 |
|
import static org.junit.Assert.*; |
| 20 |
|
|
|
|
|
| 79.5% |
Uncovered Elements: 9 (44) |
Complexity: 4 |
Complexity Density: 0.1 |
|
| 21 |
|
public class TestCluInfoDictionary |
| 22 |
|
{ |
| 23 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
1
PASS
|
|
| 24 |
1
|
@Test... |
| 25 |
|
public void testLoadCluInfoDictionary () |
| 26 |
|
{ |
| 27 |
1
|
Set<String> startingClasses = new LinkedHashSet (); |
| 28 |
1
|
startingClasses.add (CluInfo.class.getName ()); |
| 29 |
|
|
| 30 |
1
|
String contextFile = "ks-cluInfo-dictionary-context"; |
| 31 |
1
|
String outFile = "target/" + contextFile + ".txt"; |
| 32 |
1
|
DictionaryTesterHelper helper = new DictionaryTesterHelper (outFile, |
| 33 |
|
startingClasses, |
| 34 |
|
contextFile |
| 35 |
|
+ ".xml", |
| 36 |
|
false); |
| 37 |
1
|
List<String> errors = helper.doTest (); |
| 38 |
1
|
if (errors.size () > 0) |
| 39 |
|
{ |
| 40 |
0
|
fail ("failed dictionary validation:\n" + formatAsString (errors)); |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 44 |
0
|
private String formatAsString (List<String> errors)... |
| 45 |
|
{ |
| 46 |
0
|
int i = 0; |
| 47 |
0
|
StringBuilder builder = new StringBuilder (); |
| 48 |
0
|
for (String error : errors) |
| 49 |
|
{ |
| 50 |
0
|
i ++; |
| 51 |
0
|
builder.append (i + ". " + error + "\n"); |
| 52 |
|
} |
| 53 |
0
|
return builder.toString (); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1
PASS
|
|
| 57 |
1
|
@Test... |
| 58 |
|
public void testCluInfoValidation () throws OperationFailedException |
| 59 |
|
{ |
| 60 |
1
|
ApplicationContext ac = new ClassPathXmlApplicationContext ( |
| 61 |
|
"classpath:ks-cluInfo-dictionary-context.xml"); |
| 62 |
1
|
System.out.println ("h2. Validation Test"); |
| 63 |
1
|
DefaultValidatorImpl val = new DefaultValidatorImpl (); |
| 64 |
1
|
val.setDateParser (new ServerDateParser ()); |
| 65 |
1
|
val.setSearchDispatcher (new MockSearchDispatcher ()); |
| 66 |
1
|
CluInfo info = new CluInfo (); |
| 67 |
1
|
ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean ( |
| 68 |
|
info.getClass ().getName ()); |
| 69 |
1
|
List<ValidationResultInfo> validationResults = val.validateObject (info, os); |
| 70 |
1
|
System.out.println ("h3. With just a blank CluInfo"); |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
1
|
assertEquals (2, validationResults.size ()); |
| 76 |
|
|
| 77 |
|
|
| 78 |
1
|
info.setOfficialIdentifier (new CluIdentifierInfo ()); |
| 79 |
1
|
validationResults = val.validateObject (info, os); |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
1
|
assertEquals (4, validationResults.size ()); |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
1
|
info.setStdDuration (new TimeAmountInfo ()); |
| 90 |
1
|
validationResults = val.validateObject (info, os); |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
1
|
assertEquals (4, validationResults.size ()); |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
1
|
info.getStdDuration ().setTimeQuantity (1); |
| 100 |
1
|
validationResults = val.validateObject (info, os); |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
1
|
assertEquals (6, validationResults.size ()); |
| 106 |
|
|
| 107 |
|
|
| 108 |
1
|
info.setIntensity (new AmountInfo ()); |
| 109 |
1
|
validationResults = val.validateObject (info, os); |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
1
|
assertEquals (6, validationResults.size ()); |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
1
|
info.getIntensity ().setUnitQuantity ("1"); |
| 120 |
1
|
validationResults = val.validateObject (info, os); |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
1
|
assertEquals (8, validationResults.size ()); |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
} |
| 130 |
|
} |