1 package info.magnolia.cms.core.ie; 2 3 import java.io.File ; 4 import java.io.FileOutputStream ; 5 import java.io.FileReader ; 6 import java.io.OutputStream ; 7 import java.io.Reader ; 8 import java.util.Iterator ; 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 ; 18 import org.xml.sax.helpers.XMLReaderFactory ; 19 20 21 25 public class DataTransporterTest extends XMLTestCase { 26 27 30 private static Logger log = LoggerFactory.getLogger(DataTransporterTest.class); 31 32 36 public void testParseAndFormat() throws Exception { 37 38 File inputFile = new File (getClass().getResource("/test-formatted-input.xml").getFile()); 39 File outputFile = File.createTempFile("export-test-", ".xml"); OutputStream outputStream = new FileOutputStream (outputFile); 41 42 XMLReader 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 expectedReader = new FileReader (new File (getClass() 49 .getResource("/test-formatted-expected.xml") 50 .getFile())); 51 Reader actualReader = new FileReader (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 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 |