Search in sources :

Example 6 with CommandLineClient

use of org.syncany.cli.CommandLineClient in project syncany by syncany.

the class ConnectCommandWithEncryptionTest method initInteractiveWithEncryptionWithParams.

private void initInteractiveWithEncryptionWithParams() throws Exception {
    // Ensuring no console is set
    InitConsole.setInstance(null);
    // Create test repo and temp. client
    initializedRepoPassword = "somesuperlongpassword";
    initializedRepoConnectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnv("A", initializedRepoConnectionSettings);
    File tempLocalDirA = new File(clientA.get("localdir"));
    initializedRepoFolder = new File(clientA.get("repopath"));
    TestCliUtil.setCurrentDirectory(tempLocalDirA);
    String[] initArgs = new String[] { "init" };
    systemInMock.provideText(StringUtil.join(new String[] { "local", initializedRepoFolder.getAbsolutePath(), initializedRepoPassword, initializedRepoPassword }, "\n") + "\n");
    String[] cliOutputA = TestCliUtil.runAndCaptureOutput(new CommandLineClient(initArgs));
    String cliOutputSingleLineA = StringUtil.join(cliOutputA, " ");
    assertTrue(new File(initializedRepoFolder + "/syncany").exists());
    assertTrue(new File(initializedRepoFolder + "/master").exists());
    assertTrue(new File(initializedRepoFolder + "/databases").exists());
    assertTrue(new File(initializedRepoFolder + "/multichunks").exists());
    Pattern linkPattern = Pattern.compile("(syncany://[^\\s]+)");
    Matcher linkMatcher = linkPattern.matcher(cliOutputSingleLineA);
    if (!linkMatcher.find()) {
        fail("Cannot find syncany:// link");
    }
    initializedRepoConnectLink = linkMatcher.group(1);
    initializedRepoFolderCopy = TestFileUtil.createTempDirectoryInSystemTemp();
    // Make copy of the repo
    TestFileUtil.deleteDirectory(initializedRepoFolderCopy);
    FileUtils.copyDirectory(initializedRepoFolder, initializedRepoFolderCopy);
    TestFileUtil.deleteDirectory(tempLocalDirA);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File)

Example 7 with CommandLineClient

use of org.syncany.cli.CommandLineClient in project syncany by syncany.

the class RestoreCommandTest method testCliSimpleRestore.

// TODO [low] Write more restore tests: (1) change file, restore and compare file contents; (2) go back x versions, (3) restore folder
@Test
public void testCliSimpleRestore() throws Exception {
    // Setup
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    // Run
    TestFileUtil.createRandomFile(new File(clientA.get("localdir"), "file1"), 50L);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    Thread.sleep(1000);
    TestFileUtil.deleteFile(new File(clientA.get("localdir"), "file1"));
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    Thread.sleep(1000);
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--date=2s" }));
    assertTrue(cliOut.length >= 1);
    String fileHistoryId = cliOut[0].split("\\s+")[8];
    System.out.println("filehistory id is " + fileHistoryId);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "restore", "--revision=1", "--target=restoredfile", fileHistoryId }).start();
    assertTrue(new File(clientA.get("localdir"), "restoredfile").exists());
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 8 with CommandLineClient

use of org.syncany.cli.CommandLineClient in project syncany by syncany.

the class UpCommandTest method testCliSyncUpWithCleanup.

@Test
public void testCliSyncUpWithCleanup() throws Exception {
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    Map<String, String> clientB = TestCliUtil.createLocalTestEnvAndConnect("B", connectionSettings);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    for (int i = 1; i <= 20; i++) {
        new File(clientA.get("localdir") + "/somefolder" + i).mkdir();
        new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    }
    // Delete something so that cleanup actually does something
    new File(clientA.get("localdir") + "/somefolder1").delete();
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    // Apply all changes at B
    new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }).start();
    // Now cleanup
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "cleanup" }));
    assertEquals(11, cliOut.length);
    assertTrue(cliOut[8].contains("22 database files merged"));
    assertTrue(cliOut[9].contains("1 file histories shortened"));
    assertTrue(cliOut[10].contains("Cleanup successful"));
    for (int i = 1; i <= 22; i++) {
        DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
        File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
        assertFalse("Database file SHOULD NOT exist: " + databaseFileInRepo, databaseFileInRepo.exists());
    }
    for (int i = 23; i <= 23; i++) {
        DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
        File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
        assertTrue("Database file SHOULD exist: " + databaseFileInRepo, databaseFileInRepo.exists());
    }
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }));
    assertEquals(6, cliOut.length);
    assertTrue(cliOut[4].contains("1 database file(s) processed"));
    assertTrue(cliOut[5].contains("Sync down finished"));
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestCliUtil.deleteTestLocalConfigAndData(clientB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Example 9 with CommandLineClient

use of org.syncany.cli.CommandLineClient in project syncany by syncany.

the class UpCommandTest method testCliSyncDownNoArgs.

@Test
public void testCliSyncDownNoArgs() throws Exception {
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    Map<String, String> clientB = TestCliUtil.createLocalTestEnvAndConnect("B", connectionSettings);
    TestFileUtil.createRandomFilesInDirectory(new File(clientA.get("localdir")), 20 * 1024, 10);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }).start();
    assertFileListEqualsExcludeLockedAndNoRead(new File(clientA.get("localdir")), new File(clientB.get("localdir")));
    // TODO [medium] Write asserts for 'down' output
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestCliUtil.deleteTestLocalConfigAndData(clientB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Example 10 with CommandLineClient

use of org.syncany.cli.CommandLineClient in project syncany by syncany.

the class UpCommandTest method testCliSyncUpWithoutCleanup.

@Test
public void testCliSyncUpWithoutCleanup() throws Exception {
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    for (int i = 1; i <= 20; i++) {
        new File(clientA.get("localdir") + "/somefolder" + i).mkdir();
        new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }).start();
    }
    for (int i = 1; i <= 20; i++) {
        DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
        File databaseFileInRepo = new File(connectionSettings.get("path") + "/databases/" + expectedDatabaseRemoteFile.getName());
        assertTrue("Database file SHOULD exist: " + databaseFileInRepo, databaseFileInRepo.exists());
    }
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Aggregations

CommandLineClient (org.syncany.cli.CommandLineClient)28 Test (org.junit.Test)23 File (java.io.File)20 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 Properties (java.util.Properties)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1