Search in sources :

Example 36 with Config

use of org.syncany.config.Config in project syncany by syncany.

the class ConfigTest method testConfigCipherTransformersCipherFound.

@Test
@SuppressWarnings("serial")
public void testConfigCipherTransformersCipherFound() 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
    configTO.setMasterKey(createDummyMasterKey());
    // Set invalid transformer
    TransformerTO invalidTransformerTO = new TransformerTO();
    invalidTransformerTO.setType("cipher");
    invalidTransformerTO.setSettings(new HashMap<String, String>() {

        {
            put("cipherspecs", "1,2");
        }
    });
    List<TransformerTO> transformers = new ArrayList<TransformerTO>();
    transformers.add(invalidTransformerTO);
    // <<< valid
    repoTO.setTransformers(transformers);
    // Run!
    Config config = new Config(localDir, configTO, repoTO);
    // Test
    assertNotNull(config.getChunker());
    assertNotNull(config.getMultiChunker());
    assertNotNull(config.getTransformer());
    assertEquals("CipherTransformer", config.getTransformer().getClass().getSimpleName());
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) Config(org.syncany.config.Config) ArrayList(java.util.ArrayList) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 37 with Config

use of org.syncany.config.Config in project syncany by syncany.

the class ConfigTest method testConfigChunkerNull.

@Test
@Ignore
public // TODO [low] ChunkerTO is not used yet; so no test for it.
void testConfigChunkerNull() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setChunkerTO(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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with Config

use of org.syncany.config.Config in project syncany by syncany.

the class TestConfigUtil method createTestLocalConfig.

public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception {
    File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection));
    tempLocalDir.mkdirs();
    RepoTO repoTO = createRepoTO();
    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20));
    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);
    LocalTransferSettings localConnection = (LocalTransferSettings) connection;
    // Create connection TO
    Map<String, String> localConnectionSettings = new HashMap<String, String>();
    localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath());
    configTO.setTransferSettings(connection);
    // Create
    Config config = new Config(tempLocalDir, configTO, repoTO);
    config.setConnection(connection);
    config.getAppDir().mkdirs();
    config.getCacheDir().mkdirs();
    config.getDatabaseDir().mkdirs();
    config.getLogDir().mkdirs();
    config.getStateDir().mkdirs();
    // Write to config folder (required for some tests)
    new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG));
    new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO));
    return config;
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) HashMap(java.util.HashMap) UserConfig(org.syncany.config.UserConfig) Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) Persister(org.simpleframework.xml.core.Persister) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 39 with Config

use of org.syncany.config.Config in project syncany by syncany.

the class WatchServer method startWatchOperations.

private void startWatchOperations(Map<File, FolderTO> newWatchedFolderTOs) throws ConfigException, ServiceAlreadyStartedException {
    for (Map.Entry<File, FolderTO> folderEntry : newWatchedFolderTOs.entrySet()) {
        File localDir = folderEntry.getKey();
        try {
            Config watchConfig = ConfigHelper.loadConfig(localDir);
            if (watchConfig != null) {
                logger.log(Level.INFO, "- Starting watch operation at " + localDir + " ...");
                WatchOperationOptions watchOptions = folderEntry.getValue().getWatchOptions();
                if (watchOptions == null) {
                    watchOptions = new WatchOperationOptions();
                }
                WatchRunner watchRunner = new WatchRunner(watchConfig, watchOptions, daemonConfig.getPortTO());
                watchRunner.start();
                watchOperations.put(localDir, watchRunner);
            } else {
                logger.log(Level.INFO, "- CANNOT start watch, because no config found at " + localDir + " ...");
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "  + Cannot start watch operation at " + localDir + ". IGNORING.", e);
        }
    }
}
Also used : WatchOperationOptions(org.syncany.operations.watch.WatchOperationOptions) Config(org.syncany.config.Config) FolderTO(org.syncany.config.to.FolderTO) Map(java.util.Map) TreeMap(java.util.TreeMap) File(java.io.File) ConfigException(org.syncany.config.ConfigException)

Example 40 with Config

use of org.syncany.config.Config in project syncany by syncany.

the class MultiChunkDaoTest method testGetMultiChunksByDatabaseVersion2.

@Test
public void testGetMultiChunksByDatabaseVersion2() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
    Map<MultiChunkId, MultiChunkEntry> multiChunksA4 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A4"));
    Map<MultiChunkId, MultiChunkEntry> multiChunksA5 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A5"));
    // Test
    // - Database version "A4"
    assertNotNull(multiChunksA4);
    assertEquals(0, multiChunksA4.size());
    // - Database version "A5"
    assertNotNull(multiChunksA5);
    assertEquals(1, multiChunksA5.size());
    MultiChunkEntry multiChunkInA5 = multiChunksA5.get(MultiChunkId.parseMultiChunkId("dddddddddddddddddddddddddddddddddddddddd"));
    assertNotNull(multiChunkInA5);
    assertEquals("dddddddddddddddddddddddddddddddddddddddd", multiChunkInA5.getId().toString());
    assertTrue(CollectionUtil.containsExactly(multiChunkInA5.getChunks(), ChunkChecksum.parseChunkChecksum("ffffffffffffffffffffffffffffffffffffffff")));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Config(org.syncany.config.Config) Connection(java.sql.Connection) MultiChunkSqlDao(org.syncany.database.dao.MultiChunkSqlDao) MultiChunkEntry(org.syncany.database.MultiChunkEntry) Test(org.junit.Test)

Aggregations

Config (org.syncany.config.Config)55 Test (org.junit.Test)52 Connection (java.sql.Connection)25 File (java.io.File)24 MultiChunkSqlDao (org.syncany.database.dao.MultiChunkSqlDao)18 ConfigTO (org.syncany.config.to.ConfigTO)15 RepoTO (org.syncany.config.to.RepoTO)14 ChunkSqlDao (org.syncany.database.dao.ChunkSqlDao)14 FileContentSqlDao (org.syncany.database.dao.FileContentSqlDao)14 FileVersionSqlDao (org.syncany.database.dao.FileVersionSqlDao)13 DatabaseVersionSqlDao (org.syncany.database.dao.DatabaseVersionSqlDao)12 FileHistorySqlDao (org.syncany.database.dao.FileHistorySqlDao)12 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)10 DatabaseVersion (org.syncany.database.DatabaseVersion)9 ConfigException (org.syncany.config.ConfigException)7 FileVersion (org.syncany.database.FileVersion)7 ArrayList (java.util.ArrayList)6 MultiChunkEntry (org.syncany.database.MultiChunkEntry)6 UpOperation (org.syncany.operations.up.UpOperation)6 Date (java.util.Date)5