123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- * 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.rules;
-
- import java.sql.SQLException;
- import java.util.Objects;
- import java.util.stream.Collectors;
- import org.junit.Before;
- 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;
- import static org.assertj.core.api.Assertions.tuple;
- import static org.mockito.ArgumentMatchers.anyString;
-
- public class PopulateRulesUuidTest {
-
- @Rule
- public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesUuidTest.class, "schema.sql");
-
- private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
- private DataChange underTest = new PopulateRulesUuid(db.database(), uuidFactory);
-
- @Before
- public void setup() {
- insertRule(1L);
- insertRule(2L);
- insertRule(3L);
- insertRule(4L);
- }
-
- @Test
- public void add_rule_uuid_column() throws SQLException {
- underTest.execute();
-
- assertThat(db.countSql("select count(*) from rules"))
- .isEqualTo(4);
- assertThat(db.select("select uuid from rules")
- .stream()
- .map(row -> row.get("UUID"))
- .filter(Objects::isNull)
- .collect(Collectors.toList())).isEmpty();
- }
-
- private void insertRule(long id) {
- db.executeInsert("rules",
- "id", id,
- "plugin_rule_key", "rk" + id,
- "plugin_name", "rn" + id,
- "scope", "MAIN",
- "is_ad_hoc", false,
- "is_external", false);
- }
- }
|