Search in sources :

Example 1 with InitOperationOptions

use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.

the class TestConfigUtil method createTestUnreliableInitOperationOptions.

public static InitOperationOptions createTestUnreliableInitOperationOptions(String machineName, List<String> failingOperationPatterns) throws Exception {
    InitOperationOptions initOperationOptions = createTestInitOperationOptions(machineName);
    // createTestInitOperationOptions always returns LocalTransferSettings
    File tempRpoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
    UnreliableLocalTransferSettings transferSettings = Plugins.get("unreliable_local", TransferPlugin.class).createEmptySettings();
    transferSettings.setPath(tempRpoDir);
    transferSettings.setFailingOperationPatterns(failingOperationPatterns);
    initOperationOptions.getConfigTO().setTransferSettings(transferSettings);
    return initOperationOptions;
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) UnreliableLocalTransferPlugin(org.syncany.plugins.unreliable_local.UnreliableLocalTransferPlugin) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) File(java.io.File)

Example 2 with InitOperationOptions

use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.

the class TransferSettingsTest method testDeserializeCorrectClass.

@Test
public void testDeserializeCorrectClass() throws Exception {
    Serializer serializer = new Persister();
    InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
    // Always LocalTransferSettings
    serializer.write(initOperationOptions.getConfigTO(), tmpFile);
    ConfigTO confRestored = ConfigTO.load(tmpFile);
    assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
    // Tear down
    FileUtils.deleteDirectory(initOperationOptions.getLocalDir());
    FileUtils.deleteDirectory(((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath());
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) Persister(org.simpleframework.xml.core.Persister) ConfigTO(org.syncany.config.to.ConfigTO) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Example 3 with InitOperationOptions

use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.

the class ConnectOperationTest method testConnectOperationFailureNoConnection.

@Test
public void testConnectOperationFailureNoConnection() throws Exception {
    // A.init()
    InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
    InitOperationResult initOperationResultA = initOperationA.execute();
    String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
    assertNotNull(connectLinkA);
    // B.connect()
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("client-B", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    // <<< Point to non-existing repo
    ((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist"));
    connectionConfigToB.setMachineName("client-B" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.NOK_TEST_FAILED, connectOperationResultB.getResultCode());
    assertFalse(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_REPO).exists());
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
    TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Also used : ConnectOperationResult(org.syncany.operations.init.ConnectOperationResult) InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) Random(java.util.Random) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConnectOperation(org.syncany.operations.init.ConnectOperation) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions) Test(org.junit.Test)

Example 4 with InitOperationOptions

use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.

the class InitOperationTest method testInitOperation.

@Test
public void testInitOperation() throws Exception {
    InitOperationOptions operationOptions = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation op = new InitOperation(operationOptions, null);
    InitOperationResult res = op.execute();
    File repoDir = ((LocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = new File(operationOptions.getLocalDir(), ".syncany");
    // Test the repository
    assertTrue((new File(repoDir, "databases").exists()));
    assertTrue((new File(repoDir, "syncany").exists()));
    assertTrue((new File(repoDir, "multichunks").exists()));
    assertEquals((new File(repoDir, "master").exists()), TestConfigUtil.getCrypto());
    // Test the local folder
    assertTrue((new File(localDir, Config.DIR_DATABASE).exists()));
    assertTrue((new File(localDir, Config.DIR_CACHE).exists()));
    assertTrue((new File(localDir, Config.FILE_CONFIG).exists()));
    assertTrue((new File(localDir, Config.DIR_LOG).exists()));
    assertTrue((new File(localDir, Config.FILE_REPO).exists()));
    assertEquals((new File(localDir, Config.FILE_MASTER).exists()), TestConfigUtil.getCrypto());
    // Test the existance of generated link
    String link = res.getGenLinkResult().getShareLink();
    assertNotNull(link);
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 5 with InitOperationOptions

use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.

the class InitOperationTest method testFaultyInitOperation.

@Test
public void testFaultyInitOperation() throws Exception {
    // Create an unreliable connection
    List<String> failingOperationsPattern = Lists.newArrayList("rel=1.*op=upload");
    InitOperationOptions operationOptions = TestConfigUtil.createTestUnreliableInitOperationOptions("A", failingOperationsPattern);
    InitOperation op = new InitOperation(operationOptions, null);
    File repoDir = ((UnreliableLocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = new File(operationOptions.getLocalDir(), ".syncany");
    try {
        op.execute();
    } catch (StorageException e) {
        logger.log(Level.INFO, "This operation failed because of the unreliable connection.", e);
    }
    // The local directory should not exist, since the uploading of the repo file fails
    // so the local directories should be removed
    assertFalse(localDir.exists());
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Also used : InitOperation(org.syncany.operations.init.InitOperation) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) File(java.io.File) StorageException(org.syncany.plugins.transfer.StorageException) Test(org.junit.Test)

Aggregations

InitOperationOptions (org.syncany.operations.init.InitOperationOptions)10 File (java.io.File)8 Test (org.junit.Test)7 ConfigTO (org.syncany.config.to.ConfigTO)7 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)7 InitOperation (org.syncany.operations.init.InitOperation)5 Random (java.util.Random)4 InitOperationResult (org.syncany.operations.init.InitOperationResult)4 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)4 ConnectOperation (org.syncany.operations.init.ConnectOperation)3 ConnectOperationOptions (org.syncany.operations.init.ConnectOperationOptions)3 ConnectOperationResult (org.syncany.operations.init.ConnectOperationResult)3 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)3 Serializer (org.simpleframework.xml.Serializer)2 Persister (org.simpleframework.xml.core.Persister)2 RepoTO (org.syncany.config.to.RepoTO)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 UnreliableLocalTransferPlugin (org.syncany.plugins.unreliable_local.UnreliableLocalTransferPlugin)2 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1