]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10087 Add built-in flag to provided quality gate
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Nov 2017 13:47:15 +0000 (14:47 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 4 Dec 2017 12:44:55 +0000 (13:44 +0100)
21 files changed:
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDbTester.java
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest/shared.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/QualityGateDaoTest/delete-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/QualityGateDaoTest/insert-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/QualityGateDaoTest/selectAll.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/QualityGateDaoTest/update-result.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGates.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/package-info.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest/quality_gates_7_0.sql [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java

index c692eed52f4113651d76737c918b0cdee1864687..950cbde71b7e19a2cec704f0fe51fc9f157dc13d 100644 (file)
@@ -109,8 +109,8 @@ public class ComputeEngineContainerImplTest {
     );
     assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
       CONTAINER_ITSELF
+        + 14 // MigrationConfigurationModule
         + 17 // level 2
-        + 13 // MigrationConfigurationModule
     );
     assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
       COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
index f3bedc4ba6b02364ba6db94f66cdbd13df6916ae..733e8d5f09d64f4d6c5f9585b95b74f5ad448cc5 100644 (file)
@@ -229,6 +229,7 @@ CREATE UNIQUE INDEX "EVENTS_UUID" ON "EVENTS" ("UUID");
 CREATE TABLE "QUALITY_GATES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
+  "IS_BUILT_IN" BOOLEAN NULL,
   "CREATED_AT" TIMESTAMP,
   "UPDATED_AT" TIMESTAMP,
 );
index 98832bbfaae05cb9506454087bec7ddd3bec8979..2e0d294825cb7d24b146ff4e54dcd3b2ae82b7ec 100644 (file)
@@ -27,11 +27,9 @@ import java.util.Date;
 public class QualityGateDto {
 
   private Long id;
-
   private String name;
-
+  private boolean isBuiltIn;
   private Date createdAt;
-
   private Date updatedAt;
 
   public Long getId() {
@@ -52,6 +50,15 @@ public class QualityGateDto {
     return this;
   }
 
+  public boolean isBuiltIn() {
+    return isBuiltIn;
+  }
+
+  public QualityGateDto setBuiltIn(boolean builtIn) {
+    isBuiltIn = builtIn;
+    return this;
+  }
+
   public Date getCreatedAt() {
     return createdAt;
   }
index 0dfb59d5d0857288fb6557f42b2363ba778cde02..290a4966886e38e00ea52f8b3076839825df019d 100644 (file)
@@ -4,12 +4,12 @@
 <mapper namespace="org.sonar.db.qualitygate.QualityGateMapper">
 
   <insert id="insert" parameterType="QualityGate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    insert into quality_gates (name, created_at, updated_at)
-    values (#{name}, #{createdAt}, #{updatedAt})
+    insert into quality_gates (name, is_built_in, created_at, updated_at)
+    values (#{name}, #{isBuiltIn}, #{createdAt}, #{updatedAt})
   </insert>
 
   <sql id="gateColumns">
-    id, name, created_at as createdAt, updated_at as updatedAt
+    id, name, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt
   </sql>
 
   <select id="selectAll" resultType="QualityGate">
index 834cde95798e671f747356a360d7315775d32b67..fc1a907e78685d4af555c5a11da456c14f04e76e 100644 (file)
@@ -32,26 +32,35 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class QualityGateDaoTest {
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private DbSession dbSession = dbTester.getSession();
-  private QualityGateDao underTest = dbTester.getDbClient().qualityGateDao();
+  private DbSession dbSession = db.getSession();
+  private QualityGateDao underTest = db.getDbClient().qualityGateDao();
 
   @Test
   public void testInsert() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "insert.xml");
+    db.prepareDbUnit(getClass(), "insert.xml");
     QualityGateDto newQgate = new QualityGateDto().setName("My Quality Gate");
 
     underTest.insert(dbSession, newQgate);
     dbSession.commit();
 
-    dbTester.assertDbUnitTable(getClass(), "insert-result.xml", "quality_gates", "name");
+    db.assertDbUnitTable(getClass(), "insert-result.xml", "quality_gates", "name");
     assertThat(newQgate.getId()).isNotNull();
   }
 
+  @Test
+  public void insert_built_in() {
+    underTest.insert(db.getSession(), new QualityGateDto().setName("test").setBuiltIn(true));
+
+    QualityGateDto reloaded = underTest.selectByName(db.getSession(), "test");
+
+    assertThat(reloaded.isBuiltIn()).isTrue();
+  }
+
   @Test
   public void testSelectAll() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "selectAll.xml");
+    db.prepareDbUnit(getClass(), "selectAll.xml");
 
     Collection<QualityGateDto> allQualityGates = underTest.selectAll(dbSession);
 
@@ -64,35 +73,35 @@ public class QualityGateDaoTest {
 
   @Test
   public void testSelectByName() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "selectAll.xml");
+    db.prepareDbUnit(getClass(), "selectAll.xml");
     assertThat(underTest.selectByName(dbSession, "Balanced").getName()).isEqualTo("Balanced");
     assertThat(underTest.selectByName(dbSession, "Unknown")).isNull();
   }
 
   @Test
   public void testSelectById() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "selectAll.xml");
