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.amazonaws.ant.s3.DownloadFromS3TaskTests.java
@Test public void testDownloadSingleFile() throws IOException { DownloadFileFromS3Task task = new DownloadFileFromS3Task(); task.setProject(new Project()); task.setBucketName(BUCKET_NAME);//w ww .j a va 2 s . c o m task.setKey(KEY_PREFIX + testFile1.getName()); resFile1 = File.createTempFile(RES_FILE, TESTFILE_SUFFIX); resFile1.createNewFile(); task.setFile(resFile1); task.execute(); assertTrue(FileUtils.contentEquals(testFile1, resFile1)); }
From source file:de.douglas.maven.plugin.rpmsystemd.systemd.SystemdMojoTest.java
public void testGenerateSystemdFileWithOverwrittenSettings() throws Exception { final Path testBaseDir = createDir(systemdTestsBaseDir.resolve("overwrite")); createDir(testBaseDir.resolve("target")); File pom = getTestFile(systemdSrcDir.resolve("pom-overwrite.xml").toString()); SystemdMojo systemdMojo = (SystemdMojo) lookupMojo("generate-systemd-file", pom); systemdMojo.execute();/* w w w . j a v a 2 s. c om*/ assertTrue("Generated systemd service file does not equal expected one", FileUtils.contentEquals(systemdSrcDir.resolve("test-module.service-overwrite-expected").toFile(), testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin").resolve("some.service") .toFile())); }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.dao.DaoUtilsTest.java
@SuppressWarnings("resource") @Test//from www . ja va2 s . c om public void testZipFolder() { File toBeZippedFiles = new File("src/test/resources"); File zipedFiles = new File("target/" + toBeZippedFiles.getName() + ".zip"); try { ZipUtils.zipFolder(toBeZippedFiles, zipedFiles); } catch (Exception e) { LOG.info("Zipping fails" + ExceptionUtils.getRootCauseMessage(e)); } FileInputStream fs; try { fs = new FileInputStream(zipedFiles); ZipInputStream zis = new ZipInputStream(fs); ZipEntry zE; while ((zE = zis.getNextEntry()) != null) { for (File toBeZippedFile : toBeZippedFiles.listFiles()) { if ((FilenameUtils.getBaseName(toBeZippedFile.getName())) .equals(FilenameUtils.getBaseName(zE.getName()))) { // Extract the zip file, save it to temp and compare ZipFile zipFile = new ZipFile(zipedFiles); ZipEntry zipEntry = zipFile.getEntry(zE.getName()); InputStream is = zipFile.getInputStream(zipEntry); File temp = File.createTempFile("temp", ".txt"); OutputStream out = new FileOutputStream(temp); IOUtils.copy(is, out); FileUtils.contentEquals(toBeZippedFile, temp); } } zis.closeEntry(); } } catch (FileNotFoundException e) { LOG.info("zipped file not found " + ExceptionUtils.getRootCauseMessage(e)); } catch (IOException e) { LOG.info("Unable to get file " + ExceptionUtils.getRootCauseMessage(e)); } }
From source file:at.makubi.maven.plugin.avrohugger.AvrohuggerGeneratorTest.java
public void testAvrohuggerGeneratorRecursive() throws IOException { Path inputDirectory = Paths.get(getBasedir()).resolve("src/test/resources/unit/avrohugger-maven-plugin"); Path schemaDirectory = inputDirectory.resolve("schema"); File expectedRecord = inputDirectory.resolve("expected/Record.scala").toFile(); File actualRecords = outputDirectory.resolve("at/makubi/maven/plugin/model/Record.scala").toFile(); File expectedSubRecord = inputDirectory.resolve("expected/SubRecord.scala").toFile(); File actualSubRecords = outputDirectory.resolve("at/makubi/maven/plugin/model/submodel/SubRecord.scala") .toFile();/*w ww. ja v a 2 s .c o m*/ avrohuggerGenerator.generateScalaFiles(schemaDirectory.toFile(), outputDirectory.toString(), new SystemStreamLog(), true); assertTrue("Generated Scala Record file does not match expected one", FileUtils.contentEquals(expectedRecord, actualRecords)); assertTrue("Generated Scala SubRecord file does not match expected one", FileUtils.contentEquals(expectedSubRecord, actualSubRecords)); }
From source file:com.ftb2om2.view.ConverterNGTest.java
@Test(enabled = false) public void FtbOldToOsuMania() 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;/*from w ww . j ava 2s . c om*/ Metadata metadata = new Metadata("", "", "", "", "", ""); Converter instance = new Converter(new FtbOldReader(), 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.amazonaws.ant.s3.UploadFileSetToS3TaskTests.java
@Test public void testExecuteSingleFile() throws FileNotFoundException, IOException { UploadFileSetToS3Task task = new UploadFileSetToS3Task(); task.setProject(new Project()); FileSet fileset = new FileSet(); fileset.setDir(testFile1.getParentFile()); fileset.setFile(testFile1);/*from w w w . j a v a 2s .co m*/ task.addFileset(fileset); task.setBucketName(BUCKET_NAME); task.setKeyPrefix(KEY_PREFIX); task.execute(); resFile1 = File.createTempFile(RES_FILE_1, TESTFILE_SUFFIX); client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX + fileName1), resFile1); assertTrue(FileUtils.contentEquals(testFile1, resFile1)); }
From source file:gov.nih.nci.cabig.caaers.service.adverseevent.AdditionalInformationDocumentServiceIntegrationTest.java
public void testFileUploadSameFileMultipleTimes() throws IOException { for (int i = 0; i < 3; i++) { AdditionalInformationDocument additionalInformationDocument = additionalInformationDocumentService .uploadFile(file.getName(), additionalInformation, new FileInputStream(file), ADDITIONAL_INFORMATION_DOCUMENT_TYPE); AdditionalInformationDocument additionalInformationDocumentServiceByFileId = additionalInformationDocumentService .findByFileId(additionalInformationDocument.getFileId()); assertNotNull(additionalInformationDocument); assertNotNull(additionalInformationDocument.getId()); assertEquals(ADDITIONAL_INFORMATION_DOCUMENT_TYPE, additionalInformationDocument.getAdditionalInformationDocumentType()); assertTrue(FileUtils.contentEquals(file, new File(additionalInformationDocument.getFilePath()))); assertNotNull(additionalInformationDocumentServiceByFileId); assertNotNull(additionalInformationDocumentServiceByFileId.getFile()); assertTrue(additionalInformationDocumentServiceByFileId.getFile().exists()); assertTrue(FileUtils.contentEquals(file, additionalInformationDocumentServiceByFileId.getFile())); }//www . j a va 2 s. c om }
From source file:dremel.common.AvroTest.java
@SuppressWarnings("unchecked") @Test/*w w w. ja va2s .com*/ public void deepCopyTest() throws IOException { Schema inSchema = getSchema("OrecSchema.avpr.json"); File inFile = getFile("OrecDremelPaperData.avro.json"); Array<GenericRecord> inData = getData(inSchema, inFile, FileEncoding.JSON); File outFile = getTempFile("AvroTestCopyDeep.avro.json"); FileUtils.deleteQuietly(outFile); Encoder encoder = new JsonEncoder(inSchema, new FileOutputStream(outFile)); DatumWriter<Array<GenericRecord>> writer = new GenericDatumWriter<Array<GenericRecord>>(inSchema); Array<GenericRecord> outData = (Array<GenericRecord>) deepCopyRecursive(inSchema, inData); writer.write(outData, encoder); encoder.flush(); assertTrue("Copied files differs", FileUtils.contentEquals(inFile, outFile)); // FileUtils.forceDelete(outFile); FileUtils.forceDeleteOnExit(outFile); // TODO fucking file hasn't being // deleted for some reason }
From source file:com.microsoft.alm.plugin.idea.common.setup.WindowsStartupTest.java
@Test public void testDoesKeyNeedUpdated_ExistingCmdNewer() throws Exception { TEST_EXE = File.createTempFile(TEST_CMD_NAME, ".cmd"); Mockito.when(FileUtils.contentEquals(TEST_EXE, mockCmdFile)).thenReturn(false); Mockito.when(mockCmdFile.getPath()).thenReturn(TEST_CMD_NAME); Mockito.when(mockCmdFile.lastModified()).thenReturn(TEST_EXE.lastModified() - 1000); Mockito.when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, WindowsStartup.VSOI_KEY, "")) .thenReturn(TEST_EXE.getPath() + " \"%1\""); Assert.assertFalse(WindowsStartup.doesKeyNeedUpdated(mockCmdFile)); }
From source file:de.nbi.ontology.test.TextEnhancerTest.java
/** * Test, if texts are enhances properly. * /*w ww . java2s.c om*/ * @param inFile * a text * @throws IOException */ @Test(dataProviderClass = TestFileProvider.class, dataProvider = "enhanceTestFiles", groups = { "functest" }) public void exactMatch(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"); PrintWriter w = new PrintWriter(new FileWriter(outFile)); XWikiTextEnhancer enhancer = new XWikiTextEnhancer(); String text = FileUtils.readFileToString(inFile); String newText = enhancer.enhance(text); w.print(newText); w.flush(); w.close(); Assert.assertTrue(FileUtils.contentEquals(outFile, resFile)); }