@Test public void shouldProcessExistingFilesAndStartFileMonitorWhileInitializing() throws IOException, URISyntaxException { final Path tempDirectory = Files.createTempDirectory("motech-config-"); String configLocation = tempDirectory.toString(); when(coreConfigurationService.getConfigLocation()).thenReturn(new ConfigLocation(configLocation)); when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE); configFileMonitor.init(); InOrder inOrder = inOrder(configLoader, configurationService, fileMonitor); inOrder.verify(configLoader).findExistingConfigs(); inOrder.verify(configurationService).processExistingConfigs((List<File>) any()); final ArgumentCaptor<FileObject> fileObjArgCaptor = ArgumentCaptor.forClass(FileObject.class); inOrder.verify(fileMonitor).addFile(fileObjArgCaptor.capture()); final FileObject monitoredLocation = fileObjArgCaptor.getValue(); assertEquals(configLocation, new File(monitoredLocation.getURL().toURI()).getAbsolutePath()); inOrder.verify(fileMonitor).start(); }
@PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(true); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } }
ConfigFileMonitor implements FileListener { @PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(true); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } } }
ConfigFileMonitor implements FileListener { @PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(true); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } }  }
ConfigFileMonitor implements FileListener { @PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(true); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } }  void setFileMonitor(DefaultFileMonitor fileMonitor); @PostConstruct void init(); @Override void fileCreated(FileChangeEvent fileChangeEvent); @Override void fileChanged(FileChangeEvent fileChangeEvent); @Override void fileDeleted(FileChangeEvent fileChangeEvent); @PreDestroy void stop(); void updateFileMonitor(); }
ConfigFileMonitor implements FileListener { @PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(true); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } }  void setFileMonitor(DefaultFileMonitor fileMonitor); @PostConstruct void init(); @Override void fileCreated(FileChangeEvent fileChangeEvent); @Override void fileChanged(FileChangeEvent fileChangeEvent); @Override void fileDeleted(FileChangeEvent fileChangeEvent); @PreDestroy void stop(); void updateFileMonitor();  }