1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.test.integration; |
21 |
|
|
22 |
|
import java.io.BufferedReader; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.io.InputStreamReader; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.StringTokenizer; |
29 |
|
import java.util.regex.Matcher; |
30 |
|
import java.util.regex.Pattern; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
|
|
| 91.5% |
Uncovered Elements: 9 (106) |
Complexity: 23 |
Complexity Density: 0.34 |
|
47 |
|
public class TestDataParser |
48 |
|
{ |
49 |
|
private static final Pattern PATTERN_VARIABLE = Pattern.compile("(\\\\)?(\\$\\{\\{\\{(.*)\\}\\}\\})"); |
50 |
|
|
|
|
| 95.8% |
Uncovered Elements: 1 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
51 |
72 |
public static String interpret(String source)... |
52 |
|
{ |
53 |
72 |
StringBuilder result = new StringBuilder(); |
54 |
|
|
55 |
72 |
Matcher matcher = PATTERN_VARIABLE.matcher(source); |
56 |
|
|
57 |
72 |
int current = 0; |
58 |
76 |
while (matcher.find()) { |
59 |
4 |
if (matcher.group(1) == null) { |
60 |
3 |
String var = matcher.group(3); |
61 |
|
|
62 |
3 |
String value = System.getProperty(var); |
63 |
3 |
if (value != null) { |
64 |
3 |
result.append(source, current, matcher.start()); |
65 |
3 |
result.append(value); |
66 |
3 |
current = matcher.end(); |
67 |
|
} |
68 |
|
} else { |
69 |
1 |
result.append(source, current, matcher.start()); |
70 |
1 |
current = matcher.start(2); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
72 |
if (current < source.length()) { |
75 |
71 |
result.append(source, current, source.length()); |
76 |
|
} |
77 |
|
|
78 |
72 |
return result.toString(); |
79 |
|
} |
80 |
|
|
|
|
| 85.7% |
Uncovered Elements: 7 (49) |
Complexity: 9 |
Complexity Density: 0.27 |
|
81 |
15 |
public TestResourceData parse(InputStream source, String resourceName) throws IOException... |
82 |
|
{ |
83 |
15 |
TestResourceData data = new TestResourceData(); |
84 |
|
|
85 |
|
|
86 |
15 |
BufferedReader reader = new BufferedReader(new InputStreamReader(source, "UTF-8")); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
15 |
try { |
91 |
15 |
String action = null; |
92 |
15 |
String typeId = null; |
93 |
15 |
boolean skip = false; |
94 |
|
|
95 |
15 |
data.resourceName = resourceName; |
96 |
|
|
97 |
15 |
StringBuilder buffer = new StringBuilder(); |
98 |
15 |
Map<String, String> configuration = data.configuration; |
99 |
|
|
100 |
48602 |
for (String line = reader.readLine(); line != null; line = reader.readLine()) { |
101 |
48587 |
if (line.startsWith(".")) { |
102 |
105 |
if (line.startsWith(".#")) { |
103 |
|
|
104 |
71 |
if (line.toLowerCase().contains("todo")) { |
105 |
0 |
System.out.println(line); |
106 |
|
} |
107 |
34 |
} else if (line.startsWith(".configuration")) { |
108 |
4 |
StringTokenizer st = new StringTokenizer(line.substring(".configuration".length() + 1), "="); |
109 |
4 |
configuration.put(st.nextToken(), st.nextToken()); |
110 |
|
} else { |
111 |
30 |
if (!skip) { |
112 |
30 |
saveData(data, action, typeId, buffer, configuration); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
30 |
buffer.setLength(0); |
117 |
|
|
118 |
30 |
configuration = new HashMap<String, String>(); |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
30 |
StringTokenizer st = new StringTokenizer(line.substring(1), "|"); |
123 |
|
|
124 |
30 |
action = st.nextToken(); |
125 |
|
|
126 |
30 |
typeId = st.nextToken(); |
127 |
|
|
128 |
|
|
129 |
30 |
skip = false; |
130 |
30 |
if (st.hasMoreTokens()) { |
131 |
0 |
skip = true; |
132 |
0 |
System.out.println("[WARNING] Skipping test for [" + typeId + "] in resource [" |
133 |
|
+ resourceName + "] since it has been marked as skipped in the test. This needs to be " |
134 |
|
+ "reviewed and fixed."); |
135 |
|
} |
136 |
|
} |
137 |
|
} else { |
138 |
48482 |
buffer.append(line).append('\n'); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
15 |
if (!skip) { |
143 |
15 |
saveData(data, action, typeId, buffer, configuration); |
144 |
|
} |
145 |
|
|
146 |
|
} finally { |
147 |
15 |
reader.close(); |
148 |
|
} |
149 |
|
|
150 |
15 |
return data; |
151 |
|
} |
152 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 7 |
Complexity Density: 0.7 |
|
153 |
45 |
private void saveData(TestResourceData data, String action, String typeId, StringBuilder buffer,... |
154 |
|
Map<String, String> configuration) |
155 |
|
{ |
156 |
45 |
if (action != null) { |
157 |
|
|
158 |
|
|
159 |
30 |
if (buffer.length() > 0 && buffer.charAt(buffer.length() - 1) == '\n') { |
160 |
26 |
buffer.setLength(buffer.length() - 1); |
161 |
|
} |
162 |
|
|
163 |
30 |
if (action.equalsIgnoreCase("input")) { |
164 |
10 |
addInput(data, typeId, buffer, configuration); |
165 |
20 |
} else if (action.equalsIgnoreCase("expect")) { |
166 |
8 |
addExpect(data, typeId, buffer, configuration); |
167 |
12 |
} else if (action.equalsIgnoreCase("inputexpect")) { |
168 |
12 |
addExpect(data, typeId, buffer, configuration); |
169 |
12 |
addInput(data, typeId, buffer, configuration); |
170 |
|
} |
171 |
|
} |
172 |
|
} |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
174 |
22 |
private void addInput(TestResourceData data, String typeId, StringBuilder buffer, Map<String, String> configuration)... |
175 |
|
{ |
176 |
22 |
InputTestConfiguration inputConfiguration = new InputTestConfiguration(typeId, buffer.toString()); |
177 |
|
|
178 |
|
|
179 |
22 |
inputConfiguration.setEncoding("UTF-8"); |
180 |
|
|
181 |
22 |
inputConfiguration.putAll(configuration); |
182 |
|
|
183 |
22 |
data.inputs.add(inputConfiguration); |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
186 |
20 |
private void addExpect(TestResourceData data, String typeId, StringBuilder buffer, Map<String, String> configuration)... |
187 |
|
{ |
188 |
20 |
ExpectTestConfiguration expectTestConfiguration = new ExpectTestConfiguration(typeId, buffer.toString()); |
189 |
|
|
190 |
|
|
191 |
20 |
expectTestConfiguration.setEncoding("UTF-8"); |
192 |
|
|
193 |
20 |
expectTestConfiguration.putAll(configuration); |
194 |
|
|
195 |
20 |
data.expects.add(expectTestConfiguration); |
196 |
|
} |
197 |
|
} |