@Override public void start(Saito saito, List<? extends SaitoFile> sources) { log.info("Starting Livereload"); isEnabled = cfg.isLiveReloadEnabled(); if (isEnabled) { try { liveReloadServer = new LiveReloadServer(); liveReloadServer.start(); } catch (IOException e) { log.error("Problem starting LiveReload", e); } } }
@Bean @RestartScope @ConditionalOnMissingBean public LiveReloadServer liveReloadServer() { return new LiveReloadServer(this.properties.getLivereload().getPort(), Restarter.getInstance().getThreadFactory()); }
@Test public void liveReloadTriggeredOnContextRefresh() throws Exception { this.context = initializeAndRun(ConfigWithMockLiveReload.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); this.context.publishEvent(new ContextRefreshedEvent(this.context)); verify(server).triggerReload(); }
@Test public void liveReloadTriggeredOnClassPathChangeWithoutRestart() throws Exception { this.context = initializeAndRun(ConfigWithMockLiveReload.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(), false); this.context.publishEvent(event); verify(server).triggerReload(); }
@Test public void liveReloadNotTriggeredOnClassPathChangeWithRestart() throws Exception { this.context = initializeAndRun(ConfigWithMockLiveReload.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(), true); this.context.publishEvent(event); verify(server, never()).triggerReload(); }
@Test public void serverWontStart() throws Exception { LiveReloadServer delegate = mock(LiveReloadServer.class); OptionalLiveReloadServer server = new OptionalLiveReloadServer(delegate); willThrow(new RuntimeException("Error")).given(delegate).start(); server.startServer(); server.triggerReload(); verify(delegate, never()).triggerReload(); }
@Test public void liveReloadOnClassPathChanged() throws Exception { configure(); Set<ChangedFiles> changeSet = new HashSet<ChangedFiles>(); ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false); this.context.publishEvent(event); LiveReloadConfiguration configuration = this.context .getBean(LiveReloadConfiguration.class); configuration.getExecutor().shutdown(); configuration.getExecutor().awaitTermination(2, TimeUnit.SECONDS); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); verify(server).triggerReload(); }
@Test public void liveReloadTriggerdOnClassPathChangeWithoutRestart() throws Exception { this.context = initializeAndRun(ConfigWithMockLiveReload.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(), false); this.context.publishEvent(event); verify(server).triggerReload(); }
@Test public void liveReloadNotTriggerdOnClassPathChangeWithRestart() throws Exception { this.context = initializeAndRun(ConfigWithMockLiveReload.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.<ChangedFiles>emptySet(), true); this.context.publishEvent(event); verify(server, never()).triggerReload(); }
@Test public void liveReloadServer() throws Exception { this.context = initializeAndRun(Config.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); assertThat(server.isStarted()).isTrue(); }
@Bean public LiveReloadServer liveReloadServer() { return mock(LiveReloadServer.class); }
@Test public void liveReloadServer() throws Exception { this.context = initializeAndRun(Config.class); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); assertThat(server.isStarted(), equalTo(true)); }
/** * Create a new {@link OptionalLiveReloadServer} instance. * @param server the server to manage or {@code null} */ public OptionalLiveReloadServer(LiveReloadServer server) { this.server = server; }