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