From 83fff8bce48fa6e2ad5b23117995ff1645890651 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 10 Mar 2014 16:51:20 +0100 Subject: SONAR-5094 Trigger alert notifications when a quality gate is used --- .../org/sonar/plugins/core/sensors/GenerateAlertEvents.java | 8 ++++++-- .../sonar/plugins/core/sensors/GenerateAlertEventsTest.java | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'plugins/sonar-core-plugin/src') 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(); } @@ -74,6 +77,12 @@ public class GenerateAlertEventsTest { assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); } + @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())); -- cgit v1.2.3