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