Package org.syncany.operations.init

Examples of org.syncany.operations.init.InitOperationOptions


*/
public class ConnectOperationTest {
  @Test
  public void testConnectOperationSuccess() 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_TO);
    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());
  }
View Full Code Here


  }

  @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);

    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    ((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist")); // <<< Point to non-existing repo
    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());

    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();

    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
  }
View Full Code Here

    LocalTransferSettings transferSettings = Plugins.get("local", TransferPlugin.class).createEmptySettings();
    transferSettings.setPath(tempRepoDir);

    configTO.setTransferSettings(transferSettings);

    InitOperationOptions operationOptions = new InitOperationOptions();

    operationOptions.setLocalDir(tempLocalDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);

    operationOptions.setEncryptionEnabled(cryptoEnabled);
    operationOptions.setCipherSpecs(CipherSpecs.getDefaultCipherSpecs());
    operationOptions.setPassword(cryptoEnabled ? "some password" : null);

    return operationOptions;
  }
View Full Code Here

  @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.");
    }

    // 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());
  }
View Full Code Here

    return operationOptions;
  }

  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;
  }
View Full Code Here

public class InitOperationTest {
  private static final Logger logger = Logger.getLogger(InitOperation.class.getSimpleName());

  @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());
  }
View Full Code Here

    return 0;
  }

  @Override
  public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
    InitOperationOptions operationOptions = new InitOperationOptions();

    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionCreateTargetPath = parser.acceptsAll(asList("t", "create-target"));
    OptionSpec<Void> optionAdvanced = parser.acceptsAll(asList("a", "advanced"));
    OptionSpec<Void> optionNoCompression = parser.acceptsAll(asList("G", "no-compression"));
    OptionSpec<Void> optionNoEncryption = parser.acceptsAll(asList("E", "no-encryption"));
    OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
    OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
    OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
    OptionSpec<Void> optionShortUrl = parser.acceptsAll(asList("s", "short"));   
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg()

    OptionSet options = parser.parse(operationArguments);

    // Set interactivity mode 
    isInteractive = !options.has(optionPlugin);
     
    // Ask or set transfer settings
    TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);

    // Some misc settings
    boolean createTargetPath = options.has(optionCreateTargetPath);
    boolean advancedModeEnabled = options.has(optionAdvanced);
    boolean encryptionEnabled = !options.has(optionNoEncryption);
    boolean compressionEnabled = !options.has(optionNoCompression);
   
    // Cipher specs: --no-encryption, --advanced
    List<CipherSpec> cipherSpecs = getCipherSpecs(encryptionEnabled, advancedModeEnabled);

    // Chunkers (not configurable)
    ChunkerTO chunkerTO = getDefaultChunkerTO();
    MultiChunkerTO multiChunkerTO = getDefaultMultiChunkerTO();

    // Compression: --no-compression
    List<TransformerTO> transformersTO = getTransformersTO(compressionEnabled, cipherSpecs);

    // Genlink options: --short
    GenlinkOperationOptions genlinkOptions = new GenlinkOperationOptions();
    genlinkOptions.setShortUrl(options.has(optionShortUrl));
       
    // Set repo password
    String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
    operationOptions.setPassword(password);
   
    // Create configTO and repoTO
    ConfigTO configTO = createConfigTO(transferSettings);
    RepoTO repoTO = createRepoTO(chunkerTO, multiChunkerTO, transformersTO);

    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);

    operationOptions.setCreateTarget(createTargetPath);
    operationOptions.setEncryptionEnabled(encryptionEnabled);
    operationOptions.setCipherSpecs(cipherSpecs);   
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setGenlinkOptions(genlinkOptions);
   
    return operationOptions;
  }
View Full Code Here

TOP

Related Classes of org.syncany.operations.init.InitOperationOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.