List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:com.geewhiz.pacify.commandline.TestShowUsedProperties.java
@Test public void writeToFileWithPrefix() throws Exception { File targetResourceFolder = new File("target/test-classes/testShowUsedProperties"); File packagePath = new File(targetResourceFolder, "package"); File resultFile = new File(targetResourceFolder, "expectedResult/resultWithPrefix.txt"); File destinationFile = new File(targetResourceFolder, "result/resultWithPrefix.txt"); destinationFile.delete();/*from ww w . j a v a2s . c o m*/ PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline(); int result = pacifyViaCommandline.mainInternal(new String[] { "showUsedProperties", "--packagePath=" + packagePath, "--outputPrefix=###", "--destinationFile=" + destinationFile }); Assert.assertEquals("ShowUsedProperties returned with errors.", 0, result); Assert.assertTrue("Content is same", FileUtils.contentEquals(resultFile, destinationFile)); }
From source file:com.meltmedia.rodimus.DocumentTransformationTest.java
@Test public void compareAssets() throws IOException { File expectedImages = new File(expectedOutputDir, RodimusCli.IMAGE_DIR_NAME); File actualImages = new File(actualOutputDir, RodimusCli.IMAGE_DIR_NAME); assertEquals("Image directories don't match.", expectedImages.exists(), actualImages.exists()); if (!expectedImages.exists() || expectedImages.list().length == 0) { assertTrue("Images produced when none expected!", !actualImages.exists() || actualImages.list().length == 0); return;//from w w w. jav a2 s . c om } for (File expected : expectedImages.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile(); } })) { File actual = new File(actualImages, expected.getName()); if (!actual.exists() && actual.isFile()) { fail("The file " + actual + " does not exist, or is not a file."); } if (!FileUtils.contentEquals(expected, actual)) { fail("The content in " + actual + " is different than " + expected); } } }
From source file:com.ftb2om2.view.ConverterNGTest.java
@Test(enabled = true) public void FtbOldReaderTreeToOsuMania() throws Exception { System.out.println("Testing conversion between FtbClassic and o!m"); String x = getClass().getResource("/").getPath(); String inputFilePath = getClass().getResource("/ftbOldTest1.txt").getPath(); String outputFilePath = getClass().getResource("/").getPath(); String name = "osuTestOutput2"; Integer volume = 100;// ww w . ja va 2 s.c o m Metadata metadata = new Metadata("", "", "", "", "", ""); Converter instance = new Converter(new FtbOldReaderTree(), new OsuManiaV14Writer()); instance.convert(inputFilePath, outputFilePath, name, volume, metadata); // TODO review the generated test code and remove the default call to fail. File correctOutput = new File(getClass().getResource("/osuCorrectOutput2.osu").getPath()); File generatedOutput = new File(getClass().getResource("/osuTestOutput2.osu").getPath()); assertTrue(FileUtils.contentEquals(correctOutput, generatedOutput)); }
From source file:com.datatorrent.lib.io.block.FSSliceReaderTest.java
@Test public void testBytesReceived() throws IOException { long blockSize = 1500; int noOfBlocks = (int) ((testMeta.dataFile.length() / blockSize) + (((testMeta.dataFile.length() % blockSize) == 0) ? 0 : 1)); testMeta.blockReader.beginWindow(1); for (int i = 0; i < noOfBlocks; i++) { BlockMetadata.FileBlockMetadata blockMetadata = new BlockMetadata.FileBlockMetadata( testMeta.dataFile.getAbsolutePath(), i, i * blockSize, i == noOfBlocks - 1 ? testMeta.dataFile.length() : (i + 1) * blockSize, i == noOfBlocks - 1, i - 1);/*from w ww. j av a2 s. co m*/ testMeta.blockReader.blocksMetadataInput.process(blockMetadata); } testMeta.blockReader.endWindow(); List<Object> messages = testMeta.messageSink.collectedTuples; long totatBytesReceived = 0; File outputFile = new File(testMeta.output + "/reader_test_data.csv"); FileOutputStream outputStream = new FileOutputStream(outputFile); for (Object message : messages) { @SuppressWarnings("unchecked") AbstractBlockReader.ReaderRecord<Slice> msg = (AbstractBlockReader.ReaderRecord<Slice>) message; totatBytesReceived += msg.getRecord().length; outputStream.write(msg.getRecord().buffer); } outputStream.close(); Assert.assertEquals("number of bytes", testMeta.dataFile.length(), totatBytesReceived); FileUtils.contentEquals(testMeta.dataFile, outputFile); }
From source file:com.itextpdf.tool.xml.net.FileRetrieveTest.java
@Test public void retrieveStreamFromFile() throws MalformedURLException, IOException { final FileOutputStream out = new FileOutputStream(actual); InputStream css = FileRetrieveTest.class.getResourceAsStream("/css/test.css"); retriever.processFromStream(css, new ReadingProcessor() { public void process(final int inbit) { try { out.write((char) inbit); } catch (IOException e) { throw new RuntimeWorkerException(e); }/*from ww w . j av a2 s . c o m*/ } }); css.close(); out.close(); Assert.assertTrue(FileUtils.contentEquals(expected, actual)); }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that the reformat compact reads mode is capable of writing the same contents. * * @throws IOException if there is a problem reading or writing to the files *//*from w w w.jav a 2 s. co m*/ @Test public void zeroEntries() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads"; reformat.setInputFilenames(inputFilename); reformat.setStartPosition(0L); reformat.setEndPosition(0L); final String outputFilename = "test-results/reformat-test-zero-zero.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); final File inputFile = new File(inputFilename); final File outputFile = new File(outputFilename); assertFalse("The reformatted file should not be the same as the original", FileUtils.contentEquals(inputFile, outputFile)); final ReadsReader reader = new ReadsReader(FileUtils.openInputStream(outputFile)); assertFalse("There should be no reads in this file", reader.hasNext()); }
From source file:de.nbi.ontology.test.OntologyMatchTest.java
/** * Test, if terms are properly match to concept labels. The a list of terms * contains a term in each line.// w w w . j a v a2 s .c o m * * @param inFile * a list of terms * @throws IOException */ @SuppressWarnings("unchecked") @Test(dataProviderClass = TestFileProvider.class, dataProvider = "parentTestFiles", groups = { "functest" }) public void parents(File inFile) throws IOException { log.info("Processing " + inFile.getName()); String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath()); File outFile = new File(basename + ".out"); File resFile = new File(basename + ".res"); List<String> terms = FileUtils.readLines(inFile); PrintWriter w = new PrintWriter(new FileWriter(outFile)); for (String term : terms) { OntClass clazz = index.getModel().getOntClass(term); log.trace("** matching " + term); w.println(index.getParents(clazz)); } w.flush(); w.close(); Assert.assertTrue(FileUtils.contentEquals(outFile, resFile)); }
From source file:net.desgrange.pwad.service.PwadServiceTest.java
@Test public void testDownloadPicture() throws Exception { final File outputFolder = testFolder.newFolder("output_folder"); final URL pictureFile = getClass().getResource("/pictures/100_0001.JPG"); final Picture picture = new Picture(); picture.setName("01.JPG"); picture.setUrl("file://" + pictureFile.getFile()); pwadService.downloadPicture(picture, outputFolder); assertTrue(FileUtils.contentEquals(new File(pictureFile.toURI()), outputFolder.listFiles()[0])); }
From source file:com.santiagolizardo.madcommander.menu.FilesMenu.java
@Override public void actionPerformed(ActionEvent ev) { Object source = ev.getSource(); if (source == changeAttributesMenuItem) { ChangeAttributesDialog changeAttributesDialog = new ChangeAttributesDialog(mainWindow); changeAttributesDialog.setVisible(true); } else if (source == changeModificationDatetimeMenuItem) { ChangeModificationDateTimeDialog dialog = new ChangeModificationDateTimeDialog(mainWindow); dialog.setVisible(true);/*from w w w. j a v a 2 s . c om*/ } else if (source == unpackMenuItem) { List<File> list = mainWindow.getSource().getSelectedFiles(); if (list.size() == 1) { File file = list.get(0); StringBuilder buffer = new StringBuilder(); buffer.append(mainWindow.getSource().getPath()); buffer.append(File.separator); buffer.append(file.getName()); UnpackDialog unpackDialog = new UnpackDialog(buffer.toString()); unpackDialog.setVisible(true); } else { DialogFactory.showErrorMessage(mainWindow, "Only pick one file to unpack at time."); } } else if (source == printMenuItem) { FileListing listing = mainWindow.getSource(); listing.print(); } else if (source == quitMenuItem) { mainWindow.quit(); } else if (source == compareByContent) { List<File> files1 = mainWindow.getSource().getSelectedFiles(); List<File> files2 = mainWindow.getDestination().getSelectedFiles(); if (files1.isEmpty() || files2.isEmpty()) { DialogFactory.showInformationMessage(mainWindow, "Please select a file on each panel first to compare their contents."); return; } File file1 = files1.get(0); File file2 = files2.get(0); try { if (FileUtils.contentEquals(file1, file2) == true) { DialogFactory.showInformationMessage(mainWindow, "The content of the files is identical."); } else { DialogFactory.showInformationMessage(mainWindow, "The content of the files is not the same."); } } catch (IOException e) { DialogFactory.showErrorMessage(mainWindow, "Could not compare the contents of the files."); } } }
From source file:com.cisco.cta.taxii.adapter.AdapterTaskIT.java
@Test public void handleStatusMessage() throws Exception { initialRequestResponse();/*from w w w .ja v a2 s . c o m*/ requestStatusMessage(2); nextRequestResponse(3); assertThat(statistics.getPolls(), is(3L)); assertThat(statistics.getLogs(), is(2L)); assertThat(statistics.getErrors(), is(1L)); assertTrue(OUTPUT_FILE + " content expected same as " + EXPECTED_OUTPUT_FILE, FileUtils.contentEquals(OUTPUT_FILE, EXPECTED_OUTPUT_FILE)); }