Search in sources :

Example 86 with Notification

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"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 87 with Notification

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);
}
Also used : ReportAnalysisFailureNotificationBuilder(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder) ComponentDto(org.sonar.db.component.ComponentDto) Notification(org.sonar.api.notifications.Notification) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification) Test(org.junit.Test)

Example 88 with Notification

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);
}
Also used : Notification(org.sonar.api.notifications.Notification) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification) Test(org.junit.Test)

Example 89 with Notification

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntStream(java.util.stream.IntStream) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Notification(org.sonar.api.notifications.Notification) Objects.requireNonNull(java.util.Objects.requireNonNull) Long.parseLong(java.lang.Long.parseLong) Integer.parseInt(java.lang.Integer.parseInt) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState)

Example 90 with Notification

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));
}
Also used : ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) Languages(org.sonar.api.resources.Languages) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Aggregations

Notification (org.sonar.api.notifications.Notification)90 Test (org.junit.Test)83 EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)14 EmailMessage (org.sonar.server.issue.notification.EmailMessage)13 NotificationChannel (org.sonar.api.notifications.NotificationChannel)12 List (java.util.List)7 IntStream (java.util.stream.IntStream)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 ReportAnalysisFailureNotification (org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)5 Tuple (org.assertj.core.groups.Tuple)4 Languages (org.sonar.api.resources.Languages)4 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)4 Collections (java.util.Collections)3 Random (java.util.Random)3 Before (org.junit.Before)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)3 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)3