KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > core > ie > DataTransporterTest


1 package info.magnolia.cms.core.ie;
2
3 import java.io.File JavaDoc;
4 import java.io.FileOutputStream JavaDoc;
5 import java.io.FileReader JavaDoc;
6 import java.io.OutputStream JavaDoc;
7 import java.io.Reader JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 import org.apache.commons.io.IOUtils;
11 import org.custommonkey.xmlunit.DetailedDiff;
12 import org.custommonkey.xmlunit.Diff;
13 import org.custommonkey.xmlunit.Difference;
14 import org.custommonkey.xmlunit.XMLTestCase;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.xml.sax.XMLReader JavaDoc;
18 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
19
20
21 /**
22  * @author fgiust
23  * @version $Revision: 6683 $ ($Author: gjoseph $)
24  */

25 public class DataTransporterTest extends XMLTestCase {
26
27     /**
28      * Logger.
29      */

30     private static Logger log = LoggerFactory.getLogger(DataTransporterTest.class);
31
32     /**
33      * Test method for
34      * {@link info.magnolia.cms.core.ie.DataTransporter#readFormatted(org.xml.sax.XMLReader, java.io.File, java.io.OutputStream)}.
35      */

36     public void testParseAndFormat() throws Exception JavaDoc {
37
38         File JavaDoc inputFile = new File JavaDoc(getClass().getResource("/test-formatted-input.xml").getFile());
39         File JavaDoc outputFile = File.createTempFile("export-test-", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
40
OutputStream JavaDoc outputStream = new FileOutputStream JavaDoc(outputFile);
41
42         XMLReader JavaDoc reader = XMLReaderFactory.createXMLReader(org.apache.xerces.parsers.SAXParser.class.getName());
43
44         DataTransporter.readFormatted(reader, inputFile, outputStream);
45
46         IOUtils.closeQuietly(outputStream);
47
48         Reader JavaDoc expectedReader = new FileReader JavaDoc(new File JavaDoc(getClass()
49             .getResource("/test-formatted-expected.xml")
50             .getFile()));
51         Reader JavaDoc actualReader = new FileReader JavaDoc(outputFile);
52
53         DetailedDiff xmlDiff = new DetailedDiff(new Diff(expectedReader, actualReader));
54
55         IOUtils.closeQuietly(expectedReader);
56         IOUtils.closeQuietly(actualReader);
57         outputFile.delete();
58
59         for (Iterator JavaDoc iter = xmlDiff.getAllDifferences().iterator(); iter.hasNext();) {
60             Difference difference = (Difference) iter.next();
61
62             log.warn("expected> " + difference.getControlNodeDetail().getValue());
63             log.warn("actual > " + difference.getTestNodeDetail().getValue());
64
65         }
66
67         assertTrue("Document is not formatted as expected", xmlDiff.identical());
68     }
69
70 }
71
Popular Tags