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.v107;
22 import java.sql.SQLException;
23 import org.junit.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.RegisterExtension;
25 import org.sonar.db.MigrationDbTester;
27 import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.DEVOPS_PERMS_MAPPING_TABLE_NAME;
28 import static org.sonar.server.platform.db.migration.version.v107.RenameGithubPermsMappingTable.GITHUB_PERMS_MAPPING_TABLE_NAME;
30 class DropGithubPermsMappingTableIfDevopsPermsMappingTableExistsIT {
33 public static MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropGithubPermsMappingTableIfDevopsPermsMappingTableExists.class);
35 private final DropGithubPermsMappingTableIfDevopsPermsMappingTableExists underTest = new DropGithubPermsMappingTableIfDevopsPermsMappingTableExists(db.database());
38 void execute_givenGithubDevopsPermsMappingTableExistsAndDevopsPermsMappingTableDoesNotExist_doNothing() throws SQLException {
39 db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
40 db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
44 db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
45 db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
49 void execute_givenDevopsPermsMappingTableExistsAndGithubPermsMappingTableDoNotExist_doNothing() throws SQLException {
50 db.executeDdl("CREATE TABLE " + DEVOPS_PERMS_MAPPING_TABLE_NAME + " (id INT PRIMARY KEY)");
51 db.executeDdl("DROP TABLE " + GITHUB_PERMS_MAPPING_TABLE_NAME);
52 db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
53 db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
57 db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
58 db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
62 void execute_givenDevopsPermsMappingTableExistsAndGithubPermsMappingTableExist_dropGithubPermsMappingTable() throws SQLException {
63 db.executeDdl("CREATE TABLE " + DEVOPS_PERMS_MAPPING_TABLE_NAME + " (id INT PRIMARY KEY)");
64 db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
65 db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
69 db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
70 db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
74 void execute_givenDevopsPermsMappingTableDoesNotExistsAndGithubPermsMappingTableDoesNotExist_doNothing() throws SQLException {
75 db.executeDdl("DROP TABLE " + GITHUB_PERMS_MAPPING_TABLE_NAME);
76 db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
77 db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
81 db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
82 db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);