View Javadoc

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.atp.dto.AtpInfo;
14  import org.kuali.student.core.atp.dto.DateRangeInfo;
15  import org.kuali.student.core.atp.dto.MilestoneInfo;
16  import org.springframework.context.ApplicationContext;
17  import org.springframework.context.support.ClassPathXmlApplicationContext;
18  import static org.junit.Assert.*;
19  
20  public class TestAtpDictionary {
21  
22  	@Test
23  	public void testLoadAtpDictionary() {
24    System.out.println ("testing atp dictionary");
25  		Set<String> startingClasses = new LinkedHashSet();
26  		startingClasses.add(AtpInfo.class.getName ());
27  		startingClasses.add(MilestoneInfo.class.getName ());
28  		startingClasses.add(DateRangeInfo.class.getName ());
29  		String contextFile = "ks-atp-dictionary-context";
30  		String outFile = "target/" + contextFile + ".txt";
31  		DictionaryTesterHelper helper = new DictionaryTesterHelper(outFile,
32  				startingClasses, contextFile + ".xml", 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  
53  	@Test
54  	public void testAtpInfoValidation() throws OperationFailedException {
55  		ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:ks-atp-dictionary-context.xml");
56  		System.out.println("h2. Validation Test");
57  		DefaultValidatorImpl val = new DefaultValidatorImpl();
58  		val.setDateParser(new ServerDateParser());
59  		val.setSearchDispatcher(new MockSearchDispatcher());
60  		AtpInfo info = new AtpInfo ();
61  		ObjectStructureDefinition os = (ObjectStructureDefinition) ac.getBean(info.getClass().getName());
62  		List<ValidationResultInfo> validationResults = val.validateObject(info,	os);
63  		System.out.println("h3. With just a blank StatementInfo");
64  		for (ValidationResultInfo vr : validationResults)
65    {
66     System.out.println (vr.getElement () + " " + vr.getMessage ());
67    }
68  		assertEquals(3, validationResults.size());
69  	}
70  
71  }