]> source.dussan.org Git - sonarqube.git/blob
dca7661cfbe02d9aa3fcae86fa959ef79222a176
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2024 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.platform.db.migration.version.v107;
21
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;
26
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;
29
30 class DropGithubPermsMappingTableIfDevopsPermsMappingTableExistsIT {
31
32   @RegisterExtension
33   public static MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropGithubPermsMappingTableIfDevopsPermsMappingTableExists.class);
34
35   private final DropGithubPermsMappingTableIfDevopsPermsMappingTableExists underTest = new DropGithubPermsMappingTableIfDevopsPermsMappingTableExists(db.database());
36
37   @Test
38   void execute_givenGithubDevopsPermsMappingTableExistsAndDevopsPermsMappingTableDoesNotExist_doNothing() throws SQLException {
39     db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
40     db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
41
42     underTest.execute();
43
44     db.assertTableExists(GITHUB_PERMS_MAPPING_TABLE_NAME);
45     db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
46   }
47
48   @Test
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);
54
55     underTest.execute();
56
57     db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
58     db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
59   }
60
61   @Test
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);
66
67     underTest.execute();
68
69     db.assertTableExists(DEVOPS_PERMS_MAPPING_TABLE_NAME);
70     db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
71   }
72
73   @Test
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);
78
79     underTest.execute();
80
81     db.assertTableDoesNotExist(DEVOPS_PERMS_MAPPING_TABLE_NAME);
82     db.assertTableDoesNotExist(GITHUB_PERMS_MAPPING_TABLE_NAME);
83   }
84
85 }