private static final long METRIC_ID_2 = 753;
private static final Metric METRIC_1 = mock(Metric.class);
private static final Metric METRIC_2 = mock(Metric.class);
- private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setId(321).setMetricId(METRIC_ID_1).setOperator("LT")
+ private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricId(METRIC_ID_1).setOperator("LT")
+ .setErrorThreshold("error_th");
+ private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricId(METRIC_ID_2).setOperator("GT")
.setErrorThreshold("error_th");
- private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setId(456).setMetricId(METRIC_ID_2).setOperator("GT").setErrorThreshold("error_th");
private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
private QualityGateConditionDao qualityGateConditionDao = mock(QualityGateConditionDao.class);
return mapper(session).selectForQualityGate(qGateId);
}
- public QualityGateConditionDto selectById(long id, DbSession session) {
- return mapper(session).selectById(id);
+ public QualityGateConditionDto selectByUuid(String uuid, DbSession session) {
+ return mapper(session).selectByUuid(uuid);
}
public void delete(QualityGateConditionDto qGate, DbSession session) {
- mapper(session).delete(qGate.getId());
+ mapper(session).delete(qGate.getUuid());
}
public void update(QualityGateConditionDto qGate, DbSession session) {
public static final String OPERATOR_GREATER_THAN = "GT";
public static final String OPERATOR_LESS_THAN = "LT";
- private long id;
+ private String uuid;
private long qualityGateId;
private Date updatedAt;
- public long getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public QualityGateConditionDto setId(long id) {
- this.id = id;
+ public QualityGateConditionDto setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
void update(QualityGateConditionDto newCondition);
- QualityGateConditionDto selectById(long id);
+ QualityGateConditionDto selectByUuid(String uuid);
- void delete(long id);
+ void delete(String uuid);
void deleteConditionsWithInvalidMetrics();
}
<mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper">
- <insert id="insert" parameterType="QualityGateCondition" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- insert into quality_gate_conditions (qgate_id, metric_id, operator, value_error, created_at, updated_at)
- values (#{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
+ <insert id="insert" parameterType="QualityGateCondition">
+ insert into quality_gate_conditions (uuid, qgate_id, metric_id, operator, value_error, created_at, updated_at)
+ values (#{uuid}, #{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
</insert>
<sql id="conditionColumns">
- id, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
+ uuid, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
created_at as createdAt, updated_at as updatedAt
</sql>
order by created_at asc
</select>
- <select id="selectById" parameterType="long" resultType="QualityGateCondition">
+ <select id="selectByUuid" parameterType="String" resultType="QualityGateCondition">
select
<include refid="conditionColumns"/>
- from quality_gate_conditions where id=#{id}
+ from quality_gate_conditions where uuid=#{uuid}
</select>
- <update id="delete" parameterType="long">
- delete from quality_gate_conditions where id=#{id}
+ <update id="delete" parameterType="String">
+ delete from quality_gate_conditions where uuid=#{uuid}
</update>
<update id="update" parameterType="QualityGateCondition">
operator=#{operator},
value_error=#{errorThreshold},
updated_at=#{updatedAt}
- where id=#{id}
+ where uuid=#{uuid}
</update>
<delete id="deleteConditionsWithInvalidMetrics">
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;
import org.sonar.db.metric.MetricDto;
public void testInsert() {
QualityGateConditionDto newCondition = insertQGCondition(1L, 2L, "GT", "20");
- assertThat(newCondition.getId()).isNotNull();
- QualityGateConditionDto actual = underTest.selectById(newCondition.getId(), dbSession);
+ assertThat(newCondition.getUuid()).isNotNull();
+ QualityGateConditionDto actual = underTest.selectByUuid(newCondition.getUuid(), dbSession);
assertEquals(actual, newCondition);
}
Collection<QualityGateConditionDto> conditions = underTest.selectForQualityGate(dbSession, qg1Id);
assertThat(conditions).hasSize(qg1Conditions);
assertThat(conditions)
- .extracting("id")
+ .extracting("uuid")
.containsExactly(conditions.stream()
.sorted(Comparator.comparing(QualityGateConditionDto::getCreatedAt))
- .map(QualityGateConditionDto::getId).toArray());
+ .map(QualityGateConditionDto::getUuid).toArray());
conditions = underTest.selectForQualityGate(dbSession, qg2Id);
assertThat(conditions).hasSize(qg2Conditions);
assertThat(conditions)
- .extracting("id")
+ .extracting("uuid")
.containsExactly(conditions.stream()
.sorted(Comparator.comparing(QualityGateConditionDto::getCreatedAt))
- .map(QualityGateConditionDto::getId)
+ .map(QualityGateConditionDto::getUuid)
.toArray());
assertThat(underTest.selectForQualityGate(dbSession, 5)).isEmpty();
}
@Test
- public void testSelectById() {
+ public void testSelectByUuid() {
QualityGateConditionDto condition = insertQGCondition(1L, 2L, "GT", "20");
- assertEquals(underTest.selectById(condition.getId(), dbSession), condition);
- assertThat(underTest.selectById(42L, dbSession)).isNull();
+ assertEquals(underTest.selectByUuid(condition.getUuid(), dbSession), condition);
+ assertThat(underTest.selectByUuid("uuid1", dbSession)).isNull();
}
@Test
underTest.delete(condition1, dbSession);
dbSession.commit();
- assertThat(underTest.selectById(condition1.getId(), dbSession)).isNull();
- assertThat(underTest.selectById(condition2.getId(), dbSession)).isNotNull();
+ assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNull();
+ assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNotNull();
}
@Test
QualityGateConditionDto condition2 = insertQGCondition(3L);
QualityGateConditionDto newCondition1 = new QualityGateConditionDto()
- .setId(condition1.getId())
+ .setUuid(condition1.getUuid())
.setQualityGateId(condition1.getQualityGateId())
.setMetricId(7L)
.setOperator(">")
dbSession.commit();
- assertEquals(underTest.selectById(condition1.getId(), dbSession), newCondition1);
- assertEquals(underTest.selectById(condition2.getId(), dbSession), condition2);
+ assertEquals(underTest.selectByUuid(condition1.getUuid(), dbSession), newCondition1);
+ assertEquals(underTest.selectByUuid(condition2.getUuid(), dbSession), condition2);
}
@Test
dbTester.commit();
- assertThat(underTest.selectById(condition1.getId(), dbSession)).isNotNull();
- assertThat(underTest.selectById(condition2.getId(), dbSession)).isNull();
- assertThat(underTest.selectById(condition3.getId(), dbSession)).isNull();
+ assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNotNull();
+ assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNull();
+ assertThat(underTest.selectByUuid(condition3.getUuid(), dbSession)).isNull();
}
private QualityGateConditionDto insertQGCondition(long qualityGateId) {
private QualityGateConditionDto insertQGCondition(long qualityGateId, long metricId, String operator, String threshold) {
QualityGateConditionDto res = new QualityGateConditionDto()
+ .setUuid(Uuids.create())
.setQualityGateId(qualityGateId)
.setMetricId(metricId)
.setOperator(operator)
@SafeVarargs
public final QualityGateConditionDto addCondition(QualityGateDto qualityGate, MetricDto metric, Consumer<QualityGateConditionDto>... dtoPopulators) {
QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
+ .setUuid(Uuids.createFast())
.setMetricId(metric.getId())
.setOperator("GT")
.setErrorThreshold(randomNumeric(10));
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("quality_gate_conditions", "uuid").build());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToQualityGateConditionsTable extends AddUuidColumnToTable {
+ private static final String TABLE = "quality_gate_conditions";
+
+ public AddUuidColumnToQualityGateConditionsTable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;
+
+public class DropIdColumnOfQualityGateConditionsTable extends DropIdColumn {
+ private static final String TABLE = "quality_gate_conditions";
+
+ public DropIdColumnOfQualityGateConditionsTable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable extends DropPrimaryKeyOnIdColumn {
+ private static final String TABLE_NAME = "quality_gate_conditions";
+
+ public DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;
+
+public class MakeQualityGateConditionsUuidColumnNotNullable extends MakeUuidColumnNotNullable {
+ private static final String TABLE = "quality_gate_conditions";
+
+ public MakeQualityGateConditionsUuidColumnNotNullable(Database db) {
+ super(db, TABLE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+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 PopulateQualityGateConditionsUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateQualityGateConditionsUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from quality_gate_conditions where uuid is null order by id asc");
+ massUpdate.update("update quality_gate_conditions set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("quality_gate_conditions", "pk_quality_gate_conditions", "uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToQualityGateConditionsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToQualityGateConditionsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddUuidColumnToQualityGateConditionsTable(db.database());
+
+ private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
+
+ @Before
+ public void setup() {
+ insertQualityGateCondition(1L);
+ insertQualityGateCondition(2L);
+ insertQualityGateCondition(3L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("quality_gate_conditions", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("quality_gate_conditions"))
+ .isEqualTo(3);
+ }
+
+ private void insertQualityGateCondition(Long id) {
+ db.executeInsert("quality_gate_conditions",
+ "id", id,
+ "qgate_id", id + 1,
+ "period", id + 2);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfQualityGateConditionsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropIdColumnOfQualityGateConditionsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("quality_gate_conditions", "id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest {
+
+ private static final String TABLE_NAME = "quality_gate_conditions";
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+ private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+ private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable(db.database(), dropPrimaryKeySqlGenerator);
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertNoPrimaryKey(TABLE_NAME);
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeQualityGateConditionsUuidColumnNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeQualityGateConditionsUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeQualityGateConditionsUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_nullable() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("quality_gate_conditions", "uuid", VARCHAR, null, false);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateQualityGateConditionsUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateQualityGateConditionsUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateQualityGateConditionsUuid(db.database(), uuidFactory);
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertQualityGateCondition(1L);
+ insertQualityGateCondition(2L);
+ insertQualityGateCondition(3L);
+
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertQualityGateCondition(1L);
+ insertQualityGateCondition(2L);
+ insertQualityGateCondition(3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ private void verifyUuidsAreNotNull() {
+ assertThat(db.select("select uuid from quality_gate_conditions")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertQualityGateCondition(Long id) {
+ db.executeInsert("quality_gate_conditions",
+ "id", id,
+ "uuid", uuidFactory.create(),
+ "qgate_id", id + 1,
+ "period", id + 2);
+ }
+}
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
--- /dev/null
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID");
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.measures.Metric.ValueType;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.metric.MetricDto;
checkConditionDoesNotExistOnSameMetric(getConditions(dbSession, qualityGate.getId()), metric);
QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
+ .setUuid(Uuids.create())
.setMetricId(metric.getId()).setMetricKey(metric.getKey())
.setOperator(operator)
.setErrorThreshold(errorThreshold);
package org.sonar.server.qualitygate;
import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())) {
dbClient.gateConditionDao().insert(new QualityGateConditionDto()
+ .setUuid(Uuids.create())
.setQualityGateId(destinationGate.getId())
.setMetricId(sourceCondition.getMetricId())
.setOperator(sourceCondition.getOperator())
}
private static class QualityGateCondition {
- private Long id;
+ private String uuid;
private String metricKey;
private String operator;
private String errorThreshold;
public static QualityGateCondition from(QualityGateConditionDto qualityGateConditionDto, Map<Long, String> mapping) {
return new QualityGateCondition()
- .setId(qualityGateConditionDto.getId())
+ .setUuid(qualityGateConditionDto.getUuid())
.setMetricKey(mapping.get(qualityGateConditionDto.getMetricId()))
.setOperator(qualityGateConditionDto.getOperator())
.setErrorThreshold(qualityGateConditionDto.getErrorThreshold());
}
@CheckForNull
- public Long getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public QualityGateCondition setId(Long id) {
- this.id = id;
+ public QualityGateCondition setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
public QualityGateConditionDto toQualityGateDto(long qualityGateId) {
return new QualityGateConditionDto()
- .setId(id)
+ .setUuid(uuid)
.setMetricKey(metricKey)
.setOperator(operator)
.setErrorThreshold(errorThreshold)
wsSupport.checkCanEdit(qualityGate);
QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, error);
CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder()
- .setId(condition.getId())
+ // TODO
+ //.setId(condition.getUuid())
.setMetric(condition.getMetricKey())
.setError(condition.getErrorThreshold())
.setOp(condition.getOperator());
@Override
public void handle(Request request, Response response) {
- long conditionId = request.mandatoryParamAsLong(PARAM_ID);
+ // TODO
+ String conditionUuid = request.mandatoryParam(PARAM_ID);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
- QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionId);
+ QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionUuid);
QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId());
- checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionId, condition.getQualityGateId());
+ checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionUuid, condition.getQualityGateId());
wsSupport.checkCanEdit(qualityGateDto);
dbClient.gateConditionDao().delete(condition, dbSession);
"No quality gate has been found for id %s in organization %s", qualityGateId, organization.getName());
}
- QualityGateConditionDto getCondition(DbSession dbSession, long id) {
- return checkFound(dbClient.gateConditionDao().selectById(id, dbSession), "No quality gate condition with id '%d'", id);
+ QualityGateConditionDto getCondition(DbSession dbSession, String uuid) {
+ return checkFound(dbClient.gateConditionDao().selectByUuid(uuid, dbSession), "No quality gate condition with uuid '%s'", uuid);
}
boolean isQualityGateAdmin(OrganizationDto organization) {
MetricDto metric = metricsById.get(metricId);
checkState(metric != null, "Could not find metric with id %s", metricId);
ShowWsResponse.Condition.Builder builder = ShowWsResponse.Condition.newBuilder()
- .setId(condition.getId())
+ // TODO
+ //.setId(condition.getUuid())
.setMetric(metric.getKey())
.setOp(condition.getOperator());
ofNullable(condition.getErrorThreshold()).ifPresent(builder::setError);
@Override
public void handle(Request request, Response response) {
- int id = request.mandatoryParamAsInt(PARAM_ID);
+ String id = request.mandatoryParam(PARAM_ID);
String metric = request.mandatoryParam(PARAM_METRIC);
String operator = request.mandatoryParam(PARAM_OPERATOR);
String error = request.mandatoryParam(PARAM_ERROR);
wsSupport.checkCanEdit(qualityGateDto);
QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, error);
UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder()
- .setId(updatedCondition.getId())
+ // TODO
+ // .setId(updatedCondition.getUuid())
.setMetric(updatedCondition.getMetricKey())
.setError(updatedCondition.getErrorThreshold())
.setOp(updatedCondition.getOperator());
}
private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
- QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectById(dto.getId(), db.getSession());
+ QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectByUuid(dto.getUuid(), db.getSession());
assertThat(reloaded.getQualityGateId()).isEqualTo(qualityGate.getId());
assertThat(reloaded.getMetricId()).isEqualTo(metric.getId().longValue());
assertThat(reloaded.getOperator()).isEqualTo(operator);
public void builtin_quality_gate_with_incorrect_metricId_should_not_throw_an_exception() {
insertMetrics();
QualityGateConditionDto conditionDto = new QualityGateConditionDto()
+ .setUuid(Uuids.createFast())
.setMetricId(-1) // This Id does not exist
.setOperator(OPERATOR_GREATER_THAN)
.setErrorThreshold("1");
.executeProtobuf(CreateConditionResponse.class);
QualityGateConditionDto condition = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())).get(0);
- assertThat(response.getId()).isEqualTo(condition.getId());
+ assertThat(response.getId()).isEqualTo(condition.getUuid());
assertThat(response.getMetric()).isEqualTo(metric.getKey());
assertThat(response.getOp()).isEqualTo("LT");
assertThat(response.getError()).isEqualTo("45");
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
-import static java.lang.String.valueOf;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
ws.newRequest()
- .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+ .setParam(PARAM_ID, qualityGateCondition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
ws.newRequest()
- .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+ .setParam(PARAM_ID, qualityGateCondition.getUuid())
.execute();
assertThat(searchConditionsOf(qualityGate)).isEmpty();
QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
TestResponse result = ws.newRequest()
- .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+ .setParam(PARAM_ID, qualityGateCondition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName()));
ws.newRequest()
- .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+ .setParam(PARAM_ID, qualityGateCondition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
}
expectedException.expect(ForbiddenException.class);
ws.newRequest()
- .setParam(PARAM_ID, valueOf(qualityGateCondition.getId()))
+ .setParam(PARAM_ID, qualityGateCondition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
}
@Test
- public void fail_if_condition_id_is_not_found() {
+ public void fail_if_condition_uuid_is_not_found() {
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
MetricDto metric = db.measures().insertMetric();
QualityGateConditionDto qualityGateCondition = db.qualityGates().addCondition(qualityGate, metric);
- long unknownConditionId = qualityGateCondition.getId() + 42L;
+ String unknownConditionUuid = "unknown";
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("No quality gate condition with id '" + unknownConditionId + "'");
+ expectedException.expectMessage("No quality gate condition with uuid '" + unknownConditionUuid + "'");
ws.newRequest()
- .setParam(PARAM_ID, valueOf(unknownConditionId))
+ .setParam(PARAM_ID, unknownConditionUuid)
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
}
public void fail_when_condition_match_unknown_quality_gate() {
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
- QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(123L);
+ QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
db.getDbClient().gateConditionDao().insert(condition, db.getSession());
db.commit();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), 123L));
+ expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), 123L));
ws.newRequest()
- .setParam(PARAM_ID, valueOf(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
}
QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), qualityGate.getId()));
+ expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), qualityGate.getId()));
ws.newRequest()
- .setParam(PARAM_ID, valueOf(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_ORGANIZATION, organization.getKey())
.execute();
}
assertThat(response.getConditionsList())
.extracting(Condition::getId, Condition::getMetric, Condition::getOp, Condition::getError)
.containsExactlyInAnyOrder(
- tuple(condition1.getId(), metric1.getKey(), "GT", condition1.getErrorThreshold()),
- tuple(condition2.getId(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
+ tuple(condition1.getUuid(), metric1.getKey(), "GT", condition1.getErrorThreshold()),
+ tuple(condition2.getUuid(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
}
@Test
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "90")
QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric);
ws.newRequest()
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "10")
CreateConditionResponse response = ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "45")
.executeProtobuf(CreateConditionResponse.class);
- assertThat(response.getId()).isEqualTo(condition.getId());
+ assertThat(response.getId()).isEqualTo(condition.getUuid());
assertThat(response.getMetric()).isEqualTo(metric.getKey());
assertThat(response.getOp()).isEqualTo("LT");
assertThat(response.getError()).isEqualTo("45");
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "10")
db.qualityGates().addCondition(qualityGate, metric);
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("No quality gate condition with id '123'");
+ expectedException.expectMessage("No quality gate condition with uuid '123'");
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
MetricDto metric = insertMetric();
- QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(123L);
+ QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
db.getDbClient().gateConditionDao().insert(condition, dbSession);
db.commit();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getId(), 123L));
+ expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), 123L));
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID,condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "90")
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "ABC")
.setParam(PARAM_ERROR, "90")
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, updateOperator)
.setParam(PARAM_ERROR, "90")
ws.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
- .setParam(PARAM_ID, Long.toString(condition.getId()))
+ .setParam(PARAM_ID, condition.getUuid())
.setParam(PARAM_METRIC, metric.getKey())
.setParam(PARAM_OPERATOR, "LT")
.setParam(PARAM_ERROR, "90")