.setFieldValue("alertText", rawStatus.getText())
.setFieldValue("alertLevel", rawStatus.getStatus().toString())
.setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
- analysisMetadataHolder.getBranch().ifPresent(branch -> notification.setFieldValue("branch", branch.getName()));
+ analysisMetadataHolder.getBranch().filter(b -> !b.isMain())
+ .ifPresent(branch -> notification.setFieldValue("branch", branch.getName()));
notificationService.deliver(notification);
}
}
@Test
- public void verify_branch_name_is_set_in_notification() {
+ public void verify_branch_name_is_set_in_notification_when_not_main() {
String branchName = "feature1";
- analysisMetadataHolder.setBranch(new DefaultBranchImpl(branchName));
+ analysisMetadataHolder.setBranch(new DefaultBranchImpl(branchName) {
+ @Override
+ public boolean isMain() {
+ return false;
+ }
+ });
when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
reset(measureRepository, eventRepository, notificationService);
}
+ @Test
+ public void verify_branch_name_is_not_set_in_notification_when_main() {
+ analysisMetadataHolder.setBranch(new DefaultBranchImpl());
+
+ when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
+ when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
+ of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue()));
+
+ underTest.execute();
+
+ verify(notificationService).deliver(notificationArgumentCaptor.capture());
+ Notification notification = notificationArgumentCaptor.getValue();
+ assertThat(notification.getType()).isEqualTo("alerts");
+ assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+ assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
+ assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+ assertThat(notification.getFieldValue("branch")).isEqualTo(null);
+
+ reset(measureRepository, eventRepository, notificationService);
+ }
+
}