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; }
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; }
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); // Create connection TO Map<String, String> localConnectionSettings = new HashMap<String, String>(); localConnectionSettings.put("path", tempRepoDir.getAbsolutePath()); ConnectionTO connectionTO = new ConnectionTO(); connectionTO.setType("local"); connectionTO.setSettings(localConnectionSettings); configTO.setConnectionTO(connectionTO); 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 UnreliableLocalConnection createTestUnreliableLocalConnectionWithoutInit( UnreliableLocalPlugin unreliableLocalPlugin, List<String> failingOperationPatterns) throws Exception { UnreliableLocalConnection unreliableLocalConnection = (UnreliableLocalConnection) unreliableLocalPlugin.createSettings(); File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp( createUniqueName("repo", new Random().nextFloat())); unreliableLocalConnection.setRepositoryPath(tempRepoDir); unreliableLocalConnection.setFailingOperationPatterns(failingOperationPatterns); return unreliableLocalConnection; }
public static TransferSettings createTestLocalConnection() throws Exception { TransferPlugin plugin = Plugins.get("local", TransferPlugin.class); TransferSettings conn = plugin.createSettings(); File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", conn)); Map<String, String> pluginSettings = new HashMap<String, String>(); pluginSettings.put("path", tempRepoDir.getAbsolutePath()); conn.init(pluginSettings); plugin.createTransferManager(conn).init(true); return conn; }