use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class NewIssuesEmailTemplateTest method format_email_with_issue_on_branch_with_version.
@Test
public void format_email_with_issue_on_branch_with_version() {
Notification notification = newNotification(32).setFieldValue("branch", "feature1").setFieldValue("projectVersion", "42.1.1");
EmailMessage message = template.format(notification);
// TODO datetime to be completed when test is isolated from JVM timezone
assertThat(message.getMessage()).startsWith("Project: Struts\n" + "Branch: feature1\n" + "Version: 42.1.1\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-1");
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class DefaultAdminCredentialsVerifierNotificationTemplateTest method format_notification.
@Test
public void format_notification() {
Notification notification = new Notification(DefaultAdminCredentialsVerifierNotification.TYPE);
EmailMessage emailMessage = underTest.format(notification);
assertThat(emailMessage.getSubject()).isEqualTo("Default Administrator credentials are still used");
assertThat(emailMessage.getMessage()).isEqualTo("Hello,\n\n" + "Your SonarQube instance is still using default administrator credentials.\n" + "Make sure to change the password for the 'admin' account or deactivate this account.");
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class NotificationDaemon method processQueue.
private synchronized void processQueue() {
long start = now();
long lastLog = start;
long notifSentCount = 0;
Notification notifToSend = manager.getFromQueue();
while (notifToSend != null) {
notifSentCount += service.deliverEmails(singleton(notifToSend));
// compatibility with old API
notifSentCount += service.deliver(notifToSend);
if (stopping) {
break;
}
long now = now();
if (now - lastLog > delayBeforeReportingStatusInSeconds * 1000) {
long remainingNotifCount = manager.count();
lastLog = now;
long spentTimeInMinutes = (now - start) / (60 * 1000);
log(notifSentCount, remainingNotifCount, spentTimeInMinutes);
}
notifToSend = manager.getFromQueue();
}
}
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(new TestComputationStepContext());
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("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
assertThat(notification.getFieldValue("branch")).isNull();
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 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(new TestComputationStepContext());
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();
ArgumentCaptor<Collection> collectionCaptor = ArgumentCaptor.forClass(Collection.class);
verify(notificationService).deliverEmails(collectionCaptor.capture());
verify(notificationService).deliver(notificationArgumentCaptor.capture());
Notification notification = notificationArgumentCaptor.getValue();
assertThat(collectionCaptor.getValue()).hasSize(1);
assertThat(collectionCaptor.getValue().iterator().next()).isSameAs(notification);
assertThat(notification).isInstanceOf(QGChangeNotification.class);
assertThat(notification.getType()).isEqualTo("alerts");
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
assertThat(notification.getFieldValue("branch")).isNull();
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name());
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
}
Aggregations