use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class QGChangeEmailTemplateTest method shouldFormatBackToGreenMessageOnBranch.
@Test
public void shouldFormatBackToGreenMessageOnBranch() {
Notification notification = createNotification("Passed", "", "OK", "false").setFieldValue("branch", "feature");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getSubject(), is("\"Foo (feature)\" is back to green"));
assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Branch: feature\n" + "Version: V1-SNAP\n" + "Quality gate status: Passed\n" + "\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature"));
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_creates_notification_with_data_from_activity_and_project_and_deliver_it.
@Test
public void onEnd_creates_notification_with_data_from_activity_and_project_and_deliver_it() {
String taskUuid = randomAlphanumeric(12);
int createdAt = random.nextInt(999_999);
long executedAt = random.nextInt(999_999);
ComponentDto project = initMocksToPassConditions(taskUuid, createdAt, executedAt);
Notification notificationMock = mockSerializer();
underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, throwableMock);
ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
verify(notificationService).deliver(same(notificationMock));
ReportAnalysisFailureNotificationBuilder reportAnalysisFailureNotificationBuilder = notificationCaptor.getValue();
ReportAnalysisFailureNotificationBuilder.Project notificationProject = reportAnalysisFailureNotificationBuilder.getProject();
assertThat(notificationProject.getName()).isEqualTo(project.name());
assertThat(notificationProject.getKey()).isEqualTo(project.getKey());
assertThat(notificationProject.getUuid()).isEqualTo(project.uuid());
assertThat(notificationProject.getBranchName()).isEqualTo(project.getBranch());
ReportAnalysisFailureNotificationBuilder.Task notificationTask = reportAnalysisFailureNotificationBuilder.getTask();
assertThat(notificationTask.getUuid()).isEqualTo(taskUuid);
assertThat(notificationTask.getCreatedAt()).isEqualTo(createdAt);
assertThat(notificationTask.getFailedAt()).isEqualTo(executedAt);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_ignores_CeTaskResult_argument.
@Test
public void onEnd_ignores_CeTaskResult_argument() {
String taskUuid = randomAlphanumeric(12);
initMocksToPassConditions(taskUuid, random.nextInt(999_999), (long) random.nextInt(999_999));
Notification notificationMock = mockSerializer();
underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, null);
verify(notificationService).deliver(same(notificationMock));
verifyZeroInteractions(ceTaskResultMock);
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class BuiltInQPChangeNotificationBuilder method parse.
public static BuiltInQPChangeNotificationBuilder parse(Notification notification) {
checkState(BuiltInQPChangeNotification.TYPE.equals(notification.getType()), "Expected notification of type %s but got %s", BuiltInQPChangeNotification.TYPE, notification.getType());
BuiltInQPChangeNotificationBuilder notif = new BuiltInQPChangeNotificationBuilder();
String numberOfProfilesText = notification.getFieldValue(NUMBER_OF_PROFILES);
checkState(numberOfProfilesText != null, "Could not read the built-in quality profile notification");
Integer numberOfProfiles = Integer.valueOf(numberOfProfilesText);
IntStream.rangeClosed(0, numberOfProfiles - 1).mapToObj(index -> Profile.newBuilder().setProfileName(getNonNullFieldValue(notification, index + PROFILE_NAME)).setLanguageKey(getNonNullFieldValue(notification, index + LANGUAGE_KEY)).setLanguageName(getNonNullFieldValue(notification, index + LANGUAGE_NAME)).setNewRules(parseInt(getNonNullFieldValue(notification, index + NEW_RULES))).setUpdatedRules(parseInt(getNonNullFieldValue(notification, index + UPDATED_RULES))).setRemovedRules(parseInt(getNonNullFieldValue(notification, index + REMOVED_RULES))).setStartDate(parseLong(getNonNullFieldValue(notification, index + START_DATE))).setEndDate(parseLong(getNonNullFieldValue(notification, index + END_DATE))).build()).forEach(notif::addProfile);
return notif;
}
use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.
the class BuiltInQualityProfilesUpdateListenerTest method add_start_and_end_dates_to_notification.
@Test
public void add_start_and_end_dates_to_notification() {
enableNotificationInGlobalSettings();
Multimap<QProfileName, ActiveRuleChange> profiles = ArrayListMultimap.create();
Languages languages = new Languages();
addProfile(profiles, languages, ACTIVATED);
long startDate = 10_000_000_000L;
long endDate = 15_000_000_000L;
BuiltInQualityProfilesUpdateListener underTest = new BuiltInQualityProfilesUpdateListener(notificationManager, languages, settings.asConfig());
underTest.onChange(profiles, startDate, endDate);
ArgumentCaptor<Notification> notificationArgumentCaptor = ArgumentCaptor.forClass(Notification.class);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
verifyNoMoreInteractions(notificationManager);
assertThat(BuiltInQPChangeNotificationBuilder.parse(notificationArgumentCaptor.getValue()).getProfiles()).extracting(Profile::getStartDate, Profile::getEndDate).containsExactlyInAnyOrder(tuple(startDate, endDate));
}
Aggregations