3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.db.migration.version.v108;
22 import java.sql.SQLException;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.extension.RegisterExtension;
26 import org.sonar.core.util.UuidFactoryImpl;
27 import org.sonar.db.MigrationDbTester;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.assertj.core.api.Assertions.tuple;
32 class CreateNewSoftwareQualityMetricsIT {
34 public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateNewSoftwareQualityMetrics.class);
35 private final CreateNewSoftwareQualityMetrics underTest = new CreateNewSoftwareQualityMetrics(db.database(), UuidFactoryImpl.INSTANCE);
38 void execute_shouldCreateMetrics() throws SQLException {
39 assertThat(db.select("select name,direction,qualitative,enabled,best_value,optimized_best_value,delete_historical_data from metrics"))
42 assertThat(db.select("select name,direction,qualitative,enabled,best_value,optimized_best_value,delete_historical_data from metrics"))
44 .extracting(s -> s.get("name"), s -> s.get("direction"), s -> s.get("qualitative"), s -> s.get("enabled"), s -> s.get("best_value"), s -> s.get("optimized_best_value"),
45 s -> s.get("delete_historical_data"))
46 .containsExactlyInAnyOrder(
47 tuple("software_quality_reliability_issues", -1L, false, true, 0.0, true, false),
48 tuple("software_quality_security_issues", -1L, false, true, 0.0, true, false),
49 tuple("new_software_quality_reliability_issues", -1L, true, true, 0.0, true, true),
50 tuple("new_software_quality_security_issues", -1L, true, true, 0.0, true, true),
51 tuple("new_software_quality_maintainability_issues", -1L, true, true, 0.0, true, true),
52 tuple("software_quality_maintainability_issues", -1L, false, true, 0.0, true, false));
56 void execute_shouldBeReentrant() throws SQLException {
59 assertThat(db.select("select name,direction,qualitative,enabled,best_value,optimized_best_value,delete_historical_data from metrics"))
64 void execute_whenOnlyOneMetricExists_shouldCreateOtherOnes() throws SQLException {
65 String existingMetricUuid = insertMetric("software_quality_security_issues");
68 assertThat(db.select("select uuid from metrics"))
70 .extracting(e -> e.get("uuid"))
71 .contains(existingMetricUuid);
74 private String insertMetric(String key) {
75 String uuid = UuidFactoryImpl.INSTANCE.create();
76 Map<String, Object> map = Map.ofEntries(
77 Map.entry("UUID", uuid),
78 Map.entry("NAME", key));
79 db.executeInsert("metrics", map);