Search in sources :

Example 6 with InitOperation

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

the class ConnectOperationTest method testConnectOperationWithLink.

@Test
public void testConnectOperationWithLink() 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("clientB", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    connectionConfigToB.setMachineName("clientB" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
    connectOperationOptionsB.setConnectLink(connectLinkA);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.OK, connectOperationResultB.getResultCode());
    assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
    assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    // 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) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) 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 7 with InitOperation

use of org.syncany.operations.init.InitOperation 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

InitOperation (org.syncany.operations.init.InitOperation)7 InitOperationResult (org.syncany.operations.init.InitOperationResult)6 File (java.io.File)5 Test (org.junit.Test)5 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)5 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)4 Random (java.util.Random)3 ConfigTO (org.syncany.config.to.ConfigTO)3 ConnectOperation (org.syncany.operations.init.ConnectOperation)3 ConnectOperationOptions (org.syncany.operations.init.ConnectOperationOptions)3 ConnectOperationResult (org.syncany.operations.init.ConnectOperationResult)3 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)2 EventUserInteractionListener (org.syncany.operations.daemon.EventUserInteractionListener)1 StorageException (org.syncany.plugins.transfer.StorageException)1