Search in sources :

Example 11 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 12 with CommandLineClient

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

the class DownCommandTest method testDownCommandNoArgs.

@Test
public void testDownCommandNoArgs() throws Exception {
    // Setup
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    Map<String, String> clientB = TestCliUtil.createLocalTestEnvAndConnect("B", connectionSettings);
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/file1"), 20 * 1024);
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/file2"), 20 * 1024);
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/file3"), 20 * 1024);
    // Round 1: No changes
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }));
    assertEquals("Different number of output lines expected.", 3, cliOut.length);
    // Round 2: Only added files
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up", "--force-checksum" }).start();
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }));
    assertEquals("Different number of output lines expected.", 11, cliOut.length);
    assertEquals("A .syignore", cliOut[6]);
    assertEquals("A file1", cliOut[7]);
    assertEquals("A file2", cliOut[8]);
    assertEquals("A file3", cliOut[9]);
    // Round 3: Modified and deleted files
    TestFileUtil.changeRandomPartOfBinaryFile(new File(clientA.get("localdir") + "/file2"));
    new File(clientA.get("localdir") + "/file3").delete();
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up", "--force-checksum" }).start();
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientB.get("localdir"), "down" }));
    assertEquals("Different number of output lines expected.", 9, cliOut.length);
    assertEquals("M file2", cliOut[6]);
    assertEquals("D file3", cliOut[7]);
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestCliUtil.deleteTestLocalConfigAndData(clientB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 13 with CommandLineClient

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

the class GenlinkCommandTest method testGenlinkCommandShortNotEncrypted.

// TODO [low] TextFromStandardInputStream is not thread-safe. This leads to failures from time to time.
@Test
public void testGenlinkCommandShortNotEncrypted() throws Exception {
    // Setup
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    File clientLocalDirB = TestFileUtil.createTempDirectoryInSystemTemp();
    String[] cliOutA = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "genlink", "--machine-readable" }));
    assertEquals("Different number of output lines expected.", 1, cliOutA.length);
    String createdLink = cliOutA[0];
    String[] cliOutB = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientLocalDirB.getAbsolutePath(), "connect", createdLink }));
    assertEquals("Different number of output lines expected.", 3, cliOutB.length);
    assertEquals("Repository connected, and local folder initialized.", cliOutB[1]);
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestFileUtil.deleteDirectory(clientLocalDirB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 14 with CommandLineClient

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

the class InitAndConnectCommandNoEncryptionTest method testCliInitCommandUninitializedLocalDir.

@Test
public void testCliInitCommandUninitializedLocalDir() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TestCliUtil.setCurrentDirectory(tempDir);
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnv("A", connectionSettings);
    // Run
    String[] initArgs = new String[] { "init", "--plugin", "local", "--plugin-option", "path=" + clientA.get("repopath"), "--no-encryption", "--no-compression" };
    new CommandLineClient(initArgs).start();
    assertTrue(tempDir.exists());
    assertTrue(new File(tempDir + "/.syncany").exists());
    assertTrue(new File(tempDir + "/.syncany/syncany").exists());
    assertTrue(new File(tempDir + "/.syncany/config.xml").exists());
    // Tear down
    TestCliUtil.setCurrentDirectory(originalWorkingDirectory);
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestFileUtil.deleteDirectory(tempDir);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 15 with CommandLineClient

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

the class PluginCommandTest method testPluginListRemoteOnly.

@Test
public void testPluginListRemoteOnly() throws Exception {
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "plugin", "list", "--remote-only" }));
    assertTrue(cliOut.length >= 6);
    TestAssertUtil.assertRegexInLines("^sftp\\s+\\|\\s+", cliOut);
    TestAssertUtil.assertRegexInLines("^s3\\s+\\|\\s+", cliOut);
    TestAssertUtil.assertRegexInLines("^webdav\\s+\\|\\s+", cliOut);
    TestAssertUtil.assertRegexInLines("^ftp\\s+\\|\\s+", cliOut);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) Test(org.junit.Test)

Aggregations

CommandLineClient (org.syncany.cli.CommandLineClient)26 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