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());
}
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());
}
Aggregations