+    db.prepareDbUnit(getClass(), "selectAll.xml");
     assertThat(underTest.selectById(dbSession, 1L).getName()).isEqualTo("Very strict");
     assertThat(underTest.selectById(dbSession, 42L)).isNull();
   }
 
   @Test
   public void testDelete() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "selectAll.xml");
+    db.prepareDbUnit(getClass(), "selectAll.xml");
 
     underTest.delete(new QualityGateDto().setId(1L), dbSession);
     dbSession.commit();
 
-    dbTester.assertDbUnitTable(getClass(), "delete-result.xml", "quality_gates", "id", "name");
+    db.assertDbUnitTable(getClass(), "delete-result.xml", "quality_gates", "id", "name");
   }
 
   @Test
   public void testUpdate() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "selectAll.xml");
+    db.prepareDbUnit(getClass(), "selectAll.xml");
 
     underTest.update(new QualityGateDto().setId(1L).setName("Not so strict"), dbSession);
     dbSession.commit();
 
-    dbTester.assertDbUnitTable(getClass(), "update-result.xml", "quality_gates", "id", "name");
+    db.assertDbUnitTable(getClass(), "update-result.xml", "quality_gates", "id", "name");
   }
 }
index 78136a89b3588695bb57f1dd6bb094242bb68283..5b08337d2158acd101058ed4c72a2a5ed17bd36b 100644 (file)
@@ -46,7 +46,7 @@ public class QualityGateDbTester {
   }
 
   public QualityGateDto insertQualityGate(String name) {
-    QualityGateDto updatedUser = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name));
+    QualityGateDto updatedUser = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name).setBuiltIn(false));
     db.commit();
     return updatedUser;
   }
index 3b4ee850ea7ad46245190953865fbcca716958c3..6ef7233011aeab3829eea377a522b7f7e578e6e2 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
   <quality_gates id="42"
-                 name="Golden"/>
+                 name="Golden" is_built_in="[true]"/>
   <quality_gates id="43"
-                 name="Ninth"/>
+                 name="Ninth" is_built_in="[false]"/>
 
   <projects organization_uuid="org1"
             uuid="A"
index 3c0ddc793c17977a7b57743029af18992b2eb8c3..67f4fafc965dc7abb532a7dd203edeab2b74cf29 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <quality_gates id="2" name="Balanced"/>
-  <quality_gates id="3" name="Lenient"/>
+  <quality_gates id="2" name="Balanced" is_built_in="[false]"/>
+  <quality_gates id="3" name="Lenient" is_built_in="[false]"/>
 
 </dataset>
index 00881f2945bb4062ec6ab88b371dc63eb9b56665..00c28571e9d2fc13b95d91fd8d403a8579d64e07 100644 (file)
@@ -1,5 +1,5 @@
 <dataset>
 
