use of org.sonar.ce.task.projectanalysis.event.Event in project sonarqube by SonarSource.
the class PersistEventsStepTest method persist_alert_events_on_root.
@Test
public void persist_alert_events_on_root() {
when(system2.now()).thenReturn(NOW);
treeRootHolder.setRoot(ROOT);
Event alert = Event.createAlert("Failed", null, "Open issues > 0");
when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(alert));
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(2);
List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
assertThat(eventDtos).extracting(EventDto::getCategory).containsOnly(CATEGORY_ALERT, CATEGORY_VERSION);
EventDto eventDto = eventDtos.stream().filter(t -> CATEGORY_ALERT.equals(t.getCategory())).findAny().get();
assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
assertThat(eventDto.getName()).isEqualTo(alert.getName());
assertThat(eventDto.getDescription()).isEqualTo(alert.getDescription());
assertThat(eventDto.getCategory()).isEqualTo(CATEGORY_ALERT);
assertThat(eventDto.getData()).isNull();
assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
}
use of org.sonar.ce.task.projectanalysis.event.Event 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.ce.task.projectanalysis.event.Event 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);
}
use of org.sonar.ce.task.projectanalysis.event.Event in project sonarqube by SonarSource.
the class QualityProfileEventsStepTest method verify_detection_with_complex_mix_of_qps.
@Test
public void verify_detection_with_complex_mix_of_qps() {
final Set<Event> events = new HashSet<>();
doAnswer(invocationOnMock -> {
events.add((Event) invocationOnMock.getArguments()[1]);
return null;
}).when(eventRepository).add(eq(treeRootHolder.getRoot()), any(Event.class));
Date date = new Date();
QualityProfile qp1 = qp(QP_NAME_2, LANGUAGE_KEY_1, date);
QualityProfile qp2 = qp(QP_NAME_2, LANGUAGE_KEY_2, date);
QualityProfile qp3 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:13+0100"));
QualityProfile qp3_updated = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:17+0100"));
QualityProfile qp4 = qp(QP_NAME_2, LANGUAGE_KEY_3, date);
mockMeasures(treeRootHolder.getRoot(), arrayOf(qp1, qp2, qp3), arrayOf(qp3_updated, qp2, qp4));
mockNoLanguageInRepository();
qProfileStatusRepository.register(qp1.getQpKey(), REMOVED);
qProfileStatusRepository.register(qp2.getQpKey(), UNCHANGED);
qProfileStatusRepository.register(qp3.getQpKey(), UPDATED);
qProfileStatusRepository.register(qp4.getQpKey(), ADDED);
underTest.execute(new TestComputationStepContext());
assertThat(events).extracting("name").containsOnly("Stop using '" + QP_NAME_2 + "' (" + LANGUAGE_KEY_1 + ")", "Use '" + QP_NAME_2 + "' (" + LANGUAGE_KEY_3 + ")", "Changes in '" + QP_NAME_1 + "' (" + LANGUAGE_KEY_1 + ")");
}
use of org.sonar.ce.task.projectanalysis.event.Event in project sonarqube by SonarSource.
the class PersistEventsStepTest method persist_profile_events_on_root.
@Test
public void persist_profile_events_on_root() {
when(system2.now()).thenReturn(NOW);
treeRootHolder.setRoot(ROOT);
Event profile = Event.createProfile("foo", null, "bar");
when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(profile));
underTest.execute(new TestComputationStepContext());
assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(2);
List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
assertThat(eventDtos).extracting(EventDto::getCategory).containsOnly(CATEGORY_PROFILE, CATEGORY_VERSION);
EventDto eventDto = eventDtos.stream().filter(t -> CATEGORY_PROFILE.equals(t.getCategory())).findAny().get();
assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
assertThat(eventDto.getName()).isEqualTo(profile.getName());
assertThat(eventDto.getDescription()).isEqualTo(profile.getDescription());
assertThat(eventDto.getCategory()).isEqualTo(EventDto.CATEGORY_PROFILE);
assertThat(eventDto.getData()).isNull();
assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
}
Aggregations