Search in sources :

Example 6 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class RenameNoDownloadMultiChunksScenarioTest method testRenameAndCheckIfMultiChunksAreDownloaded.

@Test
public void testRenameAndCheckIfMultiChunksAreDownloaded() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run 
    // Prepare, create file at A, sync it to B
    clientA.createNewFile("A-file1");
    clientA.sync();
    clientB.sync();
    // Now move file, and sync
    clientA.moveFile("A-file1", "A-file-moved1");
    clientA.up();
    DownOperationResult downOperationResult = clientB.down();
    assertEquals("No multichunks should have been downloaded.", 0, downOperationResult.getDownloadedMultiChunks().size());
    assertTrue("Moved files should exist.", clientB.getLocalFile("A-file-moved1").exists());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 7 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class RestoreFileScenarioTest method testRestoreDeletedFileWithTargetFile.

@Test
public void testRestoreDeletedFileWithTargetFile() 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);
    operationOptions.setRelativeTargetPath("restored-file");
    clientA.restore(operationOptions);
    assertTrue(clientA.getLocalFile("restored-file").exists());
    assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("restored-file"))));
    assertEquals(deletedFile.lastModified(), clientA.getLocalFile("restored-file").lastModified());
    assertEquals(deletedFile.length(), clientA.getLocalFile("restored-file").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 8 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 9 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings 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 10 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class IdenticalFileMoveScenarioTest method testIdenticalFileMove.

@Test
public void testIdenticalFileMove() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    // Create folder structure
    clientA.createNewFolder("folder");
    clientA.createNewFolder("folder/subfolder1");
    clientA.createNewFolder("folder/subfolder2");
    // Create identical files
    clientA.createNewFile("folder/subfolder1/A-file1.jpg", 100);
    clientA.copyFile("folder/subfolder1/A-file1.jpg", "folder/subfolder2/A-file1.jpg");
    clientA.up();
    // Move the two identical files
    clientA.moveFile("folder", "moved_folder");
    clientA.up();
    // A just upped, so there should not be changes.
    assertFalse(clientA.status().getChangeSet().hasChanges());
    // Check if the file histories were based on the correct originals
    LsOperationOptions options = new LsOperationOptions();
    options.setFetchHistories(true);
    options.setPathExpression("moved_folder/subfolder1/");
    LsOperationResult lsOperationResult = clientA.ls(options);
    for (PartialFileHistory fileHistory : lsOperationResult.getFileVersions().values()) {
        assertTrue(fileHistory.getFileVersion(2).getPath().endsWith(fileHistory.getFileVersion(1).getPath()));
    }
    options.setPathExpression("moved_folder/subfolder2/");
    lsOperationResult = clientA.ls(options);
    for (PartialFileHistory fileHistory : lsOperationResult.getFileVersions().values()) {
        assertTrue(fileHistory.getFileVersion(2).getPath().endsWith(fileHistory.getFileVersion(1).getPath()));
    }
    // Tear down
    clientA.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) PartialFileHistory(org.syncany.database.PartialFileHistory) LsOperationResult(org.syncany.operations.ls.LsOperationResult) Test(org.junit.Test)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3