use of org.syncany.database.FileVersion in project syncany by syncany.
the class GetFileHistoryFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
GetFileHistoryFolderRequest concreteRequest = (GetFileHistoryFolderRequest) request;
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
return new GetFileHistoryFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), fileHistory);
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class DatabaseVersionDaoTest method testNonEmptyDatabaseVersionHeaders.
@Test
public void testNonEmptyDatabaseVersionHeaders() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
List<DatabaseVersionHeader> databaseVersionHeaders = databaseVersionDao.getNonEmptyDatabaseVersionHeaders();
Collection<String> databaseVersionHeaderStrings = databaseVersionHeaders.stream().map(dbv -> dbv.toString()).collect(Collectors.toCollection(ArrayList::new));
// Test
assertNotNull(databaseVersionHeaders);
assertEquals(6, databaseVersionHeaders.size());
assertTrue(CollectionUtil.containsExactly(Arrays.asList(new String[] { "A/(A1)/T=1388589969000", "A/(A2)/T=1388676369000", "A/(A3)/T=1388762769000", "A/(A4)/T=1388849289000", "A/(A5)/T=1388935689000", "B/(B1)/T=1388849289000" }), databaseVersionHeaderStrings));
TestSqlUtil.runSql("DELETE FROM fileversion WHERE databaseversion_id = 0", databaseConnection);
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionDaoTest method testFileVersionGetCurrentFileTree.
@Test
public void testFileVersionGetCurrentFileTree() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set2.sql");
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
Map<String, FileVersion> currentFileTree = fileVersionDao.getCurrentFileTree();
// Test
assertEquals(50, currentFileTree.size());
assertNotNull(currentFileTree.get("file1"));
assertNotNull(currentFileTree.get("file1").getChecksum());
assertEquals("fe83f217d464f6fdfa5b2b1f87fe3a1a47371196", currentFileTree.get("file1").getChecksum().toString());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class XmlDatabaseDaoTest method testWriteAndReadFileHistoryAndFileVersion.
@Test
public void testWriteAndReadFileHistoryAndFileVersion() throws IOException {
// Prepare
MemoryDatabase newDatabase = new MemoryDatabase();
DatabaseVersion newDatabaseVersion = createDatabaseVersion();
// Create directories (no content!)
// File A
PartialFileHistory fileHistoryA = new PartialFileHistory(FileHistoryId.secureRandomFileId());
newDatabaseVersion.addFileHistory(fileHistoryA);
FileVersion versionA1 = new FileVersion();
versionA1.setVersion(1L);
versionA1.setType(FileType.FOLDER);
versionA1.setPath("Pictures/2013/New York Folder");
versionA1.setStatus(FileStatus.NEW);
versionA1.setSize(0L);
versionA1.setLastModified(new Date());
fileHistoryA.addFileVersion(versionA1);
FileVersion versionA2 = new FileVersion();
versionA2.setVersion(2L);
versionA2.setType(FileType.FOLDER);
versionA2.setPath("Pictures/2013/New York");
versionA2.setStatus(FileStatus.RENAMED);
versionA2.setSize(0L);
versionA2.setLastModified(new Date());
fileHistoryA.addFileVersion(versionA2);
// File B
PartialFileHistory fileHistoryB = new PartialFileHistory(FileHistoryId.secureRandomFileId());
newDatabaseVersion.addFileHistory(fileHistoryB);
FileVersion versionB1 = new FileVersion();
versionB1.setVersion(1L);
versionB1.setType(FileType.FOLDER);
versionB1.setPath("Pictures/2013/Egypt Folder");
versionB1.setStatus(FileStatus.NEW);
versionB1.setSize(0L);
versionB1.setLastModified(new Date());
fileHistoryB.addFileVersion(versionB1);
FileVersion versionB2 = new FileVersion();
versionB2.setVersion(2L);
versionB2.setType(FileType.FOLDER);
versionB2.setPath("Pictures/2013/Egypt");
versionB2.setStatus(FileStatus.RENAMED);
versionB2.setSize(0L);
versionB2.setLastModified(new Date());
fileHistoryB.addFileVersion(versionB2);
// Add database version
newDatabase.addDatabaseVersion(newDatabaseVersion);
// Write database to disk, read it again, and compare them
MemoryDatabase loadedDatabase = writeReadAndCompareDatabase(newDatabase);
// File histories
PartialFileHistory loadedFileHistoryA = loadedDatabase.getFileHistory(fileHistoryA.getFileHistoryId());
PartialFileHistory loadedFileHistoryB = loadedDatabase.getFileHistory(fileHistoryB.getFileHistoryId());
assertEquals("File history not found in database loaded.", fileHistoryA, loadedFileHistoryA);
assertEquals("File history not found in database loaded.", fileHistoryB, loadedFileHistoryB);
assertArrayEquals("File versions differ in loaded database.", fileHistoryA.getFileVersions().values().toArray(), loadedFileHistoryA.getFileVersions().values().toArray());
assertArrayEquals("File versions differ in loaded database.", fileHistoryB.getFileVersions().values().toArray(), loadedFileHistoryB.getFileVersions().values().toArray());
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileSystemActionComparatorTest method createFileVersion.
private FileVersion createFileVersion(String path, FileType type, FileVersion basedOnFileVersion) {
if (basedOnFileVersion == null) {
FileVersion fileVersion = new FileVersion();
fileVersion.setPath(path);
fileVersion.setType(type);
fileVersion.setVersion(1L);
return fileVersion;
} else {
FileVersion fileVersion = basedOnFileVersion.clone();
fileVersion.setPath(path);
fileVersion.setType(type);
fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);
return fileVersion;
}
}
Aggregations