diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-03-10 16:51:20 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-03-10 16:51:26 +0100 |
commit | 83fff8bce48fa6e2ad5b23117995ff1645890651 (patch) | |
tree | d7fe246169f731a92b995b1a9945b99891ec0f4a /plugins/sonar-core-plugin/src | |
parent | a79bee53e7309fece4a5e4952e11ee74e1d45f96 (diff) | |
download | sonarqube-83fff8bce48fa6e2ad5b23117995ff1645890651.tar.gz sonarqube-83fff8bce48fa6e2ad5b23117995ff1645890651.zip |
SONAR-5094 Trigger alert notifications when a quality gate is used
Diffstat (limited to 'plugins/sonar-core-plugin/src')
2 files changed, 16 insertions, 3 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java index 73b79c58c3d..68a723bbe85 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java @@ -30,23 +30,27 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; +import org.sonar.batch.qualitygate.QualityGate; import java.util.List; public class GenerateAlertEvents implements Decorator { private final RulesProfile profile; + private final QualityGate qualityGate; private final TimeMachine timeMachine; private NotificationManager notificationManager; - public GenerateAlertEvents(RulesProfile profile, TimeMachine timeMachine, NotificationManager notificationManager) { + public GenerateAlertEvents(RulesProfile profile, QualityGate qualityGate, TimeMachine timeMachine, NotificationManager notificationManager) { this.profile = profile; + this.qualityGate = qualityGate; this.timeMachine = timeMachine; this.notificationManager = notificationManager; } public boolean shouldExecuteOnProject(Project project) { - return profile != null && profile.getAlerts() != null && !profile.getAlerts().isEmpty(); + return profile != null && profile.getAlerts() != null && !profile.getAlerts().isEmpty() + || qualityGate.isEnabled(); } @DependsUpon diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java index 07cd31d1642..e7e06f0e2ce 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java @@ -35,6 +35,7 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.test.ProjectTestBuilder; +import org.sonar.batch.qualitygate.QualityGate; import java.util.Arrays; import java.util.Date; @@ -50,6 +51,7 @@ public class GenerateAlertEventsTest { private GenerateAlertEvents decorator; private DecoratorContext context; private RulesProfile profile; + private QualityGate qualityGate; private TimeMachine timeMachine; private NotificationManager notificationManager; private Project project; @@ -59,8 +61,9 @@ public class GenerateAlertEventsTest { context = mock(DecoratorContext.class); timeMachine = mock(TimeMachine.class); profile = mock(RulesProfile.class); + qualityGate = mock(QualityGate.class); notificationManager = mock(NotificationManager.class); - decorator = new GenerateAlertEvents(profile, timeMachine, notificationManager); + decorator = new GenerateAlertEvents(profile, qualityGate, timeMachine, notificationManager); project = new ProjectTestBuilder().build(); } @@ -75,6 +78,12 @@ public class GenerateAlertEventsTest { } @Test + public void shouldDecorateIfQualityGateEnabled() { + when(qualityGate.isEnabled()).thenReturn(true); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + } + + @Test public void shouldDecorateIfThresholds() { when(profile.getAlerts()).thenReturn(Arrays.asList(new Alert())); assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); |