List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:ProxyAuthTest.java
private static void compareResults(File file2) throws IOException { // load the expected results File baseResultFile = new File(System.getProperty("proxyAuth.res.file"), "data/files/ProxyAuth.res"); if (!FileUtils.contentEquals(baseResultFile, file2)) { throw new IOException("File compare failed: " + file2.getPath() + " differs"); }/*from w w w. j a v a 2s.com*/ }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that setting a read length trim value will not exclude reads that are * within the limit from being written to the output. * * @throws IOException if there is a problem reading or writing to the files *///from w w w . j a v a 2 s .c om @Test public void trimReadLengthsAt35() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads"; reformat.setInputFilenames(inputFilename); reformat.setTrimReadLength(35); final String outputFilename = "test-results/reformat-test-exclude-read-lengths-at-extrreme.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); assertTrue(FileUtils.contentEquals(new File(inputFilename), new File(outputFilename))); }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void createReadJobWithBigFile() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {/* w w w . ja v a 2 s.com*/ final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final AtomicBoolean dataTransferredEventReceived = new AtomicBoolean(false); final AtomicBoolean objectCompletedEventReceived = new AtomicBoolean(false); final AtomicBoolean checksumEventReceived = new AtomicBoolean(false); final AtomicBoolean metadataEventReceived = new AtomicBoolean(false); final AtomicBoolean waitingForChunksEventReceived = new AtomicBoolean(false); final AtomicBoolean failureEventReceived = new AtomicBoolean(false); readJob.attachDataTransferredListener(new DataTransferredListener() { @Override public void dataTransferred(final long size) { dataTransferredEventReceived.set(true); assertEquals(bookSize, size); } }); readJob.attachObjectCompletedListener(new ObjectCompletedListener() { @Override public void objectCompleted(final String name) { objectCompletedEventReceived.set(true); } }); readJob.attachChecksumListener(new ChecksumListener() { @Override public void value(final BulkObject obj, final ChecksumType.Type type, final String checksum) { checksumEventReceived.set(true); assertEquals("0feqCQBgdtmmgGs9pB/Huw==", checksum); } }); readJob.attachMetadataReceivedListener(new MetadataReceivedListener() { @Override public void metadataReceived(final String filename, final Metadata metadata) { metadataEventReceived.set(true); } }); readJob.attachWaitingForChunksListener(new WaitingForChunksListener() { @Override public void waiting(final int secondsToWait) { waitingForChunksEventReceived.set(true); } }); readJob.attachFailureEventListener(new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { failureEventReceived.set(true); } }); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); readJob.transfer(new FileObjectGetter(tempDirectory)); final File originalFile = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME).toFile(); final File fileCopiedFromBP = Paths.get(tempDirectory.toString(), FILE_NAME).toFile(); assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP)); assertTrue(dataTransferredEventReceived.get()); assertTrue(objectCompletedEventReceived.get()); assertTrue(checksumEventReceived.get()); assertTrue(metadataEventReceived.get()); assertFalse(waitingForChunksEventReceived.get()); assertFalse(failureEventReceived.get()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:jetbrains.buildServer.torrent.TorrentTransportTest.java
public void testCopyIfAlreadySeeding() throws IOException, InterruptedException, NoSuchAlgorithmException { setTorrentTransportEnabled();//from www . j av a2s . c o m setDownloadHonestly(true); final File storageDir = new File(myTempDir, "storageDir"); storageDir.mkdir(); final File downloadDir = new File(myTempDir, "downloadDir"); downloadDir.mkdir(); final File torrentsDir = new File(myTempDir, "torrentsDir"); torrentsDir.mkdir(); final String fileName = "MyBuild.31.zip"; final File artifactFile = new File(storageDir, fileName); createTempFile(20250).renameTo(artifactFile); final File teamcityIvyFile = new File("agent/tests/resources/" + TorrentTransportFactory.TEAMCITY_IVY); myDownloadMap.put("/" + TorrentTransportFactory.TEAMCITY_IVY, teamcityIvyFile); final String ivyUrl = SERVER_PATH + TorrentTransportFactory.TEAMCITY_IVY; final File ivyFile = new File(myTempDir, TorrentTransportFactory.TEAMCITY_IVY); myTorrentTransport.downloadUrlTo(ivyUrl, ivyFile); Tracker tracker = new Tracker(6969); try { tracker.start(true); myDirectorySeeder.start(new InetAddress[] { InetAddress.getLocalHost() }, tracker.getAnnounceURI(), 5); final Torrent torrent = Torrent.create(artifactFile, tracker.getAnnounceURI(), "testplugin"); final File torrentFile = new File(torrentsDir, fileName + ".torrent"); torrent.save(torrentFile); myDirectorySeeder.getTorrentSeeder().seedTorrent(torrent, artifactFile); myDownloadMap.put("/.teamcity/torrents/" + fileName + ".torrent", torrentFile); final File targetFile = new File(downloadDir, fileName); final String digest = myTorrentTransport.downloadUrlTo(SERVER_PATH + fileName, targetFile); assertEquals(torrent.getHexInfoHash(), digest); assertTrue(FileUtils.contentEquals(artifactFile, targetFile)); } finally { tracker.stop(); } }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that setting a read length trim value will write the trimmed reads to * the output properly.// www .ja v a 2 s .c om * * @throws IOException if there is a problem reading or writing to the files */ public void trimReadLengthsAt23() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads"; reformat.setInputFilenames(inputFilename); final String outputFilename = "test-results/reformat-test-start.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); reformat.setTrimReadLength(23); 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)); assertTrue("There should be reads in this file", reader.hasNext()); int readCount = 0; for (final Reads.ReadEntry entry : reader) { if (readCount == 0) { assertEquals("Reader returned the wrong sequence string", "CTCATGTTCATACACCTNTCCCCCATTCTCCTCCT".subSequence(0, 22), entry.getSequence().toString(Charset.defaultCharset().name())); } readCount++; assertEquals("Entry ", readCount + " was not trimmed", entry.getReadLength()); } assertEquals("There should have been 73 entries in the reformatted file", 73, readCount); }
From source file:com.liferay.sync.engine.SyncSystemTest.java
protected void verifyFile(JsonNode stepJsonNode) throws Exception { boolean testPassed = true; String operation = getString(stepJsonNode, "operation", "exists"); if (operation.equals("equals")) { List<File> files = new ArrayList<File>(); JsonNode filesJsonNode = stepJsonNode.get("files"); for (JsonNode fileJsonNode : filesJsonNode) { Path targetFilePath = getTargetFilePath(fileJsonNode); files.add(targetFilePath.toFile()); }/*from w w w. j a v a 2 s. c o m*/ if (!FileUtils.contentEquals(files.get(0), files.get(1))) { testPassed = false; } } else if (operation.equals("exists")) { if (Files.notExists(getTargetFilePath(stepJsonNode))) { testPassed = false; } } else if (operation.equals("notExists")) { if (Files.exists(getTargetFilePath(stepJsonNode))) { testPassed = false; } } if (!testPassed) { Path testFileNameFilePath = _testFilePath.getFileName(); Assert.fail("Test " + testFileNameFilePath.toString() + " failed."); } }
From source file:azkaban.project.JdbcProjectImplTest.java
@Test public void testUploadFlowFile() throws Exception { final File testYamlFile = ExecutionsTestUtil.getFlowFile(BASIC_FLOW_YAML_DIR, BASIC_FLOW_FILE); this.loader.uploadFlowFile(PROJECT_ID, PROJECT_VERSION, testYamlFile, FLOW_VERSION); final File tempDir = Files.createTempDir(); tempDir.deleteOnExit();//from w w w.j a v a2s .co m final File file = this.loader.getUploadedFlowFile(PROJECT_ID, PROJECT_VERSION, BASIC_FLOW_FILE, FLOW_VERSION, tempDir); assertThat(file.getName()).isEqualTo(BASIC_FLOW_FILE); assertThat(FileUtils.contentEquals(testYamlFile, file)).isTrue(); }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that meta data are transfered by reformat. * The input file to this test was created with the following command: * goby 1g fasta-to-compact -k key1 -v value1 -k key2 -v value2 test-data/fastx-test-data/test-fastq-1.fq -o test-data/compact-reads/with-meta-data-input.compact-reads * * @throws IOException if there is a problem reading or writing to the files *//*from w ww.j a v a2s. c om*/ @Test public void reformatTransferMetaData() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/with-meta-data-input.compact-reads"; reformat.setInputFilenames(inputFilename); final String outputFilename = "test-results/with-meta-data-output.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); ReadsReader reader1 = new ReadsReader(inputFilename); for (Reads.ReadEntry it : reader1) { System.out.println(it.toString()); System.out.println(); } ReadsReader reader2 = new ReadsReader(outputFilename); for (Reads.ReadEntry it : reader2) { System.out.println(it.toString()); System.out.println(); } assertTrue(FileUtils.contentEquals(new File(inputFilename), new File(outputFilename))); final ReadsReader reader = new ReadsReader(FileUtils.openInputStream(new File(outputFilename))); assertTrue("There should be reads in this file", reader.hasNext()); final Reads.ReadEntry entry = reader.next(); assertNotNull("Entry should not be null", entry); Properties keyValuePairs = reader.getMetaData(); assertEquals("key/value pairs must match", "value1", keyValuePairs.get("key1")); assertEquals("key/value pairs must match", "value2", keyValuePairs.get("key2")); }
From source file:com.streamsets.pipeline.stage.origin.remote.TestRemoteDownloadSource.java
@Test public void testOverrunErrorArchiveFile() throws Exception { path = "remote-download-source/parseOverrun"; setupSSHD(path, false);//from ww w. j a v a 2s .c o m File archiveDir = testFolder.newFolder(); RemoteDownloadSource origin = new RemoteDownloadSource( getBean("sftp://localhost:" + String.valueOf(port) + "/", true, "testuser", "pass", null, null, null, true, DataFormat.JSON, archiveDir.toString())); SourceRunner runner = new SourceRunner.Builder(RemoteDownloadSource.class, origin).addOutputLane("lane") .setOnRecordError(OnRecordError.TO_ERROR).build(); runner.runInit(); List<Record> expected = getExpectedRecords(); Record record = RecordCreator.create(); record.set(Field.create(new HashMap<String, Field>())); record.set("/name", Field.create("polarbear")); record.set("/age", Field.create("6")); record.set("/characterisitics", Field.create(Arrays.asList(Field.create("cool"), Field.create("cute"), Field.create("huge"), Field.create("round"), Field.create("playful")))); expected.add(record); StageRunner.Output op = runner.runProduce("-1", 1000); List<Record> actual = op.getRecords().get("lane"); Assert.assertEquals(1, actual.size()); System.out.println(actual.get(0).get()); Assert.assertEquals(expected.get(0).get(), actual.get(0).get()); Assert.assertEquals(1, archiveDir.listFiles().length); File expectedFile = new File(currentThread().getContextClassLoader() .getResource("remote-download-source/parseOverrun").getPath()).listFiles()[0]; File actualFile = archiveDir.listFiles()[0]; Assert.assertEquals(expectedFile.getName(), actualFile.getName()); Assert.assertTrue(FileUtils.contentEquals(expectedFile, actualFile)); }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test(expected = AccessDeniedException.class) public void testReadRetryBugFixWithUnwritableDirectory() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InterruptedException { Assume.assumeFalse(iAmRoot());//from ww w .jav a 2s . c om final String tempPathPrefix = null; final Path tempDirectoryPath = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String tempDirectoryName = tempDirectoryPath.toString(); if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) { // Deny write data access to everyone, making the directory unwritable. Runtime.getRuntime().exec("icacls " + tempDirectoryName + " /deny Everyone:(WD)").waitFor(); } else { Runtime.getRuntime().exec("chmod -w " + tempDirectoryName).waitFor(); } try { disableWritePermissionForRoot(tempDirectoryName); final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); readJob.transfer(new FileObjectGetter(tempDirectoryPath)); final File originalFile = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME).toFile(); final File fileCopiedFromBP = Paths.get(tempDirectoryPath.toString(), FILE_NAME).toFile(); assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP)); } finally { enableWritePermissionForRoot(tempDirectoryName); if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) { // Grant write data access to everyone, so we can delete the directory Runtime.getRuntime().exec("icacls " + tempDirectoryName + " /grant Everyone:(WD)").waitFor(); } else { Runtime.getRuntime().exec("chmod +w " + tempDirectoryName).waitFor(); } FileUtils.deleteDirectory(tempDirectoryPath.toFile()); } }