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