Search in sources :

Example 46 with FileVersion

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));
}
Also used : FileVersion(org.syncany.database.FileVersion) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 47 with FileVersion

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);
}
Also used : FileVersion(org.syncany.database.FileVersion) File(java.io.File)

Example 48 with FileVersion

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);
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) ArrayList(java.util.ArrayList) DatabaseXmlSerializer(org.syncany.database.dao.DatabaseXmlSerializer) PartialFileHistory(org.syncany.database.PartialFileHistory) AbstractTransferOperation(org.syncany.operations.AbstractTransferOperation) UpOperation(org.syncany.operations.up.UpOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) SqlDatabase(org.syncany.database.SqlDatabase) File(java.io.File) DatabaseVersion(org.syncany.database.DatabaseVersion) Test(org.junit.Test)

Example 49 with FileVersion

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;
}
Also used : FileVersion(org.syncany.database.FileVersion) FileChecksum(org.syncany.database.FileContent.FileChecksum) Date(java.util.Date)

Example 50 with 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;
}
Also used : FileVersion(org.syncany.database.FileVersion)

Aggregations

FileVersion (org.syncany.database.FileVersion)50 PartialFileHistory (org.syncany.database.PartialFileHistory)23 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)21 Test (org.junit.Test)17 DatabaseVersion (org.syncany.database.DatabaseVersion)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)7 File (java.io.File)6 ResultSet (java.sql.ResultSet)6 FileChecksum (org.syncany.database.FileContent.FileChecksum)6 SQLException (java.sql.SQLException)5 HashMap (java.util.HashMap)5 Config (org.syncany.config.Config)5 TreeMap (java.util.TreeMap)4 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)4 List (java.util.List)3 FileContent (org.syncany.database.FileContent)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3