/** * Function called when an audio device is plugged or unplugged. * * @param event The property change event which may concern the audio device. */ public void propertyChange(PropertyChangeEvent event) { if (DeviceConfiguration.PROP_AUDIO_SYSTEM_DEVICES.equals(event.getPropertyName())) { NotificationService notificationService = getNotificationService(); if (notificationService != null) { // Registers only once to the popup message notification // handler. if (!isRegisteredToPopupMessageListener) { isRegisteredToPopupMessageListener = true; managePopupMessageListenerRegistration(true); } // Fires the popup notification. ResourceManagementService resources = NeomediaActivator.getResources(); Map<String, Object> extras = new HashMap<String, Object>(); extras.put(NotificationData.POPUP_MESSAGE_HANDLER_TAG_EXTRA, this); notificationService.fireNotification( DEVICE_CONFIGURATION_HAS_CHANGED, resources.getI18NString("impl.media.configform" + ".AUDIO_DEVICE_CONFIG_CHANGED"), resources.getI18NString( "impl.media.configform" + ".AUDIO_DEVICE_CONFIG_MANAGMENT_CLICK"), null, extras); } } }
@Override protected void onHandleIntent(Intent intent) { NotificationService notificationService = new NotificationService(); notificationService.setService(this, true); }
@Test public void hasProjectSubscribersForType() { setUpMocks(); PropertiesDao dao = mock(PropertiesDao.class); when(dbClient.propertiesDao()).thenReturn(dao); // no subscribers when(dao.hasProjectNotificationSubscribersForDispatchers( "PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))) .thenReturn(false); assertThat( service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))) .isFalse(); // has subscribers on one dispatcher (among the two) when(dao.hasProjectNotificationSubscribersForDispatchers( "PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))) .thenReturn(true); assertThat( service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))) .isTrue(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { short time = Schedule.today(this).nextTimeIndex(); switch (item.getItemId()) { case R.id.menu_location_calculation: new CalculationSettingsDialog(this).show(); break; case R.id.menu_previous: time--; if (time < CONSTANT.FAJR) { time = CONSTANT.ISHAA; } if (CONSTANT.SUNRISE == time && mPreferences.dontNotifySunrise()) { time = CONSTANT.FAJR; } NotificationService.notify( this, time, Schedule.today(this).getTimes()[time].getTimeInMillis()); break; case R.id.menu_next: if (CONSTANT.SUNRISE == time && mPreferences.dontNotifySunrise()) { time = CONSTANT.DHUHR; } NotificationService.notify( this, time, Schedule.today(this).getTimes()[time].getTimeInMillis()); break; case R.id.menu_stop: NotificationService.cancelAll(this); break; case R.id.menu_settings: startActivity(new Intent(this, SettingsActivity.class)); break; } return super.onOptionsItemSelected(item); }
/** * Idempotent operation that would use the notificationService to notifyCustomerSupport about * non-verified users OR would send out a welcome email if the user is verified * * @param userVerificationStatus */ @Task(version = 1, timeout = 1000l, retries = 2) public void checkVerificationStatus(UserVerificationStatus userVerificationStatus) { if (userVerificationStatus.isVerifiedUser()) { notificationService.sendWelcomeEmail(userVerificationStatus.getUserId()); } else { notificationService.notifyCustomerSupport(userVerificationStatus.getUserId()); } }
/** * Given: Nobody wants to receive notifications. * * <p>When: Freddy adds comment to review created by Evgeny and assigned to Simon. * * <p>Then: No notifications. */ @Test public void scenario4() { setUpMocks(); service.start(); service.stop(); verify(emailChannel, never()).deliver(any(Notification.class), anyString()); verify(gtalkChannel, never()).deliver(any(Notification.class), anyString()); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { // Reinitialize service on reboot NotificationService.actionReschedule(context); } else { NotificationService.actionUpdate(context, intent.getLongExtra("checkId", -1)); } }
@Test public void shouldNotAddNullAsUser() { setUpMocks(); doAnswer(addUser(null, gtalkChannel)) .when(commentOnIssueCreatedByMe) .dispatch(same(notification), any(NotificationDispatcher.Context.class)); service.start(); service.stop(); verify(emailChannel, never()).deliver(any(Notification.class), anyString()); verify(gtalkChannel, never()).deliver(any(Notification.class), anyString()); }
/** * Given: Simon wants to receive notifications by Email and GTLak on comments for reviews assigned * to him. * * <p>When: Freddy adds comment to review created by Evgeny and assigned to Simon. * * <p>Then: Two notifications should be delivered to Simon - one by Email and another by GTalk. */ @Test public void scenario3() { setUpMocks(); doAnswer(addUser(ASSIGNEE_SIMON, new NotificationChannel[] {emailChannel, gtalkChannel})) .when(commentOnIssueAssignedToMe) .dispatch(same(notification), any(NotificationDispatcher.Context.class)); service.start(); verify(emailChannel, timeout(2000)).deliver(notification, ASSIGNEE_SIMON); verify(gtalkChannel, timeout(2000)).deliver(notification, ASSIGNEE_SIMON); service.stop(); verify(emailChannel, never()).deliver(notification, CREATOR_EVGENY); verify(gtalkChannel, never()).deliver(notification, CREATOR_EVGENY); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationService.resetNotificationInfo(); setContentView(R.layout.activity_course_detail); getActionBar().setHomeButtonEnabled(true); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = this.getIntent(); String title = intent.getStringExtra("title"); int semester = intent.getIntExtra("semester", 0); if (title != null) { setTitle(title); } else { setTitle("Unknown Course"); } adb = new AssignmentsDatabase(this); List<Item> asgs = adb.getAllWithSemesterAndCourse(semester, title); listContent.addAll(asgs); adapter = new AssignmentAdapter(this, R.layout.course_item_row, listContent); setListAdapter(adapter); getListView().setOnItemClickListener(listener); }
@Test public void getDispatchers_empty() { Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L); service = new NotificationService(settings, manager, dbClient); assertThat(service.getDispatchers()).hasSize(0); }
@Test public void getDispatchers() { setUpMocks(); assertThat(service.getDispatchers()) .containsOnly(commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange); }
@Override public void onDestroy() { // releaseWakeLockForService(this.wakeLock); setShouldBootWithSystem(false); NotificationService.removeDataServiceRunningNotification(); }
/** * Upload files to pre-configured url. * * @param uploadLocation the location we are uploading to. * @param fileName the filename we use for the resulting filename we upload. * @param params the optional parameter names. * @param values the optional parameter values. */ static void uploadLogs(String uploadLocation, String fileName, String[] params, String[] values) { try { File tempDir = LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory(); File newDest = new File(tempDir, fileName); File optionalFile = null; // if we have some description params // save them to file and add it to archive if (params != null) { optionalFile = new File( LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory(), "description.txt"); OutputStream out = new FileOutputStream(optionalFile); for (int i = 0; i < params.length; i++) { out.write((params[i] + " : " + values[i] + "\r\n").getBytes("UTF-8")); } out.flush(); out.close(); } newDest = LogsCollector.collectLogs(newDest, optionalFile); // don't leave any unneeded information if (optionalFile != null) optionalFile.delete(); if (uploadLocation == null) return; if (HttpUtils.postFile(uploadLocation, "logs", newDest) != null) { NotificationService notificationService = LoggingUtilsActivator.getNotificationService(); if (notificationService != null) { ResourceManagementService resources = LoggingUtilsActivator.getResourceService(); String bodyMsgKey = "plugin.loggingutils.ARCHIVE_MESSAGE_OK"; notificationService.fireNotification( LOGFILES_ARCHIVED, resources.getI18NString("plugin.loggingutils.ARCHIVE_BUTTON"), resources.getI18NString(bodyMsgKey, new String[] {uploadLocation}), null); } } } catch (Throwable e) { logger.error("Cannot upload file", e); } }
@Test public void shouldLogEvery10Minutes() { setUpMocks(); // Emulate 2 notifications in DB when(manager.getFromQueue()).thenReturn(notification).thenReturn(notification).thenReturn(null); when(manager.count()).thenReturn(1L).thenReturn(0L); service = spy(service); // Emulate processing of each notification take 10 min to have a log each time when(service.now()) .thenReturn(0L) .thenReturn(10 * 60 * 1000 + 1L) .thenReturn(20 * 60 * 1000 + 2L); service.start(); verify(service, timeout(200)).log(1, 1, 10); verify(service, timeout(200)).log(2, 0, 20); service.stop(); }
@Test(expected = NotificationException.class) public void testRejectRequest() throws SystemException, PortalException, NotificationException { // Given Mockito.doThrow(new SystemException()).when(socialRelationService).rejectRequest(anyLong()); // When notificationService.rejectRequest(23353L); }
/** Test the sending of a notification. */ @Test public void testSend() { final Map<String, String> parameters = new HashMap<String, String>(); final Notification notification = new Notification(DummyNotificationAdaptor.TEST_TYPE, parameters); service.send(notification); final List<Notification> sentNotifications = adaptor.getNotifications(); Assert.assertTrue(sentNotifications.contains(notification)); }
/** * Asks user for a location to save logs by poping up a file chooser. and archiving logs and * saving them on the specified location. */ private void collectLogs() { ResourceManagementService resources = LoggingUtilsActivator.getResourceService(); SipCommFileChooser fileChooser = GenericFileDialog.create( null, resources.getI18NString("plugin.loggingutils.ARCHIVE_FILECHOOSE_TITLE"), SipCommFileChooser.SAVE_FILE_OPERATION); fileChooser.setSelectionMode(SipCommFileChooser.SAVE_FILE_OPERATION); String defaultDir = ""; try { defaultDir = LoggingUtilsActivator.getFileAccessService() .getDefaultDownloadDirectory() .getAbsolutePath() + File.separator; } catch (IOException ex) { } fileChooser.setStartPath(defaultDir + LogsCollector.getDefaultFileName()); File dest = fileChooser.getFileFromDialog(); if (dest == null) return; dest = LogsCollector.collectLogs(dest, null); NotificationService notificationService = LoggingUtilsActivator.getNotificationService(); if (notificationService != null) { String bodyMsgKey = (dest == null) ? "plugin.loggingutils.ARCHIVE_MESSAGE_NOTOK" : "plugin.loggingutils.ARCHIVE_MESSAGE_OK"; notificationService.fireNotification( LOGFILES_ARCHIVED, resources.getI18NString("plugin.loggingutils.ARCHIVE_BUTTON"), resources.getI18NString(bodyMsgKey, new String[] {dest.getAbsolutePath()}), null); } }
// SONAR-4548 @Test public void shouldNotStopWhenException() { setUpMocks(); when(manager.getFromQueue()) .thenThrow(new RuntimeException("Unexpected exception")) .thenReturn(notification) .thenReturn(null); doAnswer(addUser(ASSIGNEE_SIMON, emailChannel)) .when(commentOnIssueAssignedToMe) .dispatch(same(notification), any(NotificationDispatcher.Context.class)); doAnswer(addUser(CREATOR_SIMON, emailChannel)) .when(commentOnIssueCreatedByMe) .dispatch(same(notification), any(NotificationDispatcher.Context.class)); service.start(); verify(emailChannel, timeout(2000)).deliver(notification, ASSIGNEE_SIMON); service.stop(); verify(gtalkChannel, never()).deliver(notification, ASSIGNEE_SIMON); }
@Test public void testGetBopsId() { // Given when(usdIssuesService.getBopsId(anyString())).thenReturn("asdf"); // When String id = notificationService.getBopsId("ewiljfaölj"); // Then assertEquals("asdf", id); }
public void createAnswer(SocialUser loginUser, Long questionId, Answer answer) { Question question = questionRepository.findOne(questionId); answer.writedBy(loginUser); answer.answerTo(question); Answer savedAnswer = answerRepository.saveAndFlush(answer); notificationService.notifyToFacebook( loginUser, question, question.findNotificationUser(loginUser)); if (answer.isConnected()) { log.info("firing sendAnswerMessageToFacebook!"); facebookService.sendToAnswerMessage(loginUser, savedAnswer.getAnswerId()); } }
@Test public void shouldPeriodicallyProcessQueue() throws Exception { NotificationQueueElement queueElement = mock(NotificationQueueElement.class); Notification notification = mock(Notification.class); when(queueElement.getNotification()).thenReturn(notification); when(manager.getFromQueue()) .thenReturn(queueElement) .thenReturn(null) .thenReturn(queueElement) .thenReturn(null) .thenReturn(queueElement) .thenReturn(null); doNothing().when(service).deliver(any(Notification.class)); service.start(); Thread.sleep(1500); // sleep 1.5 second to process queue service.stop(); verify(service, times(3)) .deliver(notification); // 3 times - 1 on start, 1 after delay, 1 on stop }
@Override public void onReceive(Context context, Intent intent) { int operationId = intent.getIntExtra(Constants.OPERATION_ID, DEFAULT_VALUE); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "NotificationId: " + operationId); } NotificationService.getInstance(context.getApplicationContext()) .updateNotification(operationId); // updating notification state to DISMISSED NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(operationId); }
@Test public void testGetUsdIssues() { // Given Issue issue = new Issue(); when(usdIssuesService.getUsdIssues(anyString(), anyBoolean())).thenReturn(Arrays.asList(issue)); // When List<Issue> issues = notificationService.getUsdIssues("anyScreenName"); // Then assertEquals(1, issues.size()); }
/** * Given: Nobody wants to receive notifications. * * <p>When: Freddy adds comment to review created by Evgeny and assigned to Simon. * * <p>Then: No notifications. */ @Test public void scenario4() { Notification notification = mock(Notification.class); creator = USER_EVGENY; assignee = USER_SIMON; service.deliver(notification); verify(emailChannel, atLeast(1)).getKey(); verify(gtalkChannel, atLeast(1)).getKey(); verifyNoMoreInteractions(emailChannel); verifyNoMoreInteractions(gtalkChannel); }
@Test public void testGetUsdIssuesCount() throws Exception { // Given Issue issue = new Issue(); when(usdIssuesService.getUsdIssues(anyString(), anyBoolean())).thenReturn(Arrays.asList(issue)); // When Future<CountResult> issues = notificationService.getUsdIssuesCount("anyScreenName"); // Then assertEquals(1, (int) issues.get().getCount()); }
@Test public void testGetCount() throws Exception { User user = mock(User.class); when(user.getScreenName()).thenReturn("anyScreenName"); for (String s : NotificationServiceName.allNamesAsList()) { notificationService.getCount(s, user); } // No exception is good, meaning that no exception related to reflection occured. }
@Test public void testGetInvoices() { // Given InvoiceNotification invoiceNotification = new InvoiceNotification(); when(raindanceInvoiceService.getInvoices(anyString(), anyBoolean())) .thenReturn(Arrays.asList(invoiceNotification)); // When List<InvoiceNotification> invoiceNotifications = notificationService.getInvoices("asldkfj"); // Then assertEquals(1, invoiceNotifications.size()); }
@Test public void testGetEmailCount() throws Exception { // Given when(notesEmailCounterService.getCount(anyString())).thenReturn(1); User user = mock(User.class); when(user.getScreenName()).thenReturn("anyScreenName"); // When Future<CountResult> count = notificationService.getEmailCount(user); // Then assertEquals(1, (int) count.get().getCount()); }
@Test public void testGetMedControlCases() { // Given DeviationCase deviationCase = new DeviationCase(); when(medControlService.listDeviationCases(anyString(), anyBoolean())) .thenReturn(Arrays.asList(deviationCase)); // When User user = mock(User.class); List<DeviationCase> medControlCases = notificationService.getMedControlCases(user); // Then assertEquals(1, medControlCases.size()); }