use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class QualityGateEventsStep method notifyUsers.
/**
* @param label "Red (was Orange)"
* @param rawStatus OK, WARN or ERROR + optional text
*/
private void notifyUsers(Component project, String label, QualityGateStatus rawStatus, boolean isNewAlert) {
Notification notification = new Notification("alerts").setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label)).setFieldValue("projectName", project.getName()).setFieldValue("projectKey", project.getKey()).setFieldValue("projectUuid", project.getUuid()).setFieldValue("alertName", label).setFieldValue("alertText", rawStatus.getText()).setFieldValue("alertLevel", rawStatus.getStatus().toString()).setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
notificationService.deliver(notification);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class QualityGateEventsStepTest method verify_event_created_if_no_base_ALERT_STATUS_measure.
private void verify_event_created_if_no_base_ALERT_STATUS_measure(Measure.Level rawAlterStatus, String expectedLabel) {
QualityGateStatus someQGStatus = new QualityGateStatus(rawAlterStatus, ALERT_TEXT);
when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(someQGStatus).createNoValue()));
when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().createNoValue()));
underTest.execute();
verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric);
verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric);
verify(eventRepository).add(eq(PROJECT_COMPONENT), eventArgumentCaptor.capture());
verifyNoMoreInteractions(measureRepository, eventRepository);
Event event = eventArgumentCaptor.getValue();
assertThat(event.getCategory()).isEqualTo(Event.Category.ALERT);
assertThat(event.getName()).isEqualTo(expectedLabel);
assertThat(event.getDescription()).isEqualTo(ALERT_TEXT);
assertThat(event.getData()).isNull();
verify(notificationService).deliver(notificationArgumentCaptor.capture());
Notification notification = notificationArgumentCaptor.getValue();
assertThat(notification.getType()).isEqualTo("alerts");
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name());
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class QualityGateEventsStepTest method verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed.
private void verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(Measure.Level previousAlertStatus, QualityGateStatus newQualityGateStatus, String expectedLabel) {
when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(newQualityGateStatus).createNoValue()));
when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(previousAlertStatus)).createNoValue()));
underTest.execute();
verify(measureRepository).getRawMeasure(PROJECT_COMPONENT, alertStatusMetric);
verify(measureRepository).getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric);
verify(eventRepository).add(eq(PROJECT_COMPONENT), eventArgumentCaptor.capture());
verifyNoMoreInteractions(measureRepository, eventRepository);
Event event = eventArgumentCaptor.getValue();
assertThat(event.getCategory()).isEqualTo(Event.Category.ALERT);
assertThat(event.getName()).isEqualTo(expectedLabel);
assertThat(event.getDescription()).isEqualTo(ALERT_TEXT);
assertThat(event.getData()).isNull();
verify(notificationService).deliver(notificationArgumentCaptor.capture());
Notification notification = notificationArgumentCaptor.getValue();
assertThat(notification.getType()).isEqualTo("alerts");
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name());
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
reset(measureRepository, eventRepository, notificationService);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class DoNotFixNotificationDispatcherTest method ignore_other_resolutions.
/**
* Only false positive and won't fix resolutions
*/
@Test
public void ignore_other_resolutions() {
Multimap<String, NotificationChannel> recipients = HashMultimap.create();
recipients.put("simon", emailChannel);
recipients.put("freddy", twitterChannel);
when(notifications.findNotificationSubscribers(underTest, "struts")).thenReturn(recipients);
Notification fixedNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts").setFieldValue("changeAuthor", "godin").setFieldValue("new.resolution", Issue.RESOLUTION_FIXED).setFieldValue("assignee", "freddy");
underTest.performDispatch(fixedNotif, context);
verifyZeroInteractions(context);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class DoNotFixNotificationDispatcherTest method should_dispatch_to_subscribers.
@Test
public void should_dispatch_to_subscribers() {
Multimap<String, NotificationChannel> recipients = HashMultimap.create();
recipients.put("simon", emailChannel);
recipients.put("freddy", twitterChannel);
recipients.put("godin", twitterChannel);
when(notifications.findNotificationSubscribers(underTest, "struts")).thenReturn(recipients);
Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts").setFieldValue("changeAuthor", "godin").setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE).setFieldValue("assignee", "freddy");
underTest.performDispatch(fpNotif, context);
verify(context).addUser("simon", emailChannel);
verify(context).addUser("freddy", twitterChannel);
// do not notify the person who flagged the issue as false-positive
verify(context, never()).addUser("godin", twitterChannel);
verifyNoMoreInteractions(context);
}
Aggregations