Search in sources :

Example 16 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 17 with CommandLineClient

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

the class ConnectCommandWithEncryptionTest method testCliConnectInteractiveWithParamsEnc.

@Test
public void testCliConnectInteractiveWithParamsEnc() throws Exception {
    // Setup
    resetRepo();
    Map<String, String> clientB = TestCliUtil.createLocalTestEnv("B", initializedRepoConnectionSettings);
    // Run
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp();
    TestCliUtil.setCurrentDirectory(localDirB);
    String[] connectArgs = new String[] { "connect" };
    System.out.println("repopath = " + clientB.get("repopath"));
    systemInMock.provideText(StringUtil.join(new String[] { "local", clientB.get("repopath"), "somesuperlongpassword" }, "\n") + "\n");
    String[] cliOutputA = TestCliUtil.runAndCaptureOutput(new CommandLineClient(connectArgs));
    String cliOutputSingleLineA = StringUtil.join(cliOutputA, " ");
    assertTrue(localDirB.exists());
    assertTrue(new File(localDirB + "/.syncany").exists());
    assertTrue(new File(localDirB + "/.syncany/syncany").exists());
    assertTrue(new File(localDirB + "/.syncany/master").exists());
    assertTrue(new File(localDirB + "/.syncany/config.xml").exists());
    assertTrue(cliOutputSingleLineA.contains("Repository connected"));
    TestAssertUtil.assertFileEquals(new File(localDirB, ".syncany/syncany"), new File(initializedRepoConnectionSettings.get("path"), "syncany"), FileChange.CHANGED_ATTRIBUTES, FileChange.CHANGED_LAST_MOD_DATE);
    TestAssertUtil.assertFileEquals(new File(localDirB, ".syncany/master"), new File(initializedRepoConnectionSettings.get("path"), "master"), FileChange.CHANGED_ATTRIBUTES, FileChange.CHANGED_LAST_MOD_DATE);
    // Tear down
    TestFileUtil.deleteDirectory(localDirB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 18 with CommandLineClient

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

the class GenlinkCommandTest method testGenlinkCommandShortEncrypted.

@Test
public void testGenlinkCommandShortEncrypted() throws Exception {
    // Setup		
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnv("A", connectionSettings);
    File clientLocalDirB = TestFileUtil.createTempDirectoryInSystemTemp();
    //systemInMock.provideText("somelongpassword\nsomelongpassword\nsomelongpassword\n");
    // Run Init
    String[] initArgs = new String[] { "--localdir", clientA.get("localdir"), "init", "--plugin", "local", "--plugin-option", "path=" + clientA.get("repopath"), "--no-compression", "--password", "somelongpassword" };
    TestCliUtil.runAndCaptureOutput(new CommandLineClient(initArgs));
    // Run Genlink (on A)		
    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", "--password", "somelongpassword", createdLink }));
    assertEquals("Different number of output lines expected.", 5, cliOutB.length);
    assertEquals("Repository connected, and local folder initialized.", cliOutB[3]);
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestFileUtil.deleteDirectory(clientLocalDirB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 19 with CommandLineClient

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

the class InitAndConnectCommandNoEncryptionTest method testCliInitCommandInteractive.

@Test
public void testCliInitCommandInteractive() throws Exception {
    // Setup
    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
    TestCliUtil.setCurrentDirectory(tempDir);
    // Ensuring no console is set
    InitConsole.setInstance(null);
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnv("A", connectionSettings);
    // Run
    String[] initArgs = new String[] { "init", "--no-encryption", "--no-compression" };
    systemInMock.provideText(StringUtil.join(new String[] { "local", clientA.get("repopath") }, "\n") + "\n");
    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 20 with CommandLineClient

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

the class LsCommandTest method testLsCommand.

@Test
public void testLsCommand() throws Exception {
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    // No lines expected
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls" }));
    assertEquals("Different number of output lines expected.", 1, cliOut.length);
    assertEquals("", StringUtil.join(cliOut, ""));
    // Create some files
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/file1"), 20 * 1024);
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/file2"), 20 * 1024);
    new File(clientA.get("localdir") + "/folder/subfolder").mkdirs();
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/folder/fileinfolder"), 20 * 1024);
    TestFileUtil.createRandomFile(new File(clientA.get("localdir") + "/folder/subfolder/fileinsubfolder"), 20 * 1024);
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up", "--force-checksum" }).start();
    TestFileUtil.changeRandomPartOfBinaryFile(new File(clientA.get("localdir") + "/folder/subfolder/fileinsubfolder"));
    TestFileUtil.changeRandomPartOfBinaryFile(new File(clientA.get("localdir") + "/file2"));
    Thread.sleep(1500);
    Date beforeSecondUpTime = new Date();
    new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up", "--force-checksum" }).start();
    // Check 'ls' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls" }));
    assertEquals("Different number of output lines expected.", 4, cliOut.length);
    assertTrue(cliOut[0].contains("1 .syignore"));
    assertTrue(cliOut[1].contains("1 file1"));
    assertTrue(cliOut[2].contains("2 file2"));
    assertTrue(cliOut[3].contains("1 folder"));
    // Check 'ls --recursive' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--recursive" }));
    assertEquals("Different number of output lines expected.", 7, cliOut.length);
    assertTrue(cliOut[0].contains("1 .syignore"));
    assertTrue(cliOut[1].contains("1 file1"));
    assertTrue(cliOut[2].contains("2 file2"));
    assertTrue(cliOut[3].contains("1 folder"));
    assertTrue(cliOut[4].contains("1 folder/fileinfolder"));
    assertTrue(cliOut[5].contains("1 folder/subfolder"));
    assertTrue(cliOut[6].contains("2 folder/subfolder/fileinsubfolder"));
    // Check 'ls --versions --recursive' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--versions", "--recursive" }));
    assertEquals("Different number of output lines expected.", 9, cliOut.length);
    assertTrue(cliOut[0].contains("1 .syignore"));
    assertTrue(cliOut[1].contains("1 file1"));
    assertTrue(cliOut[2].contains("1 file2"));
    assertTrue(cliOut[3].contains("2 file2"));
    assertTrue(cliOut[4].contains("1 folder"));
    assertTrue(cliOut[5].contains("1 folder/fileinfolder"));
    assertTrue(cliOut[6].contains("1 folder/subfolder"));
    assertTrue(cliOut[7].contains("1 folder/subfolder/fileinsubfolder"));
    assertTrue(cliOut[8].contains("2 folder/subfolder/fileinsubfolder"));
    // Check 'ls --versions --group' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--versions", "--group" }));
    assertEquals("Different number of output lines expected.", 12, cliOut.length);
    assertTrue(cliOut[0].contains(", .syignore"));
    assertTrue(cliOut[1].contains("1 .syignore"));
    assertEquals("", cliOut[2].trim());
    assertTrue(cliOut[3].contains(", file1"));
    assertTrue(cliOut[4].contains("1 file1"));
    assertEquals("", cliOut[5].trim());
    assertTrue(cliOut[6].contains(", file2"));
    assertTrue(cliOut[7].contains("1 file2"));
    assertTrue(cliOut[8].contains("2 file2"));
    assertEquals("", cliOut[9].trim());
    assertTrue(cliOut[10].contains(", folder"));
    assertTrue(cliOut[11].contains("1 folder"));
    // Check 'ls --types=d' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--types=d" }));
    assertEquals("Different number of output lines expected.", 1, cliOut.length);
    assertTrue(cliOut[0].contains("folder"));
    // Check 'ls --date=..' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "--date", new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(beforeSecondUpTime) }));
    assertEquals("Different number of output lines expected.", 4, cliOut.length);
    assertTrue(cliOut[0].contains("1 .syignore"));
    assertTrue(cliOut[1].contains("1 file1"));
    assertTrue(cliOut[2].contains("1 file2"));
    assertTrue(cliOut[3].contains("folder"));
    // Check 'ls folder/' output
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "ls", "folder/" }));
    assertEquals("Different number of output lines expected.", 2, cliOut.length);
    assertTrue(cliOut[0].contains("1 folder/fileinfolder"));
    assertTrue(cliOut[1].contains("1 folder/subfolder"));
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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