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.exceptions.OperationFailedException; 10 import org.kuali.student.common.validation.dto.ValidationResultInfo; 11 import org.kuali.student.common.validator.DefaultValidatorImpl; 12 import org.kuali.student.common.validator.ServerDateParser; 13 import org.kuali.student.lum.lu.dto.CluSetInfo; 14 import org.springframework.context.ApplicationContext; 15 import org.springframework.context.support.ClassPathXmlApplicationContext; 16 import static org.junit.Assert.*; 17 18 public class TestCluSetInfoDictionary 19 { 20 21 @Test 22 public void testLoadCluSetInfoDictionary () 23 { 24 Set<String> startingClasses = new LinkedHashSet (); 25 startingClasses.add (CluSetInfo.class.getName ()); 26 String contextFile = "ks-cluSetInfo-dictionary-context"; 27 String outFile = "target/" + contextFile + ".txt"; 28 DictionaryTesterHelper helper = new DictionaryTesterHelper (outFile, 29 startingClasses, 30 contextFile 31 + ".xml", 32 false); 33 List<String> errors = helper.doTest (); 34 if (errors.size () > 0) 35 { 36 fail ("failed dictionary validation:\n" + formatAsString (errors)); 37 } 38 } 39 40 private String formatAsString (List<String> errors) 41 { 42 int i = 0; 43 StringBuilder builder = new StringBuilder (); 44 for (String error : errors) 45 { 46 i ++; 47 builder.append (i + ". " + error + "\n"); 48 } 49 return builder.toString (); 50 } 51 52 @Test 53 public void testCluSetInfoValidation () throws OperationFailedException 54 { 55 ApplicationContext ac = new ClassPathXmlApplicationContext ( 56 "classpath:ks-cluSetInfo-dictionary-context.xml"); 57 System.out.println ("h2. Validation Test"); 58 DefaultValidatorImpl val = new DefaultValidatorImpl (); 59 val.setDateParser (new ServerDateParser ()); 60 val.setSearchDispatcher (new MockSearchDispatcher ()); 61 CluSetInfo info = new CluSetInfo (); 62 ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean ( 63 info.getClass ().getName ()); 64 List<ValidationResultInfo> validationResults = val.validateObject (info, os); 65 System.out.println ("h3. With just a blank CluInfo"); 66 for (ValidationResultInfo vr : validationResults) 67 { 68 System.out.println (vr.getElement () + " " + vr.getMessage ()); 69 } 70 assertEquals (2, validationResults.size ()); 71 72 } 73 }