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