3 * Copyright (C) 2009-2020 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.v84.rules.issues;
22 import java.sql.SQLException;
23 import javax.annotation.Nullable;
24 import org.junit.Before;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.sonar.db.CoreDbTester;
28 import org.sonar.server.platform.db.migration.step.DataChange;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.assertj.core.api.Assertions.tuple;
33 public class PopulateIssuesRuleUuidColumnTest {
36 public CoreDbTester db = CoreDbTester.createForSchema(PopulateIssuesRuleUuidColumnTest.class, "schema.sql");
38 private DataChange underTest = new PopulateIssuesRuleUuidColumn(db.database());
42 insertRule(1L, "uuid-rule-1");
43 insertRule(2L, "uuid-rule-2");
44 insertRule(3L, "uuid-rule-3");
45 insertRule(4L, "uuid-rule-4");
47 insertIssue("kee-iss-1", 1L);
48 insertIssue("kee-iss-2", 1L);
49 insertIssue("kee-iss-3", 2L);
50 insertIssue("kee-iss-4", null);
51 insertIssue("kee-iss-5", null);
55 public void add_rule_uuid_column() throws SQLException {
58 assertThat(db.countSql("select count(*) from issues")).isEqualTo(5);
59 assertThat(db.select("select kee, rule_id, rule_uuid from issues"))
60 .extracting(m -> m.get("KEE"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
61 .containsExactlyInAnyOrder(
62 tuple("kee-iss-1", 1L, "uuid-rule-1"),
63 tuple("kee-iss-2", 1L, "uuid-rule-1"),
64 tuple("kee-iss-3", 2L, "uuid-rule-2"),
65 tuple("kee-iss-4", null, null),
66 tuple("kee-iss-5", null, null));
69 private void insertRule(long id, String uuid) {
70 db.executeInsert("rules",
73 "plugin_rule_key", "rk" + id,
74 "plugin_name", "rn" + id,
77 "is_external", false);
80 private void insertIssue(String kee, @Nullable Long ruleId) {
81 db.executeInsert("issues",
84 "manual_severity", false);