@Test
public void testCompareFileVersionToFile() throws Exception {
// Setup
Config config = TestConfigUtil.createTestLocalConfig();
FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
// Create File
File somefile = new File(config.getLocalDir()+"/file1");
Path somefilePath = Paths.get(somefile.getAbsolutePath());
TestFileUtil.createRandomFile(somefile, 130*1024);
somefile.setLastModified(1182196000);
if (EnvironmentUtil.isWindows()) {
Files.setAttribute(somefilePath, "dos:readonly", true);
Files.setAttribute(somefilePath, "dos:hidden", false);
Files.setAttribute(somefilePath, "dos:archive", true);
Files.setAttribute(somefilePath, "dos:system", false);
}
else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Files.setPosixFilePermissions(somefilePath, PosixFilePermissions.fromString("r--rwxrw-"));
}
// Create FileVersion
FileVersion fileVersion = new FileVersion();
fileVersion.setVersion(100L);
fileVersion.setChecksum(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 })); // << definitely differs
fileVersion.setLastModified(new Date(1182196000));
fileVersion.setPath("file1");
fileVersion.setSize(130*1024L);
fileVersion.setLinkTarget(null);
fileVersion.setStatus(FileStatus.NEW);
fileVersion.setType(FileType.FILE);
if (EnvironmentUtil.isWindows()) {
fileVersion.setDosAttributes("r-a-");
}
else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
fileVersion.setPosixPermissions("r--rwxrw-");
}
// Run
FileVersionComparison fileComparison = versionComparator.compare(fileVersion, somefile, null, true);
// Test
assertFalse(fileComparison.equals());
assertTrue(CollectionUtil.containsExactly(fileComparison.getFileChanges(), FileChange.CHANGED_CHECKSUM));