public static Map<String, String> createLocalTestEnv(String machineName, Map<String, String> connectionProperties) throws Exception { Map<String, String> clientSettings = new HashMap<String, String>(); File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("client-" + machineName, connectionProperties)); tempLocalDir.mkdirs(); // Client settings clientSettings.put("machinename", machineName); clientSettings.put("localdir", tempLocalDir.getAbsolutePath()); clientSettings.put("repopath", connectionProperties.get("path")); return clientSettings; }
public static RepoTO createRepoTO() { // Create Repo TO RepoTO repoTO = new RepoTO(); repoTO.setRepoId(new byte[] { 0x01, 0x02, 0x03 }); // Create ChunkerTO and MultiChunkerTO MultiChunkerTO multiChunkerTO = createZipMultiChunkerTO(); ChunkerTO chunkerTO = createFixedChunkerTO(); repoTO.setChunkerTO(chunkerTO); // TODO [low] Chunker not configurable right now. Not used. repoTO.setMultiChunker(multiChunkerTO); // Create TransformerTO List<TransformerTO> transformerTOs = createTransformerTOs(); repoTO.setTransformers(transformerTOs); return repoTO; }
public static Config createTestLocalConfig(String machineName) throws Exception { return createTestLocalConfig(machineName, createTestLocalConnection()); }
public static InitOperationOptions createTestInitOperationOptions(String machineName) throws Exception { File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, machineName)); File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", machineName)); tempLocalDir.mkdirs(); tempRepoDir.mkdirs(); RepoTO repoTO = createRepoTO(); // Create config TO ConfigTO configTO = new ConfigTO(); configTO.setMachineName(machineName + Math.abs(new Random().nextInt())); // Get Masterkey SaltedSecretKey masterKey = getMasterKey(); configTO.setMasterKey(masterKey); // Generic connection settings wont work anymore, because they are plugin dependent now. 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; }
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 testConfigHelperFindLocalDirInPathTwoLevelsDown() throws Exception { // Setup Config testConfig = TestConfigUtil.createTestLocalConfig(); new File(testConfig.getAppDir()+"/some/folder").mkdirs(); File startingPath = new File(testConfig.getAppDir()+"/some/folder"); // Run File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); // Test assertNotNull(actualLocalDir); assertEquals(testConfig.getLocalDir(), actualLocalDir.getCanonicalFile()); // Tear down TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }
@Test public void testConfigHelperLoadRepoTO() throws Exception { Config testConfig = TestConfigUtil.createTestLocalConfig(); assertNotNull(repoConfigTO.getRepoId()); if (TestConfigUtil.getCrypto()) { assertNotNull(repoConfigTO.getTransformers()); assertEquals(2, repoConfigTO.getTransformers().size()); TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
public static Config createTestLocalConfig() throws Exception { return createTestLocalConfig("syncanyclient"); }
public void deleteTestData() { TestConfigUtil.deleteTestLocalConfigAndData(config); }
public static UnreliableLocalTransferSettings createTestUnreliableLocalConnection(List<String> failingOperationPatterns) throws Exception { UnreliableLocalTransferPlugin unreliableLocalPlugin = new UnreliableLocalTransferPlugin(); UnreliableLocalTransferSettings unreliableLocalConnection = createTestUnreliableLocalConnectionWithoutInit(unreliableLocalPlugin, failingOperationPatterns); unreliableLocalPlugin.createTransferManager(unreliableLocalConnection, null).init(true); return unreliableLocalConnection; }
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; }
@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); } }
@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); } }
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 testConfigHelperFindLocalDirInPath() throws Exception { // Setup Config testConfig = TestConfigUtil.createTestLocalConfig(); File startingPath = testConfig.getLocalDir(); // Run File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); // Test assertNotNull(actualLocalDir); assertEquals(testConfig.getLocalDir(), actualLocalDir.getCanonicalFile()); // Tear down TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }
public TestClient(String machineName, TransferSettings connection) throws Exception { Config testConfig = TestConfigUtil.createTestLocalConfig(machineName, connection); testConfig.setMachineName(machineName); testConfig.setDisplayName(machineName); config = testConfig; }
repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO()); // <<< valid repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid
public static Map<String, String> createTestLocalConnectionSettings() throws Exception { Map<String, String> pluginSettings = new HashMap<String, String>(); File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", new Random().nextFloat())); pluginSettings.put("path", tempRepoDir.getAbsolutePath()); return pluginSettings; }
@Test public void testConfigHelperLoadConfigTO() throws Exception { // Setup Config testConfig = TestConfigUtil.createTestLocalConfig(); // Run ConfigTO loadedConfigTO = ConfigHelper.loadConfigTO(testConfig.getLocalDir()); // Test assertNotNull(loadedConfigTO); assertEquals(testConfig.getDisplayName(), loadedConfigTO.getDisplayName()); assertEquals(testConfig.getMachineName(), loadedConfigTO.getMachineName()); assertEquals(testConfig.getMasterKey(), loadedConfigTO.getMasterKey()); // Tear down TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }