]> source.dussan.org Git - sonarqube.git/commitdiff
QGate ITs now restore default qgate at the end
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 15 Feb 2016 16:22:26 +0000 (17:22 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 15 Feb 2016 16:22:26 +0000 (17:22 +0100)
As they were not restoring default quality gate, following IT ProjectOverviewTest was failing

it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java

index 5920d67713865f8d1322d96d683902a91214ebea..620c781385a0c8cf108a9a62e8504500bb346aef 100644 (file)
@@ -25,8 +25,11 @@ import com.sonar.orchestrator.selenium.Selenese;
 import it.Category1Suite;
 import java.util.Iterator;
 import javax.mail.internet.MimeMessage;
-
-import org.junit.*;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
 import org.sonar.wsclient.Sonar;
 import org.sonar.wsclient.qualitygate.NewCondition;
 import org.sonar.wsclient.qualitygate.QualityGate;
@@ -47,6 +50,8 @@ import static util.ItUtils.setServerProperty;
 
 public class QualityGateNotificationTest {
 
+  private static long DEFAULT_QUALITY_GATE;
+
   private static final String PROJECT_KEY = "sample";
 
   @ClassRule
@@ -57,11 +62,13 @@ public class QualityGateNotificationTest {
     setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
     setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
     setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
+    DEFAULT_QUALITY_GATE = qgClient().list().defaultGate().id();
   }
 
   @AfterClass
-  public static void resetPeriods() throws Exception {
+  public static void resetData() throws Exception {
     ItUtils.resetPeriods(orchestrator);
+    qgClient().setDefault(DEFAULT_QUALITY_GATE);
   }
 
   @Before
index 3e495c056a980afbd730f55a4428c273163c19ca..d25961a7e18162a199d4632af434cbd87b13c118 100644 (file)
@@ -28,6 +28,7 @@ import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Properties;
 import org.apache.commons.io.FileUtils;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
@@ -53,10 +54,12 @@ import static util.ItUtils.projectDir;
 
 public class QualityGateTest {
 
-  private static final String PROJECT_KEY = "sample";
+  private static long DEFAULT_QUALITY_GATE;
 
   private long provisionedProjectId = -1L;
 
+  private static final String PROJECT_KEY = "sample";
+
   @ClassRule
   public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
   static WsClient wsClient;
@@ -64,6 +67,12 @@ public class QualityGateTest {
   @BeforeClass
   public static void startOrchestrator() {
     wsClient = newAdminWsClient(orchestrator);
+    DEFAULT_QUALITY_GATE = qgClient().list().defaultGate().id();
+  }
+
+  @AfterClass
+  public static void restoreDefaultQualitGate() throws Exception {
+    qgClient().setDefault(DEFAULT_QUALITY_GATE);
   }
 
   @Before
index 3a874dbd4c53e8d8fd236226410a611bf2cef477..79733afc2825dd7fc3de5957d6adc1d21cf4b085 100644 (file)
@@ -45,16 +45,20 @@ public class QualityGateUiTest {
   @ClassRule
   public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
 
+  private static long DEFAULT_QUALITY_GATE;
+
   @BeforeClass
   public static void initPeriods() throws Exception {
     setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
     setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
     setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
+    DEFAULT_QUALITY_GATE = qgClient().list().defaultGate().id();
   }
 
   @AfterClass
-  public static void resetPeriods() throws Exception {
+  public static void resetData() throws Exception {
     ItUtils.resetPeriods(orchestrator);
+    qgClient().setDefault(DEFAULT_QUALITY_GATE);
   }
 
   @Before
@@ -67,7 +71,7 @@ public class QualityGateUiTest {
    */
   @Test
   public void display_alerts_correctly_in_history_page() {
-    QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient();
+    QualityGateClient qgClient = qgClient();
     QualityGate qGate = qgClient.create("AlertsForHistory");
     qgClient.setDefault(qGate.id());
 
@@ -141,4 +145,8 @@ public class QualityGateUiTest {
     orchestrator.executeBuild(scan);
   }
 
+  private static QualityGateClient qgClient() {
+    return orchestrator.getServer().adminWsClient().qualityGateClient();
+  }
+
 }