use of org.syncany.database.FileVersion in project syncany by syncany.
the class PartialFileHistoryTest method testFileHistoryGetVersionsNonEmpty.
@Test
public void testFileHistoryGetVersionsNonEmpty() {
FileVersion fileVersion = new FileVersion();
fileVersion.setVersion(5L);
fileVersion.setPath("/somepath");
PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
fileHistory.addFileVersion(fileVersion);
assertNotNull(fileHistory.getLastVersion());
assertNotNull(fileHistory.getFileVersions());
assertEquals(1, fileHistory.getFileVersions().size());
assertEquals(fileVersion, fileHistory.getLastVersion());
assertNull(fileHistory.getFileVersions().get(1L));
assertNull(fileHistory.getFileVersion(1L));
assertEquals(fileVersion, fileHistory.getFileVersions().get(5L));
assertEquals(fileVersion, fileHistory.getFileVersion(5L));
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class UpOperationTest method compareFileVersionsAgainstOriginalFiles.
private void compareFileVersionsAgainstOriginalFiles(List<File> originalFiles, List<FileVersion> localFileVersions) throws Exception {
int toFind = originalFiles.size();
for (File originalFile : originalFiles) {
String originalFileName = originalFile.getName();
for (FileVersion fileVersion : localFileVersions) {
String fileVersionFileName = fileVersion.getName();
if (fileVersionFileName.equals(originalFileName)) {
toFind--;
}
}
}
assertEquals(0, toFind);
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class UpOperationTest method testUploadLocalDatabase.
@Test
public void testUploadLocalDatabase() throws Exception {
int fileSize = 1230 * 1024;
int fileAmount = 3;
List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
// Run!
AbstractTransferOperation op = new UpOperation(testConfig);
op.execute();
// Get databases (for comparison)
LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
File localDatabaseDir = testConfig.getDatabaseDir();
File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");
assertNotNull(localDatabaseDir.listFiles());
assertTrue(localDatabaseDir.listFiles().length > 0);
assertTrue(remoteDatabaseFile.exists());
// - Memory database
DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
MemoryDatabase remoteDatabase = new MemoryDatabase();
dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL);
DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();
// - Sql Database
SqlDatabase localDatabase = new SqlDatabase(testConfig);
Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
// Compare!
assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());
assertEquals(localFileHistories.size(), fileAmount);
assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());
Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();
List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
for (PartialFileHistory partialFileHistory : remoteFileHistories) {
remoteFileVersions.add(partialFileHistory.getLastVersion());
assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
}
for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
localFileVersions.add(partialFileHistory.getLastVersion());
}
assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class TestDatabaseUtil method createFileVersion.
public static FileVersion createFileVersion(String path) {
FileVersion fileVersion = new FileVersion();
fileVersion.setChecksum(new FileChecksum(TestFileUtil.createRandomArray(20)));
fileVersion.setLastModified(new Date());
fileVersion.setPath(path);
fileVersion.setStatus(FileStatus.NEW);
fileVersion.setType(FileType.FILE);
fileVersion.setUpdated(new Date());
fileVersion.setVersion(1L);
return fileVersion;
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class TestDatabaseUtil method createFileVersion.
public static FileVersion createFileVersion(String path, FileVersion basedOnFileVersion) {
FileVersion fileVersion = basedOnFileVersion.clone();
fileVersion.setPath(path);
fileVersion.setStatus(FileStatus.CHANGED);
fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);
return fileVersion;
}
Aggregations