Search in sources :

Example 46 with TestClient

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

the class RestoreFileScenarioTest method testRestoreDeletedFile.

@Test
public void testRestoreDeletedFile() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    // A new/up
    clientA.createNewFile("A-original");
    clientA.upWithForceChecksum();
    String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
    assertNotNull(originalFileHistoryStr);
    FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
    // A "delete"
    File deletedFile = new File(tempDir, "A-original-DELETED");
    FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
    clientA.upWithForceChecksum();
    // A restore
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    operationOptions.setFileHistoryId(originalFileHistoryId);
    operationOptions.setFileVersion(1);
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
    assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
    assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
    assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").length());
    // Tear down
    clientA.deleteTestData();
    TestFileUtil.deleteDirectory(tempDir);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 47 with TestClient

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

the class RestoreFileScenarioTest method testRestoreDeletedWithSubfolders.

@Test
public void testRestoreDeletedWithSubfolders() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
    // A new/up
    clientA.createNewFolder("folder/subfolder");
    clientA.createNewFile("folder/subfolder/A-original");
    clientA.upWithForceChecksum();
    String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion where path='folder/subfolder/A-original'", databaseConnectionA);
    assertNotNull(originalFileHistoryStr);
    FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
    // A "delete"
    FileUtils.deleteDirectory(clientA.getLocalFile("folder"));
    clientA.upWithForceChecksum();
    assertFalse(clientA.getLocalFile("folder").exists());
    // A restore
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    operationOptions.setFileHistoryId(originalFileHistoryId);
    operationOptions.setFileVersion(1);
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("folder/subfolder").exists());
    assertTrue(clientA.getLocalFile("folder/subfolder/A-original (restored version 1)").exists());
    // Tear down
    clientA.deleteTestData();
    TestFileUtil.deleteDirectory(tempDir);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 48 with TestClient

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

the class SingleFileNoConflictsScenarioTest method testSingleFileChangeNoConflicts.

@Test
public void testSingleFileChangeNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create files and upload
    clientA.createNewFile("file");
    clientA.upWithForceChecksum();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("file"), clientB.getLocalFile("file"));
    clientB.changeFile("file");
    clientB.upWithForceChecksum();
    clientA.down();
    assertFileEquals(clientA.getLocalFile("file"), clientB.getLocalFile("file"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 49 with TestClient

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

the class SingleFileNoConflictsScenarioTest method testComplexNoConflicts.

@Test
public void testComplexNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    // Test
    clientA.createNewFile("1");
    clientA.upWithForceChecksum();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("1"), clientB.getLocalFile("1"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    clientA.moveFile("1", "2");
    assertFileEquals(clientA.getLocalFile("2"), clientB.getLocalFile("1"));
    clientA.upWithForceChecksum();
    clientA.upWithForceChecksum();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("2"), clientB.getLocalFile("2"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    clientC.down();
    assertFileEquals(clientA.getLocalFile("2"), clientC.getLocalFile("2"));
    assertFileEquals(clientB.getLocalFile("2"), clientC.getLocalFile("2"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    clientC.createNewFile("3");
    clientC.changeFile("2");
    clientC.upWithForceChecksum();
    clientA.down();
    assertFileEquals(clientC.getLocalFile("3"), clientA.getLocalFile("3"));
    assertFileListEquals(clientC.getLocalFilesExcludeLockedAndNoRead(), clientA.getLocalFilesExcludeLockedAndNoRead());
    clientB.down();
    assertFileEquals(clientC.getLocalFile("3"), clientB.getLocalFile("3"));
    assertFileListEquals(clientC.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    clientC.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 50 with TestClient

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

the class SingleFileNoConflictsScenarioTest method testSingleFileNewNoConflicts.

@Test
public void testSingleFileNewNoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create files and upload
    clientA.createNewFile("file");
    clientA.up();
    clientB.down();
    assertFileEquals(clientA.getLocalFile("file"), clientB.getLocalFile("file"));
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Aggregations

TestClient (org.syncany.tests.util.TestClient)126 Test (org.junit.Test)122 TransferSettings (org.syncany.plugins.transfer.TransferSettings)65 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)53 File (java.io.File)50 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)31 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)28 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)23 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)14 FilenameFilter (java.io.FilenameFilter)11 StorageException (org.syncany.plugins.transfer.StorageException)11 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)10 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)10 DownOperationResult (org.syncany.operations.down.DownOperationResult)9 UpOperationResult (org.syncany.operations.up.UpOperationResult)8 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)6 SqlDatabase (org.syncany.database.SqlDatabase)5 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)5 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)5 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)5