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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations