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.activerules;
22 import java.sql.SQLException;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.sonar.db.CoreDbTester;
27 import org.sonar.server.platform.db.migration.step.DataChange;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.assertj.core.api.Assertions.tuple;
32 public class PopulateActiveRulesRuleUuidColumnTest {
35 public CoreDbTester db = CoreDbTester.createForSchema(PopulateActiveRulesRuleUuidColumnTest.class, "schema.sql");
37 private DataChange underTest = new PopulateActiveRulesRuleUuidColumn(db.database());
41 insertRule(1L, "uuid-rule-1");
42 insertRule(2L, "uuid-rule-2");
43 insertRule(3L, "uuid-rule-3");
44 insertRule(4L, "uuid-rule-4");
46 insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
47 insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
48 insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
52 public void add_rule_uuid_column() throws SQLException {
55 assertThat(db.countSql("select count(*) from active_rules"))
57 assertThat(db.select("select uuid, rule_id, rule_uuid from active_rules"))
58 .extracting(m -> m.get("UUID"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
59 .containsExactlyInAnyOrder(
60 tuple("uuid-ar-1", 1L, "uuid-rule-1"),
61 tuple("uuid-ar-2", 1L, "uuid-rule-1"),
62 tuple("uuid-ar-3", 2L, "uuid-rule-2"));
65 private void insertRule(long id, String uuid) {
66 db.executeInsert("rules",
69 "plugin_rule_key", "rk" + id,
70 "plugin_name", "rn" + id,
73 "is_external", false);
76 private void insertActiveRule(String uuid, long ruleId, String profileUuid) {
77 db.executeInsert("active_rules",
80 "profile_uuid", profileUuid,