-  <quality_gates id="1" name="My Quality Gate"/>
+  <quality_gates id="1" name="My Quality Gate" is_built_in="[false]"/>
 
 </dataset>
index 6eb3e577e4ed2a3c720438675850a9850e8cc6d3..09799b3114ba2cefd0643e24d21aaed461c049e8 100644 (file)
@@ -1,7 +1,7 @@
 <dataset>
 
-  <quality_gates id="1" name="Very strict"/>
-  <quality_gates id="2" name="Balanced"/>
-  <quality_gates id="3" name="Lenient"/>
+  <quality_gates id="1" name="Very strict" is_built_in="[true]"/>
+  <quality_gates id="2" name="Balanced" is_built_in="[false]"/>
+  <quality_gates id="3" name="Lenient" is_built_in="[false]"/>
 
 </dataset>
index 4f80f313eae544b92478bb87f69f27ab7c6b3db1..6dfb4819362945e64624c6497ce5ff347759dd71 100644 (file)
@@ -1,7 +1,7 @@
 <dataset>
 
-  <quality_gates id="1" name="Not so strict"/>
-  <quality_gates id="2" name="Balanced"/>
-  <quality_gates id="3" name="Lenient"/>
+  <quality_gates id="1" name="Not so strict" is_built_in="[false]"/>
+  <quality_gates id="2" name="Balanced" is_built_in="[false]"/>
+  <quality_gates id="3" name="Lenient" is_built_in="[false]"/>
 
 </dataset>
index 5f7026a9b4d594c3c452198bc572a33d0362c186..87bf06403aaba38c3d051c82dd5ade58feb94048 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.server.platform.db.migration.version.v64.DbVersion64;
 import org.sonar.server.platform.db.migration.version.v65.DbVersion65;
 import org.sonar.server.platform.db.migration.version.v66.DbVersion66;
 import org.sonar.server.platform.db.migration.version.v67.DbVersion67;
