SystemUpdatesCheckTask { @Scheduled(fixedDelay = FREQUENCY, initialDelay = 60000) public void checkForUpdates() { if (!updatesCheckEnabled.get()) { logger.debug("Updates check disabled by configuration"); return; } try { final UpdatesInfoContext context = new UpdatesInfoContext() { @Override public String getCurrentVersion() { return currentVersion; } }; logger.debug("Checking for system updates, current version: {}", context.getCurrentVersion()); final VersionInfo latestStableVersion = updatesProvider.getLatestStableVersion(context); if (latestStableVersion.compareTo(new VersionInfo(context.getCurrentVersion())) > 0) { logger.debug("System update available: {}", latestStableVersion); final VelocityContext vcontext = new VelocityContext(); vcontext.put("version", latestStableVersion); vcontext.put("context", context); final StringWriter titleWriter = new StringWriter(); velocityEngine.evaluate(vcontext, titleWriter, "TemplateName", new InputStreamReader( getClass().getResourceAsStream("/snippets/system/systemUpdatesNotificationTitle.html"), "UTF-8")); final StringWriter bodyWriter = new StringWriter(); velocityEngine.evaluate(vcontext, bodyWriter, "TemplateName", new InputStreamReader( getClass().getResourceAsStream("/snippets/system/systemUpdatesNotificationBody.html"), "UTF-8")); final Notification n = new Notification(); n.setId("/system/updateAvailable/" + latestStableVersion.getName()); n.setTitle(titleWriter.toString()); n.setMessage(bodyWriter.toString()); n.setLevel(Level.INFO); n.setType(Type.TOPIC); n.setExpirationDate(new Date(new Date().getTime() + FREQUENCY)); notificationProvider.store(n, false); } else { logger.debug("System is up to date, got latest stable version: {}", latestStableVersion); } } catch (final IOException e) { logger.info("Failed to check for system updates", e); } }  @PostConstruct void deleteNotificationForCurrentVersion(); @Scheduled(fixedDelay = FREQUENCY, initialDelay = 60000) void checkForUpdates(); static final String PROP_LOGSNIFFER_UPDATES_CHECK_ENABLED; }
@Test public void testUpdateCheck() throws IOException { Mockito.when(updProvider.getLatestStableVersion(Mockito.any(UpdatesInfoContext.class))) .thenReturn(new VersionInfo("1.2.3")); task.checkForUpdates(); Mockito.verify(notificationProvider).store(Mockito.argThat(new BaseMatcher<Notification>() { @Override public boolean matches(final Object arg0) { final Notification n = (Notification) arg0; return n.getTitle().length() > 0 && n.getType() == Type.TOPIC; } @Override public void describeTo(final Description arg0) { } }), Mockito.eq(false)); }
@Test public void testDisabledCheck() throws IOException { logsnifferProperties.put(SystemUpdatesCheckTask.PROP_LOGSNIFFER_UPDATES_CHECK_ENABLED, "false"); task.checkForUpdates(); Mockito.verifyZeroInteractions(notificationProvider); }