1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
package com.jeantessier.metrics; |
34 | |
|
35 | |
import java.io.*; |
36 | |
import javax.xml.parsers.*; |
37 | |
|
38 | |
import junit.framework.*; |
39 | |
import org.xml.sax.*; |
40 | |
|
41 | 14 | public class TestMetricsConfigurationHandler extends TestCase { |
42 | |
private MetricsConfigurationHandler handler; |
43 | |
private XMLReader reader; |
44 | |
|
45 | |
protected void setUp() throws Exception { |
46 | 14 | handler = new MetricsConfigurationHandler(); |
47 | |
|
48 | 14 | reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); |
49 | 14 | reader.setDTDHandler(handler); |
50 | 14 | reader.setContentHandler(handler); |
51 | 14 | reader.setErrorHandler(handler); |
52 | 14 | if (Boolean.getBoolean("DEPENDENCYFINDER_TESTS_VALIDATE")) { |
53 | 0 | reader.setFeature("http://xml.org/sax/features/validation", true); |
54 | 0 | reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true); |
55 | |
} else { |
56 | 14 | reader.setFeature("http://xml.org/sax/features/validation", false); |
57 | 14 | reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); |
58 | |
} |
59 | 14 | } |
60 | |
|
61 | |
public void testEmptyFile() throws IOException, SAXException { |
62 | 1 | InputSource in = new InputSource(new StringReader("")); |
63 | |
|
64 | |
try { |
65 | 1 | reader.parse(in); |
66 | 0 | fail("Read empty file"); |
67 | 1 | } catch (SAXParseException ex) { |
68 | |
|
69 | 0 | } |
70 | |
|
71 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
72 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
73 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
74 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
75 | 1 | } |
76 | |
|
77 | |
public void testEmptyDocument() throws IOException, SAXException { |
78 | 1 | InputSource in = new InputSource(new StringReader("<metrics-configuration/>")); |
79 | |
|
80 | 1 | reader.parse(in); |
81 | |
|
82 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
83 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
84 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
85 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
86 | 1 | } |
87 | |
|
88 | |
public void testNonWellFormedDocument() throws IOException, SAXException { |
89 | 1 | InputSource in = new InputSource(new StringReader("<metrics-configuration>")); |
90 | |
|
91 | |
try { |
92 | 1 | reader.parse(in); |
93 | 0 | fail("Read non well formed file"); |
94 | 1 | } catch (SAXParseException ex) { |
95 | |
|
96 | 0 | } |
97 | |
|
98 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
99 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
100 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
101 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
102 | 1 | } |
103 | |
|
104 | |
public void testValidation() throws IOException, SAXException { |
105 | 1 | StringBuffer document = new StringBuffer(); |
106 | |
|
107 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
108 | 1 | document.append("<metrics-configuration>\n"); |
109 | 1 | document.append(" <project-measurements/>\n"); |
110 | 1 | document.append(" <group-measurements/>\n"); |
111 | 1 | document.append(" <class-measurements/>\n"); |
112 | 1 | document.append(" <method-measurements/>\n"); |
113 | 1 | document.append("</metrics-configuration>\n"); |
114 | |
|
115 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
116 | |
|
117 | 1 | reader.parse(in); |
118 | |
|
119 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
120 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
121 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
122 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
123 | 1 | } |
124 | |
|
125 | |
public void testPackageMeasurement() throws IOException, SAXException { |
126 | 1 | StringBuffer document = new StringBuffer(); |
127 | |
|
128 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
129 | 1 | document.append("<metrics-configuration>\n"); |
130 | 1 | document.append(" <project-measurements>\n"); |
131 | 1 | document.append(" <measurement>\n"); |
132 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
133 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
134 | 1 | document.append(" <class>com.jeantessier.metrics.StatisticalMeasurement</class>\n"); |
135 | 1 | document.append(" <init>\n"); |
136 | 1 | document.append(" SLOC\n"); |
137 | 1 | document.append(" DISPOSE_SUM\n"); |
138 | 1 | document.append(" </init>\n"); |
139 | 1 | document.append(" </measurement>\n"); |
140 | 1 | document.append(" </project-measurements>\n"); |
141 | 1 | document.append(" <group-measurements/>\n"); |
142 | 1 | document.append(" <class-measurements/>\n"); |
143 | 1 | document.append(" <method-measurements/>\n"); |
144 | 1 | document.append("</metrics-configuration>\n"); |
145 | |
|
146 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
147 | |
|
148 | 1 | reader.parse(in); |
149 | |
|
150 | 1 | assertEquals("ProjectMeasurements", 1, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
151 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
152 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
153 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
154 | |
|
155 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getProjectMeasurements().get(0); |
156 | 1 | assertEquals("SLOC", descriptor.getShortName()); |
157 | 1 | assertEquals("Single Lines of Code", descriptor.getLongName()); |
158 | 1 | assertEquals(com.jeantessier.metrics.StatisticalMeasurement.class, descriptor.getClassFor()); |
159 | 1 | assertEquals("SLOC\n DISPOSE_SUM", descriptor.getInitText()); |
160 | 1 | assertNull("descriptor.LowerThreshold()", descriptor.getLowerThreshold()); |
161 | 1 | assertNull("descriptor.UpperThreshold()", descriptor.getUpperThreshold()); |
162 | 1 | } |
163 | |
|
164 | |
public void testGroupMeasurement() throws IOException, SAXException { |
165 | 1 | StringBuffer document = new StringBuffer(); |
166 | |
|
167 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
168 | 1 | document.append("<metrics-configuration>\n"); |
169 | 1 | document.append(" <project-measurements/>\n"); |
170 | 1 | document.append(" <group-measurements>\n"); |
171 | 1 | document.append(" <measurement>\n"); |
172 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
173 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
174 | 1 | document.append(" <class>com.jeantessier.metrics.StatisticalMeasurement</class>\n"); |
175 | 1 | document.append(" <init>\n"); |
176 | 1 | document.append(" SLOC\n"); |
177 | 1 | document.append(" DISPOSE_SUM\n"); |
178 | 1 | document.append(" </init>\n"); |
179 | 1 | document.append(" </measurement>\n"); |
180 | 1 | document.append(" </group-measurements>\n"); |
181 | 1 | document.append(" <class-measurements/>\n"); |
182 | 1 | document.append(" <method-measurements/>\n"); |
183 | 1 | document.append("</metrics-configuration>\n"); |
184 | |
|
185 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
186 | |
|
187 | 1 | reader.parse(in); |
188 | |
|
189 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
190 | 1 | assertEquals("GroupMeasurements", 1, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
191 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
192 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
193 | |
|
194 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getGroupMeasurements().get(0); |
195 | 1 | assertEquals("SLOC", descriptor.getShortName()); |
196 | 1 | assertEquals("Single Lines of Code", descriptor.getLongName()); |
197 | 1 | assertEquals(com.jeantessier.metrics.StatisticalMeasurement.class, descriptor.getClassFor()); |
198 | 1 | assertEquals("SLOC\n DISPOSE_SUM", descriptor.getInitText()); |
199 | 1 | assertNull("descriptor.LowerThreshold()", descriptor.getLowerThreshold()); |
200 | 1 | assertNull("descriptor.UpperThreshold()", descriptor.getUpperThreshold()); |
201 | 1 | } |
202 | |
|
203 | |
public void testClassMeasurement() throws IOException, SAXException { |
204 | 1 | StringBuffer document = new StringBuffer(); |
205 | |
|
206 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
207 | 1 | document.append("<metrics-configuration>\n"); |
208 | 1 | document.append(" <project-measurements/>\n"); |
209 | 1 | document.append(" <group-measurements/>\n"); |
210 | 1 | document.append(" <class-measurements>\n"); |
211 | 1 | document.append(" <measurement>\n"); |
212 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
213 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
214 | 1 | document.append(" <class>com.jeantessier.metrics.StatisticalMeasurement</class>\n"); |
215 | 1 | document.append(" <init>\n"); |
216 | 1 | document.append(" SLOC\n"); |
217 | 1 | document.append(" </init>\n"); |
218 | 1 | document.append(" </measurement>\n"); |
219 | 1 | document.append(" </class-measurements>\n"); |
220 | 1 | document.append(" <method-measurements/>\n"); |
221 | 1 | document.append("</metrics-configuration>\n"); |
222 | |
|
223 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
224 | |
|
225 | 1 | reader.parse(in); |
226 | |
|
227 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
228 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
229 | 1 | assertEquals("ClassMeasurements", 1, handler.getMetricsConfiguration().getClassMeasurements().size()); |
230 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
231 | |
|
232 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getClassMeasurements().get(0); |
233 | 1 | assertEquals("SLOC", descriptor.getShortName()); |
234 | 1 | assertEquals("Single Lines of Code", descriptor.getLongName()); |
235 | 1 | assertEquals(com.jeantessier.metrics.StatisticalMeasurement.class, descriptor.getClassFor()); |
236 | 1 | assertEquals("SLOC", descriptor.getInitText()); |
237 | 1 | assertNull("descriptor.LowerThreshold()", descriptor.getLowerThreshold()); |
238 | 1 | assertNull("descriptor.UpperThreshold()", descriptor.getUpperThreshold()); |
239 | 1 | } |
240 | |
|
241 | |
public void testMethodMeasurement() throws IOException, SAXException { |
242 | 1 | StringBuffer document = new StringBuffer(); |
243 | |
|
244 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
245 | 1 | document.append("<metrics-configuration>\n"); |
246 | 1 | document.append(" <project-measurements/>\n"); |
247 | 1 | document.append(" <group-measurements/>\n"); |
248 | 1 | document.append(" <class-measurements/>\n"); |
249 | 1 | document.append(" <method-measurements>\n"); |
250 | 1 | document.append(" <measurement>\n"); |
251 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
252 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
253 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
254 | 1 | document.append(" <upper-threshold>50</upper-threshold>\n"); |
255 | 1 | document.append(" </measurement>\n"); |
256 | 1 | document.append(" </method-measurements>\n"); |
257 | 1 | document.append("</metrics-configuration>\n"); |
258 | |
|
259 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
260 | |
|
261 | 1 | reader.parse(in); |
262 | |
|
263 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
264 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
265 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
266 | 1 | assertEquals("MethodMeasurements", 1, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
267 | |
|
268 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
269 | 1 | assertEquals("SLOC", descriptor.getShortName()); |
270 | 1 | assertEquals("Single Lines of Code", descriptor.getLongName()); |
271 | 1 | assertEquals(com.jeantessier.metrics.CounterMeasurement.class, descriptor.getClassFor()); |
272 | 1 | assertNull("descriptor.Init()", descriptor.getInitText()); |
273 | 1 | assertNull("descriptor.LowerThreshold()", descriptor.getLowerThreshold()); |
274 | 1 | assertEquals("descriptor.UpperThreshold()", "50", descriptor.getUpperThreshold()); |
275 | 1 | } |
276 | |
|
277 | |
public void testTrueVisible() throws IOException, SAXException { |
278 | 1 | StringBuffer document = new StringBuffer(); |
279 | |
|
280 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
281 | 1 | document.append("<metrics-configuration>\n"); |
282 | 1 | document.append(" <project-measurements/>\n"); |
283 | 1 | document.append(" <group-measurements/>\n"); |
284 | 1 | document.append(" <class-measurements/>\n"); |
285 | 1 | document.append(" <method-measurements>\n"); |
286 | 1 | document.append(" <measurement visible=\"true\">\n"); |
287 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
288 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
289 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
290 | 1 | document.append(" </measurement>\n"); |
291 | 1 | document.append(" </method-measurements>\n"); |
292 | 1 | document.append("</metrics-configuration>\n"); |
293 | |
|
294 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
295 | |
|
296 | 1 | reader.parse(in); |
297 | |
|
298 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
299 | 1 | assertTrue("Not visible", descriptor.isVisible()); |
300 | 1 | } |
301 | |
|
302 | |
public void testYesVisible() throws IOException, SAXException { |
303 | 1 | StringBuffer document = new StringBuffer(); |
304 | |
|
305 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
306 | 1 | document.append("<metrics-configuration>\n"); |
307 | 1 | document.append(" <project-measurements/>\n"); |
308 | 1 | document.append(" <group-measurements/>\n"); |
309 | 1 | document.append(" <class-measurements/>\n"); |
310 | 1 | document.append(" <method-measurements>\n"); |
311 | 1 | document.append(" <measurement visible=\"yes\">\n"); |
312 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
313 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
314 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
315 | 1 | document.append(" </measurement>\n"); |
316 | 1 | document.append(" </method-measurements>\n"); |
317 | 1 | document.append("</metrics-configuration>\n"); |
318 | |
|
319 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
320 | |
|
321 | 1 | reader.parse(in); |
322 | |
|
323 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
324 | 1 | assertTrue("Not visible", descriptor.isVisible()); |
325 | 1 | } |
326 | |
|
327 | |
public void testOnVisible() throws IOException, SAXException { |
328 | 1 | StringBuffer document = new StringBuffer(); |
329 | |
|
330 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
331 | 1 | document.append("<metrics-configuration>\n"); |
332 | 1 | document.append(" <project-measurements/>\n"); |
333 | 1 | document.append(" <group-measurements/>\n"); |
334 | 1 | document.append(" <class-measurements/>\n"); |
335 | 1 | document.append(" <method-measurements>\n"); |
336 | 1 | document.append(" <measurement visible=\"on\">\n"); |
337 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
338 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
339 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
340 | 1 | document.append(" </measurement>\n"); |
341 | 1 | document.append(" </method-measurements>\n"); |
342 | 1 | document.append("</metrics-configuration>\n"); |
343 | |
|
344 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
345 | |
|
346 | 1 | reader.parse(in); |
347 | |
|
348 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
349 | 1 | assertTrue("Not visible", descriptor.isVisible()); |
350 | 1 | } |
351 | |
|
352 | |
public void testDefaultVisible() throws IOException, SAXException { |
353 | 1 | StringBuffer document = new StringBuffer(); |
354 | |
|
355 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
356 | 1 | document.append("<metrics-configuration>\n"); |
357 | 1 | document.append(" <project-measurements/>\n"); |
358 | 1 | document.append(" <group-measurements/>\n"); |
359 | 1 | document.append(" <class-measurements/>\n"); |
360 | 1 | document.append(" <method-measurements>\n"); |
361 | 1 | document.append(" <measurement>\n"); |
362 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
363 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
364 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
365 | 1 | document.append(" </measurement>\n"); |
366 | 1 | document.append(" </method-measurements>\n"); |
367 | 1 | document.append("</metrics-configuration>\n"); |
368 | |
|
369 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
370 | |
|
371 | 1 | reader.parse(in); |
372 | |
|
373 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
374 | 1 | assertTrue("Not visible", descriptor.isVisible()); |
375 | 1 | } |
376 | |
|
377 | |
public void testNotVisible() throws IOException, SAXException { |
378 | 1 | StringBuffer document = new StringBuffer(); |
379 | |
|
380 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
381 | 1 | document.append("<metrics-configuration>\n"); |
382 | 1 | document.append(" <project-measurements/>\n"); |
383 | 1 | document.append(" <group-measurements/>\n"); |
384 | 1 | document.append(" <class-measurements/>\n"); |
385 | 1 | document.append(" <method-measurements>\n"); |
386 | 1 | document.append(" <measurement visible=\"no\">\n"); |
387 | 1 | document.append(" <short-name>SLOC</short-name>\n"); |
388 | 1 | document.append(" <long-name>Single Lines of Code</long-name>\n"); |
389 | 1 | document.append(" <class>com.jeantessier.metrics.CounterMeasurement</class>\n"); |
390 | 1 | document.append(" </measurement>\n"); |
391 | 1 | document.append(" </method-measurements>\n"); |
392 | 1 | document.append("</metrics-configuration>\n"); |
393 | |
|
394 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
395 | |
|
396 | 1 | reader.parse(in); |
397 | |
|
398 | 1 | MeasurementDescriptor descriptor = (MeasurementDescriptor) handler.getMetricsConfiguration().getMethodMeasurements().get(0); |
399 | 1 | assertTrue("Visible", !descriptor.isVisible()); |
400 | 1 | } |
401 | |
|
402 | |
public void testGroupDefinitions() throws IOException, SAXException { |
403 | 1 | StringBuffer document = new StringBuffer(); |
404 | |
|
405 | 1 | document.append("<!DOCTYPE metrics-configuration SYSTEM \"http://depfind.sourceforge.net/dtd/metrics-configuration.dtd\">\n"); |
406 | 1 | document.append("<metrics-configuration>\n"); |
407 | 1 | document.append(" <project-measurements/>\n"); |
408 | 1 | document.append(" <group-definitions>\n"); |
409 | 1 | document.append(" <group-definition>\n"); |
410 | 1 | document.append(" <name>Jean Tessier</name>\n"); |
411 | 1 | document.append(" <pattern>/^com.jeantessier/</pattern>\n"); |
412 | 1 | document.append(" </group-definition>\n"); |
413 | 1 | document.append(" </group-definitions>\n"); |
414 | 1 | document.append(" <group-measurements/>\n"); |
415 | 1 | document.append(" <class-measurements/>\n"); |
416 | 1 | document.append(" <method-measurements/>\n"); |
417 | 1 | document.append("</metrics-configuration>\n"); |
418 | |
|
419 | 1 | InputSource in = new InputSource(new StringReader(document.toString())); |
420 | |
|
421 | 1 | reader.parse(in); |
422 | |
|
423 | 1 | assertEquals("ProjectMeasurements", 0, handler.getMetricsConfiguration().getProjectMeasurements().size()); |
424 | 1 | assertEquals("GroupMeasurements", 0, handler.getMetricsConfiguration().getGroupMeasurements().size()); |
425 | 1 | assertEquals("ClassMeasurements", 0, handler.getMetricsConfiguration().getClassMeasurements().size()); |
426 | 1 | assertEquals("MethodMeasurements", 0, handler.getMetricsConfiguration().getMethodMeasurements().size()); |
427 | |
|
428 | 1 | assertEquals("groups for foobar", 0, handler.getMetricsConfiguration().getGroups("foobar").size()); |
429 | 1 | assertEquals("groups for com.jeantessier.metrics", 1, handler.getMetricsConfiguration().getGroups("com.jeantessier.metrics").size()); |
430 | 1 | assertEquals("Jean Tessier", handler.getMetricsConfiguration().getGroups("com.jeantessier.metrics").iterator().next()); |
431 | 1 | } |
432 | |
} |