Search in sources :

Example 41 with TestClient

use of org.syncany.tests.util.TestClient 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 42 with TestClient

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

the class EmptyFileScenarioTest method testEmptyFileCreateAndSync.

@Test
public void testEmptyFileCreateAndSync() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    clientA.createNewFile("A-file1.jpg", 0);
    clientA.up();
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    clientB.createNewFile("B-file2", 0);
    clientB.moveFile("A-file1.jpg", "B-file1-moved");
    clientB.up();
    SqlDatabase database = clientB.loadLocalDatabase();
    DatabaseVersionHeader lastDatabaseVersionHeaderBeforeUp = database.getLastDatabaseVersionHeader();
    // double-up, has caused problems
    clientB.up();
    DatabaseVersionHeader lastDatabaseVersionHeaderAfterUp = database.getLastDatabaseVersionHeader();
    assertEquals("Nothing changed. Local database file should not change.", lastDatabaseVersionHeaderBeforeUp, lastDatabaseVersionHeaderAfterUp);
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    Map<String, File> beforeSyncDownFileList = clientB.getLocalFilesExcludeLockedAndNoRead();
    // double-down, has caused problems
    clientA.down();
    assertFileListEquals("No change in file lists expected. Nothing changed", beforeSyncDownFileList, clientA.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) File(java.io.File) Test(org.junit.Test)

Example 43 with TestClient

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

the class FileLockedScenarioTest method testPermissionDeniedNotReadable.

@Test
public void testPermissionDeniedNotReadable() throws Exception {
    if (EnvironmentUtil.isWindows()) {
        // Not possible in windows
        return;
    }
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    // Run
    File noReadPermissionFile = clientA.createNewFile("no-read-permission-file");
    Path filePath = Paths.get(noReadPermissionFile.getAbsolutePath());
    Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.GROUP_READ);
    perms.add(PosixFilePermission.OTHERS_READ);
    Files.setPosixFilePermissions(filePath, perms);
    runUpAndTestForConsistentDatabase(testConnection, clientA);
    // Tear down
    clientA.deleteTestData();
}
Also used : Path(java.nio.file.Path) TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) RandomAccessFile(java.io.RandomAccessFile) LockFile(org.syncany.tests.integration.scenarios.framework.LockFile) File(java.io.File) UnlockFile(org.syncany.tests.integration.scenarios.framework.UnlockFile) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with TestClient

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

the class FileLockedScenarioTest method testLockUnlockFile.

@Test
public void testLockUnlockFile() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    ClientActions.run(clientA, null, new CreateFileTree(), new Executable() {

        @Override
        public void execute() throws Exception {
            clientA.upWithForceChecksum();
            clientB.down();
            assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
            assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
        }
    });
    ClientActions.run(clientA, null, new LockFile(), new Executable() {

        @Override
        public void execute() throws Exception {
            clientA.upWithForceChecksum();
            clientB.down();
            assertEquals(clientA.getLocalFilesExcludeLockedAndNoRead().size(), clientB.getLocalFilesExcludeLockedAndNoRead().size() - 1);
        }
    });
    ClientActions.run(clientA, null, new UnlockFile(), new Executable() {

        @Override
        public void execute() throws Exception {
            clientA.upWithForceChecksum();
            clientB.down();
            assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
            assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
        }
    });
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : UnlockFile(org.syncany.tests.integration.scenarios.framework.UnlockFile) LockFile(org.syncany.tests.integration.scenarios.framework.LockFile) TestClient(org.syncany.tests.util.TestClient) CreateFileTree(org.syncany.tests.integration.scenarios.framework.CreateFileTree) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Executable(org.syncany.tests.integration.scenarios.framework.Executable) Test(org.junit.Test)

Example 45 with TestClient

use of org.syncany.tests.util.TestClient 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

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