Search in sources :

Example 1 with TestSqlDatabase

use of org.syncany.tests.util.TestSqlDatabase in project syncany by syncany.

the class RenameFileWithDiffModifiedDateScenarioTest method testChangedModifiedDate.

@Test
public void testChangedModifiedDate() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run 
    // A, create two files with identical content and change mod. date of one of them
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg");
    clientA.getLocalFile("A-file1.jpg").setLastModified(0);
    clientA.up();
    // B, down, then move BOTH files
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg");
    clientB.moveFile("A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg");
    clientB.up();
    TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
    PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
    PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-with-different-modified-date-moved.jpg");
    assertNotNull(file1Orig);
    assertNotNull(file1WithDiffLastModDate);
    FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1);
    FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2);
    FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1);
    FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2);
    assertNotNull(fileVersion1OrigV1);
    assertNotNull(fileVersion1OrigV2);
    assertNotNull(fileVersion1WithDiffLastModDateV1);
    assertNotNull(fileVersion1WithDiffLastModDateV2);
    assertEquals("A-file1.jpg", fileVersion1OrigV1.getName());
    assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName());
    assertEquals("A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName());
    assertEquals("A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Example 2 with TestSqlDatabase

use of org.syncany.tests.util.TestSqlDatabase in project syncany by syncany.

the class FileSystemActionReconciliatorTest method testFileSystemActionReconDeleteNonExistingFolder.

@Test
public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    Config testConfigA = clientA.getConfig();
    // - Create first database version
    clientA.createNewFolder("new folder/some subfolder");
    clientA.upWithForceChecksum();
    // Delete this!
    clientA.deleteFile("new folder/some subfolder");
    // - Create new version (delete folder)
    TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
    PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");
    FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
    deletedFolderVersion.setStatus(FileStatus.DELETED);
    deletedFolderVersion.setVersion(deletedFolderVersion.getVersion() + 1);
    PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
    deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
    DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());
    winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
    // - Create memory database with this version
    MemoryDatabase winnersDatabase = new MemoryDatabase();
    winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
    // Run! Finally!
    DownOperationResult outDownOperationResult = new DownOperationResult();
    FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
    List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
    assertNotNull(fileSystemActions);
    assertEquals(0, fileSystemActions.size());
    // Tear down
    clientA.deleteTestData();
}
Also used : Config(org.syncany.config.Config) DownOperationResult(org.syncany.operations.down.DownOperationResult) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) FileSystemActionReconciliator(org.syncany.operations.down.FileSystemActionReconciliator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 FileVersion (org.syncany.database.FileVersion)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 TestClient (org.syncany.tests.util.TestClient)2 TestSqlDatabase (org.syncany.tests.util.TestSqlDatabase)2 Config (org.syncany.config.Config)1 DatabaseVersion (org.syncany.database.DatabaseVersion)1 MemoryDatabase (org.syncany.database.MemoryDatabase)1 DownOperationResult (org.syncany.operations.down.DownOperationResult)1 FileSystemActionReconciliator (org.syncany.operations.down.FileSystemActionReconciliator)1 FileSystemAction (org.syncany.operations.down.actions.FileSystemAction)1