]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5094 Trigger alert notifications when a quality gate is used
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 15:51:20 +0000 (16:51 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 15:51:26 +0000 (16:51 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java

index 73b79c58c3d45dbeadf26a1ef3fd7c811183ffae..68a723bbe8530a4fa0199bde31a5710d5ec91b64 100644 (file)
@@ -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
index 07cd31d1642c1cdaf30b733201d90d05d26fa239..e7e06f0e2cec5327d9389325f507eff0705d3a62 100644 (file)
@@ -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()));