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