Search in sources :

Example 11 with ConfigTO

use of org.syncany.config.to.ConfigTO in project syncany by syncany.

the class ConfigTest method testConfigValid.

@Test
public void testConfigValid() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO());
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // Run!
    Config config = new Config(localDir, configTO, repoTO);
    // Test
    assertEquals("/some/folder/.syncany", config.getAppDir().getAbsolutePath());
    assertEquals("/some/folder/.syncany/cache", config.getCacheDir().getAbsolutePath());
    assertEquals("/some/folder/.syncany/db", config.getDatabaseDir().getAbsolutePath());
    assertEquals("/some/folder/.syncany/db/local.db", config.getDatabaseFile().getAbsolutePath());
    assertNotNull(config.getChunker());
    assertEquals("FixedChunker", config.getChunker().getClass().getSimpleName());
    assertEquals("SHA1", config.getChunker().getChecksumAlgorithm());
    assertNotNull(config.getMultiChunker());
    assertEquals("ZipMultiChunker", config.getMultiChunker().getClass().getSimpleName());
    assertNotNull(config.getTransformer());
    assertEquals("NoTransformer", config.getTransformer().getClass().getSimpleName());
    assertNotNull(config.getCache());
}
Also used : Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 12 with ConfigTO

use of org.syncany.config.to.ConfigTO in project syncany by syncany.

the class ConfigTest method testConfigInitRepoTONull.

@Test(expected = ConfigException.class)
public void testConfigInitRepoTONull() throws Exception {
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = null;
    new Config(localDir, configTO, repoTO);
}
Also used : Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 13 with ConfigTO

use of org.syncany.config.to.ConfigTO in project syncany by syncany.

the class ConfigTest method testConfigMachineNameInvalidNull.

@Test
public void testConfigMachineNameInvalidNull() throws Exception {
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< Invalid
    configTO.setMachineName(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Machine name should not have been accepted.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("Machine name", e);
    }
}
Also used : Config(org.syncany.config.Config) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 14 with ConfigTO

use of org.syncany.config.to.ConfigTO in project syncany by syncany.

the class TestConfigUtil method createDummyConfig.

public static Config createDummyConfig() throws Exception {
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName("dummymachine");
    RepoTO repoTO = new RepoTO();
    repoTO.setTransformers(null);
    repoTO.setChunkerTO(createFixedChunkerTO());
    repoTO.setMultiChunker(createZipMultiChunkerTO());
    return new Config(new File("/dummy"), configTO, repoTO);
}
Also used : UserConfig(org.syncany.config.UserConfig) Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 15 with ConfigTO

use of org.syncany.config.to.ConfigTO in project syncany by syncany.

the class InitCommand method parseOptions.

@Override
public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
    InitOperationOptions operationOptions = new InitOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionNoCreateTarget = parser.acceptsAll(asList("T", "no-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<Void> optionHeadlessMode = parser.acceptsAll(asList("l", "headless"));
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
    OptionSet options = parser.parse(operationArguments);
    // Set interactivity mode
    isInteractive = !options.has(optionPlugin);
    // Set headless mode
    isHeadless = options.has(optionHeadlessMode);
    // Ask or set transfer settings
    TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
    // Some misc settings
    boolean createTargetPath = !options.has(optionNoCreateTarget);
    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);
    // Compression: --no-compression
    // DefaultRepoTOFactory also creates default chunkers
    RepoTOFactory repoTOFactory = new DefaultRepoTOFactory(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 = repoTOFactory.createRepoTO();
    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;
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) TransferSettings(org.syncany.plugins.transfer.TransferSettings) GenlinkOperationOptions(org.syncany.operations.init.GenlinkOperationOptions) OptionParser(joptsimple.OptionParser) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) RepoTOFactory(org.syncany.config.to.RepoTOFactory) CipherSpec(org.syncany.crypto.CipherSpec) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) RepoTO(org.syncany.config.to.RepoTO)

Aggregations

ConfigTO (org.syncany.config.to.ConfigTO)27 File (java.io.File)21 Test (org.junit.Test)18 RepoTO (org.syncany.config.to.RepoTO)17 Config (org.syncany.config.Config)15 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)7 ConfigException (org.syncany.config.ConfigException)6 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)6 Random (java.util.Random)4 Persister (org.simpleframework.xml.core.Persister)4 ConnectOperationOptions (org.syncany.operations.init.ConnectOperationOptions)4 ArrayList (java.util.ArrayList)3 Serializer (org.simpleframework.xml.Serializer)3 TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)3 SaltedSecretKey (org.syncany.crypto.SaltedSecretKey)3 ConnectOperation (org.syncany.operations.init.ConnectOperation)3 ConnectOperationResult (org.syncany.operations.init.ConnectOperationResult)3 InitOperation (org.syncany.operations.init.InitOperation)3 InitOperationResult (org.syncany.operations.init.InitOperationResult)3 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)3