use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListener method onEnd.
@Override
public void onEnd(CeTask ceTask, CeActivityDto.Status status, Duration duration, @Nullable CeTaskResult taskResult, @Nullable Throwable error) {
if (status == CeActivityDto.Status.SUCCESS) {
return;
}
String projectUuid = ceTask.getComponent().map(CeTask.Component::getUuid).orElse(null);
if (!CeTaskTypes.REPORT.equals(ceTask.getType()) || projectUuid == null) {
return;
}
if (notificationService.hasProjectSubscribersForTypes(projectUuid, singleton(ReportAnalysisFailureNotification.class))) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto projectDto = dbClient.componentDao().selectOrFailByUuid(dbSession, projectUuid);
checkScopeAndQualifier(projectDto);
CeActivityDto ceActivityDto = dbClient.ceActivityDao().selectByUuid(dbSession, ceTask.getUuid()).orElseThrow(() -> new RowNotFoundException(format("CeActivity with uuid '%s' not found", ceTask.getUuid())));
ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, error);
ReportAnalysisFailureNotification notification = taskFailureNotificationSerializer.toNotification(taskFailureNotification);
notificationService.deliverEmails(singleton(notification));
// compatibility with old API
notificationService.deliver(notification);
}
}
}
use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_creates_notification_with_null_error_message_if_Throwable_is_null.
@Test
public void onEnd_creates_notification_with_null_error_message_if_Throwable_is_null() {
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));
ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
ReportAnalysisFailureNotificationBuilder reportAnalysisFailureNotificationBuilder = notificationCaptor.getValue();
assertThat(reportAnalysisFailureNotificationBuilder.getErrorMessage()).isNull();
}
use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_creates_notification_with_error_message_from_Throwable_argument_message.
@Test
public void onEnd_creates_notification_with_error_message_from_Throwable_argument_message() {
initMocksToPassConditions(randomAlphanumeric(12), random.nextInt(999_999), (long) random.nextInt(999_999));
String message = randomAlphanumeric(66);
when(throwableMock.getMessage()).thenReturn(message);
underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, throwableMock);
ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
ReportAnalysisFailureNotificationBuilder reportAnalysisFailureNotificationBuilder = notificationCaptor.getValue();
assertThat(reportAnalysisFailureNotificationBuilder.getErrorMessage()).isEqualTo(message);
}
use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_uses_system_data_as_failedAt_if_task_has_no_executedAt.
@Test
public void onEnd_uses_system_data_as_failedAt_if_task_has_no_executedAt() {
String taskUuid = randomAlphanumeric(12);
initMocksToPassConditions(taskUuid, random.nextInt(999_999), null);
long now = random.nextInt(999_999);
when(system2.now()).thenReturn(now);
Notification notificationMock = mockSerializer();
underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, null);
verify(notificationService).deliver(same(notificationMock));
ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
assertThat(notificationCaptor.getValue().getTask().getFailedAt()).isEqualTo(now);
}
use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder 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);
}
Aggregations