private DaemonOperationResult executeList() { logger.log(Level.INFO, "Listing daemon-managed folders ..."); loadOrCreateConfig(); return new DaemonOperationResult(DaemonResultCode.OK, daemonConfig.getFolders()); }
@Test public void setWatchList() { ArrayList<FolderTO> newList = new ArrayList<FolderTO>(); result.setWatchList(newList); ArrayList<FolderTO> res = result.getWatchList(); assertNotNull(res); assertTrue(res.isEmpty()); }
@Test public void testExecuteRemove() throws Exception { when(options.getAction()).thenReturn(DaemonAction.REMOVE); List<String> watchRoots = new ArrayList<String>(); watchRoots.add(tempWatchRootAppFolder.getParent()); when(options.getWatchRoots()).thenReturn(watchRoots); DaemonOperationResult res = deamonOp.execute(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res.getResultCode()); assertNotNull(res.getWatchList()); assertTrue(res.getWatchList().isEmpty()); }
@Test public void testSetResultCode() { result.setResultCode(DaemonResultCode.NOK); DaemonResultCode res = result.getResultCode(); assertNotNull(res); assertEquals(DaemonResultCode.NOK, res); }
private void printResultAdd(DaemonOperationResult operationResult) { switch (operationResult.getResultCode()) { case OK: out.println("Folder(s) successfully added to daemon config."); out.println("Run 'sy daemon reload' to apply the changes."); out.println(); break; case OK_PARTIAL: out.println("Not all folder(s) were added successfully. Please check the following"); out.println("list to see which folders could not be added:"); out.println(); printResultList(operationResult); break; case NOK: out.println("Folder(s) were NOT added, because they might already exists in the daemon configuration."); out.println(); break; default: throw new RuntimeException("Invalid result code for this action: " + operationResult.getResultCode()); } }
private void printResultList(DaemonOperationResult operationResult) { List<String[]> tableValues = new ArrayList<String[]>(); tableValues.add(new String[] { "#", "Enabled", "Path" }); for (int i=0; i<operationResult.getWatchList().size(); i++) { FolderTO folderTO = operationResult.getWatchList().get(i); String number = Integer.toString(i+1); String enabledStr = folderTO.isEnabled() ? "yes" : "no"; tableValues.add(new String[] { number, enabledStr, folderTO.getPath() }); } CliTableUtil.printTable(out, tableValues, "No managed folders found."); }
@Test public void testExecuteAdd() throws Exception { when(options.getAction()).thenReturn(DaemonAction.ADD); List<String> watchRoots = new ArrayList<String>(); watchRoots.add(tempWatchRootAppFolder.getParent()); when(options.getWatchRoots()).thenReturn(watchRoots); DaemonOperationResult res = deamonOp.execute(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res.getResultCode()); assertNotNull(res.getWatchList()); assertEquals(1, res.getWatchList().size()); assertEquals(tempWatchRootAppFolder.getParentFile().getAbsolutePath(), res.getWatchList().get(0).getPath()); }
private void printResultRemove(DaemonOperationResult operationResult) { switch (operationResult.getResultCode()) { case OK: out.println("Folder(s) successfully removed from the daemon config."); out.println("Run 'sy daemon reload' to apply the changes."); out.println(); break; case NOK_PARTIAL: out.println("Not all folder(s) were removed successfully. Please check the following"); out.println("list to see which folders could not be added:"); out.println(); printResultList(operationResult); break; case NOK: out.println("Folder(s) could not be NOT removed, because they did not exist in the daemon config."); out.println(); break; default: throw new RuntimeException("Invalid result code for this action: " + operationResult.getResultCode()); } } }
@Test public void testGetWatchList() { ArrayList<FolderTO> res = result.getWatchList(); assertNotNull(res); assertFalse(res.isEmpty()); assertTrue(res.contains(folder)); }
@Test public void testExecuteList() throws Exception { when(options.getAction()).thenReturn(DaemonAction.LIST); DaemonOperationResult res = deamonOp.execute(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res.getResultCode()); assertNotNull(res.getWatchList()); }
private DaemonOperationResult executeAdd() throws Exception { // Check all folders for (String watchRoot : options.getWatchRoots()) { File watchRootFolder = new File(watchRoot); File watchRootAppFolder = new File(watchRootFolder, Config.DIR_APPLICATION); if (!watchRootFolder.isDirectory() || !watchRootAppFolder.isDirectory()) { throw new Exception("Given argument is not an existing folder, or a valid Syncany folder: " + watchRoot); } } // Add them for (String watchRoot : options.getWatchRoots()) { DaemonConfigHelper.addFolder(new File(watchRoot)); } // Determine return code loadOrCreateConfig(); int watchedMatchingFoldersCount = countWatchedMatchingFolders(); if (watchedMatchingFoldersCount == options.getWatchRoots().size()) { return new DaemonOperationResult(DaemonResultCode.OK, daemonConfig.getFolders()); } else if (watchedMatchingFoldersCount > 0) { return new DaemonOperationResult(DaemonResultCode.OK_PARTIAL, daemonConfig.getFolders()); } else { return new DaemonOperationResult(DaemonResultCode.NOK, daemonConfig.getFolders()); } }
@Test public void testGetResultCode() { DaemonResultCode res = result.getResultCode(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res); }
private DaemonOperationResult executeRemove() throws ConfigException { // Sort Collections.sort(options.getWatchRoots(), Ordering.natural().reverse()); // Remove all folders for (String watchRoot : options.getWatchRoots()) { logger.log(Level.INFO, "- Removing folder from daemon config: " + watchRoot + " ..."); DaemonConfigHelper.removeFolder(watchRoot); } // Check if folders were removed loadOrCreateConfig(); int watchedMatchingFoldersCount = countWatchedMatchingFolders(); if (watchedMatchingFoldersCount == options.getWatchRoots().size()) { return new DaemonOperationResult(DaemonResultCode.NOK, daemonConfig.getFolders()); } else if (watchedMatchingFoldersCount > 0) { return new DaemonOperationResult(DaemonResultCode.NOK_PARTIAL, daemonConfig.getFolders()); } else { return new DaemonOperationResult(DaemonResultCode.OK, daemonConfig.getFolders()); } }
@Before public void setUp() { folder = new FolderTO("test"); watchList = new ArrayList<FolderTO>(); watchList.add(folder); result = new DaemonOperationResult(DaemonResultCode.OK, watchList); }
private DaemonOperationResult executeRun() throws Exception { if (PidFileUtil.isProcessRunning(pidFile)) { throw new ServiceAlreadyStartedException("Syncany daemon already running."); } PidFileUtil.createPidFile(pidFile); initEventBus(); loadOrCreateConfig(); startWebServer(); startWatchServer(); enterControlLoop(); // This blocks until SHUTDOWN is received! return new DaemonOperationResult(DaemonResultCode.OK); }