| 1 |  | package org.kuali.student.lum.course.service.impl; | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  | import java.io.File; | 
            
  
    | 4 |  | import java.io.FileNotFoundException; | 
            
  
    | 5 |  | import java.io.FileOutputStream; | 
            
  
    | 6 |  | import java.io.OutputStream; | 
            
  
    | 7 |  | import java.io.PrintStream; | 
            
  
    | 8 |  | import java.util.Date; | 
            
  
    | 9 |  | import java.util.List; | 
            
  
    | 10 |  | import java.util.Map; | 
            
  
    | 11 |  | import org.kuali.student.core.search.dto.SearchCriteriaTypeInfo; | 
            
  
    | 12 |  | import org.kuali.student.core.search.dto.SearchResultTypeInfo; | 
            
  
    | 13 |  | import org.kuali.student.core.search.dto.SearchTypeInfo; | 
            
  
    | 14 |  | import org.kuali.student.core.search.service.impl.SearchConfigFormatter; | 
            
  
    | 15 |  | import org.kuali.student.core.search.service.impl.SearchConfigValidator; | 
            
  
    | 16 |  | import org.springframework.context.ApplicationContext; | 
            
  
    | 17 |  | import org.springframework.context.support.ClassPathXmlApplicationContext; | 
            
  
    | 18 |  |  | 
               
        |  |  | 
           
           |  | 73.7% | Uncovered Elements: 10 (38) | Complexity: 5 | Complexity Density: 0.15 |  | 
  
  
    | 19 |  | public class SearchConfigTesterHelper | 
            
  
    | 20 |  | { | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  | private String outputFileName; | 
            
  
    | 23 |  | private File file; | 
            
  
    | 24 |  | private OutputStream os; | 
            
  
    | 25 |  | private PrintStream out; | 
            
  
    | 26 |  | private String searchConfigFileName; | 
            
  
    | 27 |  | private String projectLocation; | 
            
  
    | 28 |  | private Map<String, SearchTypeInfo> searchInfoTypeMap; | 
            
  
    | 29 |  | private Map<String, SearchCriteriaTypeInfo> searchCriteriaTypeMap; | 
            
  
    | 30 |  | private Map<String, SearchResultTypeInfo> searchResultTypeInfoMap; | 
            
  
    | 31 |  | private Map<String, String> queryMap; | 
            
  
    | 32 |  |  | 
               
        |  |  | 
           
           |  | 87.5% | Uncovered Elements: 1 (8) | Complexity: 2 | Complexity Density: 0.25 |  | 
  
  
    | 33 | 3 |  public SearchConfigTesterHelper (String outputFileName,... | 
            
  
    | 34 |  | String projectLocation, | 
            
  
    | 35 |  | String searchConfigFileName) | 
            
  
    | 36 |  | { | 
            
  
    | 37 | 3 | this.outputFileName = outputFileName; | 
            
  
    | 38 | 3 | this.projectLocation = projectLocation; | 
            
  
    | 39 | 3 | this.searchConfigFileName = searchConfigFileName; | 
            
  
    | 40 |  |  | 
            
  
    | 41 | 3 | this.file = new File (this.outputFileName); | 
            
  
    | 42 | 3 | try | 
            
  
    | 43 |  | { | 
            
  
    | 44 | 3 | os = new FileOutputStream (file, false); | 
            
  
    | 45 |  | } | 
            
  
    | 46 |  | catch (FileNotFoundException ex) | 
            
  
    | 47 |  | { | 
            
  
    | 48 | 0 | throw new IllegalArgumentException (ex); | 
            
  
    | 49 |  | } | 
            
  
    | 50 | 3 | this.out = new PrintStream (os); | 
            
  
    | 51 |  | } | 
            
  
    | 52 |  |  | 
               
        |  |  | 
           
           |  | 90.5% | Uncovered Elements: 2 (21) | Complexity: 2 | Complexity Density: 0.11 |  | 
  
  
    | 53 | 3 |  public void doTest ()... | 
            
  
    | 54 |  | { | 
            
  
    | 55 | 3 | ApplicationContext ac = new ClassPathXmlApplicationContext ( | 
            
  
    | 56 |  | "classpath:" + searchConfigFileName); | 
            
  
    | 57 | 3 | searchInfoTypeMap = ac.getBeansOfType (SearchTypeInfo.class); | 
            
  
    | 58 | 3 | searchCriteriaTypeMap = ac.getBeansOfType (SearchCriteriaTypeInfo.class); | 
            
  
    | 59 | 3 | searchResultTypeInfoMap = ac.getBeansOfType (SearchResultTypeInfo.class); | 
            
  
    | 60 | 3 | queryMap = (Map<String, String>) ac.getBean ("queryMap"); | 
            
  
    | 61 |  |  | 
            
  
    | 62 | 3 | out.println ("(!) This page was automatically generated on " + new Date ()); | 
            
  
    | 63 | 3 | out.println ("DO NOT UPDATE MANUALLY!"); | 
            
  
    | 64 | 3 | out.println (""); | 
            
  
    | 65 | 3 | out.print ("This page represents a formatted view of [" + searchConfigFileName | 
            
  
    | 66 |  | + "|https://test.kuali.org/svn/student/trunk/" + projectLocation | 
            
  
    | 67 |  | + "/src/main/resources/" | 
            
  
    | 68 |  | + searchConfigFileName + "]"); | 
            
  
    | 69 | 3 | out.println (""); | 
            
  
    | 70 | 3 | out.println ("----"); | 
            
  
    | 71 | 3 | out.println ("{toc}"); | 
            
  
    | 72 | 3 | out.println ("----"); | 
            
  
    | 73 | 3 | SearchConfigValidator validator = new SearchConfigValidator (searchInfoTypeMap, | 
            
  
    | 74 |  | queryMap); | 
            
  
    | 75 |  |  | 
            
  
    | 76 | 3 | List<String> errors = validator.validate (); | 
            
  
    | 77 | 3 | if (errors.size () > 0) | 
            
  
    | 78 |  | { | 
            
  
    | 79 | 0 | throw new RuntimeException (searchConfigFileName + " failed search config validation:\n" | 
            
  
    | 80 |  | + this.formatAsString (errors)); | 
            
  
    | 81 |  | } | 
            
  
    | 82 |  |  | 
            
  
    | 83 | 3 | SearchConfigFormatter formatter = new SearchConfigFormatter (searchInfoTypeMap, | 
            
  
    | 84 |  | queryMap); | 
            
  
    | 85 | 3 | out.println (formatter.formatForWiki ()); | 
            
  
    | 86 |  | } | 
            
  
    | 87 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 6 (6) | Complexity: 1 | Complexity Density: 0.17 |  | 
  
  
    | 88 | 0 |  private String formatAsString (List<String> discrepancies)... | 
            
  
    | 89 |  | { | 
            
  
    | 90 | 0 | int i = 0; | 
            
  
    | 91 | 0 | StringBuilder builder = new StringBuilder (); | 
            
  
    | 92 | 0 | for (String discrep : discrepancies) | 
            
  
    | 93 |  | { | 
            
  
    | 94 | 0 | i ++; | 
            
  
    | 95 | 0 | builder.append (i + ". " + discrep + "\n"); | 
            
  
    | 96 |  | } | 
            
  
    | 97 | 0 | return builder.toString (); | 
            
  
    | 98 |  | } | 
            
  
    | 99 |  | } |