use of org.syncany.database.FileVersion in project syncany by syncany.
the class LogOperation method createLightweightDatabaseVersion.
private LightweightDatabaseVersion createLightweightDatabaseVersion(DatabaseVersion databaseVersion) {
// Create changeset
ChangeSet changedFiles = new ChangeSet();
for (PartialFileHistory fileHistory : databaseVersion.getFileHistories()) {
FileVersion fileVersion = fileHistory.getLastVersion();
switch(fileVersion.getStatus()) {
case NEW:
changedFiles.getNewFiles().add(fileVersion.getPath());
break;
case CHANGED:
case RENAMED:
changedFiles.getChangedFiles().add(fileVersion.getPath());
break;
case DELETED:
changedFiles.getDeletedFiles().add(fileVersion.getPath());
break;
}
}
// Create lightweight database version
LightweightDatabaseVersion lightweightDatabaseVersion = new LightweightDatabaseVersion();
lightweightDatabaseVersion.setClient(databaseVersion.getHeader().getClient());
lightweightDatabaseVersion.setDate(databaseVersion.getHeader().getDate());
lightweightDatabaseVersion.setChangeSet(changedFiles);
return lightweightDatabaseVersion;
}
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 PartialFileHistoryTest method testFileHistoryClone.
@Test
public void testFileHistoryClone() {
FileVersion fileVersion1 = new FileVersion();
fileVersion1.setVersion(1L);
fileVersion1.setPath("/somepath");
FileVersion fileVersion2 = new FileVersion();
fileVersion2.setVersion(2L);
fileVersion2.setPath("/somepath");
PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
fileHistory.addFileVersion(fileVersion1);
fileHistory.addFileVersion(fileVersion2);
PartialFileHistory fileHistoryClone = fileHistory.clone();
assertEquals(fileHistory, fileHistoryClone);
assertEquals(fileHistory.getFileVersions().size(), fileHistoryClone.getFileVersions().size());
assertEquals(fileHistory.getFileVersions(), fileHistoryClone.getFileVersions());
FileVersion fileVersion3 = new FileVersion();
fileVersion3.setVersion(3L);
fileVersion3.setPath("/somepath");
fileHistoryClone.addFileVersion(fileVersion3);
assertEquals(fileHistory.getFileVersions().size() + 1, fileHistoryClone.getFileVersions().size());
}
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));
}
Aggregations