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.v103;
22 import java.sql.SQLException;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.sonar.db.MigrationDbTester;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME;
30 public class PopulateCreationMethodColumnInProjectsTableIT {
33 public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateCreationMethodColumnInProjectsTable.class);
34 private final PopulateCreationMethodColumnInProjectsTable underTest = new PopulateCreationMethodColumnInProjectsTable(db.database());
37 public void execute_whenProjectsTableIsEmpty_shouldDoNothing() throws SQLException {
40 assertThat(db.select("select creation_method from projects")).isEmpty();
44 public void execute_whenProjectsExist_shouldPopulateCreationMethodColumn() throws SQLException {
45 insertProject("uuid-1");
46 insertProject("uuid-2");
50 assertThat(db.select("select creation_method from projects"))
51 .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD"))
52 .containsExactlyInAnyOrder("UNKNOWN", "UNKNOWN");
56 public void execute_isReentrant() throws SQLException {
57 insertProject("uuid-1");
62 assertThat(db.select("select creation_method from projects"))
63 .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD"))
64 .containsExactlyInAnyOrder("UNKNOWN");
67 private void insertProject(String uuid) {
68 db.executeInsert(PROJECTS_TABLE_NAME,