|
| 1 | +/* |
| 2 | + * SonarQube |
| 3 | + * Copyright (C) 2009-2025 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.v202506; |
| 21 | + |
| 22 | +import java.sql.SQLException; |
| 23 | +import java.sql.Types; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 26 | +import org.sonar.db.MigrationDbTester; |
| 27 | + |
| 28 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_AGGREGATION_ID; |
| 29 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_AGGREGATION_TYPE; |
| 30 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_HOTSPOT_COUNT; |
| 31 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_HOTSPOT_RATING; |
| 32 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_ISSUE_COUNT; |
| 33 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_RATING; |
| 34 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.COLUMN_RULE_KEY; |
| 35 | +import static org.sonar.server.platform.db.migration.version.v202506.CreateIssueStatsByRuleKeyTable.TABLE_NAME; |
| 36 | + |
| 37 | +class CreateIssueStatsByRuleKeyTableTest { |
| 38 | + |
| 39 | + @RegisterExtension |
| 40 | + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateJiraWorkItemsTable.class); |
| 41 | + |
| 42 | + private final CreateIssueStatsByRuleKeyTable underTest = new CreateIssueStatsByRuleKeyTable(db.database()); |
| 43 | + |
| 44 | + @Test |
| 45 | + void migration_should_create_table() throws SQLException { |
| 46 | + db.assertTableDoesNotExist(TABLE_NAME); |
| 47 | + |
| 48 | + underTest.execute(); |
| 49 | + |
| 50 | + db.assertTableExists(TABLE_NAME); |
| 51 | + db.assertPrimaryKey(TABLE_NAME, "pk_issue_stats_by_rule_key", COLUMN_AGGREGATION_TYPE, COLUMN_AGGREGATION_ID, COLUMN_RULE_KEY); |
| 52 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_AGGREGATION_TYPE, Types.VARCHAR, 20, false); |
| 53 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_AGGREGATION_ID, Types.VARCHAR, 40, false); |
| 54 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_RULE_KEY, Types.VARCHAR, 100, false); |
| 55 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_ISSUE_COUNT, Types.INTEGER, null, false); |
| 56 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_RATING, Types.INTEGER, null, false); |
| 57 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_HOTSPOT_COUNT, Types.INTEGER, null, true); |
| 58 | + db.assertColumnDefinition(TABLE_NAME, COLUMN_HOTSPOT_RATING, Types.INTEGER, null, true); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void migration_should_be_reentrant() throws SQLException { |
| 63 | + db.assertTableDoesNotExist(TABLE_NAME); |
| 64 | + |
| 65 | + underTest.execute(); |
| 66 | + underTest.execute(); |
| 67 | + |
| 68 | + db.assertTableExists(TABLE_NAME); |
| 69 | + } |
| 70 | +} |
0 commit comments