Search in sources :

Example 1 with CommandLineClient

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

the class CommandLineInterfaceTest method testAppFoldersExist.

@Test
public void testAppFoldersExist() throws Exception {
    // Setup
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    // Run!
    new File(clientA.get("localdir") + "/somefolder").mkdir();
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "up" }));
    // Test folder existence
    File appFolder = new File(clientA.get("localdir") + "/" + Config.DIR_APPLICATION);
    File logFolder = new File(appFolder + "/" + Config.DIR_LOG);
    File dbFolder = new File(appFolder + "/" + Config.DIR_DATABASE);
    File cacheFolder = new File(appFolder + "/" + Config.DIR_CACHE);
    assertTrue("App folder should exist", appFolder.exists());
    assertTrue("Logs folder should exist", logFolder.exists());
    assertTrue("Log file should exist", logFolder.list().length > 0);
    assertTrue("Database folder should exist", dbFolder.exists());
    assertTrue("Cache folder should exist", cacheFolder.exists());
    // Test output
    assertEquals("Different number of output lines expected.", 15, cliOut.length);
    assertEquals("A somefolder", cliOut[13]);
    // Cleanup
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 2 with CommandLineClient

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

the class CommandLineInterfaceTest method testCliInitAndConnect.

@Test
public void testCliInitAndConnect() throws Exception {
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnv("A", connectionSettings);
    Map<String, String> clientB = TestCliUtil.createLocalTestEnv("B", connectionSettings);
    // Init
    String[] initArgs = new String[] { "--localdir", clientA.get("localdir"), "init", "--plugin", "local", "--plugin-option", "path=" + clientA.get("repopath"), "--no-encryption", "--no-compression" };
    logger.log(Level.INFO, "Running syncany with argument: " + StringUtil.join(initArgs, " "));
    new CommandLineClient(initArgs).start();
    assertTrue("Repo file in repository should exist.", new File(clientA.get("repopath") + "/syncany").exists());
    assertTrue("Repo file in local client should exist.", new File(clientA.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_REPO).exists());
    assertTrue("Config file in local client should exist.", new File(clientA.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG).exists());
    // Connect
    String[] connectArgs = new String[] { "connect", "--localdir", clientB.get("localdir"), "--plugin", "local", "--plugin-option", "path=" + clientB.get("repopath") };
    logger.log(Level.INFO, "Running syncany with argument: " + StringUtil.join(connectArgs, " "));
    new CommandLineClient(connectArgs).start();
    assertTrue("Repo file in local client should exist.", new File(clientB.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_REPO).exists());
    assertTrue("Config file in local client should exist.", new File(clientB.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG).exists());
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
    TestCliUtil.deleteTestLocalConfigAndData(clientB);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 3 with CommandLineClient

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

the class ConnectCommandWithEncryptionTest method testCliConnectInteractiveWithLinkEnc.

@Test
public void testCliConnectInteractiveWithLinkEnc() throws Exception {
    // Setup
    resetRepo();
    // 2. Connect
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp();
    TestCliUtil.setCurrentDirectory(localDirB);
    String[] connectArgs = new String[] { "connect", initializedRepoConnectLink };
    systemInMock.provideText(StringUtil.join(new String[] { // No path or params, not needed because link provided
    initializedRepoPassword }, "\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 4 with CommandLineClient

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

the class StatusCommandTest method testStatusCommandWithNoDelete.

@Test
public void testStatusCommandWithNoDelete() 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();
    }
    // Delete file
    new File(clientA.get("localdir") + "/somefolder1").delete();
    // Test status without no-delete parameter
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "status" }));
    assertEquals("Number of output lines", 3, cliOut.length);
    assertTrue(cliOut[2].contains("D somefolder1"));
    // Test status with no-delete parameter
    cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--localdir", clientA.get("localdir"), "status", "--no-delete" }));
    assertEquals("Number of output lines", 3, cliOut.length);
    assertTrue(cliOut[2].contains("No local changes."));
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) Test(org.junit.Test)

Example 5 with CommandLineClient

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

the class StatusCommandTest method testStatusCommandWithLogLevelOff.

@Test
public void testStatusCommandWithLogLevelOff() throws Exception {
    // Setup
    Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
    Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
    // Run!
    new File(clientA.get("localdir") + "/somefolder1").mkdir();
    new File(clientA.get("localdir") + "/somefolder2").mkdir();
    String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] { "--loglevel", "OFF", "--localdir", clientA.get("localdir"), "status" }));
    // Test
    assertEquals("Different number of output lines expected.", 5, cliOut.length);
    assertEquals("? .syignore", cliOut[2]);
    assertEquals("? somefolder1", cliOut[3]);
    assertEquals("? somefolder2", cliOut[4]);
    // TODO [medium] This test case does NOT test the loglevel option
    // Cleanup
    TestCliUtil.deleteTestLocalConfigAndData(clientA);
}
Also used : CommandLineClient(org.syncany.cli.CommandLineClient) File(java.io.File) 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