Search in sources :

Example 76 with TransferSettings

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

the class SymlinkSyncScenarioTest method testSymlinkMultipleUpsAndDowns.

@Test
public void testSymlinkMultipleUpsAndDowns() throws Exception {
    if (!EnvironmentUtil.symlinksSupported()) {
        // Skip test for Windows, no symlinks there!
        return;
    }
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    clientA.createNewFile("symlink-target");
    File symlinkFile = clientA.getLocalFile("symlink-name");
    // << relative target
    FileUtil.createSymlink("symlink-target", symlinkFile);
    assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
    clientA.up();
    // B down
    clientB.down();
    assertEquals("Local folder should contain two files (symlink and target!)", 2, clientB.getLocalFilesExcludeLockedAndNoRead().size());
    File localSymlinkFile = clientB.getLocalFile("symlink-name");
    assertTrue("Local symlink file should exist.", Files.exists(Paths.get(localSymlinkFile.getAbsolutePath()), LinkOption.NOFOLLOW_LINKS));
    assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
    assertEquals("Local symlink file should point to actual target.", "symlink-target", FileUtil.readSymlinkTarget(localSymlinkFile));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 77 with TransferSettings

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

the class SymlinkSyncScenarioTest method testSymlinkOneUpOneDown.

@Test
public void testSymlinkOneUpOneDown() throws Exception {
    if (!EnvironmentUtil.symlinksSupported()) {
        // Skip test for Windows, no symlinks there!
        return;
    }
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run
    File symlinkFile = clientA.getLocalFile("symlink-name");
    FileUtil.createSymlink("/etc/hosts", symlinkFile);
    assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
    UpOperationResult upResult = clientA.up();
    StatusOperationResult statusResult = upResult.getStatusResult();
    // Test 1: Check result sets for inconsistencies
    assertTrue("Status should return changes.", statusResult.getChangeSet().hasChanges());
    assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
    // Test 2: Check database for inconsistencies
    SqlDatabase database = clientA.loadLocalDatabase();
    assertEquals("File should be uploaded.", 1, database.getFileList("symlink-name", null, false, false, false, null).size());
    assertNotNull("There should be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
    // Test 3: Check file system for inconsistencies
    File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
    String[] repoFileList = repoPath.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith("database-");
        }
    });
    assertEquals("Repository should contain only ONE database file, not multichunks.", 1, repoFileList.length);
    // B down
    clientB.down();
    assertEquals("Local folder should contain one file (link!)", 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
    File localSymlinkFile = clientB.getLocalFile("symlink-name");
    assertTrue("Local symlink file should exist.", localSymlinkFile.exists());
    assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
    assertEquals("Local symlink file should point to actual target.", "/etc/hosts", FileUtil.readSymlinkTarget(localSymlinkFile));
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Example 78 with TransferSettings

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

the class SymlinkSyncScenarioTest method testSymlinkSyncToNonExistingFolder.

@Test
public void testSymlinkSyncToNonExistingFolder() throws Exception {
    if (!EnvironmentUtil.symlinksSupported()) {
        // Skip test for Windows, no symlinks there!
        return;
    }
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // A
    clientA.createNewFolder("folder1");
    clientA.up();
    // B
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // A
    File symlinkFile = clientA.getLocalFile("folder1/symlink-name");
    FileUtil.createSymlink("/does/not/exist", symlinkFile);
    clientA.up();
    // B
    clientB.deleteFile("folder1");
    clientB.down();
    assertTrue(FileUtil.exists(clientB.getLocalFile("folder1/symlink-name")));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) 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