]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10134 Add QUALITY_GATES.UUID column
authorEric Hartmann <hartmann.eric@gmail.com>
Fri, 1 Dec 2017 10:57:03 +0000 (11:57 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
30 files changed:
server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
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/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest/shared.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGates.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGates.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGates.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGatesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest/quality_gates.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest/quality_gates.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGatesTest/quality_gates.sql [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGateUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java

index 62b162cb561cc9d5baddd64f5a27341c4793d449..4daf0dff72c5846ecbb5c2ec3a3f7232779be76a 100644 (file)
@@ -5,7 +5,7 @@ INSERT INTO GROUPS(ID, ORGANIZATION_UUID, NAME, DESCRIPTION, CREATED_AT, UPDATED
 INSERT INTO GROUPS(ID, ORGANIZATION_UUID, NAME, DESCRIPTION, CREATED_AT, UPDATED_AT) VALUES (2, 'AVdqnciQUUs7Zd3KPvFD', 'sonar-users', 'Any new users created will automatically join this group', '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0');
 ALTER TABLE GROUPS ALTER COLUMN ID RESTART WITH 3;
 
-INSERT INTO QUALITY_GATES(ID, NAME, IS_BUILT_IN, CREATED_AT, UPDATED_AT) VALUES (1, 'Sonar Way', true, '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0');
+INSERT INTO QUALITY_GATES(ID, UUID, NAME, IS_BUILT_IN, CREATED_AT, UPDATED_AT) VALUES (1, 'AWASGWAKYOI_InFKS3UF', 'Sonar Way', true, '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0');
 
 INSERT INTO ORGANIZATIONS (UUID, KEE, NAME, GUARDED, NEW_PROJECT_PRIVATE, DEFAULT_GROUP_ID, DEFAULT_QUALITY_GATE_UUID, CREATED_AT, UPDATED_AT) VALUES ('AVdqnciQUUs7Zd3KPvFD', 'default-organization', 'Default Organization', true, false, 2, 1, '1474962596482', '1474962596482');
 INSERT INTO INTERNAL_PROPERTIES (KEE, IS_EMPTY, TEXT_VALUE, CREATED_AT) VALUES ('organization.default', false, 'AVdqnciQUUs7Zd3KPvFD', '1474962596482');
index 45c29bee706b24139bca25b0cb6b7a13904b2b52..1b1db706784d856e1146cb5f5bd917c76e1ee4cc 100644 (file)
@@ -229,12 +229,14 @@ 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),
+  "UUID" VARCHAR(40) NOT NULL,
   "NAME" VARCHAR(100) NOT NULL,
   "IS_BUILT_IN" BOOLEAN NOT NULL,
   "CREATED_AT" TIMESTAMP,
   "UPDATED_AT" TIMESTAMP,
 );
 CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES" ("UUID");
 
 
 CREATE TABLE "QUALITY_GATE_CONDITIONS" (
index 2e0d294825cb7d24b146ff4e54dcd3b2ae82b7ec..1d75a2ef04849d6dd3375e0251768133a4f786fb 100644 (file)
@@ -28,10 +28,20 @@ public class QualityGateDto {
 
   private Long id;
   private String name;
+  private String uuid;
   private boolean isBuiltIn;
   private Date createdAt;
   private Date updatedAt;
 
+  public String getUuid() {
+    return uuid;
+  }
+
+  public QualityGateDto setUuid(String uuid) {
+    this.uuid = uuid;
+    return this;
+  }
+
   public Long getId() {
     return id;
   }
index 9454c6a507088ff5a929f7e22a0d76d78818993f..35bd1ace13e14c92132b12f2fdbc10f9c7149f55 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, is_built_in, created_at, updated_at)
-    values (#{name}, #{isBuiltIn}, #{createdAt}, #{updatedAt})
+    insert into quality_gates (name, uuid, is_built_in, created_at, updated_at)
+    values (#{name}, #{uuid}, #{isBuiltIn}, #{createdAt}, #{updatedAt})
   </insert>
 
   <sql id="gateColumns">
-    id, name, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt
+    id, name, uuid, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt
   </sql>
 
   <select id="selectAll" resultType="QualityGate">
@@ -50,7 +50,7 @@
     name=#{name},
     is_built_in=#{isBuiltIn},
     updated_at=#{updatedAt}
-    where id=#{id}
+    where uuid=#{uuid}
   </update>
 
   <update id="ensureOneBuiltInQualityGate" parameterType="string">
index b9c2b7c98a67dcb3f47b8fbbdadacb2dbf7f9506..24f286e9bfa760622acb213eb65b79167e4b741e 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.qualitygate;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 
@@ -39,7 +40,7 @@ public class QualityGateDaoTest {
 
   @Test
   public void testInsert() {
-    QualityGateDto newQgate = new QualityGateDto().setName("My Quality Gate");
+    QualityGateDto newQgate = new QualityGateDto().setName("My Quality Gate").setUuid(Uuids.createFast());
 
     underTest.insert(dbSession, newQgate);
     dbSession.commit();
@@ -53,7 +54,7 @@ public class QualityGateDaoTest {
 
   @Test
   public void insert_built_in() {
-    underTest.insert(db.getSession(), new QualityGateDto().setName("test").setBuiltIn(true));
+    underTest.insert(db.getSession(), new QualityGateDto().setName("test").setBuiltIn(true).setUuid(Uuids.createFast()));
 
     QualityGateDto reloaded = underTest.selectByName(db.getSession(), "test");
 
index 84e53e052fd1e6b2f316f575360c0978de6e3f4c..b2d0eb3412c39e0cd50923b7d42fcd7d6261e0ea 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.db.qualitygate;
 
 import java.util.Arrays;
 import java.util.function.Consumer;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -51,6 +52,7 @@ public class QualityGateDbTester {
   public final QualityGateDto insertQualityGate(Consumer<QualityGateDto>... dtoPopulators) {
     QualityGateDto qualityGate = new QualityGateDto()
       .setName(randomAlphanumeric(30))
+      .setUuid(Uuids.createFast())
       .setBuiltIn(false);
     Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(qualityGate));
     QualityGateDto updatedUser = dbClient.qualityGateDao().insert(dbSession, qualityGate);
index 3fb4a9241dbc627f7e903e118467fd627fb1bbec..fd2312fd5469cdd5b46b6668e4f7a9a7b4daf5ea 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Arrays;
 import java.util.Optional;
 import java.util.function.Consumer;
 import org.sonar.api.rule.Severity;
-import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -116,7 +116,7 @@ public class QualityProfileDbTester {
   public void addUserPermission(QProfileDto profile, UserDto user){
     checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
     dbClient.qProfileEditUsersDao().insert(dbSession, new QProfileEditUsersDto()
-      .setUuid(UuidFactoryFast.getInstance().create())
+      .setUuid(Uuids.createFast())
       .setUserId(user.getId())
       .setQProfileUuid(profile.getKee())
     );
@@ -126,7 +126,7 @@ public class QualityProfileDbTester {
   public void addGroupPermission(QProfileDto profile, GroupDto group){
     checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
     dbClient.qProfileEditGroupsDao().insert(dbSession, new QProfileEditGroupsDto()
-      .setUuid(UuidFactoryFast.getInstance().create())
+      .setUuid(Uuids.createFast())
       .setGroupId(group.getId())
       .setQProfileUuid(profile.getKee())
     );
index 6ef7233011aeab3829eea377a522b7f7e578e6e2..830b74c8798d6d0d4f999548b44dad1f36444924 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <quality_gates id="42"
+  <quality_gates id="42" uuid="1"
                  name="Golden" is_built_in="[true]"/>
-  <quality_gates id="43"
+  <quality_gates id="43" uuid="2"
                  name="Ninth" is_built_in="[false]"/>
 
   <projects organization_uuid="org1"
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGates.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGates.java
new file mode 100644 (file)
index 0000000..1b5fc19
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddUuidToQualityGates extends DdlChange {
+
+  public AddUuidToQualityGates(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "quality_gates")
+      .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+        .setColumnName("uuid")
+        .setIsNullable(true)
+        .setLimit(VarcharColumnDef.UUID_SIZE)
+        .build())
+      .build());
+  }
+}
index 05261e0d16c091e44b59d6f789a74d5ba321f9e5..f11b627b5d4973d3f14cf20408e3a5cd286fa8ca 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform.db.migration.version.v70;
 
+import java.util.UUID;
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
 
@@ -39,6 +40,9 @@ public class DbVersion70 implements DbVersion {
       .add(1909, "Drop index on project_measures.person_id", DropIndexOnPersonMeasures.class)
       .add(1910, "Create ORG_QUALITY_GATES table", CreateOrgQualityGatesTable.class)
       .add(1911, "Add ORGANIZATIONS.DEFAULT_QUALITY_GATE_UUID", AddDefaultQualityGateUuidToOrganizations.class)
+      .add(1912, "Create QUALITY_GATES.UUID", AddUuidToQualityGates.class)
+      .add(1913, "Populate QUALITY_GATES.UUID", PopulateUuidOnQualityGates.class)
+      .add(1914, "Make QUALITY_GATES.UUID not nullable", MakeUuidNotNullableOnQualityGates.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGates.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGates.java
new file mode 100644 (file)
index 0000000..ae6af52
--- /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.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class MakeUuidNotNullableOnQualityGates extends DdlChange {
+
+  private static final VarcharColumnDef UUID_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(false)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+  private static final String TABLE_NAME = "quality_gates";
+
+  public MakeUuidNotNullableOnQualityGates(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
+      .updateColumn(UUID_COLUMN)
+      .build());
+
+    context.execute(new CreateIndexBuilder(getDialect())
+      .addColumn(UUID_COLUMN)
+      .setUnique(true)
+      .setTable(TABLE_NAME)
+      .setName("uniq_quality_gates_uuid")
+      .build()
+    );
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGates.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGates.java
new file mode 100644 (file)
index 0000000..d618971
--- /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 java.util.Date;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateUuidOnQualityGates extends DataChange {
+
+  private final System2 system2;
+  private final UuidFactory uuidFactory;
+
+  public PopulateUuidOnQualityGates(Database db, System2 system2, UuidFactory uuidFactory) {
+    super(db);
+    this.system2 = system2;
+    this.uuidFactory = uuidFactory;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("select id, name from quality_gates where uuid is null");
+    massUpdate.rowPluralName("quality gates");
+    massUpdate.update("update quality_gates set uuid=?, updated_at=? where id=?");
+    massUpdate.execute((row, update) -> {
+      String name = row.getString(2);
+      update.setString(1, uuidFactory.create());
+      update.setDate(2, new Date(system2.now()));
+      update.setLong(3, row.getLong(1));
+      return true;
+    });
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest.java
new file mode 100644 (file)
index 0000000..e953b5d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.VARCHAR;
+
+public class AddUuidToQualityGatesTest {
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(AddUuidToQualityGatesTest.class, "quality_gates.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddUuidToQualityGates underTest = new AddUuidToQualityGates(dbTester.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("quality_gates", "uuid", VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
index ff36b7f85f763a3cd9c480cf2d33429f55e7ac72..3ad5338b4e6774e584f676150fece0f41a10f475 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion70Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 11);
+    verifyMigrationCount(underTest, 15);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest.java
new file mode 100644 (file)
index 0000000..297d0ab
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.VARCHAR;
+
+public class MakeUuidNotNullableOnQualityGatesTest {
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(MakeUuidNotNullableOnQualityGatesTest.class, "quality_gates.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private MakeUuidNotNullableOnQualityGates underTest = new MakeUuidNotNullableOnQualityGates(dbTester.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("quality_gates", "uuid", VARCHAR, 40, false);
+    dbTester.assertUniqueIndex("quality_gates", "uniq_quality_gates_uuid", "uuid");
+  }
+
+  @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/PopulateUuidOnQualityGatesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGatesTest.java
new file mode 100644 (file)
index 0000000..e0a8b5c
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.assertj.core.api.AbstractListAssert;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.internal.TestSystem2;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+
+import static java.util.stream.Collectors.toList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateUuidOnQualityGatesTest {
+
+  private final static long PAST = 10_000_000_000L;
+  private final static long NOW = 50_000_000_000L;
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateUuidOnQualityGatesTest.class, "quality_gates.sql");
+
+  private System2 system2 = new TestSystem2().setNow(NOW);
+
+  private PopulateUuidOnQualityGates underTest = new PopulateUuidOnQualityGates(db.database(), system2, UuidFactoryFast.getInstance());
+
+  @Test
+  public void has_no_effect_if_table_is_empty() throws SQLException {
+    underTest.execute();
+
+    assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(0);
+  }
+
+  @Test
+  public void updates_uuid_when_uuid_is_null() throws SQLException {
+    insertQualityGate("Test 1", null);
+    insertQualityGate("Test 2", null);
+
+    underTest.execute();
+
+    List<Tuple> tuples = selectAllQualityGates("NAME", "IS_BUILT_IN", "CREATED_AT", "UPDATED_AT");
+
+    assertThat(selectAllQualityGates("NAME", "IS_BUILT_IN", "CREATED_AT", "UPDATED_AT"))
+      .containsExactlyInAnyOrder(
+        tuple("Test 1", false, new Date(PAST), new Date(NOW)),
+        tuple("Test 2", false, new Date(PAST), new Date(NOW)));
+
+    selectAllQualityGates("UUID").forEach(c -> assertThat(c).isNotNull());
+  }
+
+  @Test
+  public void does_not_update_uuid_when_uuid_is_not_null() throws SQLException {
+    insertQualityGate("Test 1", "1");
+    insertQualityGate("Test 2", "2");
+
+    underTest.execute();
+
+    assertThat(selectAllQualityGates("UUID", "NAME", "IS_BUILT_IN", "CREATED_AT", "UPDATED_AT"))
+      .containsExactlyInAnyOrder(
+        tuple("1", "Test 1", false, new Date(PAST), new Date(PAST)),
+        tuple("2", "Test 2", false, new Date(PAST), new Date(PAST)));
+  }
+
+  @Test
+  public void execute_is_reentreant() throws SQLException {
+    insertQualityGate("Test 1", null);
+    insertQualityGate("Test 2", null);
+
+    underTest.execute();
+    underTest.execute();
+
+    assertThat(selectAllQualityGates("NAME", "IS_BUILT_IN", "CREATED_AT", "UPDATED_AT"))
+      .containsExactlyInAnyOrder(
+        tuple("Test 1", false, new Date(PAST), new Date(NOW)),
+        tuple("Test 2", false, new Date(PAST), new Date(NOW)));
+
+    selectAllQualityGates("UUID").forEach(c -> assertThat(c).isNotNull());
+  }
+
+  private List<Tuple> selectAllQualityGates(String... columns) {
+    return db.select("SELECT UUID, NAME, IS_BUILT_IN, CREATED_AT, UPDATED_AT FROM QUALITY_GATES")
+      .stream()
+      .map(map -> new Tuple(Arrays.stream(columns).map(c -> map.get(c)).collect(toList()).toArray()))
+      .collect(toList());
+  }
+
+  private void insertQualityGate(String name, @Nullable String uuid) {
+    db.executeInsert(
+      "QUALITY_GATES",
+      "NAME", name,
+      "UUID", uuid,
+      "IS_BUILT_IN", false,
+      "CREATED_AT", new Date(PAST),
+      "UPDATED_AT", new Date(PAST));
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest/quality_gates.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/AddUuidToQualityGatesTest/quality_gates.sql
new file mode 100644 (file)
index 0000000..f7e89fe
--- /dev/null
@@ -0,0 +1,8 @@
+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 NOT NULL,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+);
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest/quality_gates.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/MakeUuidNotNullableOnQualityGatesTest/quality_gates.sql
new file mode 100644 (file)
index 0000000..8ea8647
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "QUALITY_GATES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "UUID" VARCHAR(40),
+  "NAME" VARCHAR(100) NOT NULL,
+  "IS_BUILT_IN" BOOLEAN NOT NULL,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+);
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGatesTest/quality_gates.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/PopulateUuidOnQualityGatesTest/quality_gates.sql
new file mode 100644 (file)
index 0000000..8ea8647
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "QUALITY_GATES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "UUID" VARCHAR(40),
+  "NAME" VARCHAR(100) NOT NULL,
+  "IS_BUILT_IN" BOOLEAN NOT NULL,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+);
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
index 4115a651a532b7461f5cfb77b2ea5b92f0d628a8..70b27988e0e8a9a273f6b526de0e29a1455bfb16 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.qualitygate;
 import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.Nullable;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.property.PropertyDto;
@@ -38,14 +39,19 @@ public class QualityGateUpdater {
   public static final String SONAR_QUALITYGATE_PROPERTY = "sonar.qualitygate";
 
   private final DbClient dbClient;
+  private final UuidFactory uuidFactory;
 
-  public QualityGateUpdater(DbClient dbClient) {
+  public QualityGateUpdater(DbClient dbClient, UuidFactory uuidFactory) {
     this.dbClient = dbClient;
+    this.uuidFactory = uuidFactory;
   }
 
   public QualityGateDto create(DbSession dbSession, String name) {
     validateQualityGate(dbSession, null, name);
-    QualityGateDto newQualityGate = new QualityGateDto().setName(name).setBuiltIn(false);
+    QualityGateDto newQualityGate = new QualityGateDto()
+      .setName(name)
+      .setBuiltIn(false)
+      .setUuid(uuidFactory.create());
     dbClient.qualityGateDao().insert(dbSession, newQualityGate);
     return newQualityGate;
   }
index 8564a66bf00edf7b36df46ff3b8d91be24433999..ecd19b6e94670e1190506ba3c0c905e2d391f70e 100644 (file)
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
@@ -58,14 +59,16 @@ public class QualityGates {
   private final PropertiesDao propertiesDao;
   private final UserSession userSession;
   private final DefaultOrganizationProvider organizationProvider;
+  private final UuidFactory uuidFactory;
 
-  public QualityGates(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider organizationProvider) {
+  public QualityGates(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider organizationProvider, UuidFactory uuidFactory) {
     this.dbClient = dbClient;
     this.dao = dbClient.qualityGateDao();
     this.conditionDao = dbClient.gateConditionDao();
     this.propertiesDao = dbClient.propertiesDao();
     this.userSession = userSession;
     this.organizationProvider = organizationProvider;
+    this.uuidFactory = uuidFactory;
   }
 
   public QualityGateDto copy(long sourceId, String destinationName) {
@@ -73,7 +76,7 @@ public class QualityGates {
     getNonNullQgate(sourceId);
     try (DbSession dbSession = dbClient.openSession(false)) {
       validateQualityGate(dbSession, null, destinationName);
-      QualityGateDto destinationGate = new QualityGateDto().setName(destinationName).setBuiltIn(false);
+      QualityGateDto destinationGate = new QualityGateDto().setName(destinationName).setBuiltIn(false).setUuid(uuidFactory.create());
       dao.insert(dbSession, destinationGate);
       for (QualityGateConditionDto sourceCondition : conditionDao.selectForQualityGate(dbSession, sourceId)) {
         conditionDao.insert(new QualityGateConditionDto().setQualityGateId(destinationGate.getId())
index 2d22f446ce6e0f4e19905aa74801acd0f0164d86..ea7a71ce3bb6148d59aa518babe61cdc9ef1497e 100644 (file)
@@ -30,6 +30,7 @@ import org.picocontainer.Startable;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -71,16 +72,18 @@ public class RegisterQualityGates implements Startable {
   private final QualityGateUpdater qualityGateUpdater;
   private final QualityGateDao qualityGateDao;
   private final QualityGateConditionDao qualityGateConditionDao;
+  private final UuidFactory uuidFactory;
   private final System2 system2;
 
   public RegisterQualityGates(DbClient dbClient, QualityGateUpdater qualityGateUpdater,
-    QualityGateConditionsUpdater qualityGateConditionsUpdater, QualityGateFinder qualityGateFinder, System2 system2) {
+    QualityGateConditionsUpdater qualityGateConditionsUpdater, QualityGateFinder qualityGateFinder, UuidFactory uuidFactory, System2 system2) {
     this.dbClient = dbClient;
     this.qualityGateConditionsUpdater = qualityGateConditionsUpdater;
     this.qualityGateUpdater = qualityGateUpdater;
     this.qualityGateFinder = qualityGateFinder;
     this.qualityGateDao = dbClient.qualityGateDao();
     this.qualityGateConditionDao = dbClient.gateConditionDao();
+    this.uuidFactory = uuidFactory;
     this.system2 = system2;
   }
 
@@ -154,6 +157,7 @@ public class RegisterQualityGates implements Startable {
     QualityGateDto qualityGate = new QualityGateDto()
       .setName(name)
       .setBuiltIn(true)
+      .setUuid(uuidFactory.create())
       .setCreatedAt(new Date(system2.now()));
     return dbClient.qualityGateDao().insert(dbSession, qualityGate);
   }
index 9f019ba098753e4c7419b7651fbd888de1d0f2ad..fee90f42ebad13db2cbc0ac39256726d4a5fdac1 100644 (file)
@@ -29,6 +29,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -71,13 +72,13 @@ public class QgateProjectFinderTest {
 
   @Before
   public void setUp() throws Exception {
-    qGate = new QualityGateDto().setName("Default Quality Gate");
+    qGate = new QualityGateDto().setName("Default Quality Gate").setUuid(Uuids.createFast());
     dbClient.qualityGateDao().insert(dbSession, qGate);
     dbTester.commit();
   }
 
   @Test
-  public void return_empty_association() throws Exception {
+  public void return_empty_association() {
     Association result = underTest.find(
       builder()
         .gateId(Long.toString(qGate.getId()))
@@ -87,7 +88,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void return_all_projects() throws Exception {
+  public void return_all_projects() {
     OrganizationDto org = dbTester.organizations().insert();
     ComponentDto associatedProject = insertProject(ComponentTesting.newPublicProjectDto(org));
     ComponentDto unassociatedProject = insertProject(ComponentTesting.newPublicProjectDto(org));
@@ -106,7 +107,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void return_only_associated_project() throws Exception {
+  public void return_only_associated_project() {
     OrganizationDto org = dbTester.organizations().insert();
     ComponentDto associatedProject = insertProject(ComponentTesting.newPublicProjectDto(org));
     insertProject(ComponentTesting.newPublicProjectDto(org));
@@ -124,7 +125,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void return_only_unassociated_project() throws Exception {
+  public void return_only_unassociated_project() {
     OrganizationDto org = dbTester.organizations().insert();
     ComponentDto associatedProject = insertProject(ComponentTesting.newPublicProjectDto(org));
     ComponentDto unassociatedProject = insertProject(ComponentTesting.newPublicProjectDto(org));
@@ -142,7 +143,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void return_only_authorized_projects() throws Exception {
+  public void return_only_authorized_projects() {
     UserDto user = dbTester.users().insertUser("a_login");
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto project1 = componentDbTester.insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto));
@@ -161,7 +162,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void do_not_verify_permissions_if_user_is_root() throws Exception {
+  public void do_not_verify_permissions_if_user_is_root() {
     OrganizationDto org = dbTester.organizations().insert();
     ComponentDto project = componentDbTester.insertPrivateProject(org);
     ProjectQgateAssociationQuery query = builder()
@@ -225,7 +226,7 @@ public class QgateProjectFinderTest {
   }
 
   @Test
-  public void fail_on_unknown_quality_gate() throws Exception {
+  public void fail_on_unknown_quality_gate() {
     expectedException.expect(NotFoundException.class);
     underTest.find(builder().gateId("123").build());
   }
index accccda8eafb56c5468a735592b9bcdcfc54725d..b279e974812c72849031b85fc6e13bad482afbda 100644 (file)
@@ -23,6 +23,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -43,10 +45,10 @@ public class QualityGateUpdaterTest {
 
   private DbClient dbClient = db.getDbClient();
   private DbSession dbSession = db.getSession();
-  private QualityGateUpdater underTest = new QualityGateUpdater(dbClient);
+  private QualityGateUpdater underTest = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
 
   @Test
-  public void create_quality_gate() throws Exception {
+  public void create_quality_gate() {
     QualityGateDto result = underTest.create(dbSession, QGATE_NAME);
 
     assertThat(result).isNotNull();
@@ -58,7 +60,7 @@ public class QualityGateUpdaterTest {
   }
 
   @Test
-  public void fail_to_create_when_name_is_empty() throws Exception {
+  public void fail_to_create_when_name_is_empty() {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Name can't be empty");
 
@@ -66,8 +68,8 @@ public class QualityGateUpdaterTest {
   }
 
   @Test
-  public void fail_to_create_when_name_already_exists() throws Exception {
-    dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(QGATE_NAME));
+  public void fail_to_create_when_name_already_exists() {
+    dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(QGATE_NAME).setUuid(Uuids.createFast()));
     dbSession.commit();
 
     expectedException.expect(BadRequestException.class);
index 52e6027c2337420cb7864990e342ae32816e3fec..f7759e715042d795af70676541708e398a0353f1 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
+import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -84,7 +85,7 @@ public class QualityGatesTest {
     when(componentDao.selectOrFailById(eq(dbSession), anyLong())).thenReturn(
       newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setId(1L).setDbKey(PROJECT_KEY));
 
-    underTest = new QualityGates(dbClient, userSession, organizationProvider);
+    underTest = new QualityGates(dbClient, userSession, organizationProvider, UuidFactoryFast.getInstance());
 
     userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_GATES, organizationProvider.get().getUuid());
   }
index 599f7b09b91c74d5affcf27b9d9512cdbb2709e4..9b11e2c39dd9128ecc2656581b4fec45e26f4b9a 100644 (file)
@@ -29,6 +29,8 @@ import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.Uuids;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -71,10 +73,11 @@ public class RegisterQualityGatesTest {
   private QualityGateConditionDao gateConditionDao = dbClient.gateConditionDao();
   private MetricDao metricDao = dbClient.metricDao();
   private QualityGateConditionsUpdater qualityGateConditionsUpdater = new QualityGateConditionsUpdater(dbClient);
-  private QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient);
+  private QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance());
   private QualityGateFinder qualityGateFinder = new QualityGateFinder(dbClient);
 
-  private RegisterQualityGates underTest = new RegisterQualityGates(dbClient, qualityGateUpdater, qualityGateConditionsUpdater, qualityGateFinder, System2.INSTANCE);
+  private RegisterQualityGates underTest = new RegisterQualityGates(dbClient, qualityGateUpdater, qualityGateConditionsUpdater, qualityGateFinder,
+    UuidFactoryFast.getInstance(), System2.INSTANCE);
 
   @Before
   public void setup() {
@@ -102,7 +105,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void upgrade_empty_quality_gate() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
     dbSession.commit();
 
@@ -117,7 +120,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void upgrade_should_remove_deleted_condition() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
 
     createBuiltInConditions(builtin);
@@ -138,7 +141,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void upgrade_should_add_missing_condition() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
 
     List<QualityGateConditionDto> builtInConditions = createBuiltInConditions(builtin);
@@ -160,7 +163,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void should_set_SonarWay_as_builtin_when_not_set() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(false);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(false).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
 
     createBuiltInConditions(builtin);
@@ -177,7 +180,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void should_not_update_builtin_quality_gate_if_already_uptodate() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
 
     createBuiltInConditions(builtin);
@@ -202,7 +205,7 @@ public class RegisterQualityGatesTest {
   @Test
   public void ensure_only_one_built_in_quality_gate() {
     String qualityGateName = "IncorrectQualityGate";
-    QualityGateDto builtin = new QualityGateDto().setName(qualityGateName).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(qualityGateName).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
     dbSession.commit();
 
@@ -230,7 +233,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void ensure_only_that_builtin_is_set_as_default_when_no_default_quality_gate() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
     dbSession.commit();
 
@@ -246,7 +249,7 @@ public class RegisterQualityGatesTest {
 
   @Test
   public void builtin_quality_gate_with_incorrect_metricId_should_not_throw_an_exception() {
-    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true);
+    QualityGateDto builtin = new QualityGateDto().setName(BUILT_IN_NAME).setBuiltIn(true).setUuid(Uuids.createFast());
     qualityGateDao.insert(dbSession, builtin);
     QualityGateConditionDto conditionDto = new QualityGateConditionDto()
       .setMetricId(-1) // This Id does not exist
index 8e877eac7d9c68213e320d22dda75f7dfd9a7685..aedf83ffdc696b5e349a8de825abed2ec0b6213b 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -53,7 +54,7 @@ public class CreateActionTest {
   private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
   private DbClient dbClient = db.getDbClient();
   private DbSession dbSession = db.getSession();
-  private CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient), defaultOrganizationProvider);
+  private CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance()), defaultOrganizationProvider);
   private WsActionTester ws = new WsActionTester(underTest);
 
   @Test
index 5904f1aff495c117a1e58410acdd40a12e8c4ec4..daf097341aa3e2b0cc7a8e0cccaf7fa87171b1de 100644 (file)
@@ -27,6 +27,8 @@ import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -61,7 +63,7 @@ public class DeselectActionTest {
   private DbClient dbClient = db.getDbClient();
   private DbSession dbSession = db.getSession();
   private TestDefaultOrganizationProvider organizationProvider = TestDefaultOrganizationProvider.from(db);
-  private QualityGates qualityGates = new QualityGates(dbClient, userSession, organizationProvider);
+  private QualityGates qualityGates = new QualityGates(dbClient, userSession, organizationProvider, UuidFactoryFast.getInstance());
   private WsActionTester ws;
   private ComponentDto project;
   private QualityGateDto gate;
@@ -232,7 +234,7 @@ public class DeselectActionTest {
   }
 
   private QualityGateDto insertQualityGate() {
-    QualityGateDto gate = new QualityGateDto().setName("Custom");
+    QualityGateDto gate = new QualityGateDto().setName("Custom").setUuid(Uuids.createFast());
     dbClient.qualityGateDao().insert(dbSession, gate);
     dbSession.commit();
     return gate;
index cfbd5e10c1f66ff3a2469b63c68d2d3e6a8646fd..5a7da83aa671a42605665319cbb350d4c69064c9 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -230,7 +231,7 @@ public class GetByProjectActionTest {
   }
 
   private QualityGateDto insertQualityGate(String name) {
-    QualityGateDto qualityGate = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name));
+    QualityGateDto qualityGate = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name).setUuid(Uuids.createFast()));
     db.commit();
     return qualityGate;
   }
index f6530f7616af4ffdfee07ac37b59e1cd27135e8a..537fadd3bbfa0389ba672ce152d50e40be432121 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
@@ -199,7 +200,7 @@ public class SelectActionTest {
   }
 
   private QualityGateDto insertQualityGate() {
-    QualityGateDto gate = new QualityGateDto().setName("Custom");
+    QualityGateDto gate = new QualityGateDto().setName("Custom").setUuid(Uuids.createFast());
     dbClient.qualityGateDao().insert(dbSession, gate);
     dbSession.commit();
     return gate;