@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); }
@Test(expected = ConfigException.class) public void testConfigInitConfigTONull() throws Exception { File localDir = new File("/some/folder"); ConfigTO configTO = null; RepoTO repoTO = new RepoTO(); new Config(localDir, configTO, repoTO); }
return new Config(localDir, configTO, repoTO);
@Test(expected = ConfigException.class) public void testConfigInitLocalDirNull() throws Exception { File localDir = null; ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); new Config(localDir, configTO, repoTO); }
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); }
@Test public void testConfigMachineNameInvalidNull() throws Exception { File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName(null); // <<< Invalid // Run! try { new Config(localDir, configTO, repoTO); fail("Machine name should not have been accepted."); } catch (ConfigException e) { TestAssertUtil.assertErrorStackTraceContains("Machine name", e); } }
@Test public void testConfigMachineNameInvalidChars() throws Exception { File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("invalid machine name"); // Run! try { new Config(localDir, configTO, repoTO); fail("Machine name should not have been accepted."); } catch (ConfigException e) { TestAssertUtil.assertErrorStackTraceContains("Machine name", e); } }
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; }
@Test public void testConfigCipherTransformersInvalidType() throws Exception { // Setup File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("somevalidmachinename"); // <<< valid repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO()); // <<< valid repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid // Set invalid transformer TransformerTO invalidTransformerTO = new TransformerTO(); invalidTransformerTO.setType("invalid-typeXXX"); invalidTransformerTO.setSettings(new HashMap<String, String>()); List<TransformerTO> transformers = new ArrayList<TransformerTO>(); transformers.add(invalidTransformerTO); repoTO.setTransformers(transformers); // <<< INVALID ! // Run! try { new Config(localDir, configTO, repoTO); fail("Transformer should NOT have been found."); } catch (ConfigException e) { TestAssertUtil.assertErrorStackTraceContains("invalid-typeXXX", e); } }
@Test public void testConfigValid() throws Exception { // Setup File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("somevalidmachinename"); // <<< valid repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO()); // <<< valid repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid repoTO.setTransformers(null); // <<< valid // 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()); }
@Test public void testConfigMultiChunkerNull() throws Exception { // Setup File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("somevalidmachinename"); // <<< valid repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid repoTO.setTransformers(null); // <<< valid repoTO.setMultiChunker(null); // <<< INVALID !! // Run! try { new Config(localDir, configTO, repoTO); fail("Config should not been have initialized."); } catch (ConfigException e) { TestAssertUtil.assertErrorStackTraceContains("No multichunker", e); } }
new Config(localDir, configTO, repoTO); fail("Transformer should NOT have been able to initialize.");
Config config = new Config(localDir, configTO, repoTO);
@Test @Ignore // TODO [low] ChunkerTO is not used yet; so no test for it. public void testConfigChunkerNull() throws Exception { // Setup File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("somevalidmachinename"); // <<< valid repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid repoTO.setTransformers(null); // <<< valid repoTO.setChunkerTO(null); // <<< INVALID !! // Run! try { new Config(localDir, configTO, repoTO); fail("Config should not been have initialized."); } catch (ConfigException e) { TestAssertUtil.assertErrorStackTraceContains("No multichunker", e); } }