Search in sources :

Example 11 with RepoTO

use of org.syncany.config.to.RepoTO 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 : ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 12 with RepoTO

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

the class ConfigTest method testConfigMultiChunkerNull.

@Test
public void testConfigMultiChunkerNull() 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.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setMultiChunker(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Config should not been have initialized.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("No multichunker", e);
    }
}
Also used : ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 13 with RepoTO

use of org.syncany.config.to.RepoTO 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 14 with RepoTO

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

the class ConfigHelper method loadConfig.

/**
 * Loads a {@link Config} object from the given local directory.
 *
 * <p>If the config file (.syncany/config.xml) does not exist, <tt>null</tt>
 * is returned. If it does, the method tries to do the following:
 * <ul>
 *  <li>Load the .syncany/config.xml file and load the plugin given by the config file</li>
 *  <li>Read .syncany/repo, decrypt it using the master key (if necessary) and load it</li>
 *  <li>Instantiate a {@link Config} object with the transfer objects</li>
 * </ul>
 *
 * @return Returns an instantiated {@link Config} object, or <tt>null</tt> if
 *         the config file does not exist
 * @throws Throws an exception if the config is invalid
 */
public static Config loadConfig(File localDir) throws ConfigException {
    if (localDir == null) {
        throw new ConfigException("Argument localDir cannot be null.");
    }
    File appDir = new File(localDir, Config.DIR_APPLICATION);
    if (appDir.exists()) {
        logger.log(Level.INFO, "Loading config from {0} ...", localDir);
        ConfigTO configTO = ConfigHelper.loadConfigTO(localDir);
        RepoTO repoTO = ConfigHelper.loadRepoTO(localDir, configTO);
        String pluginId = (configTO.getTransferSettings() != null) ? configTO.getTransferSettings().getType() : null;
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            logger.log(Level.WARNING, "Not loading config! Plugin with id '{0}' does not exist.", pluginId);
            throw new ConfigException("Plugin with id '" + pluginId + "' does not exist. Try 'sy plugin install " + pluginId + "'.");
        }
        logger.log(Level.INFO, "Initializing Config instance ...");
        return new Config(localDir, configTO, repoTO);
    } else {
        logger.log(Level.INFO, "Not loading config, app dir does not exist: {0}", appDir);
        return null;
    }
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 15 with RepoTO

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

the class ConfigTest method testConfigMultiChunkerNull.

@Test
public void testConfigMultiChunkerNull() 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.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setMultiChunker(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Config should not been have initialized.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("No multichunker", 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)

Aggregations

RepoTO (org.syncany.config.to.RepoTO)30 ConfigTO (org.syncany.config.to.ConfigTO)29 File (java.io.File)26 Test (org.junit.Test)24 Config (org.syncany.config.Config)14 TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)7 ArrayList (java.util.ArrayList)6 ConfigException (org.syncany.config.ConfigException)6 Ignore (org.junit.Ignore)2 UserConfig (org.syncany.config.UserConfig)2 SaltedSecretKey (org.syncany.crypto.SaltedSecretKey)2 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)2 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 Persister (org.simpleframework.xml.core.Persister)1