assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file1, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file2, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(file2, file2, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(file2, file1, null)); FileUtils.contentEqualsIgnoreEOL(getTestDirectory(), getTestDirectory(), null); fail("Comparing directories should fail with an IOException"); } catch (final IOException ioe) { assertTrue(FileUtils.contentEqualsIgnoreEOL(tfile1, tfile1, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(tfile2, tfile2, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(tfile3, tfile3, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(tfile1, tfile2, null)); assertFalse(FileUtils.contentEqualsIgnoreEOL(tfile1, tfile3, null)); assertFalse(FileUtils.contentEqualsIgnoreEOL(tfile2, tfile3, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(cr, cr, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(crlf, crlf, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(lf, lf, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(cr, crlf, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(cr, lf, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(crlf, lf, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file1, null)); assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file2, null));
public static boolean contentEqualsIgnoreEOL(ActionContext actionContext) throws IOException{ Thing self = actionContext.getObject("self"); File file1 = getFile(self, "getFile1", actionContext); File file2 = getFile(self, "getFile2", actionContext); String charsetName = (String) self.doAction("getCharsetName", actionContext); return FileUtils.contentEqualsIgnoreEOL(file1, file2, charsetName); }
@Test public void testCsv() throws Exception { BandData root = createRootCsvTree(); FileOutputStream outputStream = new FileOutputStream("./result/integration/result.csv"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("csv", root, new ReportTemplateImpl("", "test.csv", "./modules/core/test/integration/test.csv", ReportOutputType.csv), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); File sample = new File("./modules/core/test/integration/ethalon.csv"); File result = new File("./result/integration/result.csv"); boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null); Assert.assertTrue("Files are not equal", isTwoEqual); }
@Test public void testCsvQuote() throws Exception { BandData root = createRootCsvTree(); FileOutputStream outputStream = new FileOutputStream("./result/integration/result-quote.csv"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("csv", root, new ReportTemplateImpl("", "test-quote.csv", "./modules/core/test/integration/test-quote.csv", ReportOutputType.csv), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); File sample = new File("./modules/core/test/integration/ethalon-quote.csv"); File result = new File("./result/integration/result-quote.csv"); boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null); Assert.assertTrue("Files are not equal", isTwoEqual); }
@Test public void testRecoveryMode() throws IOException { // edits generated by nnHelper (MiniDFSCluster), should have all op codes // binary, XML, reparsed binary String edits = nnHelper.generateEdits(); FileOutputStream os = new FileOutputStream(edits, true); // Corrupt the file by truncating the end FileChannel editsFile = os.getChannel(); editsFile.truncate(editsFile.size() - 5); String editsParsedXml = folder.newFile("editsRecoveredParsed.xml") .getAbsolutePath(); String editsReparsed = folder.newFile("editsRecoveredReparsed") .getAbsolutePath(); String editsParsedXml2 = folder.newFile("editsRecoveredParsed2.xml") .getAbsolutePath(); // Can't read the corrupted file without recovery mode assertEquals(-1, runOev(edits, editsParsedXml, "xml", false)); // parse to XML then back to binary assertEquals(0, runOev(edits, editsParsedXml, "xml", true)); assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false)); assertEquals(0, runOev(editsReparsed, editsParsedXml2, "xml", false)); // judgment time assertTrue("Test round trip", FileUtils.contentEqualsIgnoreEOL( new File(editsParsedXml), new File(editsParsedXml2), "UTF-8")); os.close(); }
@Test public void testHtmlFormatter() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); BandData userBand = new BandData("User", root, BandOrientation.HORIZONTAL); userBand.addData("active", true); userBand.addData("login", "admin"); root.addChild(userBand); root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("User"); FileOutputStream outputStream = new FileOutputStream("./result/integration/html-groovy-test-result.html"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("html", root, new ReportTemplateImpl("", "./modules/core/test/integration/html-groovy-test-template.html", "./modules/core/test/integration/html-groovy-test-template.html", ReportOutputType.html, true), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); File sample = new File("./modules/core/test/integration/html-groovy-test-template-result.html"); File result = new File("./result/integration/html-groovy-test-result.html"); boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null); Assert.assertTrue("Files are not equal", isTwoEqual); } }
@Test public void testStored() throws IOException { // reference edits stored with source code (see build.xml) final String cacheDir = System.getProperty("test.cache.data", "build/test/cache"); // binary, XML, reparsed binary String editsStored = cacheDir + "/editsStored"; String editsStoredParsedXml = cacheDir + "/editsStoredParsed.xml"; String editsStoredReparsed = cacheDir + "/editsStoredReparsed"; // reference XML version of editsStored (see build.xml) String editsStoredXml = cacheDir + "/editsStored.xml"; // parse to XML then back to binary assertEquals(0, runOev(editsStored, editsStoredParsedXml, "xml", false)); assertEquals(0, runOev(editsStoredParsedXml, editsStoredReparsed, "binary", false)); // judgement time assertTrue("Edits " + editsStored + " should have all op codes", hasAllOpCodes(editsStored)); assertTrue("Reference XML edits and parsed to XML should be same", FileUtils.contentEqualsIgnoreEOL(new File(editsStoredXml), new File(editsStoredParsedXml), "UTF-8")); assertTrue( "Reference edits and reparsed (bin to XML to bin) should be same", filesEqualIgnoreTrailingZeros(editsStored, editsStoredReparsed)); }
boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null);