@Test public void watchingAdditionalPaths() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("spring.devtools.restart.additional-paths", "src/main/java,src/test/java"); this.context = initializeAndRun(Config.class, properties); ClassPathFileSystemWatcher classPathWatcher = this.context .getBean(ClassPathFileSystemWatcher.class); Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher"); @SuppressWarnings("unchecked") Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils .getField(watcher, "folders"); assertThat(folders).hasSize(2) .containsKey(new File("src/main/java").getAbsoluteFile()) .containsKey(new File("src/test/java").getAbsoluteFile()); }
@Test public void watchingAdditionalPaths() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("spring.devtools.restart.additional-paths", "src/main/java,src/test/java"); this.context = initializeAndRun(Config.class, properties); ClassPathFileSystemWatcher classPathWatcher = this.context .getBean(ClassPathFileSystemWatcher.class); Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher"); @SuppressWarnings("unchecked") Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils .getField(watcher, "folders"); assertThat(folders.size(), is(equalTo(2))); assertThat(folders, hasKey(new File("src/main/java").getAbsoluteFile())); assertThat(folders, hasKey(new File("src/test/java").getAbsoluteFile())); }
@Bean @ConditionalOnMissingBean public ClassPathFileSystemWatcher classPathFileSystemWatcher() { URL[] urls = Restarter.getInstance().getInitialUrls(); ClassPathFileSystemWatcher watcher = new ClassPathFileSystemWatcher( fileSystemWatcherFactory(), classPathRestartStrategy(), urls); watcher.setStopWatcherOnRestart(true); return watcher; }
@Bean public ClassPathFileSystemWatcher classPathFileSystemWatcher() { DefaultRestartInitializer restartInitializer = new DefaultRestartInitializer(); URL[] urls = restartInitializer.getInitialUrls(Thread.currentThread()); if (urls == null) { urls = new URL[0]; } return new ClassPathFileSystemWatcher(getFileSystemWatcherFactory(), classPathRestartStrategy(), urls); }
@Test public void restartWatchingClassPath() throws Exception { this.context = initializeAndRun(Config.class); ClassPathFileSystemWatcher watcher = this.context .getBean(ClassPathFileSystemWatcher.class); assertThat(watcher).isNotNull(); }
@Test public void restartDisabled() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("spring.devtools.restart.enabled", false); this.context = initializeAndRun(Config.class, properties); this.thrown.expect(NoSuchBeanDefinitionException.class); this.context.getBean(ClassPathFileSystemWatcher.class); }
@Test public void restartWithTriggerFile() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("spring.devtools.restart.trigger-file", "somefile.txt"); this.context = initializeAndRun(Config.class, properties); ClassPathFileSystemWatcher classPathWatcher = this.context .getBean(ClassPathFileSystemWatcher.class); Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher"); Object filter = ReflectionTestUtils.getField(watcher, "triggerFilter"); assertThat(filter).isInstanceOf(TriggerFileFilter.class); }
@Test public void restartWatchingClassPath() throws Exception { this.context = initializeAndRun(Config.class); ClassPathFileSystemWatcher watcher = this.context .getBean(ClassPathFileSystemWatcher.class); assertThat(watcher, notNullValue()); }
@Test public void restartWithTriggerFile() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("spring.devtools.restart.trigger-file", "somefile.txt"); this.context = initializeAndRun(Config.class, properties); ClassPathFileSystemWatcher classPathWatcher = this.context .getBean(ClassPathFileSystemWatcher.class); Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher"); Object filter = ReflectionTestUtils.getField(watcher, "triggerFilter"); assertThat(filter, instanceOf(TriggerFileFilter.class)); }
@Test public void remoteRestartDisabled() throws Exception { configure("spring.devtools.remote.restart.enabled:false"); this.thrown.expect(NoSuchBeanDefinitionException.class); this.context.getBean(ClassPathFileSystemWatcher.class); }