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