public synchronized void copyLocalDependency(String srcPath, File destPath) throws IOException { if (StringUtils.isBlank(srcPath)) { return; } File srcFile = new File(srcPath); File destFile = new File(destPath, srcFile.getName()); if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) { FileUtils.copyFile(srcFile, destFile); logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath); } }
assertTrue(FileUtils.contentEquals(cr, cr)); assertTrue(FileUtils.contentEquals(crlf, crlf)); assertTrue(FileUtils.contentEquals(lf, lf)); assertFalse(FileUtils.contentEquals(cr, crlf)); assertFalse(FileUtils.contentEquals(cr, lf)); assertFalse(FileUtils.contentEquals(crlf, lf));
public List<File> load(String artifact, Collection<String> excludes, File destPath) throws RepositoryException, IOException { List<File> libs = new LinkedList<>(); if (StringUtils.isNotBlank(artifact)) { libs = load(artifact, excludes); for (File srcFile : libs) { File destFile = new File(destPath, srcFile.getName()); if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) { FileUtils.copyFile(srcFile, destFile); logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath); } } } return libs; }
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"); } } }
if (!outputFile.exists()) { report.addNew(); } else if (!FileUtils.contentEquals(file, outputFile)) { getLog().info(format("%s has changed", relPath)); if (!outputFile.delete()) {
@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(); 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(); }
private boolean areDirsEqualUtil(final File file1, final File file2, final boolean isRoot, final boolean ignoreRoot) throws IOException { if (!file1.getName().equals(file2.getName())) { if (!isRoot && ignoreRoot) { return false; } } if (file1.isDirectory() && file2.isDirectory()) { if (file1.listFiles().length != file2.listFiles().length) { return false; } final File[] fileList1 = file1.listFiles(); final File[] fileList2 = file2.listFiles(); Arrays.sort(fileList1, NameFileComparator.NAME_COMPARATOR); Arrays.sort(fileList2, NameFileComparator.NAME_COMPARATOR); for (int i = 0; i < fileList1.length; i++) { if (!areDirsEqualUtil(fileList1[i], fileList2[i], false, ignoreRoot)) { return false; } } return true; } else if (file1.isFile() && file2.isFile()) { return file1.getName().equals(file2.getName()) && FileUtils.contentEquals(file1, file2); } else { return false; } }
final File file2 = new File(getTestDirectory(), getName() + "2"); assertTrue(FileUtils.contentEquals(file, file)); assertTrue(FileUtils.contentEquals(file, file2)); assertTrue(FileUtils.contentEquals(file2, file2)); assertTrue(FileUtils.contentEquals(file2, file)); FileUtils.contentEquals(getTestDirectory(), getTestDirectory()); fail("Comparing directories should fail with an IOException"); } catch (final IOException ioe) { objFile2); assertFalse(FileUtils.contentEquals(objFile1, objFile2)); assertFalse(FileUtils.contentEquals(objFile1b, objFile2)); assertTrue(FileUtils.contentEquals(objFile1, objFile1b)); assertTrue(FileUtils.contentEquals(objFile1, objFile1)); assertTrue(FileUtils.contentEquals(objFile1b, objFile1b)); assertTrue(FileUtils.contentEquals(objFile2, objFile2)); assertTrue(FileUtils.contentEquals(file, file)); assertTrue(FileUtils.contentEquals(file, file2));
); assertTrue(expectedTargetFile.exists()); assertTrue(FileUtils.contentEquals(testFile, expectedTargetFile)); final File getFile = new File("tmp.get"); FileUtils.copyInputStreamToFile(getIs, getFile); assertTrue(FileUtils.contentEquals(testFile, getFile));
@Test public void copyFolderToContainerFolderTest() throws Exception { try ( GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") .withCommand("top") ) { alpineCopyToContainer.start(); final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/"); alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/test/"); File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt"); alpineCopyToContainer.copyFileFromContainer("/home/test/test-resource.txt", actualFile.getPath()); File expectedFile = new File(mountableFile.getResolvedPath() + "/test-resource.txt"); assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile)); } }
@Test public void copyFileToContainerFileTest() throws Exception { try ( GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") .withCommand("top") ) { alpineCopyToContainer.start(); final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); alpineCopyToContainer.copyFileToContainer(mountableFile, "/test.txt"); File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt"); alpineCopyToContainer.copyFileFromContainer("/test.txt", actualFile.getPath()); File expectedFile = new File(mountableFile.getResolvedPath()); assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile)); } }
@Test public void copyFileToContainerFolderTest() throws Exception { try ( GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") .withCommand("top") ) { alpineCopyToContainer.start(); final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt"); alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath()); File expectedFile = new File(mountableFile.getResolvedPath()); assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile)); } }
@Test public void shouldCopyFileFromContainerTest() throws IOException { try ( GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") .withCommand("top") ) { alpineCopyToContainer.start(); final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_from_container.txt"); alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath()); File expectedFile = new File(mountableFile.getResolvedPath()); assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile)); } } }
Assert.assertTrue(FileUtils.contentEquals(ON_HEAP_INVERTED_INDEX, OFF_HEAP_INVERTED_INDEX));
Assert.assertTrue(FileUtils.contentEquals(ON_HEAP_INVERTED_INDEX, OFF_HEAP_INVERTED_INDEX));
@Test public void testHTTPResultDefaultRows() throws IOException { File localFileForUpload = getInputFile( "existingFile1", ".tmp" ); File tempFileForDownload = File.createTempFile( "downloadedFile1", ".tmp" ); localFileForUpload.deleteOnExit(); tempFileForDownload.deleteOnExit(); Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile", localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() }; RowMeta rowMetaDefault = new RowMeta(); rowMetaDefault.addValueMeta( new ValueMetaString( "URL" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "UPLOAD" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "DESTINATION" ) ); List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>(); rows.add( new RowMetaAndData( rowMetaDefault, r ) ); Result previousResult = new Result(); previousResult.setRows( rows ); JobEntryHTTP http = new JobEntryHTTP(); http.setParentJob( new Job() ); http.setRunForEveryRow( true ); http.setAddFilenameToResult( false ); http.execute( previousResult, 0 ); assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) ); }
@Test public void testHTTPResultCustomRows() throws IOException { File localFileForUpload = getInputFile( "existingFile2", ".tmp" ); File tempFileForDownload = File.createTempFile( "downloadedFile2", ".tmp" ); localFileForUpload.deleteOnExit(); tempFileForDownload.deleteOnExit(); Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile", localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() }; RowMeta rowMetaDefault = new RowMeta(); rowMetaDefault.addValueMeta( new ValueMetaString( "MyURL" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "MyUpload" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "MyDestination" ) ); List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>(); rows.add( new RowMetaAndData( rowMetaDefault, r ) ); Result previousResult = new Result(); previousResult.setRows( rows ); JobEntryHTTP http = new JobEntryHTTP(); http.setParentJob( new Job() ); http.setRunForEveryRow( true ); http.setAddFilenameToResult( false ); http.setUrlFieldname( "MyURL" ); http.setUploadFieldname( "MyUpload" ); http.setDestinationFieldname( "MyDestination" ); http.execute( previousResult, 0 ); assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) ); }
assertFalse(FileUtils.contentEquals(previousFile, currentFile));
@Test public void itCanSetPlaceholderValueInANewFile() throws Exception { File targetFile = copyResourceTo("with_placeholder.html", "index.html"); File expectedOutputFile = copyResourceTo("with_placeholder_replaced.html", "expected.html"); fileContentManipulator.setJsonToIndexFile("{}", targetFile); assertTrue("The files differ!", FileUtils.contentEquals(targetFile, expectedOutputFile)); }
@Override protected boolean compare(File baselineFile, File comparisonFile) { try { return FileUtils.contentEquals(baselineFile, comparisonFile); } catch (IOException e) { throw new TransformationUtilityException("An exception has happened when comparing files", e); } }