+import org.sonar.server.platform.db.migration.version.v70.DbVersion70;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -49,6 +50,7 @@ public class MigrationConfigurationModule extends Module {
       DbVersion65.class,
       DbVersion66.class,
       DbVersion67.class,
+      DbVersion70.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGates.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGates.java
new file mode 100644 (file)
index 0000000..e826573
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v70;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class AddIsBuiltInToQualityGates extends DdlChange {
+
+  public AddIsBuiltInToQualityGates(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "quality_gates")
+      .addColumn(newBooleanColumnDefBuilder()
+        .setColumnName("is_built_in")
+        .setIsNullable(true)
+        .build())
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
new file mode 100644 (file)
index 0000000..48c677f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v70;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion70 implements DbVersion {
+
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(1900, "Add QUALITY_GATES.IS_BUILT_IN", AddIsBuiltInToQualityGates.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/package-info.java
new file mode 100644 (file)
index 0000000..78095d8
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v70;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 313c1dec0eaba85b81a12b602309ce4d2f6c23fd..6c41663182c963b0c7b377debb50e008b3c89901 100644 (file)
@@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest {
     assertThat(container.getPicoContainer().getComponentAdapters())
       .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER
         // DbVersion classes
-        + 10
+        + 11
         // Others
         + 3);
   }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest.java
new file mode 100644 (file)
index 0000000..3cdfb04
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v70;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.BOOLEAN;
+
+public class AddIsBuiltInToQualityGatesTest {
+
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(AddIsBuiltInToQualityGatesTest.class, "quality_gates_7_0.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddIsBuiltInToQualityGates underTest = new AddIsBuiltInToQualityGates(dbTester.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("quality_gates", "is_built_in", BOOLEAN, null, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
new file mode 100644 (file)
index 0000000..f28d675
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v70;
+
+import org.junit.Test;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion70Test {
+
+  private DbVersion70 underTest = new DbVersion70();
+
+  @Test
+  public void migrationNumber_starts_at_1830() {
+    verifyMinimumMigrationNumber(underTest, 1900);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 1);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest/quality_gates_7_0.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddIsBuiltInToQualityGatesTest/quality_gates_7_0.sql
new file mode 100644 (file)
index 0000000..811a5d4
--- /dev/null
@@ -0,0 +1,7 @@
+CREATE TABLE "QUALITY_GATES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+);
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
index 24f161e79dd14a0d559790d964af17b3a9ee6227..05394b65ed690df5f8ecd03703324e2dca016588 100644 (file)
@@ -41,15 +41,13 @@ public class RegisterQualityGates implements Startable {
   private static final int LEAK_PERIOD = 1;
 
   private final DbClient dbClient;
-  private final QualityGateUpdater qualityGateUpdater;
   private final QualityGateConditionsUpdater qualityGateConditionsUpdater;
   private final LoadedTemplateDao loadedTemplateDao;
   private final QualityGates qualityGates;
 
-  public RegisterQualityGates(DbClient dbClient, QualityGateUpdater qualityGateUpdater, QualityGateConditionsUpdater qualityGateConditionsUpdater,
+  public RegisterQualityGates(DbClient dbClient, QualityGateConditionsUpdater qualityGateConditionsUpdater,
     LoadedTemplateDao loadedTemplateDao, QualityGates qualityGates) {
     this.dbClient = dbClient;
-    this.qualityGateUpdater = qualityGateUpdater;
     this.qualityGateConditionsUpdater = qualityGateConditionsUpdater;
     this.loadedTemplateDao = loadedTemplateDao;
     this.qualityGates = qualityGates;
@@ -77,7 +75,7 @@ public class RegisterQualityGates implements Startable {
 
   private void createBuiltinQualityGate(DbSession dbSession) {
     String ratingAValue = Integer.toString(RatingGrid.Rating.A.getIndex());
-    QualityGateDto builtin = qualityGateUpdater.create(dbSession, BUILTIN_QUALITY_GATE);
+    QualityGateDto builtin = createQualityGate(dbSession, BUILTIN_QUALITY_GATE);
     qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(),
       NEW_SECURITY_RATING_KEY, OPERATOR_GREATER_THAN, null, ratingAValue, LEAK_PERIOD);
     qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(),
@@ -91,6 +89,14 @@ public class RegisterQualityGates implements Startable {
     qualityGates.setDefault(dbSession, builtin.getId());
   }
 
+  private QualityGateDto createQualityGate(DbSession dbSession, String name){
+    QualityGateDto qualityGate = new QualityGateDto()
+      .setName(name)
+      .setBuiltIn(true);
+    dbClient.qualityGateDao().insert(dbSession, qualityGate);
+    return qualityGate;
+  }
+
   private void registerBuiltinQualityGate(DbSession dbSession) {
     loadedTemplateDao.insert(new LoadedTemplateDto(BUILTIN_QUALITY_GATE, LoadedTemplateDto.QUALITY_GATE_TYPE), dbSession);
   }
index 5e3900543d044b6809ec24442b4491d9970d6b75..79e661ada9d2b6c92b92db07f3773fb340efa844 100644 (file)
@@ -58,7 +58,6 @@ public class RegisterQualityGatesTest {
 
   QualityGates qualityGates = mock(QualityGates.class);
   RegisterQualityGates task = new RegisterQualityGates(dbClient,
-    new QualityGateUpdater(dbClient),
     new QualityGateConditionsUpdater(dbClient),
     dbClient.loadedTemplateDao(),
     qualityGates);
@@ -77,6 +76,7 @@ public class RegisterQualityGatesTest {
     assertThat(dbClient.loadedTemplateDao().countByTypeAndKey("QUALITY_GATE", "SonarQube way", dbSession)).isEqualTo(1);
     QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByName(dbSession, "SonarQube way");
     assertThat(qualityGateDto).isNotNull();
+    assertThat(qualityGateDto.isBuiltIn()).isTrue();
     assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId()))
       .extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator, QualityGateConditionDto::getWarningThreshold,
         QualityGateConditionDto::getErrorThreshold, QualityGateConditionDto::getPeriod)