KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestXMLPrinter


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependency;
34
35 import java.io.*;
36
37 import org.xml.sax.*;
38 import org.xml.sax.helpers.*;
39
40 import org.apache.oro.text.perl.*;
41
42 import junit.framework.*;
43
44 public class TestXMLPrinter extends TestCase implements ErrorHandler {
45     private static final String JavaDoc READER_CLASSNAME = "org.apache.xerces.parsers.SAXParser";
46
47     private static final String JavaDoc SPECIFIC_ENCODING = "iso-latin-1";
48     private static final String JavaDoc SPECIFIC_DTD_PREFIX = "./etc";
49
50     private XMLReader reader;
51     private Perl5Util perl;
52
53     private NodeFactory factory;
54     private StringWriter out;
55     private XMLPrinter printer;
56
57     protected void setUp() throws Exception JavaDoc {
58         reader = XMLReaderFactory.createXMLReader(READER_CLASSNAME);
59         reader.setFeature("http://xml.org/sax/features/validation", true);
60         reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
61         reader.setErrorHandler(this);
62
63         perl = new Perl5Util();
64
65         factory = new NodeFactory();
66         out = new StringWriter();
67     }
68
69     public void testDefaultDTDPrefix() {
70         printer = new XMLPrinter(new PrintWriter(out));
71
72         String JavaDoc xmlDocument = out.toString();
73         assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
74         assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"" + XMLPrinter.DEFAULT_DTD_PREFIX + "\"", perl.group(1).startsWith(XMLPrinter.DEFAULT_DTD_PREFIX));
75         
76         try {
77             reader.parse(new InputSource(new StringReader(xmlDocument)));
78             fail("Parsed non-existant document\n" + xmlDocument);
79         } catch (SAXException ex) {
80             // Ignore
81
} catch (IOException ex) {
82             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
83         }
84     }
85     
86     public void testSpecificDTDPrefix() {
87         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
88
89         String JavaDoc xmlDocument = out.toString();
90         assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
91         assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"./etc\"", perl.group(1).startsWith(SPECIFIC_DTD_PREFIX));
92         
93         try {
94             reader.parse(new InputSource(new StringReader(xmlDocument)));
95             fail("Parsed non-existant document\n" + xmlDocument);
96         } catch (SAXException ex) {
97             // Ignore
98
} catch (IOException ex) {
99             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
100         }
101     }
102
103     public void testDefaultEncoding() {
104         printer = new XMLPrinter(new PrintWriter(out));
105
106         String JavaDoc xmlDocument = out.toString();
107         assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument));
108         assertEquals("Encoding", XMLPrinter.DEFAULT_ENCODING, perl.group(1));
109         
110         try {
111             reader.parse(new InputSource(new StringReader(xmlDocument)));
112             fail("Parsed non-existant document\n" + xmlDocument);
113         } catch (SAXException ex) {
114             // Ignore
115
} catch (IOException ex) {
116             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
117         }
118     }
119
120     public void testSpecificEncoding() {
121         printer = new XMLPrinter(new PrintWriter(out), SPECIFIC_ENCODING, XMLPrinter.DEFAULT_DTD_PREFIX);
122
123         String JavaDoc xmlDocument = out.toString();
124         assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument));
125         assertEquals("Encoding", SPECIFIC_ENCODING, perl.group(1));
126         
127         try {
128             reader.parse(new InputSource(new StringReader(xmlDocument)));
129             fail("Parsed non-existant document\n" + xmlDocument);
130         } catch (SAXException ex) {
131             // Ignore
132
} catch (IOException ex) {
133             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
134         }
135     }
136
137     public void testShowInboundsPackageTrue() throws IOException {
138         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
139         factory.createPackage("empty");
140
141         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
142         printer.setShowInbounds(true);
143         printer.setShowOutbounds(false);
144
145         printer.traverseNodes(factory.getPackages().values());
146
147         int lineNumber = 0;
148         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
149
150         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
151         assertEquals("line " + ++lineNumber, "", in.readLine());
152         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
153         assertEquals("line " + ++lineNumber, "", in.readLine());
154         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
155         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
156         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
157         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
158         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
159         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
160         assertEquals("line " + ++lineNumber, " <inbound type=\"package\" confirmed=\"no\">outbound</inbound>", in.readLine());
161         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
162         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
163         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
164         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
165         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
166
167         assertEquals("End of file", null, in.readLine());
168     }
169
170     public void testShowInboundsPackageFalse() throws IOException {
171         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
172         factory.createPackage("empty");
173
174         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
175         printer.setShowInbounds(false);
176         printer.setShowOutbounds(false);
177
178         printer.traverseNodes(factory.getPackages().values());
179
180         int lineNumber = 0;
181         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
182
183         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
184         assertEquals("line " + ++lineNumber, "", in.readLine());
185         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
186         assertEquals("line " + ++lineNumber, "", in.readLine());
187         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
188         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
189         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
190         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
191         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
192         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
193         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
194         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
195         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
196         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
197         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
198
199         assertEquals("End of file", null, in.readLine());
200     }
201
202     public void testShowInboundsClassTrue() throws IOException {
203         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
204         factory.createClass("empty.Empty");
205
206         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
207         printer.setShowInbounds(true);
208         printer.setShowOutbounds(false);
209
210         printer.traverseNodes(factory.getPackages().values());
211
212         int lineNumber = 0;
213         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
214
215         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
216         assertEquals("line " + ++lineNumber, "", in.readLine());
217         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
218         assertEquals("line " + ++lineNumber, "", in.readLine());
219         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
220         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
221         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
222         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
223         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
224         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
225         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
226         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
227         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
228         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
229         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
230         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"no\">outbound.Outbound</inbound>", in.readLine());
231         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
232         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
233         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
234         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
235         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
236         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
237         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
238         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
239         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
240
241         assertEquals("End of file", null, in.readLine());
242     }
243
244     public void testShowInboundsClassFalse() throws IOException {
245         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
246         factory.createClass("empty.Empty");
247
248         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
249         printer.setShowInbounds(false);
250         printer.setShowOutbounds(false);
251
252         printer.traverseNodes(factory.getPackages().values());
253
254         int lineNumber = 0;
255         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
256
257         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
258         assertEquals("line " + ++lineNumber, "", in.readLine());
259         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
260         assertEquals("line " + ++lineNumber, "", in.readLine());
261         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
262         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
263         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
264         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
265         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
266         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
267         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
268         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
269         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
270         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
271         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
272         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
273         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
274         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
275         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
276         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
277         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
278         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
279         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
280         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
281
282         assertEquals("End of file", null, in.readLine());
283     }
284
285     public void testShowInboundsFeatureTrue() throws IOException {
286         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
287         factory.createFeature("empty.Empty.empty()");
288
289         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
290         printer.setShowInbounds(true);
291         printer.setShowOutbounds(false);
292
293         printer.traverseNodes(factory.getPackages().values());
294
295         int lineNumber = 0;
296         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
297
298         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
299         assertEquals("line " + ++lineNumber, "", in.readLine());
300         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
301         assertEquals("line " + ++lineNumber, "", in.readLine());
302         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
303         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
304         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
305         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
306         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
307         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
308         assertEquals("line " + ++lineNumber, " <name>empty.Empty.empty()</name>", in.readLine());
309         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
310         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
311         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
312         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
313         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
314         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
315         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
316         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
317         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
318         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
319         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
320         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
321         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
322         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
323         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
324         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
325         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
326         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
327         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
328         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
329         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
330         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
331         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
332
333         assertEquals("End of file", null, in.readLine());
334     }
335
336     public void testShowInboundsFeatureFalse() throws IOException {
337         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
338         factory.createFeature("empty.Empty.empty()");
339
340         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
341         printer.setShowInbounds(false);
342         printer.setShowOutbounds(false);
343
344         printer.traverseNodes(factory.getPackages().values());
345
346         int lineNumber = 0;
347         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
348
349         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
350         assertEquals("line " + ++lineNumber, "", in.readLine());
351         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
352         assertEquals("line " + ++lineNumber, "", in.readLine());
353         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
354         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
355         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
356         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
357         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
358         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
359         assertEquals("line " + ++lineNumber, " <name>empty.Empty.empty()</name>", in.readLine());
360         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
361         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
362         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
363         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
364         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
365         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
366         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
367         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
368         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
369         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
370         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
371         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
372         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
373         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
374         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
375         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
376         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
377         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
378         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
379         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
380         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
381         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
382
383         assertEquals("End of file", null, in.readLine());
384     }
385
386     public void testShowOutboundsPackageTrue() throws IOException {
387         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
388         factory.createPackage("empty");
389
390         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
391         printer.setShowInbounds(false);
392         printer.setShowOutbounds(true);
393
394         printer.traverseNodes(factory.getPackages().values());
395
396         int lineNumber = 0;
397         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
398
399         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
400         assertEquals("line " + ++lineNumber, "", in.readLine());
401         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
402         assertEquals("line " + ++lineNumber, "", in.readLine());
403         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
404         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
405         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
406         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
407         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
408         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
409         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
410         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
411         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
412         assertEquals("line " + ++lineNumber, " <outbound type=\"package\" confirmed=\"no\">inbound</outbound>", in.readLine());
413         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
414         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
415
416         assertEquals("End of file", null, in.readLine());
417     }
418
419     public void testShowOutboundsPackageFalse() throws IOException {
420         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
421         factory.createPackage("empty");
422
423         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
424         printer.setShowInbounds(false);
425         printer.setShowOutbounds(false);
426
427         printer.traverseNodes(factory.getPackages().values());
428
429         int lineNumber = 0;
430         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
431
432         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
433         assertEquals("line " + ++lineNumber, "", in.readLine());
434         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
435         assertEquals("line " + ++lineNumber, "", in.readLine());
436         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
437         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
438         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
439         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
440         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
441         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
442         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
443         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
444         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
445         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
446         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
447
448         assertEquals("End of file", null, in.readLine());
449     }
450
451     public void testShowOutboundsClassTrue() throws IOException {
452         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
453         factory.createClass("empty.Empty");
454
455         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
456         printer.setShowInbounds(false);
457         printer.setShowOutbounds(true);
458
459         printer.traverseNodes(factory.getPackages().values());
460
461         int lineNumber = 0;
462         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
463
464         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
465         assertEquals("line " + ++lineNumber, "", in.readLine());
466         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
467         assertEquals("line " + ++lineNumber, "", in.readLine());
468         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
469         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
470         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
471         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
472         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
473         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
474         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
475         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
476         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
477         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
478         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
479         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
480         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
481         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
482         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
483         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
484         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
485         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"no\">inbound.Inbound</outbound>", in.readLine());
486         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
487         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
488         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
489
490         assertEquals("End of file", null, in.readLine());
491     }
492
493     public void testShowOutboundsClassFalse() throws IOException {
494         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
495         factory.createClass("empty.Empty");
496
497         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
498         printer.setShowInbounds(false);
499         printer.setShowOutbounds(false);
500
501         printer.traverseNodes(factory.getPackages().values());
502
503         int lineNumber = 0;
504         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
505
506         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
507         assertEquals("line " + ++lineNumber, "", in.readLine());
508         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
509         assertEquals("line " + ++lineNumber, "", in.readLine());
510         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
511         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
512         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
513         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
514         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
515         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
516         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
517         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
518         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
519         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
520         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
521         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
522         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
523         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
524         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
525         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
526         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
527         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
528         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
529         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
530
531         assertEquals("End of file", null, in.readLine());
532     }
533
534     public void testShowOutboundsFeatureTrue() throws IOException {
535         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
536         factory.createFeature("empty.Empty.empty()");
537
538         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
539         printer.setShowInbounds(false);
540         printer.setShowOutbounds(true);
541
542         printer.traverseNodes(factory.getPackages().values());
543
544         int lineNumber = 0;
545         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
546
547         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
548         assertEquals("line " + ++lineNumber, "", in.readLine());
549         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
550         assertEquals("line " + ++lineNumber, "", in.readLine());
551         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
552         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
553         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
554         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
555         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
556         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
557         assertEquals("line " + ++lineNumber, " <name>empty.Empty.empty()</name>", in.readLine());
558         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
559         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
560         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
561         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
562         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
563         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
564         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
565         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
566         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
567         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
568         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
569         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
570         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
571         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
572         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
573         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
574         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
575         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
576         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
577         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
578         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
579         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
580         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
581
582         assertEquals("End of file", null, in.readLine());
583     }
584
585     public void testShowOutboundsFeatureFalse() throws IOException {
586         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
587         factory.createFeature("empty.Empty.empty()");
588
589         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
590         printer.setShowInbounds(false);
591         printer.setShowOutbounds(false);
592
593         printer.traverseNodes(factory.getPackages().values());
594
595         int lineNumber = 0;
596         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
597
598         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
599         assertEquals("line " + ++lineNumber, "", in.readLine());
600         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
601         assertEquals("line " + ++lineNumber, "", in.readLine());
602         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
603         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
604         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
605         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
606         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
607         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
608         assertEquals("line " + ++lineNumber, " <name>empty.Empty.empty()</name>", in.readLine());
609         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
610         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
611         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
612         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
613         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
614         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
615         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
616         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
617         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
618         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
619         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
620         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
621         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
622         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
623         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
624         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
625         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
626         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
627         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
628         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
629         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
630         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
631
632         assertEquals("End of file", null, in.readLine());
633     }
634     
635     public void testShowEmptyPackageTrue() throws IOException {
636         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
637         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
638         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
639         factory.createPackage("empty");
640
641         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
642         printer.setShowEmptyNodes(true);
643
644         printer.traverseNodes(factory.getPackages().values());
645
646         int lineNumber = 0;
647         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
648
649         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
650         assertEquals("line " + ++lineNumber, "", in.readLine());
651         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
652         assertEquals("line " + ++lineNumber, "", in.readLine());
653         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
654         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
655         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
656         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
657         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
658         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
659         assertEquals("line " + ++lineNumber, " <inbound type=\"package\" confirmed=\"no\">outbound</inbound>", in.readLine());
660         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
661         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
662         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"no\">outbound.Outbound</inbound>", in.readLine());
663         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
664         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
665         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
666         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
667         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
668         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
669         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
670         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
671         assertEquals("line " + ++lineNumber, " <outbound type=\"package\" confirmed=\"no\">inbound</outbound>", in.readLine());
672         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
673         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
674         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"no\">inbound.Inbound</outbound>", in.readLine());
675         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
676         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
677         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
678         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
679         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
680         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
681         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
682
683         assertEquals("End of file", null, in.readLine());
684     }
685     
686     public void testShowEmptyPackageTrueWithConfirmed() throws IOException {
687         factory.createPackage("outbound", true).addDependency(factory.createPackage("inbound", true));
688         factory.createClass("outbound.Outbound", true).addDependency(factory.createClass("inbound.Inbound", true));
689         factory.createFeature("outbound.Outbound.outbound()", true).addDependency(factory.createFeature("inbound.Inbound.inbound()", true));
690         factory.createPackage("empty", true);
691
692         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
693         printer.setShowEmptyNodes(true);
694
695         printer.traverseNodes(factory.getPackages().values());
696
697         int lineNumber = 0;
698         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
699
700         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
701         assertEquals("line " + ++lineNumber, "", in.readLine());
702         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
703         assertEquals("line " + ++lineNumber, "", in.readLine());
704         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
705         assertEquals("line " + ++lineNumber, " <package confirmed=\"yes\">", in.readLine());
706         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
707         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
708         assertEquals("line " + ++lineNumber, " <package confirmed=\"yes\">", in.readLine());
709         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
710         assertEquals("line " + ++lineNumber, " <inbound type=\"package\" confirmed=\"yes\">outbound</inbound>", in.readLine());
711         assertEquals("line " + ++lineNumber, " <class confirmed=\"yes\">", in.readLine());
712         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
713         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"yes\">outbound.Outbound</inbound>", in.readLine());
714         assertEquals("line " + ++lineNumber, " <feature confirmed=\"yes\">", in.readLine());
715         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
716         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"yes\">outbound.Outbound.outbound()</inbound>", in.readLine());
717         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
718         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
719         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
720         assertEquals("line " + ++lineNumber, " <package confirmed=\"yes\">", in.readLine());
721         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
722         assertEquals("line " + ++lineNumber, " <outbound type=\"package\" confirmed=\"yes\">inbound</outbound>", in.readLine());
723         assertEquals("line " + ++lineNumber, " <class confirmed=\"yes\">", in.readLine());
724         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
725         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"yes\">inbound.Inbound</outbound>", in.readLine());
726         assertEquals("line " + ++lineNumber, " <feature confirmed=\"yes\">", in.readLine());
727         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
728         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"yes\">inbound.Inbound.inbound()</outbound>", in.readLine());
729         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
730         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
731         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
732         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
733
734         assertEquals("End of file", null, in.readLine());
735     }
736
737     public void testShowEmptyPackageFalse() throws IOException {
738         factory.createPackage("outbound").addDependency(factory.createPackage("inbound"));
739         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
740         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
741         factory.createPackage("empty");
742
743         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
744         printer.setShowEmptyNodes(false);
745
746         printer.traverseNodes(factory.getPackages().values());
747
748         int lineNumber = 0;
749         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
750
751         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
752         assertEquals("line " + ++lineNumber, "", in.readLine());
753         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
754         assertEquals("line " + ++lineNumber, "", in.readLine());
755         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
756         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
757         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
758         assertEquals("line " + ++lineNumber, " <inbound type=\"package\" confirmed=\"no\">outbound</inbound>", in.readLine());
759         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
760         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
761         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"no\">outbound.Outbound</inbound>", in.readLine());
762         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
763         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
764         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
765         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
766         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
767         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
768         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
769         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
770         assertEquals("line " + ++lineNumber, " <outbound type=\"package\" confirmed=\"no\">inbound</outbound>", in.readLine());
771         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
772         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
773         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"no\">inbound.Inbound</outbound>", in.readLine());
774         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
775         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
776         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
777         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
778         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
779         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
780         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
781
782         assertEquals("End of file", null, in.readLine());
783     }
784
785     public void testShowEmptyClassTrue() throws IOException {
786         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
787         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
788         factory.createClass("empty.Empty");
789
790         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
791         printer.setShowEmptyNodes(true);
792
793         printer.traverseNodes(factory.getPackages().values());
794
795         int lineNumber = 0;
796         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
797
798         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
799         assertEquals("line " + ++lineNumber, "", in.readLine());
800         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
801         assertEquals("line " + ++lineNumber, "", in.readLine());
802         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
803         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
804         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
805         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
806         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
807         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
808         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
809         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
810         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
811         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
812         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
813         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"no\">outbound.Outbound</inbound>", in.readLine());
814         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
815         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
816         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
817         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
818         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
819         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
820         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
821         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
822         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
823         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
824         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"no\">inbound.Inbound</outbound>", in.readLine());
825         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
826         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
827         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
828         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
829         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
830         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
831         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
832
833         assertEquals("End of file", null, in.readLine());
834     }
835
836     public void testShowEmptyClassFalse() throws IOException {
837         factory.createClass("outbound.Outbound").addDependency(factory.createClass("inbound.Inbound"));
838         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
839         factory.createClass("empty.Empty");
840
841         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
842         printer.setShowEmptyNodes(false);
843
844         printer.traverseNodes(factory.getPackages().values());
845
846         int lineNumber = 0;
847         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
848
849         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
850         assertEquals("line " + ++lineNumber, "", in.readLine());
851         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
852         assertEquals("line " + ++lineNumber, "", in.readLine());
853         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
854         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
855         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
856         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
857         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
858         assertEquals("line " + ++lineNumber, " <inbound type=\"class\" confirmed=\"no\">outbound.Outbound</inbound>", in.readLine());
859         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
860         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
861         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
862         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
863         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
864         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
865         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
866         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
867         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
868         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
869         assertEquals("line " + ++lineNumber, " <outbound type=\"class\" confirmed=\"no\">inbound.Inbound</outbound>", in.readLine());
870         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
871         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
872         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
873         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
874         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
875         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
876         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
877
878         assertEquals("End of file", null, in.readLine());
879     }
880
881     public void testShowEmptyFeatureTrue() throws IOException {
882         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
883         factory.createFeature("empty.Empty.empty()");
884
885         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
886         printer.setShowEmptyNodes(true);
887
888         printer.traverseNodes(factory.getPackages().values());
889
890         int lineNumber = 0;
891         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
892
893         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
894         assertEquals("line " + ++lineNumber, "", in.readLine());
895         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
896         assertEquals("line " + ++lineNumber, "", in.readLine());
897         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
898         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
899         assertEquals("line " + ++lineNumber, " <name>empty</name>", in.readLine());
900         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
901         assertEquals("line " + ++lineNumber, " <name>empty.Empty</name>", in.readLine());
902         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
903         assertEquals("line " + ++lineNumber, " <name>empty.Empty.empty()</name>", in.readLine());
904         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
905         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
906         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
907         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
908         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
909         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
910         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
911         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
912         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
913         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
914         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
915         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
916         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
917         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
918         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
919         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
920         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
921         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
922         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
923         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
924         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
925         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
926         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
927         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
928
929         assertEquals("End of file", null, in.readLine());
930     }
931
932     public void testShowEmptyFeatureFalse() throws IOException {
933         factory.createFeature("outbound.Outbound.outbound()").addDependency(factory.createFeature("inbound.Inbound.inbound()"));
934         factory.createFeature("empty.Empty.empty()");
935
936         printer = new XMLPrinter(new PrintWriter(out), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
937         printer.setShowEmptyNodes(false);
938
939         printer.traverseNodes(factory.getPackages().values());
940
941         int lineNumber = 0;
942         BufferedReader in = new BufferedReader(new StringReader(out.toString()));
943
944         assertEquals("line " + ++lineNumber, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", in.readLine());
945         assertEquals("line " + ++lineNumber, "", in.readLine());
946         assertEquals("line " + ++lineNumber, "<!DOCTYPE dependencies SYSTEM \"./etc/dependencies.dtd\">", in.readLine());
947         assertEquals("line " + ++lineNumber, "", in.readLine());
948         assertEquals("line " + ++lineNumber, "<dependencies>", in.readLine());
949         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
950         assertEquals("line " + ++lineNumber, " <name>inbound</name>", in.readLine());
951         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
952         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound</name>", in.readLine());
953         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
954         assertEquals("line " + ++lineNumber, " <name>inbound.Inbound.inbound()</name>", in.readLine());
955         assertEquals("line " + ++lineNumber, " <inbound type=\"feature\" confirmed=\"no\">outbound.Outbound.outbound()</inbound>", in.readLine());
956         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
957         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
958         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
959         assertEquals("line " + ++lineNumber, " <package confirmed=\"no\">", in.readLine());
960         assertEquals("line " + ++lineNumber, " <name>outbound</name>", in.readLine());
961         assertEquals("line " + ++lineNumber, " <class confirmed=\"no\">", in.readLine());
962         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound</name>", in.readLine());
963         assertEquals("line " + ++lineNumber, " <feature confirmed=\"no\">", in.readLine());
964         assertEquals("line " + ++lineNumber, " <name>outbound.Outbound.outbound()</name>", in.readLine());
965         assertEquals("line " + ++lineNumber, " <outbound type=\"feature\" confirmed=\"no\">inbound.Inbound.inbound()</outbound>", in.readLine());
966         assertEquals("line " + ++lineNumber, " </feature>", in.readLine());
967         assertEquals("line " + ++lineNumber, " </class>", in.readLine());
968         assertEquals("line " + ++lineNumber, " </package>", in.readLine());
969         assertEquals("line " + ++lineNumber, "</dependencies>", in.readLine());
970
971         assertEquals("End of file", null, in.readLine());
972     }
973
974     public void error(SAXParseException ex) {
975         // Ignore
976
}
977
978     public void fatalError(SAXParseException ex) {
979         // Ignore
980
}
981
982     public void warning(SAXParseException ex) {
983         // Ignore
984
}
985 }
986
Popular Tags