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); LocalConnection localConnection = (LocalConnection) connection; // Create connection TO Map<String, String> localConnectionSettings = new HashMap<String, String>(); localConnectionSettings.put("path", localConnection.getRepositoryPath().getAbsolutePath()); ConnectionTO connectionTO = new ConnectionTO(); if (connection instanceof UnreliableLocalConnection) { // Dirty hack UnreliableLocalConnection unreliableConnection = (UnreliableLocalConnection) connection; String failingPatterns = StringUtil.join(unreliableConnection.getFailingOperationPatterns(), ","); localConnectionSettings.put("patterns", failingPatterns); connectionTO.setType("unreliable_local"); connectionTO.setSettings(localConnectionSettings); } else { connectionTO.setType("local"); connectionTO.setSettings(localConnectionSettings); } configTO.setConnectionTO(connectionTO); // 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; }
private static void deleteTestLocalConnection(Config config) { LocalConnection connection = (LocalConnection) config.getConnection(); TestFileUtil.deleteDirectory(connection.getRepositoryPath()); }