From f81a11d995da5cb0493ce5ea1dbb81dbf862f0ca Mon Sep 17 00:00:00 2001 From: Léo Geoffroy Date: Thu, 16 Nov 2023 18:02:00 +0100 Subject: SONAR-21002 Move db-migration tests to ITs --- .../db/migration/charset/SelectExecutorIT.java | 57 ++ .../db/migration/charset/SqlExecutorIT.java | 72 +++ .../migration/history/MigrationHistoryImplIT.java | 91 ++++ .../history/MigrationHistoryTableImplIT.java | 79 +++ .../history/NoTableMigrationHistoryImplIT.java | 46 ++ .../db/migration/sql/CreateTableBuilderIT.java | 132 +++++ .../sql/DbPrimaryKeyConstraintFinderIT.java | 102 ++++ .../platform/db/migration/step/DataChangeIT.java | 594 +++++++++++++++++++++ .../step/ForceReloadingOfAllPluginsIT.java | 88 +++ .../version/v00/CreateInitialSchemaIT.java | 142 +++++ .../version/v00/PopulateInitialSchemaIT.java | 236 ++++++++ .../version/v100/AddNclocToProjectsIT.java | 54 ++ .../version/v100/CreateScimGroupsTableIT.java | 60 +++ .../v100/CreateUniqueIndexForScimGroupsUuidIT.java | 55 ++ .../v100/DropBModuleUuidInComponentsIT.java | 51 ++ .../v100/DropBModuleUuidPathInComponentsIT.java | 51 ++ .../DropIndexProjectsModuleUuidInComponentsIT.java | 61 +++ .../DropIndexProjectsRootUuidInComponentsIT.java | 51 ++ .../version/v100/DropModuleUuidInComponentsIT.java | 51 ++ .../v100/DropModuleUuidPathInComponentsIT.java | 51 ++ .../version/v100/DropRootUuidInComponentsIT.java | 51 ++ .../version/v100/DropScimUserProvisioningIT.java | 63 +++ .../v100/DropSonarScimEnabledPropertyIT.java | 63 +++ ...MessageIfSonarScimEnabledPresentPropertyIT.java | 91 ++++ .../MakeColumnUserLocalNotNullableInUsersIT.java | 51 ++ .../v100/PopulateNclocForForProjectsIT.java | 144 +++++ .../RemoveOrphanRulesFromQualityProfilesIT.java | 128 +++++ .../v100/UpdateUserLocalValueInUsersIT.java | 95 ++++ .../v101/AddCodeVariantsColumnInIssuesTableIT.java | 53 ++ .../v101/AddIsMainColumnInProjectBranchesIT.java | 52 ++ .../version/v101/AddReportSchedulesTableIT.java | 65 +++ .../v101/AddReportSubscriptionsTableIT.java | 63 +++ .../v101/AlterIsMainColumnInProjectBranchesIT.java | 52 ++ .../version/v101/CreateExternalGroupsTableIT.java | 66 +++ .../v101/CreateIndexForEmailOnUsersTableIT.java | 52 ++ ...eateIndexForScmAccountOnScmAccountsTableIT.java | 52 ++ ...ternalIdAndIdentityOnExternalGroupsTableIT.java | 56 ++ .../v101/CreateProjectUuidInUserTokensIT.java | 51 ++ .../version/v101/CreateScmAccountsTableIT.java | 63 +++ ...CreateUniqueIndexForReportSchedulesTableIT.java | 54 ++ ...teUniqueIndexForReportSubscriptionsTableIT.java | 55 ++ .../version/v101/DropProjectKeyInUserTokensIT.java | 51 ++ .../version/v101/DropScmAccountsInUsersIT.java | 52 ++ .../v101/FixDifferentUuidsForSubportfoliosIT.java | 165 ++++++ ...ncreaseKeeColumnSizeInInternalPropertiesIT.java | 52 ++ .../IncreaseTaskTypeColumnSizeInCeActivityIT.java | 52 ++ .../IncreaseTaskTypeColumnSizeInCeQueueIT.java | 52 ++ ...MigrateScmAccountsFromUsersToScmAccountsIT.java | 183 +++++++ .../v101/PopulateProjectUuidInUserTokensIT.java | 112 ++++ .../version/v101/PopulateReportSchedulesIT.java | 123 +++++ .../v101/PopulateReportSubscriptionsIT.java | 121 +++++ .../version/v101/RemoveOrphanUserTokensIT.java | 98 ++++ .../version/v101/RemoveReportPropertiesIT.java | 81 +++ .../RenameColumnComponentUuidInPropertiesIT.java | 52 ++ .../UpdateIsMainColumnInProjectBranchesIT.java | 105 ++++ .../v102/AddCleanCodeAttributeInRulesIT.java | 51 ++ ...tRequiredIfGithubAutoProvisioningEnabledIT.java | 105 ++++ .../v102/CreateAnticipatedTransitionsTableIT.java | 70 +++ .../CreateBooleanPurgedColumnInSnapshotsIT.java | 53 ++ .../CreateGithubOrganizationsGroupsTableIT.java | 61 +++ .../CreateIndexCreatedAtInWebhookDeliveriesIT.java | 54 ++ .../v102/CreateIndexEntityUuidInCeActivityIT.java | 48 ++ .../v102/CreateIndexEntityUuidInCeQueueIT.java | 48 ++ .../v102/CreateIndexEntityUuidInGroupRolesIT.java | 48 ++ .../v102/CreateIndexEntityUuidInUserRolesIT.java | 48 ++ ...xProjectUuidCreatedAtInWebhookDeliveriesIT.java | 53 ++ .../CreateIndexProjectUuidInProjectBranchesIT.java | 50 ++ .../CreateIndexRootComponentUuidInSnapshotsIT.java | 50 ++ ...ndexTaskUuidCreatedAtInWebhookDeliveriesIT.java | 53 ++ ...xWebhookUuidCreatedAtInWebhookDeliveriesIT.java | 54 ++ .../version/v102/CreateIssueImpactsTableIT.java | 60 +++ ...reviousNonCompliantValueInNewCodePeriodsIT.java | 53 ++ .../v102/CreateRulesDefaultImpactsTableIT.java | 61 +++ .../CreateUniqueConstraintOnIssuesImpactsIT.java | 50 ++ ...ateUniqueConstraintOnRulesDefaultImpactsIT.java | 51 ++ .../v102/DropIndexComponentUuidInGroupRolesIT.java | 62 +++ .../v102/DropIndexComponentUuidInSnapshotsIT.java | 57 ++ .../v102/DropIndexComponentUuidInUserRolesIT.java | 62 +++ ...ropIndexComponentUuidInWebhookDeliveriesIT.java | 57 ++ .../DropIndexMainComponentUuidInCeActivityIT.java | 57 ++ .../DropIndexMainComponentUuidInCeQueueIT.java | 57 ++ .../v102/DropIndexOnMainBranchProjectUuidIT.java | 51 ++ .../DropIndexProjectUuidInWebhookDeliveriesIT.java | 61 +++ .../DropIndexTaskUuidInWebhookDeliveriesIT.java | 56 ++ .../DropIndexWebhookUuidInWebhookDeliveriesIT.java | 57 ++ .../DropMainBranchProjectUuidInComponentsIT.java | 52 ++ .../v102/DropPurgeStatusColumnInSnapshotsIT.java | 53 ++ .../version/v102/DropTableProjectMappingsIT.java | 50 ++ .../v102/FixSqaleIndexMetricDescriptionIT.java | 65 +++ .../v102/IncreaseIsLastKeyInCeActivityIT.java | 53 ++ .../v102/IncreaseMainIsLastKeyInCeActivityIT.java | 53 ++ ...ojectUuidNullableInUserDismissedMessagesIT.java | 53 ++ .../MakePurgedColumnNotNullableInSnapshotsIT.java | 52 ++ .../PopulateCleanCodeAttributeColumnInRulesIT.java | 110 ++++ .../v102/PopulateDefaultImpactsInRulesIT.java | 221 ++++++++ .../v102/PopulatePurgedColumnInSnapshotsIT.java | 72 +++ .../version/v102/RenameBuildDateInSnapshotsIT.java | 55 ++ .../v102/RenameComponentUuidInGroupRolesIT.java | 51 ++ .../v102/RenameComponentUuidInSnapshotsIT.java | 51 ++ .../v102/RenameComponentUuidInUserRolesIT.java | 51 ++ .../RenameComponentUuidInWebhookDeliveriesIT.java | 60 +++ .../RenameMainComponentUuidInCeActivityIT.java | 51 ++ .../v102/RenameMainComponentUuidInCeQueueIT.java | 51 ++ ...reviousNonCompliantValueInNewCodePeriodsIT.java | 69 +++ ...AddCleanCodeAttributeColumnInIssuesTableIT.java | 50 ++ .../AddCreationMethodColumnInProjectsTableIT.java | 50 ++ ...ddRuleChangesUuidColumnInQProfileChangesIT.java | 52 ++ ...AddSqVersionColumnInQprofileChangesTableIT.java | 51 ++ .../CreateGithubPermissionsMappingTableIT.java | 61 +++ .../CreateIndexForRuleImpactChangesTableIT.java | 53 ++ .../version/v103/CreateRuleChangesTableIT.java | 63 +++ .../v103/CreateRuleImpactChangesTableIT.java | 65 +++ ...queIndexForGithubPermissionsMappingTableIT.java | 53 ++ .../CreateUniqueIndexForPropertiesTableIT.java | 54 ++ .../version/v103/DeduplicatePropertiesTableIT.java | 109 ++++ ...reationMethodColumnInProjectsNotNullableIT.java | 50 ++ ...ulateCreationMethodColumnInProjectsTableIT.java | 75 +++ .../v103/PopulateGithubPermissionsMappingIT.java | 99 ++++ ...AllowQualityProfileDisableInheritedRulesIT.java | 79 +++ ...leteRedundantFailedAlertsForApplicationsIT.java | 157 ++++++ .../version/v104/RenameWontFixIssuesMetricIT.java | 83 +++ .../charset/SelectExecutorIT/users_table.sql | 4 + .../charset/SqlExecutorIT/users_table.sql | 5 + .../MigrationHistoryImplIT/schema_migration.sql | 4 + .../history/MigrationHistoryTableImplIT/empty.sql | 0 .../NoTableMigrationHistoryImplIT/empty.sql | 0 .../sql/DbPrimaryKeyConstraintFinderIT/schema.sql | 4 + .../db/migration/step/DataChangeIT/schema.sql | 14 + .../step/ForceReloadingOfAllPluginsIT/schema.sql | 12 + .../schema.sql | 9 + .../DropIndexComponentUuidInUserRolesIT/schema.sql | 9 + .../schema.sql | 19 + .../db/migration/charset/SelectExecutorTest.java | 57 -- .../db/migration/charset/SqlExecutorTest.java | 72 --- .../history/MigrationHistoryImplTest.java | 91 ---- .../history/MigrationHistoryTableImplTest.java | 79 --- .../history/NoTableMigrationHistoryImplTest.java | 46 -- .../sql/CreateTableBuilderDbTesterTest.java | 132 ----- .../sql/DbPrimaryKeyConstraintFinderTest.java | 102 ---- .../platform/db/migration/step/DataChangeTest.java | 594 --------------------- .../step/ForceReloadingOfAllPluginsTest.java | 88 --- .../version/v00/CreateInitialSchemaTest.java | 142 ----- .../version/v00/PopulateInitialSchemaTest.java | 236 -------- .../version/v100/AddNclocToProjectsTest.java | 54 -- .../version/v100/CreateScimGroupsTableTest.java | 60 --- .../CreateUniqueIndexForScimGroupsUuidTest.java | 55 -- .../v100/DropBModuleUuidInComponentsTest.java | 51 -- .../v100/DropBModuleUuidPathInComponentsTest.java | 51 -- ...ropIndexProjectsModuleUuidInComponentsTest.java | 61 --- .../DropIndexProjectsRootUuidInComponentsTest.java | 51 -- .../v100/DropModuleUuidInComponentsTest.java | 51 -- .../v100/DropModuleUuidPathInComponentsTest.java | 51 -- .../version/v100/DropRootUuidInComponentsTest.java | 51 -- .../version/v100/DropScimUserProvisioningTest.java | 63 --- .../v100/DropSonarScimEnabledPropertyTest.java | 63 --- ...ssageIfSonarScimEnabledPresentPropertyTest.java | 91 ---- .../MakeColumnUserLocalNotNullableInUsersTest.java | 51 -- .../v100/PopulateNclocForForProjectsTest.java | 144 ----- .../RemoveOrphanRulesFromQualityProfilesTest.java | 128 ----- .../v100/UpdateUserLocalValueInUsersTest.java | 95 ---- .../AddCodeVariantsColumnInIssuesTableTest.java | 53 -- .../v101/AddIsMainColumnInProjectBranchesTest.java | 52 -- .../version/v101/AddReportSchedulesTableTest.java | 65 --- .../v101/AddReportSubscriptionsTableTest.java | 63 --- .../AlterIsMainColumnInProjectBranchesTest.java | 52 -- .../v101/CreateExternalGroupsTableTest.java | 66 --- .../v101/CreateIndexForEmailOnUsersTableTest.java | 52 -- ...teIndexForScmAccountOnScmAccountsTableTest.java | 52 -- ...rnalIdAndIdentityOnExternalGroupsTableTest.java | 56 -- .../v101/CreateProjectUuidInUserTokensTest.java | 51 -- .../version/v101/CreateScmAccountsTableTest.java | 63 --- ...eateUniqueIndexForReportSchedulesTableTest.java | 54 -- ...UniqueIndexForReportSubscriptionsTableTest.java | 55 -- .../v101/DropProjectKeyInUserTokensTest.java | 51 -- .../version/v101/DropScmAccountsInUsersTest.java | 52 -- .../FixDifferentUuidsForSubportfoliosTest.java | 165 ------ ...reaseKeeColumnSizeInInternalPropertiesTest.java | 52 -- ...IncreaseTaskTypeColumnSizeInCeActivityTest.java | 52 -- .../IncreaseTaskTypeColumnSizeInCeQueueTest.java | 52 -- ...grateScmAccountsFromUsersToScmAccountsTest.java | 183 ------- .../v101/PopulateProjectUuidInUserTokensTest.java | 112 ---- .../version/v101/PopulateReportSchedulesTest.java | 123 ----- .../v101/PopulateReportSubscriptionsTest.java | 121 ----- .../version/v101/RemoveOrphanUserTokensTest.java | 98 ---- .../version/v101/RemoveReportPropertiesTest.java | 81 --- .../RenameColumnComponentUuidInPropertiesTest.java | 52 -- .../UpdateIsMainColumnInProjectBranchesTest.java | 105 ---- .../v102/AddCleanCodeAttributeInRulesTest.java | 51 -- ...equiredIfGithubAutoProvisioningEnabledTest.java | 105 ---- .../CreateAnticipatedTransitionsTableTest.java | 70 --- .../CreateBooleanPurgedColumnInSnapshotsTest.java | 53 -- .../CreateGithubOrganizationsGroupsTableTest.java | 61 --- ...reateIndexCreatedAtInWebhookDeliveriesTest.java | 54 -- .../CreateIndexEntityUuidInCeActivityTest.java | 48 -- .../v102/CreateIndexEntityUuidInCeQueueTest.java | 48 -- .../CreateIndexEntityUuidInGroupRolesTest.java | 48 -- .../v102/CreateIndexEntityUuidInUserRolesTest.java | 48 -- ...rojectUuidCreatedAtInWebhookDeliveriesTest.java | 53 -- ...reateIndexProjectUuidInProjectBranchesTest.java | 50 -- ...reateIndexRootComponentUuidInSnapshotsTest.java | 50 -- ...exTaskUuidCreatedAtInWebhookDeliveriesTest.java | 53 -- ...ebhookUuidCreatedAtInWebhookDeliveriesTest.java | 54 -- .../version/v102/CreateIssueImpactsTableTest.java | 60 --- ...viousNonCompliantValueInNewCodePeriodsTest.java | 53 -- .../v102/CreateRulesDefaultImpactsTableTest.java | 61 --- .../CreateUniqueConstraintOnIssuesImpactsTest.java | 50 -- ...eUniqueConstraintOnRulesDefaultImpactsTest.java | 51 -- .../DropIndexComponentUuidInGroupRolesTest.java | 62 --- .../DropIndexComponentUuidInSnapshotsTest.java | 57 -- .../DropIndexComponentUuidInUserRolesTest.java | 62 --- ...pIndexComponentUuidInWebhookDeliveriesTest.java | 57 -- ...DropIndexMainComponentUuidInCeActivityTest.java | 57 -- .../DropIndexMainComponentUuidInCeQueueTest.java | 57 -- .../v102/DropIndexOnMainBranchProjectUuidTest.java | 51 -- ...ropIndexProjectUuidInWebhookDeliveriesTest.java | 61 --- .../DropIndexTaskUuidInWebhookDeliveriesTest.java | 56 -- ...ropIndexWebhookUuidInWebhookDeliveriesTest.java | 57 -- .../DropMainBranchProjectUuidInComponentsTest.java | 52 -- .../v102/DropPurgeStatusColumnInSnapshotsTest.java | 53 -- .../version/v102/DropTableProjectMappingsTest.java | 50 -- .../v102/FixSqaleIndexMetricDescriptionTest.java | 65 --- .../v102/IncreaseIsLastKeyInCeActivityTest.java | 53 -- .../IncreaseMainIsLastKeyInCeActivityTest.java | 53 -- ...ectUuidNullableInUserDismissedMessagesTest.java | 53 -- ...MakePurgedColumnNotNullableInSnapshotsTest.java | 52 -- ...opulateCleanCodeAttributeColumnInRulesTest.java | 110 ---- .../v102/PopulateDefaultImpactsInRulesTest.java | 221 -------- .../v102/PopulatePurgedColumnInSnapshotsTest.java | 72 --- .../v102/RenameBuildDateInSnapshotsTest.java | 55 -- .../v102/RenameComponentUuidInGroupRolesTest.java | 51 -- .../v102/RenameComponentUuidInSnapshotsTest.java | 51 -- .../v102/RenameComponentUuidInUserRolesTest.java | 51 -- ...RenameComponentUuidInWebhookDeliveriesTest.java | 60 --- .../RenameMainComponentUuidInCeActivityTest.java | 51 -- .../v102/RenameMainComponentUuidInCeQueueTest.java | 51 -- ...viousNonCompliantValueInNewCodePeriodsTest.java | 69 --- ...dCleanCodeAttributeColumnInIssuesTableTest.java | 50 -- ...AddCreationMethodColumnInProjectsTableTest.java | 50 -- ...RuleChangesUuidColumnInQProfileChangesTest.java | 52 -- ...dSqVersionColumnInQprofileChangesTableTest.java | 51 -- .../CreateGithubPermissionsMappingTableTest.java | 61 --- .../CreateIndexForRuleImpactChangesTableTest.java | 53 -- .../version/v103/CreateRuleChangesTableTest.java | 63 --- .../v103/CreateRuleImpactChangesTableTest.java | 65 --- ...eIndexForGithubPermissionsMappingTableTest.java | 53 -- .../CreateUniqueIndexForPropertiesTableTest.java | 54 -- .../v103/DeduplicatePropertiesTableTest.java | 109 ---- ...ationMethodColumnInProjectsNotNullableTest.java | 50 -- ...ateCreationMethodColumnInProjectsTableTest.java | 75 --- .../v103/PopulateGithubPermissionsMappingTest.java | 99 ---- ...lowQualityProfileDisableInheritedRulesTest.java | 79 --- ...teRedundantFailedAlertsForApplicationsTest.java | 157 ------ .../v104/RenameWontFixIssuesMetricTest.java | 83 --- .../AutoDbMigrationH2Test/schema_migrations.sql | 4 - .../charset/SelectExecutorTest/users_table.sql | 4 - .../charset/SqlExecutorTest/users_table.sql | 5 - .../MigrationHistoryImplTest/schema_migration.sql | 4 - .../MigrationHistoryTableImplTest/empty.sql | 0 .../NoTableMigrationHistoryImplTest/empty.sql | 0 .../DbPrimaryKeyConstraintFinderTest/schema.sql | 4 - .../db/migration/step/DataChangeTest/schema.sql | 14 - .../step/ForceReloadingOfAllPluginsTest/schema.sql | 12 - .../schema.sql | 9 - .../schema.sql | 9 - .../schema.sql | 19 - 265 files changed, 9098 insertions(+), 9102 deletions(-) create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SelectExecutorIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SqlExecutorIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/DataChangeIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricIT.java create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorIT/users_table.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorIT/users_table.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT/schema_migration.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT/empty.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT/empty.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT/schema.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/DataChangeIT/schema.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT/schema.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT/schema.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT/schema.sql create mode 100644 server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT/schema.sql delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SelectExecutorTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricTest.java delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/AutoDbMigrationH2Test/schema_migrations.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorTest/users_table.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorTest/users_table.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest/schema_migration.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest/empty.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest/empty.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/DataChangeTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql (limited to 'server') diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SelectExecutorIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SelectExecutorIT.java new file mode 100644 index 00000000000..9b55fabdc28 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SelectExecutorIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.charset; + +import java.sql.Connection; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SelectExecutorIT { + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(SelectExecutorIT.class, "users_table.sql"); + + SqlExecutor underTest = new SqlExecutor(); + + @Test + public void testExecuteQuery() throws Exception { + insertUser("him", "Him"); + insertUser("her", "Her"); + + try (Connection connection = dbTester.openConnection()) { + List rows = underTest.select(connection, "select login, name from users order by login", new SqlExecutor.StringsConverter(2)); + assertThat(rows).hasSize(2); + assertThat(rows.get(0)[0]).isEqualTo("her"); + assertThat(rows.get(0)[1]).isEqualTo("Her"); + assertThat(rows.get(1)[0]).isEqualTo("him"); + assertThat(rows.get(1)[1]).isEqualTo("Him"); + } + } + + private void insertUser(String login, String name) { + dbTester.executeInsert("users", + "LOGIN", login, + "NAME", name); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SqlExecutorIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SqlExecutorIT.java new file mode 100644 index 00000000000..875c739481a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/charset/SqlExecutorIT.java @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.charset; + +import java.sql.Connection; +import java.util.List; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SqlExecutorIT { + + private static final String LOGIN_DB_COLUMN = "login"; + private static final String NAME_DB_COLUMN = "name"; + private static final String USERS_DB_TABLE = "users"; + private static final String IS_ROOT_DB_COLUMN = "is_root"; + + private SqlExecutor underTest = new SqlExecutor(); + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(SqlExecutorIT.class, "users_table.sql"); + + @Test + public void executeSelect_executes_PreparedStatement() throws Exception { + dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "login1", NAME_DB_COLUMN, "name one", IS_ROOT_DB_COLUMN, false); + dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "login2", NAME_DB_COLUMN, "name two", IS_ROOT_DB_COLUMN, false); + + try (Connection connection = dbTester.openConnection()) { + List users = underTest.select(connection, "select " + LOGIN_DB_COLUMN + ", " + NAME_DB_COLUMN + " from users order by login", new SqlExecutor.StringsConverter( + 2)); + assertThat(users).hasSize(2); + assertThat(users.get(0)[0]).isEqualTo("login1"); + assertThat(users.get(0)[1]).isEqualTo("name one"); + assertThat(users.get(1)[0]).isEqualTo("login2"); + assertThat(users.get(1)[1]).isEqualTo("name two"); + } + } + + @Test + public void executeUpdate_executes_PreparedStatement() throws Exception { + dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "the_login", NAME_DB_COLUMN, "the name", IS_ROOT_DB_COLUMN, false); + + try (Connection connection = dbTester.openConnection()) { + underTest.executeDdl(connection, "update users set " + NAME_DB_COLUMN + "='new name' where " + LOGIN_DB_COLUMN + "='the_login'"); + } + Map row = dbTester.selectFirst("select " + NAME_DB_COLUMN + " from users where " + LOGIN_DB_COLUMN + "='the_login'"); + assertThat(row) + .isNotEmpty() + .containsEntry("NAME", "new name"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT.java new file mode 100644 index 00000000000..710e16972d8 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT.java @@ -0,0 +1,91 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.history; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Arrays; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; +import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class MigrationHistoryImplIT { + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(MigrationHistoryImplIT.class, "schema_migration.sql"); + + private MigrationHistoryMeddler migrationHistoryMeddler = mock(MigrationHistoryMeddler.class); + private MigrationHistoryImpl underTest = new MigrationHistoryImpl(dbTester.database(), migrationHistoryMeddler); + + @Test + public void start_does_not_fail_if_table_history_exists_and_calls_meddler() { + underTest.start(); + + verify(migrationHistoryMeddler).meddle(underTest); + } + + @Test + public void getLastMigrationNumber_returns_empty_if_history_table_is_empty() { + assertThat(underTest.getLastMigrationNumber()).isEmpty(); + } + + @Test + public void getLastMigrationNumber_returns_last_version_assuming_version_are_only_number() throws SQLException { + insert(12, 5, 30, 8); + + assertThat(underTest.getLastMigrationNumber()).contains(30L); + } + + @Test + public void done_fails_with_NPE_if_argument_is_null() { + assertThatThrownBy(() -> underTest.done(null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void done_adds_migration_number_to_table() { + underTest.done(new RegisteredMigrationStep(12, "aa", MigrationStep.class)); + + assertThat(underTest.getLastMigrationNumber()).contains(12L); + } + + private void insert(int... versions) throws SQLException { + try (Connection connection = dbTester.database().getDataSource().getConnection()) { + Arrays.stream(versions).forEach(version -> insert(connection, version)); + } + } + + private void insert(Connection connection, long version) { + try (PreparedStatement statement = connection.prepareStatement("insert into schema_migrations(version) values (?)")) { + statement.setString(1, String.valueOf(version)); + statement.execute(); + connection.commit(); + } catch (SQLException e) { + throw new IllegalStateException(String.format("Failed to insert row with value %s", version), e); + } + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT.java new file mode 100644 index 00000000000..2212b3c6ea7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT.java @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.history; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.dialect.MsSql; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MigrationHistoryTableImplIT { + private static final String TABLE_SCHEMA_MIGRATIONS = "schema_migrations"; + + @Rule + public MigrationDbTester dbTester = MigrationDbTester.createEmpty(); + + private MigrationHistoryTableImpl underTest = new MigrationHistoryTableImpl(dbTester.database()); + + @Test + public void start_creates_table_on_empty_schema() { + underTest.start(); + + verifyTable(); + } + + @Test + public void start_does_not_fail_if_table_exists() throws SQLException { + executeDdl(String.format("create table %s (version %s(255) not null)", TABLE_SCHEMA_MIGRATIONS, getFieldType())); + verifyTable(); + + underTest.start(); + + verifyTable(); + } + + private String getFieldType() { + if (dbTester.database().getDialect().getId().equals(MsSql.ID)) { + return "nvarchar"; + } + return "varchar"; + } + + private void executeDdl(String sql) throws SQLException { + try (Connection connection = dbTester.database().getDataSource().getConnection()) { + connection.setAutoCommit(false); + try (Statement statement = connection.createStatement()) { + statement.execute(sql); + connection.commit(); + } + } + } + + private void verifyTable() { + assertThat(dbTester.countRowsOfTable(TABLE_SCHEMA_MIGRATIONS)).isZero(); + dbTester.assertColumnDefinition(TABLE_SCHEMA_MIGRATIONS, "version", Types.VARCHAR, 255, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT.java new file mode 100644 index 00000000000..fd114d51c76 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.history; + +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyNoInteractions; + +public class NoTableMigrationHistoryImplIT { + @Rule + public MigrationDbTester dbTester = MigrationDbTester.createEmpty(); + + private MigrationHistoryMeddler migrationHistoryMeddler = mock(MigrationHistoryMeddler.class); + private MigrationHistoryImpl underTest = new MigrationHistoryImpl(dbTester.database(), migrationHistoryMeddler); + + @Test + public void start_fails_with_ISE_if_table_history_does_not_exist() { + assertThatThrownBy(() -> { + underTest.start(); + verifyNoInteractions(migrationHistoryMeddler); + }) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Migration history table is missing"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderIT.java new file mode 100644 index 00000000000..3e1e4282f19 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderIT.java @@ -0,0 +1,132 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.sql; + +import java.util.Map; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.db.dialect.Dialect; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.def.TinyIntColumnDef; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; +import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; +import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT; + +public class CreateTableBuilderIT { + @ClassRule + public static final MigrationDbTester dbTester = MigrationDbTester.createEmpty(); + + private final Dialect dialect = dbTester.database().getDialect(); + private static int tableNameGenerator = 0; + + @Test + public void create_no_primary_key_table() { + newCreateTableBuilder() + .addColumn(newBooleanColumnDefBuilder().setColumnName("bool_col_1").build()) + .addColumn(newBooleanColumnDefBuilder().setColumnName("bool_col_2").setIsNullable(false).build()) + .addColumn(newIntegerColumnDefBuilder().setColumnName("i_col_1").build()) + .addColumn(newIntegerColumnDefBuilder().setColumnName("i_col_2").setIsNullable(false).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("bi_col_1").build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("bi_col_2").setIsNullable(false).build()) + .addColumn(newClobColumnDefBuilder().setColumnName("clob_col_1").build()) + .addColumn(newClobColumnDefBuilder().setColumnName("clob_col_2").setIsNullable(false).build()) + .addColumn(newDecimalColumnDefBuilder().setColumnName("dec_col_1").build()) + .addColumn(newDecimalColumnDefBuilder().setColumnName("dec_col_2").setIsNullable(false).build()) + .addColumn(new TinyIntColumnDef.Builder().setColumnName("tiny_col_1").build()) + .addColumn(new TinyIntColumnDef.Builder().setColumnName("tiny_col_2").setIsNullable(false).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_1").setLimit(40).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) + .addColumn(newBlobColumnDefBuilder().setColumnName("blob_col_1").build()) + .addColumn(newBlobColumnDefBuilder().setColumnName("blob_col_2").setIsNullable(false).build()) + .build() + .forEach(dbTester::executeDdl); + } + + @Test + public void create_single_column_primary_key_table() { + newCreateTableBuilder() + .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_1").setIsNullable(false).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) + .build() + .forEach(dbTester::executeDdl); + } + + @Test + public void create_multi_column_primary_key_table() { + newCreateTableBuilder() + .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_1").setIsNullable(false).build()) + .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_2").setIsNullable(false).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) + .build() + .forEach(dbTester::executeDdl); + } + + @Test + public void create_autoincrement_notnullable_integer_primary_key_table() { + String tableName = createTableName(); + new CreateTableBuilder(dialect, tableName) + .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) + .addColumn(valColumnDef()) + .build() + .forEach(dbTester::executeDdl); + + verifyAutoIncrementIsWorking(tableName); + } + + @Test + public void create_autoincrement_notnullable_biginteger_primary_key_table() { + String tableName = createTableName(); + new CreateTableBuilder(dialect, tableName) + .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) + .addColumn(valColumnDef()) + .build() + .forEach(dbTester::executeDdl); + + verifyAutoIncrementIsWorking(tableName); + } + + private static VarcharColumnDef valColumnDef() { + return newVarcharColumnDefBuilder().setColumnName("val").setLimit(10).setIsNullable(false).build(); + } + + private void verifyAutoIncrementIsWorking(String tableName) { + dbTester.executeInsert(tableName, "val", "toto"); + + Map row = dbTester.selectFirst("select id as \"id\", val as \"val\" from " + tableName); + assertThat(row.get("id")).isNotNull(); + assertThat(row).containsEntry("val", "toto"); + } + + private CreateTableBuilder newCreateTableBuilder() { + return new CreateTableBuilder(dialect, createTableName()); + } + + private static String createTableName() { + return "table_" + tableNameGenerator++; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT.java new file mode 100644 index 00000000000..a14da8bdd6d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT.java @@ -0,0 +1,102 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.sql; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Optional; +import javax.sql.DataSource; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.db.Database; +import org.sonar.db.dialect.H2; +import org.sonar.db.dialect.MsSql; +import org.sonar.db.dialect.Oracle; +import org.sonar.db.dialect.PostgreSql; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DbPrimaryKeyConstraintFinderIT { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DbPrimaryKeyConstraintFinderIT.class, "schema.sql"); + + private final Database dbMock = mock(Database.class); + private final DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(dbMock); + + private static final PostgreSql POSTGRESQL = new PostgreSql(); + private static final MsSql MS_SQL = new MsSql(); + private static final Oracle ORACLE = new Oracle(); + private static final org.sonar.db.dialect.H2 H2 = new H2(); + + @Test + public void findConstraintName_constraint_exists() throws SQLException { + DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); + Optional constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY"); + assertThat(constraintName).isPresent(); + assertThat(constraintName.get()).contains("PK_TEST_PRIMARY_KEY"); + } + + @Test + public void findConstraintName_constraint_not_exist_fails_silently() throws SQLException { + DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); + assertThat(underTest.findConstraintName("NOT_EXISTING_TABLE")).isNotPresent(); + } + + @Test + public void getDbVendorSpecificQuery_mssql() { + when(dbMock.getDialect()).thenReturn(MS_SQL); + + assertThat(underTest.getDbVendorSpecificQuery("my_table")) + .isEqualTo("SELECT name FROM sys.key_constraints WHERE type = 'PK' AND OBJECT_NAME(parent_object_id) = 'my_table'"); + } + + @Test + public void getDbVendorSpecificQuery_postgresql() throws SQLException { + DataSource dataSource = mock(DataSource.class); + Connection connection = mock(Connection.class); + when(dataSource.getConnection()).thenReturn(connection); + when(connection.getSchema()).thenReturn("SonarQube"); + when(dbMock.getDialect()).thenReturn(POSTGRESQL); + when(dbMock.getDataSource()).thenReturn(dataSource); + + assertThat(underTest.getDbVendorSpecificQuery("my_table")) + .isEqualTo("SELECT conname FROM pg_constraint c JOIN pg_namespace n on c.connamespace = n.oid JOIN pg_class cls on c.conrelid = cls.oid WHERE cls.relname = 'my_table' AND n.nspname = 'SonarQube'"); + } + + @Test + public void getDbVendorSpecificQuery_oracle() { + when(dbMock.getDialect()).thenReturn(ORACLE); + + assertThat(underTest.getDbVendorSpecificQuery("my_table")) + .isEqualTo("SELECT constraint_name FROM user_constraints WHERE table_name = UPPER('my_table') AND constraint_type='P'"); + } + + @Test + public void getDbVendorSpecificQuery_h2() { + when(dbMock.getDialect()).thenReturn(H2); + + assertThat(underTest.getDbVendorSpecificQuery("my_table")) + .isEqualTo("SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'MY_TABLE' and constraint_type = 'PRIMARY KEY'"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/DataChangeIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/DataChangeIT.java new file mode 100644 index 00000000000..77b37c52169 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/DataChangeIT.java @@ -0,0 +1,594 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.step; + +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nullable; +import org.apache.commons.lang.StringUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.Select.Row; +import org.sonar.server.platform.db.migration.step.Select.RowReader; + +import static java.util.Collections.emptySet; +import static java.util.stream.Collectors.toSet; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.fail; + +public class DataChangeIT { + + private static final int MAX_BATCH_SIZE = 250; + private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DataChangeIT.class, "schema.sql"); + + @Before + public void setUp() { + db.executeUpdateSql("truncate table persons"); + } + + @Test + public void query() throws Exception { + insertPersons(); + + AtomicBoolean executed = new AtomicBoolean(false); + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + assertThat(context.prepareSelect("select id from persons order by id desc").list(Select.LONG_READER)) + .containsExactly(3L, 2L, 1L); + assertThat(context.prepareSelect("select id from persons where id=?").setLong(1, 2L).get(Select.LONG_READER)) + .isEqualTo(2L); + assertThat(context.prepareSelect("select id from persons where id=?").setLong(1, 12345L).get(Select.LONG_READER)) + .isNull(); + executed.set(true); + } + }.execute(); + assertThat(executed.get()).isTrue(); + } + + @Test + public void read_column_types() throws Exception { + insertPersons(); + + List persons = new ArrayList<>(); + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + persons.addAll(context + .prepareSelect("select id,login,age,enabled,updated_at,coeff from persons where id=2") + .list(new UserReader())); + } + }.execute(); + assertThat(persons).hasSize(1); + assertThat(persons.get(0)[0]).isEqualTo(2L); + assertThat(persons.get(0)[1]).isEqualTo("emmerik"); + assertThat(persons.get(0)[2]).isEqualTo(14); + assertThat(persons.get(0)[3]).isEqualTo(true); + assertThat(persons.get(0)[4]).isNotNull(); + assertThat(persons.get(0)[5]).isEqualTo(5.2); + } + + @Test + public void parameterized_query() throws Exception { + insertPersons(); + + final List ids = new ArrayList<>(); + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + ids.addAll(context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list(Select.LONG_READER)); + } + }.execute(); + assertThat(ids).containsOnly(2L, 3L); + } + + @Test + public void display_current_row_details_if_error_during_get() throws Exception { + insertPersons(); + + assertThatThrownBy(() -> { + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).get((RowReader) row -> { + throw new IllegalStateException("Unexpected error"); + }); + } + }.execute(); + }) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Error during processing of row: [id=2]"); + } + + @Test + public void display_current_row_details_if_error_during_list() throws Exception { + insertPersons(); + + assertThatThrownBy(() -> { + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list((RowReader) row -> { + throw new IllegalStateException("Unexpected error"); + }); + } + }.execute(); + }) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Error during processing of row: [id=2]"); + } + + @Test + public void bad_parameterized_query() throws Exception { + insertPersons(); + + DataChange change = new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + // parameter value is not set + context.prepareSelect("select id from persons where id>=?").list(Select.LONG_READER); + } + }; + + assertThatThrownBy(() -> change.execute()) + .isInstanceOf(SQLException.class); + } + + @Test + public void scroll() throws Exception { + insertPersons(); + + final List ids = new ArrayList<>(); + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + context.prepareSelect("select id from persons order by id desc").scroll(row -> ids.add(row.getNullableLong(1))); + } + }.execute(); + assertThat(ids).containsExactly(3L, 2L, 1L); + } + + @Test + public void insert() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)") + .setLong(1, 10L) + .setString(2, "kurt") + .setInt(3, 27) + .setBoolean(4, true) + .setDouble(5, 2.2) + .execute().commit().close(); + } + }.execute(); + + assertThat(db.select("select id as \"ID\" from persons")) + .extracting(t -> t.get("ID")) + .containsOnly(1L, 2L, 3L, 10L); + assertInitialPersons(); + assertPerson(10L, "kurt", 27L, true, null, 2.2d); + } + + @Test + public void batch_inserts() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)"); + boolean committed = upsert + .setLong(1, 10L) + .setString(2, "kurt") + .setInt(3, 27) + .setBoolean(4, true) + .setDouble(5, 2.2) + .addBatch(); + assertThat(committed).isFalse(); + + committed = upsert + .setLong(1, 11L) + .setString(2, "courtney") + .setInt(3, 25) + .setBoolean(4, false) + .setDouble(5, 2.3) + .addBatch(); + assertThat(committed).isFalse(); + + upsert.execute().commit().close(); + } + }.execute(); + + assertThat(db.select("select id as \"ID\" from persons")) + .extracting(t -> t.get("ID")) + .containsOnly(1L, 2L, 3L, 10L, 11L); + assertInitialPersons(); + assertPerson(10L, "kurt", 27L, true, null, 2.2d); + assertPerson(11L, "courtney", 25L, false, null, 2.3d); + } + + @Test + public void override_size_of_batch_inserts() throws Exception { + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)") + .setBatchSize(3); + long id = 100L; + assertThat(addBatchInsert(upsert, id++)).isFalse(); + assertThat(addBatchInsert(upsert, id++)).isFalse(); + assertThat(addBatchInsert(upsert, id++)).isTrue(); + assertThat(addBatchInsert(upsert, id++)).isFalse(); + assertThat(addBatchInsert(upsert, id++)).isFalse(); + assertThat(addBatchInsert(upsert, id++)).isTrue(); + assertThat(addBatchInsert(upsert, id)).isFalse(); + upsert.execute().commit().close(); + } + }.execute(); + assertThat(db.countRowsOfTable("persons")).isEqualTo(7); + for (int i = 100; i < 107; i++) { + assertPerson(i, "kurt", 27L, true, null, 2.2d); + } + } + + private boolean addBatchInsert(Upsert upsert, long id) throws SQLException { + return upsert + .setLong(1, id) + .setString(2, "kurt") + .setInt(3, 27) + .setBoolean(4, true) + .setDouble(5, 2.2) + .addBatch(); + } + + @Test + public void update_null() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + Upsert upsert = context.prepareUpsert("update persons set login=?,age=?,enabled=?, updated_at=?, coeff=? where id=?"); + upsert + .setString(1, null) + .setInt(2, null) + .setBoolean(3, null) + .setDate(4, null) + .setDouble(5, null) + .setLong(6, 2L) + .execute() + .commit() + .close(); + } + }.execute(); + + assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); + assertPerson(2L, null, null, null, null, null); + assertPerson(3L, "morgan", 3L, true, "2014-01-25", 5.4d); + } + + @Test + public void mass_batch_insert() throws Exception { + db.executeUpdateSql("truncate table persons"); + + final int count = MAX_BATCH_SIZE + 10; + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)"); + for (int i = 0; i < count; i++) { + upsert + .setLong(1, 10L + i) + .setString(2, "login" + i) + .setInt(3, 10 + i) + .setBoolean(4, true) + .setDouble(5, i + 0.5) + .addBatch(); + } + upsert.execute().commit().close(); + + } + }.execute(); + + assertThat(db.countRowsOfTable("persons")).isEqualTo(count); + } + + @Test + public void scroll_and_update() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + final Upsert upsert = context.prepareUpsert("update persons set login=?, age=? where id=?"); + context.prepareSelect("select id from persons").scroll(new Select.RowHandler() { + @Override + public void handle(Row row) throws SQLException { + long id = row.getNullableLong(1); + upsert.setString(1, "login" + id).setInt(2, 10 + (int) id).setLong(3, id); + upsert.execute(); + } + }); + upsert.commit().close(); + } + }.execute(); + + assertPerson(1L, "login1", 11L, false, "2014-01-25", 1.5d); + assertPerson(2L, "login2", 12L, true, "2014-01-25", 5.2d); + assertPerson(3L, "login3", 13L, true, "2014-01-25", 5.4d); + } + + @Test + public void display_current_row_details_if_error_during_scroll() throws Exception { + insertPersons(); + + assertThatThrownBy(() -> { + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + final Upsert upsert = context.prepareUpsert("update persons set login=?, age=? where id=?"); + context.prepareSelect("select id from persons").scroll(row -> { + throw new IllegalStateException("Unexpected error"); + }); + upsert.commit().close(); + } + }.execute(); + }) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Error during processing of row: [id=1]"); + } + + @Test + public void mass_update() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id from persons where id>=?").setLong(1, 2L); + massUpdate.update("update persons set login=?, age=? where id=?"); + massUpdate.execute((row, update) -> { + long id = row.getNullableLong(1); + update + .setString(1, "login" + id) + .setInt(2, 10 + (int) id) + .setLong(3, id); + return true; + }); + } + }.execute(); + + assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); + assertPerson(2L, "login2", 12L, true, "2014-01-25", 5.2d); + assertPerson(3L, "login3", 13L, true, "2014-01-25", 5.4d); + } + + @Test + public void row_splitter_should_split_correctly() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + MassRowSplitter massRowSplitter = context.prepareMassRowSplitter(); + massRowSplitter.select("select id, phone_numbers from persons where id>?").setLong(1, -2L); + massRowSplitter.splitRow(row -> { + try { + int personId = row.getInt(1); + String phoneNumbers = row.getString(2); + if (phoneNumbers == null) { + return emptySet(); + } + return Arrays.stream(StringUtils.split(phoneNumbers, '\n')) + .map(number -> new PhoneNumberRow(personId, number)) + .collect(toSet()); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); + + massRowSplitter.insert("insert into phone_numbers (person_id, phone_number) values (?, ?)"); + massRowSplitter.execute((row, insert) -> { + insert.setLong(1, row.personId()) + .setString(2, row.phoneNumber()); + return true; + }); + } + }.execute(); + + Set actualRows = getPhoneNumberRows(); + + assertThat(actualRows) + .containsExactlyInAnyOrder( + new PhoneNumberRow(1, "1"), + new PhoneNumberRow(1, "32234"), + new PhoneNumberRow(1, "42343"), + new PhoneNumberRow(2, "432423") + ); + } + + private Set getPhoneNumberRows() { + return db + .select("select person_id as personId, phone_number as phoneNumber from phone_numbers") + .stream() + .map(row -> new PhoneNumberRow((long) row.get("PERSONID"), (String) row.get("PHONENUMBER"))) + .collect(toSet()); + } + + private record PhoneNumberRow(long personId, String phoneNumber){} + + @Test + public void display_current_row_details_if_error_during_mass_update() throws Exception { + insertPersons(); + + assertThatThrownBy(() -> { + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id from persons where id>=?").setLong(1, 2L); + massUpdate.update("update persons set login=?, age=? where id=?"); + massUpdate.execute((row, update) -> { + throw new IllegalStateException("Unexpected error"); + }); + } + }.execute(); + }) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Error during processing of row: [id=2]"); + } + + @Test + public void mass_update_nothing() throws Exception { + insertPersons(); + + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id from persons where id>=?").setLong(1, 2L); + massUpdate.update("update persons set login=?, age=? where id=?"); + massUpdate.execute((row, update) -> false); + } + }.execute(); + + assertInitialPersons(); + } + + @Test + public void bad_mass_update() throws Exception { + insertPersons(); + + DataChange change = new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id from persons where id>=?").setLong(1, 2L); + // update is not set + massUpdate.execute((row, update) -> false); + } + }; + try { + change.execute(); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("SELECT or UPDATE requests are not defined"); + } + } + + @Test + public void read_not_null_fields() throws Exception { + insertPersons(); + + List persons = new ArrayList<>(); + new DataChange(db.database()) { + @Override + public void execute(Context context) throws SQLException { + persons.addAll(context + .prepareSelect("select id,login,age,enabled,updated_at,coeff from persons where id=2") + .list(row -> new Object[] { + // id, login, age, enabled + row.getLong(1), + row.getString(2), + row.getInt(3), + row.getBoolean(4), + row.getDate(5), + row.getDouble(6), + })); + } + }.execute(); + assertThat(persons).hasSize(1); + assertThat(persons.get(0)[0]).isEqualTo(2L); + assertThat(persons.get(0)[1]).isEqualTo("emmerik"); + assertThat(persons.get(0)[2]).isEqualTo(14); + assertThat(persons.get(0)[3]).isEqualTo(true); + assertThat(persons.get(0)[4]).isNotNull(); + assertThat(persons.get(0)[5]).isEqualTo(5.2); + } + + static class UserReader implements RowReader { + @Override + public Object[] read(Row row) throws SQLException { + return new Object[] { + // id, login, age, enabled + row.getNullableLong(1), + row.getNullableString(2), + row.getNullableInt(3), + row.getNullableBoolean(4), + row.getNullableDate(5), + row.getNullableDouble(6), + }; + } + } + + private void insertPersons() throws ParseException { + insertPerson(1, "barbara", 56, false, "2014-01-25", 1.5d, "\n1\n32234\n42343\n"); + insertPerson(2, "emmerik", 14, true, "2014-01-25", 5.2d, "432423"); + insertPerson(3, "morgan", 3, true, "2014-01-25", 5.4d, null); + } + + private void assertInitialPersons() throws ParseException { + assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); + assertPerson(2L, "emmerik", 14L, true, "2014-01-25", 5.2d); + assertPerson(3L, "morgan", 3L, true, "2014-01-25", 5.4d); + } + + private void insertPerson(int id, String login, int age, boolean enabled, String updatedAt, double coeff, @Nullable String newLineSeparatedPhoneNumbers) throws ParseException { + db.executeInsert("persons", + "ID", id, + "LOGIN", login, + "AGE", age, + "ENABLED", enabled, + "UPDATED_AT", dateFormat.parse(updatedAt), + "COEFF", coeff, + "PHONE_NUMBERS", newLineSeparatedPhoneNumbers); + } + + private void assertPerson(long id, @Nullable String login, @Nullable Long age, @Nullable Boolean enabled, @Nullable String updatedAt, @Nullable Double coeff) + throws ParseException { + List> rows = db + .select("select id as \"ID\", login as \"LOGIN\", age as \"AGE\", enabled as \"ENABLED\", coeff as \"COEFF\", updated_at as \"UPDATED\" from persons where id=" + id); + assertThat(rows).describedAs("id=" + id).hasSize(1); + Map row = rows.get(0); + assertThat(row).containsEntry("ID", id); + assertThat(row).containsEntry("LOGIN", login); + assertThat(row).containsEntry("AGE", age); + assertThat(row).containsEntry("ENABLED", enabled); + assertThat(row).containsEntry("UPDATED", updatedAt == null ? null : dateFormat.parse(updatedAt)); + assertThat(row).containsEntry("COEFF", coeff); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT.java new file mode 100644 index 00000000000..cf1d915ebf2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT.java @@ -0,0 +1,88 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.step; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +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 static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.step.ForceReloadingOfAllPlugins.OVERWRITE_HASH; + +public class ForceReloadingOfAllPluginsIT { + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(ForceReloadingOfAllPluginsIT.class, "schema.sql"); + + private final DataChange underTest = new ForceReloadingOfAllPlugins(db.database()); + + @Test + public void migration_overwrite_file_hash_on_all_plugins() throws SQLException { + String pluginUuid1 = insertPlugin(); + String pluginUuid2 = insertPlugin(); + + underTest.execute(); + + assertPluginFileHashOverwrite(pluginUuid1); + assertPluginFileHashOverwrite(pluginUuid2); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String pluginUuid1 = insertPlugin(); + String pluginUuid2 = insertPlugin(); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertPluginFileHashOverwrite(pluginUuid1); + assertPluginFileHashOverwrite(pluginUuid2); + } + + private void assertPluginFileHashOverwrite(String pluginUuid) { + String selectSql = String.format("select file_hash from plugins where uuid='%s'", pluginUuid); + var selectResult = db.select(selectSql); + assertThat(selectResult.get(0)).containsEntry("FILE_HASH", OVERWRITE_HASH); + } + + private String insertPlugin() { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("KEE", randomAlphabetic(20)); + map.put("FILE_HASH", randomAlphabetic(32)); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("UPDATED_AT", System.currentTimeMillis()); + map.put("TYPE", "EXTERNAL"); + map.put("REMOVED", false); + db.executeInsert("plugins", map); + + return uuid; + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaIT.java new file mode 100644 index 00000000000..c2bee65e6a2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaIT.java @@ -0,0 +1,142 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v00; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CreateInitialSchemaIT { + + private static final Set SCHEMAS_TO_IGNORE = Set.of("INFORMATION_SCHEMA", "sys", "SYS", "SYSTEM", "CTXSYS", "MDSYS", "XDB"); + + @Rule + public final MigrationDbTester dbTester = MigrationDbTester.createForMigrationStep(CreateInitialSchema.class); + + private final CreateInitialSchema underTest = new CreateInitialSchema(dbTester.database()); + + @Test + public void creates_tables_on_empty_db() throws Exception { + underTest.execute(); + + List tables = new ArrayList<>(); + try (Connection connection = dbTester.openConnection(); + ResultSet rs = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"})) { + + while (rs.next()) { + String schema = rs.getString("TABLE_SCHEM"); + if (!SCHEMAS_TO_IGNORE.contains(schema)) { + tables.add(rs.getString("TABLE_NAME").toLowerCase(Locale.ENGLISH)); + } + } + } + + assertThat(tables) + .containsOnly( + "active_rules", + "active_rule_parameters", + "app_branch_project_branch", + "alm_pats", + "app_projects", + "alm_settings", + "audits", + "project_alm_settings", + "analysis_properties", + "ce_activity", + "ce_queue", + "ce_scanner_context", + "ce_task_characteristics", + "ce_task_input", + "ce_task_message", + "components", + "default_qprofiles", + "deprecated_rule_keys", + "duplications_index", + "es_queue", + "events", + "event_component_changes", + "file_sources", + "groups", + "groups_users", + "group_roles", + "internal_component_props", + "internal_properties", + "issues", + "issue_changes", + "live_measures", + "metrics", + "new_code_periods", + "new_code_reference_issues", + "notifications", + "org_qprofiles", + "permission_templates", + "perm_templates_groups", + "perm_templates_users", + "perm_tpl_characteristics", + "plugins", + "portfolios", + "portfolio_projects", + "portfolio_proj_branches", + "portfolio_references", + "projects", + "project_badge_token", + "project_branches", + "project_links", + "project_mappings", + "project_measures", + "project_qprofiles", + "project_qgates", + "properties", + "push_events", + "qgate_group_permissions", + "qgate_user_permissions", + "qprofile_changes", + "qprofile_edit_groups", + "qprofile_edit_users", + "quality_gates", + "quality_gate_conditions", + "rules", + "rules_parameters", + "rules_profiles", + "rule_repositories", + "rule_desc_sections", + "saml_message_ids", + "scanner_analysis_cache", + "schema_migrations", + "scim_users", + "session_tokens", + "snapshots", + "users", + "user_dismissed_messages", + "user_roles", + "user_tokens", + "webhooks", + "webhook_deliveries"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaIT.java new file mode 100644 index 00000000000..4b55620185c --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaIT.java @@ -0,0 +1,236 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v00; + +import java.sql.SQLException; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class PopulateInitialSchemaIT { + + private static final long NOW = 1_500L; + + private final Random random = new Random(); + private final Version version = Version.create(1 + random.nextInt(10), 1 + random.nextInt(10), random.nextInt(10)); + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private final System2 system2 = mock(System2.class); + private final SonarQubeVersion sonarQubeVersion = mock(SonarQubeVersion.class); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateInitialSchema.class); + + private final PopulateInitialSchema underTest = new PopulateInitialSchema(db.database(), system2, uuidFactory, sonarQubeVersion); + + @Before + public void setUp() { + when(sonarQubeVersion.get()).thenReturn(version); + } + + @Test + public void migration_inserts_users_and_groups() throws SQLException { + when(system2.now()).thenReturn(NOW); + + underTest.execute(); + + verifyAdminUser(); + verifyGroup("sonar-users", "Every authenticated user automatically belongs to this group"); + verifyGroup("sonar-administrators", "System administrators"); + String qualityGateUuid = verifyQualityGate(); + verifyInternalProperties(); + verifyProperties(qualityGateUuid); + verifyRolesOfAdminsGroup(); + verifyRolesOfUsersGroup(); + verifyRolesOfAnyone(); + verifyMembershipOfAdminUser(); + } + + private void verifyAdminUser() { + Map cols = db.selectFirst("select " + + "login as \"LOGIN\", " + + "name as \"NAME\", " + + "email as \"EMAIL\", " + + "external_id as \"EXTERNAL_ID\", " + + "external_login as \"EXTERNAL_LOGIN\", " + + "external_identity_provider as \"EXT_IDENT_PROVIDER\", " + + "user_local as \"USER_LOCAL\", " + + "crypted_password as \"CRYPTED_PASSWORD\", " + + "salt as \"SALT\", " + + "hash_method as \"HASH_METHOD\", " + + "created_at as \"CREATED_AT\", " + + "updated_at as \"UPDATED_AT\", " + + "reset_password as \"RESET_PASSWORD\" " + + "from users where login='admin'"); + + assertThat(cols) + .containsEntry("LOGIN", "admin") + .containsEntry("NAME", "Administrator") + .containsEntry("EXTERNAL_ID", "admin") + .containsEntry("EXTERNAL_LOGIN", "admin") + .containsEntry("EXT_IDENT_PROVIDER", "sonarqube") + .containsEntry("USER_LOCAL", true) + .containsEntry("CRYPTED_PASSWORD", "$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi") + .containsEntry("HASH_METHOD", "BCRYPT") + .containsEntry("CREATED_AT", NOW) + .containsEntry("RESET_PASSWORD", true) + .containsEntry("UPDATED_AT", NOW); + + assertThat(cols.get("EMAIL")).isNull(); + assertThat(cols.get("SALT")).isNull(); + } + + private void verifyGroup(String expectedName, String expectedDescription) { + List> rows = db.select("select " + + "uuid as \"UUID\"," + + "name as \"name\", " + + "description as \"description\", " + + "created_at as \"CREATED_AT\", " + + "updated_at as \"UPDATED_AT\" " + + "from groups where name='" + expectedName + "'"); + assertThat(rows).hasSize(1); + + Map row = rows.get(0); + assertThat(row).containsEntry("name", expectedName); + assertThat(row).containsEntry("description", expectedDescription); + assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); + assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); + + } + + private String verifyQualityGate() { + List> rows = db.select("select " + + "uuid as \"UUID\", " + + "name as \"NAME\", " + + "is_built_in as \"BUILTIN\"," + + "created_at as \"CREATED_AT\", " + + "updated_at as \"UPDATED_AT\"" + + " from quality_gates"); + assertThat(rows).hasSize(1); + + Map row = rows.get(0); + assertThat(row).containsEntry("NAME", "Sonar way"); + assertThat(row).containsEntry("BUILTIN", true); + assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); + assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); + return (String) row.get("UUID"); + } + + private void verifyInternalProperties() { + List> rows = db.select("select " + + "kee as \"KEE\", " + + "is_empty as \"EMPTY\", " + + "text_value as \"VAL\"," + + "created_at as \"CREATED_AT\" " + + " from internal_properties"); + assertThat(rows).hasSize(2); + + Map> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("KEE"), Function.identity())); + verifyInternalProperty(rowsByKey, "installation.date", String.valueOf(system2.now())); + verifyInternalProperty(rowsByKey, "installation.version", version.toString()); + } + + private static void verifyInternalProperty(Map> rowsByKey, String key, String val) { + Map row = rowsByKey.get(key); + assertThat(row) + .containsEntry("KEE", key) + .containsEntry("EMPTY", false) + .containsEntry("VAL", val) + .containsEntry("CREATED_AT", NOW); + } + + private void verifyProperties(String qualityGateUuid) { + List> rows = db.select("select " + + "prop_key as \"PROP_KEY\", " + + "is_empty as \"EMPTY\", " + + "text_value as \"VAL\"," + + "created_at as \"CREATED_AT\" " + + " from properties"); + assertThat(rows).hasSize(4); + + Map> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("PROP_KEY"), Function.identity())); + verifyProperty(rowsByKey, "sonar.forceAuthentication", "true"); + verifyProperty(rowsByKey, "sonar.qualityProfiles.allowDisableInheritedRules", "true"); + verifyProperty(rowsByKey, "projects.default.visibility", "public"); + verifyProperty(rowsByKey, "qualitygate.default", qualityGateUuid); + } + + private static void verifyProperty(Map> rowsByKey, String key, String val) { + Map row = rowsByKey.get(key); + assertThat(row) + .containsEntry("PROP_KEY", key) + .containsEntry("EMPTY", false) + .containsEntry("VAL", val) + .containsEntry("CREATED_AT", NOW); + } + + private void verifyRolesOfAdminsGroup() { + assertThat(selectRoles("sonar-administrators")).containsOnly("admin", "profileadmin", "gateadmin", "provisioning", "applicationcreator", "portfoliocreator"); + } + + private void verifyRolesOfUsersGroup() { + assertThat(selectRoles("sonar-users")).containsOnly("provisioning", "scan"); + } + + private void verifyRolesOfAnyone() { + List> rows = db.select("select gr.role as \"role\" " + + "from group_roles gr where gr.group_uuid is null"); + Stream roles = rows.stream() + .map(row -> (String) row.get("role")); + assertThat(roles).isEmpty(); + } + + private Stream selectRoles(String groupName) { + List> rows = db.select("select gr.role as \"role\" " + + "from group_roles gr " + + "inner join groups g on gr.group_uuid = g.uuid " + + "where g.name='" + groupName + "'"); + return rows.stream() + .map(row -> (String) row.get("role")); + } + + private void verifyMembershipOfAdminUser() { + List> rows = db.select("select g.name as \"groupName\" from groups g " + + "inner join groups_users gu on gu.group_uuid = g.uuid " + + "inner join users u on gu.user_uuid = u.uuid " + + "where u.login='admin'"); + List groupNames = rows.stream() + .map(row -> (String) row.get("groupName")) + .toList(); + assertThat(groupNames).containsOnly("sonar-administrators", "sonar-users"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsIT.java new file mode 100644 index 00000000000..47a0f52c474 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsIT.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class AddNclocToProjectsIT { + + private static final String TABLE_NAME = "projects"; + private static final String COLUMN_NAME = "ncloc"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddNclocToProjects.class); + private final DdlChange underTest = new AddNclocToProjects(db.database()); + + @Test + public void add_column() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, true); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableIT.java new file mode 100644 index 00000000000..c5a6a01fbf1 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableIT.java @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v100.CreateScimGroupsTable.TABLE_NAME; + +public class CreateScimGroupsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateScimGroupsTable.class); + + private final DdlChange underTest = new CreateScimGroupsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "scim_uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertPrimaryKey(TABLE_NAME, "pk_scim_groups", "scim_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidIT.java new file mode 100644 index 00000000000..b706c454eab --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidIT.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v100.CreateScimGroupsTable.TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v100.CreateUniqueIndexForScimGroupsUuid.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v100.CreateUniqueIndexForScimGroupsUuid.INDEX_NAME; + +public class CreateUniqueIndexForScimGroupsUuidIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForScimGroupsUuid.class); + private final DdlChange underTest = new CreateUniqueIndexForScimGroupsUuid(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsIT.java new file mode 100644 index 00000000000..df6212d6f48 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropBModuleUuidInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "b_module_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropBModuleUuidInComponents.class); + private final DdlChange underTest = new DropBModuleUuidInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsIT.java new file mode 100644 index 00000000000..313b8e0cd55 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropBModuleUuidPathInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "b_module_uuid_path"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropBModuleUuidPathInComponents.class); + private final DdlChange underTest = new DropBModuleUuidPathInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsIT.java new file mode 100644 index 00000000000..394deec58f0 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsIT.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexProjectsModuleUuidInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "module_uuid"; + private static final String INDEX_NAME = "projects_module_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexProjectsModuleUuidInComponents.class); + private final DdlChange underTest = new DropIndexProjectsModuleUuidInComponents(db.database()); + + @Test + public void drops_index() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + public void execute_whenIndexNameWithPrefix_shouldStillDelete() throws SQLException { + String alteredIndexName = "idx_1234567891345678916456789_" + INDEX_NAME; + db.renameIndex(TABLE_NAME, INDEX_NAME, alteredIndexName); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + db.assertIndex(TABLE_NAME, alteredIndexName, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, alteredIndexName); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsIT.java new file mode 100644 index 00000000000..3dbe6a9ecf7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexProjectsRootUuidInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "root_uuid"; + private static final String INDEX_NAME = "projects_root_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexProjectsRootUuidInComponents.class); + private final DdlChange underTest = new DropIndexProjectsRootUuidInComponents(db.database()); + + @Test + public void drops_index() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsIT.java new file mode 100644 index 00000000000..78ad0cd449d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropModuleUuidInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "module_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropModuleUuidInComponents.class); + private final DdlChange underTest = new DropModuleUuidInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsIT.java new file mode 100644 index 00000000000..815dfb543cb --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropModuleUuidPathInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "module_uuid_path"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropModuleUuidPathInComponents.class); + private final DdlChange underTest = new DropModuleUuidPathInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsIT.java new file mode 100644 index 00000000000..fc3275d8cd2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropRootUuidInComponentsIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "root_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropRootUuidInComponents.class); + private final DdlChange underTest = new DropRootUuidInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, false); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningIT.java new file mode 100644 index 00000000000..31cbdf3bf37 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningIT.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DropScimUserProvisioningIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropScimUserProvisioning.class); + private final DataChange underTest = new DropScimUserProvisioning(db.database()); + + @Test + public void migration_should_truncate_scim_users_table() throws SQLException { + insertScimUser(1); + insertScimUser(2); + + underTest.execute(); + + assertThat(db.select("select * from scim_users")).isEmpty(); + } + + private void insertScimUser(long id) { + db.executeInsert("scim_users", + "scim_uuid", "any-scim-uuid-" + id, + "user_uuid", "any-user-uuid-" + id + ); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertScimUser(1); + insertScimUser(2); + + underTest.execute(); + underTest.execute(); + assertThat(db.select("select * from scim_users")).isEmpty(); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyIT.java new file mode 100644 index 00000000000..7de46c7f79b --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyIT.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.assertj.core.api.Assertions; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +public class DropSonarScimEnabledPropertyIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropSonarScimEnabledProperty.class); + private final DataChange underTest = new DropSonarScimEnabledProperty(db.database()); + + @Test + public void migration_should_remove_scim_property() throws SQLException { + insertScimProperty(db); + + underTest.execute(); + + Assertions.assertThat(db.select("select * from properties")).isEmpty(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertScimProperty(db); + + underTest.execute(); + underTest.execute(); + + Assertions.assertThat(db.select("select * from properties")).isEmpty(); + } + + private void insertScimProperty(MigrationDbTester db) { + db.executeInsert("properties ", + "prop_key", "sonar.scim.enabled", + "is_empty", false, + "text_value", "true", + "created_at", 100_000L, + "uuid", "some-random-uuid" + ); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyIT.java new file mode 100644 index 00000000000..9f287dbc858 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyIT.java @@ -0,0 +1,91 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.version.v100.LogMessageIfSonarScimEnabledPresentProperty.SONAR_SCIM_ENABLED; + +public class LogMessageIfSonarScimEnabledPresentPropertyIT { + + @Rule + public LogTester logger = new LogTester(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(LogMessageIfSonarScimEnabledPresentProperty.class); + private final DataChange underTest = new LogMessageIfSonarScimEnabledPresentProperty(db.database()); + + @Before + public void before() { + logger.clear(); + } + + @Test + public void migration_should_log_message_when_scim_property() throws SQLException { + db.executeInsert("properties ", + "prop_key", "sonar.scim.enabled", + "is_empty", false, + "text_value", "true", + "created_at", 100_000L, + "uuid", "some-random-uuid" + ); + + underTest.execute(); + + assertThat(logger.logs(Level.WARN)) + .hasSize(1) + .containsExactly("'" + SONAR_SCIM_ENABLED + "' property is defined but not read anymore. Please read the upgrade notes" + + " for the instruction to upgrade. User provisioning is deactivated until reactivated from the SonarQube" + + " Administration Interface (\"General->Authentication\"). " + + "See documentation: https://docs.sonarsource.com/sonarqube/10.1/instance-administration/authentication/saml/scim/overview/"); + } + + @Test + public void migration_should_not_log_if_no_scim_property() throws SQLException { + + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).isEmpty(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.executeInsert("properties ", + "prop_key", "sonar.scim.enabled", + "is_empty", false, + "text_value", "true", + "created_at", 100_000L, + "uuid", "some-random-uuid" + ); + + underTest.execute(); + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).hasSize(2); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersIT.java new file mode 100644 index 00000000000..c8a9a65ec21 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.BOOLEAN; + +public class MakeColumnUserLocalNotNullableInUsersIT { + private static final String TABLE_NAME = "users"; + private static final String COLUMN_NAME = "user_local"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeColumnUserLocalNotNullableInUsers.class); + private final MakeColumnUserLocalNotNullableInUsers underTest = new MakeColumnUserLocalNotNullableInUsers(db.database()); + + @Test + public void user_local_column_is_not_null() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java new file mode 100644 index 00000000000..827ffa7d73b --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java @@ -0,0 +1,144 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateNclocForForProjectsIT { + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateNclocForForProjects.class); + + private final DataChange underTest = new PopulateNclocForForProjects(db.database()); + + @Test + public void migration_populates_ncloc_for_projects() throws SQLException { + Map expectedNclocByProjectUuid = populateData(); + underTest.execute(); + verifyNclocCorrectlyPopulatedForProjects(expectedNclocByProjectUuid); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + Map expectedNclocByProjectUuid = populateData(); + underTest.execute(); + // re-entrant + underTest.execute(); + verifyNclocCorrectlyPopulatedForProjects(expectedNclocByProjectUuid); + } + + private Map populateData() { + String nclocMetricUuid = insertMetric("ncloc"); + + String projectUuid1 = insertProject(); + String project1Branch1 = insertProjectBranch(projectUuid1); + String project1Branch2 = insertProjectBranch(projectUuid1); + + long project1maxNcloc = 100; + insertLiveMeasure(nclocMetricUuid, projectUuid1, project1Branch1, 80L); + insertLiveMeasure(nclocMetricUuid, projectUuid1, project1Branch2, project1maxNcloc); + + String otherMetricUuid = insertMetric("other"); + insertLiveMeasure(otherMetricUuid, projectUuid1, project1Branch1, 5000L); + insertLiveMeasure(otherMetricUuid, projectUuid1, project1Branch2, 6000L); + + String projectUuid2 = insertProject(); + String project2Branch1 = insertProjectBranch(projectUuid2); + String project2Branch2 = insertProjectBranch(projectUuid2); + String project2Branch3 = insertProjectBranch(projectUuid2); + + long project2maxNcloc = 60; + insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch1, 20L); + insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch2, 50L); + insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch3, project2maxNcloc); + + return Map.of(projectUuid1, project1maxNcloc, projectUuid2, project2maxNcloc); + } + + private void verifyNclocCorrectlyPopulatedForProjects(Map expectedNclocByProjectUuid) { + for (Map.Entry entry : expectedNclocByProjectUuid.entrySet()) { + String query = String.format("select ncloc from projects where uuid='%s'", entry.getKey()); + Long nclocFromProject = (Long) db.selectFirst(query).get("NCLOC"); + assertThat(nclocFromProject).isEqualTo(entry.getValue()); + } + } + + private String insertMetric(String name) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("NAME", name); + db.executeInsert("metrics", map); + return uuid; + } + + private String insertProject() { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("KEE", randomAlphabetic(20)); + map.put("QUALIFIER", "TRK"); + map.put("PRIVATE", true); + map.put("UPDATED_AT", System.currentTimeMillis()); + db.executeInsert("projects", map); + return uuid; + } + + private String insertProjectBranch(String projectUuid) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("PROJECT_UUID", projectUuid); + map.put("KEE", randomAlphabetic(20)); + map.put("BRANCH_TYPE", "PULL_REQUEST"); + map.put("UPDATED_AT", System.currentTimeMillis()); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("NEED_ISSUE_SYNC", false); + db.executeInsert("project_branches", map); + return uuid; + } + + private void insertLiveMeasure(String metricUuid, String projectUuid, String componentUuid, Long value) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("PROJECT_UUID", projectUuid); + map.put("COMPONENT_UUID", componentUuid); + map.put("METRIC_UUID", metricUuid); + map.put("VALUE", value); + map.put("UPDATED_AT", System.currentTimeMillis()); + map.put("CREATED_AT", System.currentTimeMillis()); + db.executeInsert("live_measures", map); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesIT.java new file mode 100644 index 00000000000..0b9c45680ee --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesIT.java @@ -0,0 +1,128 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.core.util.SequenceUuidFactory; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.MigrationDbTester; +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.Mockito.mock; +import static org.mockito.Mockito.when; + +public class RemoveOrphanRulesFromQualityProfilesIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveOrphanRulesFromQualityProfiles.class); + private final System2 system2 = mock(System2.class); + private final UuidFactory instance = new SequenceUuidFactory(); + private final DataChange underTest = new RemoveOrphanRulesFromQualityProfiles(db.database(), instance, system2); + + @Before + public void before() { + when(system2.now()).thenReturn(1L); + } + + @Test + public void migration_should_remove_orphans() throws SQLException { + insertData(); + + underTest.execute(); + + assertOrphanRuleRemoved(); + assertQualityProfileChanges(); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + insertData(); + + // re-entrant + underTest.execute(); + underTest.execute(); + + assertOrphanRuleRemoved(); + assertQualityProfileChanges(); + } + + private void insertData() { + insertRule("uuid-rule-1", "language-1", "rule1"); + insertRule("uuid-rule-2", "language-2", "rule2"); + insertProfile("uuid-profile-1", "language-1"); + insertProfile("uuid-profile-2", "language-2"); + activateRule("uuid-active-rule-1", "uuid-profile-1", "uuid-rule-1"); + activateRule("uuid-active-rule-2", "uuid-profile-1", "uuid-rule-2"); + activateRule("uuid-active-rule-3", "uuid-profile-2", "uuid-rule-2"); + } + + private void insertRule(String uuid, String language, String ruleKey) { + Map rule = new HashMap<>(); + rule.put("uuid", uuid); + rule.put("plugin_rule_key", language + ":" + ruleKey); + rule.put("plugin_name", "plugin-name-1"); + rule.put("scope", "MAIN"); + rule.put("language", language); + rule.put("is_template", false); + rule.put("is_ad_hoc", false); + rule.put("is_external", false); + db.executeInsert("rules", rule); + } + + private void insertProfile(String uuid, String language) { + Map profile = new HashMap<>(); + profile.put("uuid", uuid); + profile.put("name", "profile-name-1"); + profile.put("language", language); + profile.put("is_built_in", false); + db.executeInsert("rules_profiles", profile); + } + + private void activateRule(String activeRuleUuid, String profileUuid, String ruleUuid) { + Map active_rule = new HashMap<>(); + active_rule.put("uuid", activeRuleUuid); + active_rule.put("failure_level", 3); + active_rule.put("profile_uuid", profileUuid); + active_rule.put("rule_uuid", ruleUuid); + db.executeInsert("active_rules", active_rule); + } + + private void assertOrphanRuleRemoved() { + assertThat(db.select("SELECT * from active_rules")) + .extracting(r -> r.get("UUID")) + .containsExactly("uuid-active-rule-1", "uuid-active-rule-3"); + } + + private void assertQualityProfileChanges() { + assertThat(db.select("SELECT * from qprofile_changes")) + .extracting(r -> r.get("KEE"), r -> r.get("RULES_PROFILE_UUID"), r -> r.get("CHANGE_TYPE"), r -> r.get("USER_UUID"), r -> r.get("CHANGE_DATA"), r -> r.get("CREATED_AT")) + .containsExactly(tuple("1", "uuid-profile-1", "DEACTIVATED", null, "ruleUuid=uuid-rule-2", 1L)); + } + + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersIT.java new file mode 100644 index 00000000000..ab45d623f94 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersIT.java @@ -0,0 +1,95 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v100; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang.RandomStringUtils.randomNumeric; +import static org.assertj.core.api.Assertions.assertThat; + +public class UpdateUserLocalValueInUsersIT { + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateUserLocalValueInUsers.class); + + private final DataChange underTest = new UpdateUserLocalValueInUsers(db.database()); + + @Test + public void migration_updates_user_local_if_null() throws SQLException { + String userUuid1 = insertUser(true); + String userUuid2 = insertUser(false); + String userUuid3 = insertUser(null); + + underTest.execute(); + + assertUserLocalIsUpdatedCorrectly(userUuid1, true); + assertUserLocalIsUpdatedCorrectly(userUuid2, false); + assertUserLocalIsUpdatedCorrectly(userUuid3, true); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String userUuid1 = insertUser(true); + String userUuid2 = insertUser(false); + String userUuid3 = insertUser(null); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertUserLocalIsUpdatedCorrectly(userUuid1, true); + assertUserLocalIsUpdatedCorrectly(userUuid2, false); + assertUserLocalIsUpdatedCorrectly(userUuid3, true); + } + + private void assertUserLocalIsUpdatedCorrectly(String userUuid, boolean expected) { + String selectSql = String.format("select user_local from users where uuid='%s'", userUuid); + assertThat(db.select(selectSql).stream() + .map(row -> row.get("USER_LOCAL")) + .toList()) + .containsExactlyInAnyOrder(expected); + } + + private String insertUser(Boolean userLocal) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("LOGIN", randomAlphabetic(20)); + map.put("EXTERNAL_LOGIN", randomAlphabetic(20)); + map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube"); + map.put("EXTERNAL_ID", randomNumeric(5)); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("USER_LOCAL", userLocal); + map.put("RESET_PASSWORD", false); + db.executeInsert("users", map); + return uuid; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableIT.java new file mode 100644 index 00000000000..66f9c061153 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class AddCodeVariantsColumnInIssuesTableIT { + + private static final String TABLE_NAME = "issues"; + private static final String COLUMN_NAME = "code_variants"; + private static final int COLUMN_SIZE = 4000; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCodeVariantsColumnInIssuesTable.class); + private final AddCodeVariantsColumnInIssuesTable underTest = new AddCodeVariantsColumnInIssuesTable(db.database()); + + @Test + public void migration_should_add_column() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, COLUMN_SIZE, true); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, COLUMN_SIZE, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesIT.java new file mode 100644 index 00000000000..3bc39ceffb4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.BOOLEAN; + +public class AddIsMainColumnInProjectBranchesIT { + + private static final String TABLE_NAME = "project_branches"; + private static final String COLUMN_NAME = "is_main"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddIsMainColumnInProjectBranches.class); + private final AddIsMainColumnInProjectBranches underTest = new AddIsMainColumnInProjectBranches(db.database()); + + @Test + public void is_main_column_exists_with_null_value() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableIT.java new file mode 100644 index 00000000000..9a9f64718af --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableIT.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.AddReportSchedulesTable.TABLE_NAME; + +public class AddReportSchedulesTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddReportSchedulesTable.class); + + private final DdlChange underTest = new AddReportSchedulesTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "portfolio_uuid", Types.VARCHAR, UUID_SIZE, true); + db.assertColumnDefinition(TABLE_NAME, "branch_uuid", Types.VARCHAR, UUID_SIZE, true); + db.assertColumnDefinition(TABLE_NAME, "last_send_time_in_ms", Types.BIGINT, null, false); + db.assertPrimaryKey(TABLE_NAME, "pk_report_schedules", "uuid"); + + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + } + + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableIT.java new file mode 100644 index 00000000000..5fce8756391 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableIT.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.AddReportSubscriptionsTable.TABLE_NAME; + +public class AddReportSubscriptionsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddReportSubscriptionsTable.class); + + private final DdlChange underTest = new AddReportSubscriptionsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "portfolio_uuid", Types.VARCHAR, UUID_SIZE, true); + db.assertColumnDefinition(TABLE_NAME, "branch_uuid", Types.VARCHAR, UUID_SIZE, true); + db.assertColumnDefinition(TABLE_NAME, "user_uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertPrimaryKey(TABLE_NAME, "pk_report_subscriptions", "uuid"); + + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesIT.java new file mode 100644 index 00000000000..4c089385ab7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.BOOLEAN; + +public class AlterIsMainColumnInProjectBranchesIT { + + private static final String TABLE_NAME = "project_branches"; + private static final String COLUMN_NAME = "is_main"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AlterIsMainColumnInProjectBranches.class); + private final AlterIsMainColumnInProjectBranches underTest = new AlterIsMainColumnInProjectBranches(db.database()); + + @Test + public void execute_shouldNotBeNullable() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableIT.java new file mode 100644 index 00000000000..14cb88545e2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableIT.java @@ -0,0 +1,66 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_GROUP_ID_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.GROUP_UUID_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.TABLE_NAME; + +public class CreateExternalGroupsTableIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateExternalGroupsTable.class); + + private final DdlChange createExternalGroupsTable = new CreateExternalGroupsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + createExternalGroupsTable.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, GROUP_UUID_COLUMN_NAME, Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME, Types.VARCHAR, 255, false); + db.assertColumnDefinition(TABLE_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, Types.VARCHAR, 100, false); + db.assertPrimaryKey(TABLE_NAME, "pk_external_groups", GROUP_UUID_COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + createExternalGroupsTable.execute(); + // re-entrant + createExternalGroupsTable.execute(); + + db.assertTableExists(TABLE_NAME); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableIT.java new file mode 100644 index 00000000000..71e650d7733 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.INDEX_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.TABLE_NAME; + +public class CreateIndexForEmailOnUsersTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForEmailOnUsersTable.class); + private final CreateIndexForEmailOnUsersTable createIndexForEmailOnUsersTable = new CreateIndexForEmailOnUsersTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndexForEmailOnUsersTable.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndexForEmailOnUsersTable.execute(); + createIndexForEmailOnUsersTable.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableIT.java new file mode 100644 index 00000000000..5ffa961e6fc --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForScmAccountOnScmAccountsTable.INDEX_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNTS_TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME; + +public class CreateIndexForScmAccountOnScmAccountsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForScmAccountOnScmAccountsTable.class); + private final CreateIndexForScmAccountOnScmAccountsTable createIndexForScmAccountOnScmAccountsTable = new CreateIndexForScmAccountOnScmAccountsTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME); + + createIndexForScmAccountOnScmAccountsTable.execute(); + + db.assertIndex(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndexForScmAccountOnScmAccountsTable.execute(); + createIndexForScmAccountOnScmAccountsTable.execute(); + + db.assertIndex(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableIT.java new file mode 100644 index 00000000000..ed2fb6eea45 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableIT.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_GROUP_ID_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.INDEX_NAME; + +public class CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.class); + private final CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable createIndexOnExternalIdAndIdentityOnExternalGroupsTable = new CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable( + db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); + createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensIT.java new file mode 100644 index 00000000000..223ee32cf30 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class CreateProjectUuidInUserTokensIT { + private static final String TABLE_NAME = "user_tokens"; + private static final String COLUMN_NAME = "project_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateProjectUuidInUserTokens.class); + private final CreateProjectUuidInUserTokens underTest = new CreateProjectUuidInUserTokens(db.database()); + + @Test + public void migration_creates_new_column() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, null); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, null); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableIT.java new file mode 100644 index 00000000000..a2c07b75cab --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableIT.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNTS_TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.USER_UUID_COLUMN_NAME; + +public class CreateScmAccountsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateScmAccountsTable.class); + + private final DdlChange createScmAccountsTable = new CreateScmAccountsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(SCM_ACCOUNTS_TABLE_NAME); + + createScmAccountsTable.execute(); + + db.assertTableExists(SCM_ACCOUNTS_TABLE_NAME); + db.assertColumnDefinition(SCM_ACCOUNTS_TABLE_NAME, USER_UUID_COLUMN_NAME, Types.VARCHAR, USER_UUID_SIZE, false); + db.assertColumnDefinition(SCM_ACCOUNTS_TABLE_NAME, SCM_ACCOUNT_COLUMN_NAME, Types.VARCHAR, SCM_ACCOUNT_SIZE, false); + db.assertPrimaryKey(SCM_ACCOUNTS_TABLE_NAME, "pk_scm_accounts", USER_UUID_COLUMN_NAME, SCM_ACCOUNT_COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(SCM_ACCOUNTS_TABLE_NAME); + + createScmAccountsTable.execute(); + // re-entrant + createScmAccountsTable.execute(); + + db.assertTableExists(SCM_ACCOUNTS_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableIT.java new file mode 100644 index 00000000000..2c8c88efed4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableIT.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v101.AddReportSchedulesTable.TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.COLUMN_NAME_BRANCH; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.COLUMN_NAME_PORTFOLIO; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.INDEX_NAME; + + +public class CreateUniqueIndexForReportSchedulesTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForReportSchedulesTable.class); + private final CreateUniqueIndexForReportSchedulesTable createUniqueIndexForReportSchedulesTable = new CreateUniqueIndexForReportSchedulesTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createUniqueIndexForReportSchedulesTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createUniqueIndexForReportSchedulesTable.execute(); + createUniqueIndexForReportSchedulesTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableIT.java new file mode 100644 index 00000000000..6dc3f0dff7a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableIT.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v101.AddReportSubscriptionsTable.TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_BRANCH; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_PORTFOLIO; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_USER; +import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.INDEX_NAME; + + +public class CreateUniqueIndexForReportSubscriptionsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForReportSubscriptionsTable.class); + private final CreateUniqueIndexForReportSubscriptionsTable createUniqueIndexForReportSubscriptionsTable = new CreateUniqueIndexForReportSubscriptionsTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createUniqueIndexForReportSubscriptionsTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH, COLUMN_NAME_USER); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createUniqueIndexForReportSubscriptionsTable.execute(); + createUniqueIndexForReportSubscriptionsTable.execute(); + + db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH, COLUMN_NAME_USER); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensIT.java new file mode 100644 index 00000000000..dd316845335 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v101.DropProjectKeyInUserTokens.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.DropProjectKeyInUserTokens.TABLE_NAME; + +public class DropProjectKeyInUserTokensIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropProjectKeyInUserTokens.class); + private final DdlChange underTest = new DropProjectKeyInUserTokens(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersIT.java new file mode 100644 index 00000000000..293175ab345 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v101.DropScmAccountsInUsers.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.DropScmAccountsInUsers.TABLE_NAME; + +public class DropScmAccountsInUsersIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropScmAccountsInUsers.class); + private final DdlChange dropScmAccountsInUsers = new DropScmAccountsInUsers(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); + dropScmAccountsInUsers.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); + dropScmAccountsInUsers.execute(); + dropScmAccountsInUsers.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosIT.java new file mode 100644 index 00000000000..6311e673e74 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosIT.java @@ -0,0 +1,165 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.assertj.core.api.Assertions; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.resources.Qualifiers; +import org.sonar.db.MigrationDbTester; + +import static java.util.stream.Collectors.toSet; + +public class FixDifferentUuidsForSubportfoliosIT { + private static final String OLD_UUID = "differentSubPfUuid"; + private static final String SUB_PF_KEY = "subPfKey"; + private static final String NEW_SUBPF_UUID = "subPfUuid"; + private static final String PF_UUID = "pfUuid"; + private static final String NEW_CHILD_SUBPF_UUID = "childsubpfUuid"; + private static final String OLD_CHILD_SUBPF_UUID = "old_child_subpf_uuid"; + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(FixDifferentUuidsForSubportfolios.class); + private final FixDifferentUuidsForSubportfolios underTest = new FixDifferentUuidsForSubportfolios(db.database()); + + @Test + public void execute_shouldUpdatePortfoliosAndPortfolioProjectsAndPortfolioReferenceTable() throws SQLException { + insertPortfolio("pfKey", PF_UUID); + insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); + insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); + insertPortfolioProject("projUuid", OLD_UUID); + insertPortfolioReference("refUuid", OLD_UUID); + + underTest.execute(); + + Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); + } + + @Test + public void execute_shouldBeRentrant() throws SQLException { + insertPortfolio("pfKey", PF_UUID); + insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); + insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); + insertPortfolioProject("projUuid", OLD_UUID); + insertPortfolioReference("refUuid", OLD_UUID); + + underTest.execute(); + underTest.execute(); + + Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); + } + + @Test + public void execute_shouldFixUuidForSubPortfolioAtDifferentLevels() throws SQLException { + insertPortfolio("pfKey", PF_UUID); + + insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); + insertComponent("child_subpfkey", NEW_CHILD_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); + + insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); + insertSubPortfolio("child_subpfkey", OLD_UUID, PF_UUID, OLD_CHILD_SUBPF_UUID); + insertPortfolioProject("projUuid", OLD_CHILD_SUBPF_UUID); + insertPortfolioReference("refUuid", OLD_CHILD_SUBPF_UUID); + + underTest.execute(); + + Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID, NEW_CHILD_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolios", "parent_uuid")).containsExactlyInAnyOrder(null, PF_UUID, NEW_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_CHILD_SUBPF_UUID); + Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_CHILD_SUBPF_UUID); + } + + private Set findValueIn(String table, String field) { + return db.select(String.format("select %s FROM %s", field, table)) + .stream() + .map(row -> (String) row.get(field)) + .collect(toSet()); + } + + + private String insertComponent(String key, String uuid, String branchUuid, String qualifier) { + Map map = new HashMap<>(); + map.put("UUID", uuid); + map.put("KEE", key); + map.put("BRANCH_UUID", branchUuid); + map.put("UUID_PATH", "." + uuid + "."); + map.put("QUALIFIER", qualifier); + map.put("ENABLED", true); + map.put("PRIVATE", true); + + db.executeInsert("components", map); + return uuid; + } + + private String insertPortfolio(String kee, String uuid) { + return insertSubPortfolio(kee, uuid, uuid); + } + + private String insertSubPortfolio(String kee, String rootUuid, String uuid) { + return insertSubPortfolio(kee, null, rootUuid, uuid); + } + + private String insertSubPortfolio(String kee, @Nullable String parentUuid, String rootUuid, String uuid) { + Map map = new HashMap<>(); + map.put("UUID", uuid); + map.put("KEE", kee); + map.put("NAME", uuid); + map.put("ROOT_UUID", rootUuid); + map.put("PRIVATE", false); + map.put("SELECTION_MODE", "MANUAL"); + map.put("PARENT_UUID", parentUuid); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("UPDATED_AT", System.currentTimeMillis()); + + + db.executeInsert("portfolios", map); + return uuid; + } + + private String insertPortfolioReference(String uuid, String portfolioUuid) { + Map map = new HashMap<>(); + map.put("UUID", uuid); + map.put("PORTFOLIO_UUID", portfolioUuid); + map.put("REFERENCE_UUID", "reference"); + map.put("CREATED_AT", System.currentTimeMillis()); + + db.executeInsert("portfolio_references", map); + return uuid; + } + + private String insertPortfolioProject(String uuid, String portfolioUuid) { + Map map = new HashMap<>(); + map.put("UUID", uuid); + map.put("PORTFOLIO_UUID", portfolioUuid); + map.put("PROJECT_UUID", portfolioUuid); + map.put("CREATED_AT", System.currentTimeMillis()); + + db.executeInsert("portfolio_projects", map); + return uuid; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesIT.java new file mode 100644 index 00000000000..24cb3cf0b26 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.TABLE_NAME; + +public class IncreaseKeeColumnSizeInInternalPropertiesIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseKeeColumnSizeInInternalProperties.class); + private final IncreaseKeeColumnSizeInInternalProperties underTest = new IncreaseKeeColumnSizeInInternalProperties(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 20, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 20, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityIT.java new file mode 100644 index 00000000000..1a86734587d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.TABLE_NAME; + +public class IncreaseTaskTypeColumnSizeInCeActivityIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseTaskTypeColumnSizeInCeActivity.class); + private final IncreaseTaskTypeColumnSizeInCeActivity underTest = new IncreaseTaskTypeColumnSizeInCeActivity(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueIT.java new file mode 100644 index 00000000000..99e6f21f482 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.TABLE_NAME; + +public class IncreaseTaskTypeColumnSizeInCeQueueIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseTaskTypeColumnSizeInCeQueue.class); + private final IncreaseTaskTypeColumnSizeInCeQueue underTest = new IncreaseTaskTypeColumnSizeInCeQueue(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsIT.java new file mode 100644 index 00000000000..7663f7dcd2c --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsIT.java @@ -0,0 +1,183 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.ScmAccountRow; + +import static java.lang.String.format; +import static java.util.stream.Collectors.toSet; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.SCM_ACCOUNTS_SEPARATOR_CHAR; + +public class MigrateScmAccountsFromUsersToScmAccountsIT { + + private static final UuidFactory UUID_FACTORY = UuidFactoryFast.getInstance(); + private static final String SCM_ACCOUNT1 = "scmaccount"; + private static final String SCM_ACCOUNT2 = "scmaccount2"; + private static final String SCM_ACCOUNT_CAMELCASE = "scmAccount3"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MigrateScmAccountsFromUsersToScmAccounts.class); + private final DataChange migrateScmAccountsFromUsersToScmAccounts = new MigrateScmAccountsFromUsersToScmAccounts(db.database()); + + @Test + public void execute_whenUserHasNullScmAccounts_doNotInsertInScmAccounts() throws SQLException { + insertUserAndGetUuid(null); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).isEmpty(); + } + + @Test + public void execute_whenUserHasEmptyScmAccounts_doNotInsertInScmAccounts() throws SQLException { + insertUserAndGetUuid(""); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).isEmpty(); + } + + @Test + public void execute_whenUserHasEmptyScmAccountsWithOneSeparator_doNotInsertInScmAccounts() throws SQLException { + insertUserAndGetUuid(String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR)); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).isEmpty(); + } + + @Test + public void execute_whenUserHasEmptyScmAccountsWithTwoSeparators_doNotInsertInScmAccounts() throws SQLException { + insertUserAndGetUuid(SCM_ACCOUNTS_SEPARATOR_CHAR + String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR)); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).isEmpty(); + } + + @Test + public void execute_whenUserHasOneScmAccountWithoutSeparator_insertsInScmAccounts() throws SQLException { + String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); + } + + @Test + public void execute_whenUserHasOneScmAccountWithSeparators_insertsInScmAccounts() throws SQLException { + String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR)); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); + } + + @Test + public void execute_whenUserHasOneScmAccountWithMixedCase_insertsInScmAccountsInLowerCase() throws SQLException { + String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT_CAMELCASE, SCM_ACCOUNTS_SEPARATOR_CHAR)); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT_CAMELCASE.toLowerCase(Locale.ENGLISH))); + } + + @Test + public void execute_whenUserHasTwoScmAccount_insertsInScmAccounts() throws SQLException { + String userUuid = insertUserAndGetUuid(format("%s%s%s%s%s", + SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT2, SCM_ACCOUNTS_SEPARATOR_CHAR)); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).containsExactlyInAnyOrder( + new ScmAccountRow(userUuid, SCM_ACCOUNT1), + new ScmAccountRow(userUuid, SCM_ACCOUNT2) + ); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1); + + migrateScmAccountsFromUsersToScmAccounts.execute(); + migrateScmAccountsFromUsersToScmAccounts.execute(); + + Set scmAccounts = findAllScmAccounts(); + assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); + } + + @Test + public void migration_should_be_reentrant_if_scm_account_column_dropped() { + db.executeDdl("alter table users drop column scm_accounts"); + + assertThatNoException().isThrownBy(migrateScmAccountsFromUsersToScmAccounts::execute); + } + + + private Set findAllScmAccounts() { + Set scmAccounts = db.select("select user_uuid, scm_account from scm_accounts") + .stream() + .map(row -> new ScmAccountRow((String) row.get("user_uuid"), (String) row.get("scm_account"))) + .collect(toSet()); + return scmAccounts; + } + + private String insertUserAndGetUuid(@Nullable String scmAccounts) { + + Map map = new HashMap<>(); + String uuid = UUID_FACTORY.create(); + String login = "login_" + uuid; + map.put("UUID", uuid); + map.put("LOGIN", login); + map.put("HASH_METHOD", "tagada"); + map.put("EXTERNAL_LOGIN", login); + map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube"); + map.put("EXTERNAL_ID", login); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("RESET_PASSWORD", false); + map.put("USER_LOCAL", true); + map.put("SCM_ACCOUNTS", scmAccounts); + db.executeInsert("users", map); + return uuid; + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensIT.java new file mode 100644 index 00000000000..cbffa92cae2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensIT.java @@ -0,0 +1,112 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; + +public class PopulateProjectUuidInUserTokensIT { + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateProjectUuidInUserTokens.class); + + private final DataChange underTest = new PopulateProjectUuidInUserTokens(db.database()); + + @Test + public void migration_populates_project_uuid_for_tokens() throws SQLException { + String project1Uuid = insertProject("project1"); + String project2Uuid = insertProject("project2"); + + String token1Uuid = insertUserToken("project1"); + String token2Uuid = insertUserToken("project1"); + String token3Uuid = insertUserToken("project2"); + String token4Uuid = insertUserToken(null); + + underTest.execute(); + assertThat(db.select("select * from user_tokens")) + .extracting(r -> r.get("UUID"), r -> r.get("PROJECT_UUID")) + .containsOnly( + tuple(token1Uuid, project1Uuid), + tuple(token2Uuid, project1Uuid), + tuple(token3Uuid, project2Uuid), + tuple(token4Uuid, null)); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String project1Uuid = insertProject("project1"); + String project2Uuid = insertProject("project2"); + + String token1Uuid = insertUserToken("project1"); + String token2Uuid = insertUserToken("project1"); + String token3Uuid = insertUserToken("project2"); + String token4Uuid = insertUserToken(null); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from user_tokens")) + .extracting(r -> r.get("UUID"), r -> r.get("PROJECT_UUID")) + .containsOnly( + tuple(token1Uuid, project1Uuid), + tuple(token2Uuid, project1Uuid), + tuple(token3Uuid, project2Uuid), + tuple(token4Uuid, null)); + } + + private String insertUserToken(@Nullable String projectKey) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("USER_UUID", "user" + uuid); + map.put("NAME", "name" + uuid); + map.put("TOKEN_HASH", "token" + uuid); + map.put("CREATED_AT", 1); + map.put("PROJECT_KEY", projectKey); + map.put("TYPE", "PROJECT_ANALYSIS_TOKEN"); + + db.executeInsert("user_tokens", map); + return uuid; + } + + private String insertProject(String projectKey) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("KEE", projectKey); + map.put("QUALIFIER", "TRK"); + map.put("PRIVATE", true); + map.put("UPDATED_AT", System.currentTimeMillis()); + db.executeInsert("projects", map); + return uuid; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesIT.java new file mode 100644 index 00000000000..ff508256565 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesIT.java @@ -0,0 +1,123 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +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; + +public class PopulateReportSchedulesIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateReportSchedules.class); + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private final DataChange underTest = new PopulateReportSchedules(db.database()); + + @Test + public void execute_shouldPopulateFromPortfolioProperties() throws SQLException { + insertPortfolio("uuid1"); + insertPortfolioProperty("uuid1", "1234"); + + underTest.execute(); + + assertThat(db.select("select * from report_schedules")) + .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS")) + .containsOnly(tuple("uuid1", null, 1234L)); + } + + @Test + public void execute_shouldPopulateFromBranchProperties() throws SQLException { + insertBranch("uuid1"); + insertProjectBranchProperty("uuid1", "1234"); + + underTest.execute(); + + assertThat(db.select("select * from report_schedules")) + .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS")) + .containsOnly(tuple(null, "uuid1", 1234L)); + } + + @Test + public void execute_whenPropertyMatchesBothBranchAndPortfolio_shouldNotPopulate() throws SQLException { + insertBranch("uuid1"); + insertPortfolio("uuid1"); + insertProjectBranchProperty("uuid1", "1234"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from report_schedules")).isEmpty(); + } + + private void insertPortfolio(String uuid) { + db.executeInsert("portfolios", + "uuid", uuid, + "kee", "kee_" + uuid, + "name", "name_" + uuid, + "root_uuid", uuid, + "private", true, + "selection_mode", "manual", + "created_at", 1000, + "updated_at", 1000 + ); + } + + private void insertProjectBranchProperty(String portfolioUuid, String value) { + db.executeInsert("properties", + "uuid", uuidFactory.create(), + "prop_key", "sonar.governance.report.project.branch.lastSendTimeInMs", + "is_empty", false, + "text_value", value, + "created_at", 1000, + "entity_uuid", portfolioUuid + ); + } + + private void insertPortfolioProperty(String portfolioUuid, String value) { + db.executeInsert("properties", + "uuid", uuidFactory.create(), + "prop_key", "sonar.governance.report.lastSendTimeInMs", + "is_empty", false, + "text_value", value, + "created_at", 1000, + "entity_uuid", portfolioUuid + ); + } + + private void insertBranch(String uuid) { + db.executeInsert("project_branches", + "uuid", uuid, + "project_uuid", "project_" + uuid, + "kee", "kee_" + uuid, + "branch_type", "BRANCH", + "created_at", 1000, + "updated_at", 1000, + "need_issue_sync", false, + "is_main", true + ); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsIT.java new file mode 100644 index 00000000000..cc0e607098b --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsIT.java @@ -0,0 +1,121 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +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; + +public class PopulateReportSubscriptionsIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateReportSubscriptions.class); + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private final DataChange underTest = new PopulateReportSubscriptions(db.database()); + + @Test + public void execute_shouldPopulateFromPortfolioProperties() throws SQLException { + insertPortfolio("uuid1"); + insertPortfolioProperty("uuid1", "1234"); + + underTest.execute(); + + assertThat(db.select("select * from report_subscriptions")) + .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("USER_UUID")) + .containsOnly(tuple("uuid1", null, "1234")); + } + + @Test + public void execute_shouldPopulateFromBranchProperties() throws SQLException { + insertBranch("uuid1"); + insertBranchProperty("uuid1", "1234"); + + underTest.execute(); + + assertThat(db.select("select * from report_subscriptions")) + .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("USER_UUID")) + .containsOnly(tuple(null, "uuid1", "1234")); + } + + @Test + public void execute_whenPropertyMatchesBothBranchAndPortfolio_shouldNotPopulate() throws SQLException { + insertBranch("uuid1"); + insertPortfolio("uuid1"); + insertBranchProperty("uuid1", "1234"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from report_subscriptions")).isEmpty(); + } + + private void insertPortfolio(String uuid) { + db.executeInsert("portfolios", + "uuid", uuid, + "kee", "kee_" + uuid, + "name", "name_" + uuid, + "root_uuid", uuid, + "private", true, + "selection_mode", "manual", + "created_at", 1000, + "updated_at", 1000 + ); + } + + private void insertBranchProperty(String branchUuid, String userUuid){ + insertProperty( branchUuid, userUuid, "sonar.governance.report.userNotification"); + } + + private void insertPortfolioProperty(String branchUuid, String userUuid){ + insertProperty( branchUuid, userUuid, "sonar.governance.report.project.branch.userNotification"); + } + + private void insertProperty(String componentUuid, String userUuid, String propertyKey) { + db.executeInsert("properties", + "uuid", uuidFactory.create(), + "prop_key", propertyKey, + "is_empty", false, + "text_value", "true", + "created_at", 1000, + "entity_uuid", componentUuid, + "user_uuid", userUuid + ); + } + + private void insertBranch(String uuid) { + db.executeInsert("project_branches", + "uuid", uuid, + "project_uuid", "project_" + uuid, + "kee", "kee_" + uuid, + "branch_type", "BRANCH", + "created_at", 1000, + "updated_at", 1000, + "need_issue_sync", false, + "is_main", true + ); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensIT.java new file mode 100644 index 00000000000..1261992557d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensIT.java @@ -0,0 +1,98 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RemoveOrphanUserTokensIT { + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveOrphanUserTokens.class); + + private final DataChange underTest = new RemoveOrphanUserTokens(db.database()); + + @Test + public void migration_deletes_orphan_tokens() throws SQLException { + String project1Uuid = insertProject("project1"); + + String token1Uuid = insertUserToken("project1"); + String token2Uuid = insertUserToken("orphan"); + String token3Uuid = insertUserToken(null); + + underTest.execute(); + assertThat(db.select("select * from user_tokens")) + .extracting(r -> r.get("UUID")) + .containsOnly(token1Uuid, token3Uuid); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String project1Uuid = insertProject("project1"); + + String token1Uuid = insertUserToken("project1"); + String token2Uuid = insertUserToken("orphan"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from user_tokens")) + .extracting(r -> r.get("UUID")) + .containsOnly(token1Uuid); + } + + private String insertUserToken( @Nullable String projectKey) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("USER_UUID", "user" + uuid); + map.put("NAME", "name" + uuid); + map.put("TOKEN_HASH", "token" + uuid); + map.put("CREATED_AT", 1); + map.put("PROJECT_KEY", projectKey); + map.put("TYPE", "PROJECT_ANALYSIS_TOKEN"); + + db.executeInsert("user_tokens", map); + return uuid; + } + + private String insertProject(String projectKey) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + map.put("KEE", projectKey); + map.put("QUALIFIER", "TRK"); + map.put("PRIVATE", true); + map.put("UPDATED_AT", System.currentTimeMillis()); + db.executeInsert("projects", map); + return uuid; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesIT.java new file mode 100644 index 00000000000..3078f9867cd --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesIT.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RemoveReportPropertiesIT { + + private static final String SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION = "sonar.governance.report.userNotification"; + private static final String SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION = "sonar.governance.report.project.branch.userNotification"; + private static final String SONAR_GOVERNANCE_REPORT_LAST_SEND_TIME_IN_MS = "sonar.governance.report.lastSendTimeInMs"; + private static final String SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_LAST_SEND_TIME_IN_MS = "sonar.governance.report.project.branch.lastSendTimeInMs"; + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveReportProperties.class); + + private final DataChange underTest = new RemoveReportProperties(db.database()); + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Test + public void execute_shouldRemoveRelevantPropertiesFromTable() throws SQLException { + insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION, "true"); + insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION, "true"); + insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_LAST_SEND_TIME_IN_MS, "12"); + insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_LAST_SEND_TIME_IN_MS, "123"); + insertProperty( "portfolio_uuid", "user_uuid", "sonar.other.property", "123"); + + underTest.execute(); + + assertThat(db.select("select * from properties")).hasSize(1) + .extracting(r->r.get("PROP_KEY")).containsExactly("sonar.other.property"); + } + + @Test + public void execute_shouldBeIdempotent() throws SQLException { + insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION, "true"); + insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION, "true"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from properties")).isEmpty(); + } + + private void insertProperty(String componentUuid, String userUuid, String propertyKey, String value) { + db.executeInsert("properties", + "uuid", uuidFactory.create(), + "prop_key", propertyKey, + "is_empty", false, + "text_value", value, + "created_at", 1000, + "entity_uuid", componentUuid, + "user_uuid", userUuid + ); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesIT.java new file mode 100644 index 00000000000..780572144b7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameColumnComponentUuidInPropertiesIT { + + public static final String TABLE_NAME = "properties"; + public static final String NEW_COLUMN_NAME = "entity_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameColumnComponentUuidInProperties.class); + private final RenameColumnComponentUuidInProperties underTest = new RenameColumnComponentUuidInProperties(db.database()); + + @Test + public void columnIsRenamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesIT.java new file mode 100644 index 00000000000..17e016b5b39 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesIT.java @@ -0,0 +1,105 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v101; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.UuidFactory; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class UpdateIsMainColumnInProjectBranchesIT { + + private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateIsMainColumnInProjectBranches.class); + + private final DataChange underTest = new UpdateIsMainColumnInProjectBranches(db.database()); + + private static int not_random_value_always_incremented = 0; + + @Test + public void migration_updates_is_main_if_row_has_the_same_uuids() throws SQLException { + String branchUuid1 = insertProjectBranch(true); + String branchUuid2 = insertProjectBranch(false); + + underTest.execute(); + + assertBranchIsMain(branchUuid1); + assertBranchIsNotMain(branchUuid2); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + String branchUuid1 = insertProjectBranch(true); + String branchUuid2 = insertProjectBranch(false); + + underTest.execute(); + // re-entrant + underTest.execute(); + + assertBranchIsMain(branchUuid1); + assertBranchIsNotMain(branchUuid2); + } + + private void assertBranchIsMain(String branchUuid) { + assertBranchIs(branchUuid, true); + } + + private void assertBranchIsNotMain(String branchUuid) { + assertBranchIs(branchUuid, false); + } + + private void assertBranchIs(String branchUuid, boolean isMain) { + String selectSql = String.format("select is_main from project_branches where uuid='%s'", branchUuid); + assertThat(db.select(selectSql).stream() + .map(row -> row.get("IS_MAIN")) + .toList()) + .containsExactlyInAnyOrder(isMain); + } + + private String insertProjectBranch(boolean sameUuids) { + Map map = new HashMap<>(); + String uuid = uuidFactory.create(); + map.put("UUID", uuid); + if(sameUuids) { + map.put("PROJECT_UUID", uuid); + } else { + map.put("PROJECT_UUID", "uuid" + not_random_value_always_incremented++); + } + map.put("KEE", "randomKey"); + map.put("BRANCH_TYPE", "BRANCH"); + map.put("MERGE_BRANCH_UUID", null); + map.put("CREATED_AT", System.currentTimeMillis()); + map.put("UPDATED_AT", System.currentTimeMillis()); + map.put("PULL_REQUEST_BINARY", null); + map.put("EXCLUDE_FROM_PURGE", true); + map.put("NEED_ISSUE_SYNC", false); + db.executeInsert("project_branches", map); + return uuid; + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesIT.java new file mode 100644 index 00000000000..32484acd72a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +public class AddCleanCodeAttributeInRulesIT { + private static final String TABLE_NAME = "rules"; + private static final String COLUMN_NAME = "clean_code_attribute"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCleanCodeAttributeInRules.class); + + private final AddCleanCodeAttributeInRules underTest = new AddCleanCodeAttributeInRules(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); + } + + @Test + public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledIT.java new file mode 100644 index 00000000000..8b47336d8a4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledIT.java @@ -0,0 +1,105 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; +import org.sonar.api.utils.System2; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.version.v102.AddUserConsentRequiredIfGithubAutoProvisioningEnabled.PROP_KEY; +import static org.sonar.server.platform.db.migration.version.v102.AddUserConsentRequiredIfGithubAutoProvisioningEnabled.PROVISIONING_GITHUB_ENABLED_PROP_KEY; + +public class AddUserConsentRequiredIfGithubAutoProvisioningEnabledIT { + + @Rule + public LogTester logger = new LogTester(); + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddUserConsentRequiredIfGithubAutoProvisioningEnabled.class); + private final DataChange underTest = new AddUserConsentRequiredIfGithubAutoProvisioningEnabled(db.database(), new System2(), UuidFactoryFast.getInstance()); + + @Before + public void before() { + logger.clear(); + } + + @Test + public void migration_whenGitHubAutoProvisioningPropertyNotPresent_shouldNotRequireConsent() throws SQLException { + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).isEmpty(); + assertThat(isConsentRequired()).isFalse(); + } + + @Test + public void migration_whenGitHubAutoProvisioningDisabled_shouldNotRequireConsent() throws SQLException { + disableGithubProvisioning(); + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).isEmpty(); + assertThat(isConsentRequired()).isFalse(); + } + + @Test + public void migration_whenGitHubAutoProvisioningEnabled_shouldRequireConsent() throws SQLException { + enableGithubProvisioning(); + + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).containsExactly("Automatic synchronization was previously activated for GitHub. It requires user consent to continue working as new" + + " features were added with the synchronization. Please read the upgrade notes."); + assertThat(isConsentRequired()).isTrue(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + enableGithubProvisioning(); + + underTest.execute(); + underTest.execute(); + + assertThat(logger.logs(Level.WARN)).containsExactly("Automatic synchronization was previously activated for GitHub. It requires user consent to continue working as new" + + " features were added with the synchronization. Please read the upgrade notes."); + assertThat(isConsentRequired()).isTrue(); + } + + private void disableGithubProvisioning() { + toggleGithubProvisioning(false); + } + private void enableGithubProvisioning() { + toggleGithubProvisioning(true); + } + + private boolean isConsentRequired() { + return db.countSql("select count(*) from properties where prop_key = '" + PROP_KEY + "'") >= 1; + } + + private void toggleGithubProvisioning(boolean enabled) { + db.executeInsert("internal_properties", "kee", PROVISIONING_GITHUB_ENABLED_PROP_KEY, "text_value", String.valueOf(enabled), "is_empty", true, "created_at", 0); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableIT.java new file mode 100644 index 00000000000..82142e58739 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableIT.java @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.CreateAnticipatedTransitionsTable.ANTICIPATED_TRANSITIONS_TABLE_NAME; + +public class CreateAnticipatedTransitionsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateAnticipatedTransitionsTable.class); + + private final DdlChange createAnticipatedTransitionsTable = new CreateAnticipatedTransitionsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME); + + createAnticipatedTransitionsTable.execute(); + + db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "project_uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "user_uuid", Types.VARCHAR, USER_UUID_SIZE, false); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition", Types.VARCHAR, 20, false); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition_comment", Types.VARCHAR, MAX_SIZE, true); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line", Types.INTEGER, null, true); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "message", Types.VARCHAR, MAX_SIZE, true); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line_hash", Types.VARCHAR, 255, true); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "rule_key", Types.VARCHAR, 200, false); + db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "file_path", Types.VARCHAR, 1500, false); + db.assertPrimaryKey(ANTICIPATED_TRANSITIONS_TABLE_NAME, "pk_anticipated_transitions", "uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME); + + createAnticipatedTransitionsTable.execute(); + // re-entrant + createAnticipatedTransitionsTable.execute(); + + db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsIT.java new file mode 100644 index 00000000000..0d5908be954 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.BOOLEAN; + +public class CreateBooleanPurgedColumnInSnapshotsIT { + + private static final String TABLE_NAME = "snapshots"; + private static final String COLUMN_NAME = "purged"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateBooleanPurgedColumnInSnapshots.class); + + private final CreateBooleanPurgedColumnInSnapshots underTest = new CreateBooleanPurgedColumnInSnapshots(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreatePurgedColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); + } + + @Test + public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableIT.java new file mode 100644 index 00000000000..a5cc79a8ef5 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableIT.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.GROUP_UUID_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.ORGANIZATION_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.TABLE_NAME; + +public class CreateGithubOrganizationsGroupsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateGithubOrganizationsGroupsTable.class); + private final DdlChange createGithubOrganizationsGroupsTable = new CreateGithubOrganizationsGroupsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + createGithubOrganizationsGroupsTable.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, GROUP_UUID_COLUMN_NAME, Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, ORGANIZATION_COLUMN_NAME, Types.VARCHAR, 100, false); + db.assertPrimaryKey(TABLE_NAME, "pk_github_orgs_groups", GROUP_UUID_COLUMN_NAME); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + createGithubOrganizationsGroupsTable.execute(); + // re-entrant + createGithubOrganizationsGroupsTable.execute(); + + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..38c4cb6b4f8 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesIT.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIndexCreatedAtInWebhookDeliveriesIT { + + public static final String TABLE_NAME = "webhook_deliveries"; + public static final String INDEX_NAME = "wd_created_at"; + public static final String EXPECTED_COLUMN = "created_at"; + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexCreatedAtInWebhookDeliveries.class); + private final DdlChange createIndex = new CreateIndexCreatedAtInWebhookDeliveries(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, EXPECTED_COLUMN); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, EXPECTED_COLUMN); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityIT.java new file mode 100644 index 00000000000..7155a292352 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityIT.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +public class CreateIndexEntityUuidInCeActivityIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInCeActivity.class); + private final CreateIndexEntityUuidInCeActivity createIndex = new CreateIndexEntityUuidInCeActivity(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("ce_activity", "ce_activity_entity_uuid"); + + createIndex.execute(); + + db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueIT.java new file mode 100644 index 00000000000..04ba15ea4cf --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueIT.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +public class CreateIndexEntityUuidInCeQueueIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInCeQueue.class); + private final CreateIndexEntityUuidInCeQueue createIndex = new CreateIndexEntityUuidInCeQueue(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("ce_queue", "ce_queue_entity_uuid"); + + createIndex.execute(); + + db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesIT.java new file mode 100644 index 00000000000..07fccf7c38f --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesIT.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +public class CreateIndexEntityUuidInGroupRolesIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInGroupRoles.class); + private final CreateIndexEntityUuidInGroupRoles createIndex = new CreateIndexEntityUuidInGroupRoles(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("group_roles", "group_roles_entity_uuid"); + + createIndex.execute(); + + db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesIT.java new file mode 100644 index 00000000000..522fa39952e --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesIT.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +public class CreateIndexEntityUuidInUserRolesIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInUserRoles.class); + private final CreateIndexEntityUuidInUserRoles createIndex = new CreateIndexEntityUuidInUserRoles(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("user_roles", "user_roles_entity_uuid"); + + createIndex.execute(); + + db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..db3e1e43925 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIndexProjectUuidCreatedAtInWebhookDeliveriesIT { + + public static final String TABLE_NAME = "webhook_deliveries"; + public static final String INDEX_NAME = "wd_project_uuid_created_at"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexProjectUuidCreatedAtInWebhookDeliveries.class); + private final DdlChange createIndex = new CreateIndexProjectUuidCreatedAtInWebhookDeliveries(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesIT.java new file mode 100644 index 00000000000..6a09e04102a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class CreateIndexProjectUuidInProjectBranchesIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexProjectUuidInProjectBranches.class); + private final CreateIndexProjectUuidInProjectBranches createIndex = new CreateIndexProjectUuidInProjectBranches(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("project_branches", "project_branches_project_uuid"); + + createIndex.execute(); + + db.assertIndex("project_branches", "project_branches_project_uuid", "project_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("project_branches", "project_branches_project_uuid", "project_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsIT.java new file mode 100644 index 00000000000..29f761ac6fc --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class CreateIndexRootComponentUuidInSnapshotsIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexRootComponentUuidInSnapshots.class); + private final CreateIndexRootComponentUuidInSnapshots createIndex = new CreateIndexRootComponentUuidInSnapshots(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("snapshots", "snapshots_root_component_uuid"); + + createIndex.execute(); + + db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..cb7c5a301e1 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIndexTaskUuidCreatedAtInWebhookDeliveriesIT { + + public static final String TABLE_NAME = "webhook_deliveries"; + public static final String INDEX_NAME = "wd_ce_task_uuid_created_at"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexTaskUuidCreatedAtInWebhookDeliveries.class); + private final DdlChange createIndex = new CreateIndexTaskUuidCreatedAtInWebhookDeliveries(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..7de3be35eb7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesIT.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesIT { + + public static final String TABLE_NAME = "webhook_deliveries"; + public static final String INDEX_NAME = "wd_webhook_uuid_created_at"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexWebhookUuidCreatedAtInWebhookDeliveries.class); + private final DdlChange createIndex = new CreateIndexWebhookUuidCreatedAtInWebhookDeliveries(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableIT.java new file mode 100644 index 00000000000..e636e235ad2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableIT.java @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class CreateIssueImpactsTableIT { + private static final String EXPECTED_TABLE_NAME = "issues_impacts"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIssueImpactsTable.class); + + private final DdlChange underTest = new CreateIssueImpactsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "issue_key", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false); + db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsIT.java new file mode 100644 index 00000000000..4fd079cfb52 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class CreatePreviousNonCompliantValueInNewCodePeriodsIT { + + private static final String COLUMN_NAME= "previous_non_compliant_value"; + + private static final String TABLE_NAME = "new_code_periods"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreatePreviousNonCompliantValueInNewCodePeriods.class); + private final CreatePreviousNonCompliantValueInNewCodePeriods underTest = new CreatePreviousNonCompliantValueInNewCodePeriods(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreatePurgedColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, null); + } + + @Test + public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, null); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableIT.java new file mode 100644 index 00000000000..c646654f5a7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableIT.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + + +public class CreateRulesDefaultImpactsTableIT { + private static final String EXPECTED_TABLE_NAME = "rules_default_impacts"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRulesDefaultImpactsTable.class); + + private final DdlChange underTest = new CreateRulesDefaultImpactsTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "rule_uuid", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false); + db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsIT.java new file mode 100644 index 00000000000..17c7bfdd9e9 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class CreateUniqueConstraintOnIssuesImpactsIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueConstraintOnIssuesImpacts.class); + private final CreateUniqueConstraintOnIssuesImpacts underTest = new CreateUniqueConstraintOnIssuesImpacts(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("issues_impacts", "uniq_iss_key_sof_qual"); + + underTest.execute(); + + db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsIT.java new file mode 100644 index 00000000000..d4616cf6c5d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + + +public class CreateUniqueConstraintOnRulesDefaultImpactsIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueConstraintOnRulesDefaultImpacts.class); + private final CreateUniqueConstraintOnRulesDefaultImpacts underTest = new CreateUniqueConstraintOnRulesDefaultImpacts(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist("rules_default_impacts", "uniq_rul_uuid_sof_qual"); + + underTest.execute(); + + db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT.java new file mode 100644 index 00000000000..9f0dc1287ed --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT.java @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexComponentUuidInGroupRolesIT { + + private static final String TABLE_NAME = "group_roles"; + private static final String COLUMN_NAME = "component_uuid"; + private static final String INDEX_NAME = "group_roles_component_uuid"; + + /** + * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid + * also updated the index + */ + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInGroupRolesIT.class, "schema.sql"); + private final DropIndexComponentUuidInGroupRoles underTest = new DropIndexComponentUuidInGroupRoles(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsIT.java new file mode 100644 index 00000000000..1959b09fa9d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexComponentUuidInSnapshotsIT { + + private static final String TABLE_NAME = "snapshots"; + private static final String COLUMN_NAME = "component_uuid"; + private static final String INDEX_NAME = "snapshot_component"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexComponentUuidInSnapshots.class); + private final DropIndexComponentUuidInSnapshots underTest = new DropIndexComponentUuidInSnapshots(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT.java new file mode 100644 index 00000000000..22a48bf9d0f --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT.java @@ -0,0 +1,62 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexComponentUuidInUserRolesIT { + + private static final String TABLE_NAME = "user_roles"; + private static final String COLUMN_NAME = "component_uuid"; + private static final String INDEX_NAME = "user_roles_component_uuid"; + + /** + * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid + * also updated the index + */ + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInUserRolesIT.class, "schema.sql"); + private final DropIndexComponentUuidInUserRoles underTest = new DropIndexComponentUuidInUserRoles(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..1c36c83f4c8 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexComponentUuidInWebhookDeliveriesIT { + + private static final String TABLE_NAME = "webhook_deliveries"; + private static final String COLUMN_NAME = "component_uuid"; + private static final String INDEX_NAME = "component_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexComponentUuidInWebhookDeliveries.class); + private final DropIndexComponentUuidInWebhookDeliveries underTest = new DropIndexComponentUuidInWebhookDeliveries(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityIT.java new file mode 100644 index 00000000000..5737beebc17 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexMainComponentUuidInCeActivityIT { + + private static final String TABLE_NAME = "ce_activity"; + private static final String COLUMN_NAME = "main_component_uuid"; + private static final String INDEX_NAME = "ce_activity_main_component"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexMainComponentUuidInCeActivity.class); + private final DropIndexMainComponentUuidInCeActivity underTest = new DropIndexMainComponentUuidInCeActivity(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueIT.java new file mode 100644 index 00000000000..a190553f90f --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropIndexMainComponentUuidInCeQueueIT { + + private static final String TABLE_NAME = "ce_queue"; + private static final String COLUMN_NAME = "main_component_uuid"; + private static final String INDEX_NAME = "ce_queue_main_component"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexMainComponentUuidInCeQueue.class); + private final DropIndexMainComponentUuidInCeQueue underTest = new DropIndexMainComponentUuidInCeQueue(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidIT.java new file mode 100644 index 00000000000..41dec958a40 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexOnMainBranchProjectUuidIT { + private static final String TABLE_NAME = "components"; + private static final String COLUMN_NAME = "main_branch_project_uuid"; + private static final String INDEX_NAME = "idx_main_branch_prj_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexOnMainBranchProjectUuid.class); + private final DdlChange underTest = new DropIndexOnMainBranchProjectUuid(db.database()); + + @Test + public void drops_index() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..6e7c857ea5a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexProjectUuidInWebhookDeliveriesIT { + + private static final String TABLE_NAME = "webhook_deliveries"; + private static final String COLUMN_NAME = "project_uuid"; + private static final String INDEX_NAME = "wd_project_uuid"; + + /** + * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid + * also updated the index + */ + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexProjectUuidInWebhookDeliveriesIT.class, "schema.sql"); + private final DdlChange underTest = new DropIndexProjectUuidInWebhookDeliveries(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..94750e895a6 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesIT.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexTaskUuidInWebhookDeliveriesIT { + + private static final String TABLE_NAME = "webhook_deliveries"; + private static final String COLUMN_NAME = "ce_task_uuid"; + private static final String INDEX_NAME = "ce_task_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexTaskUuidInWebhookDeliveries.class); + private final DdlChange underTest = new DropIndexTaskUuidInWebhookDeliveries(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..b181be51b40 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesIT.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIndexWebhookUuidInWebhookDeliveriesIT { + + private static final String TABLE_NAME = "webhook_deliveries"; + private static final String COLUMN_NAME = "webhook_uuid"; + private static final String INDEX_NAME = "idx_wbhk_dlvrs_wbhk_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexWebhookUuidInWebhookDeliveries.class); + private final DdlChange underTest = new DropIndexWebhookUuidInWebhookDeliveries(db.database()); + + @Test + public void index_is_dropped() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + + underTest.execute(); + underTest.execute(); + + db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsIT.java new file mode 100644 index 00000000000..4fffbac40bf --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.TABLE_NAME; + +public class DropMainBranchProjectUuidInComponentsIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropMainBranchProjectUuidInComponents.class); + private final DdlChange underTest = new DropMainBranchProjectUuidInComponents(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsIT.java new file mode 100644 index 00000000000..f7e71c4f412 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropPurgeStatusColumnInSnapshotsIT { + + private static final String TABLE_NAME = "snapshots"; + private static final String COLUMN_NAME = "purge_status"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropPurgeStatusColumnInSnapshots.class); + private final DropPurgeStatusColumnInSnapshots underTest = new DropPurgeStatusColumnInSnapshots(db.database()); + + @Test + public void drops_column() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.INTEGER, null, null); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.INTEGER, null, null); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsIT.java new file mode 100644 index 00000000000..5df77d52639 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class DropTableProjectMappingsIT { + public static final String TABLE_NAME = "project_mappings"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropTableProjectMappings.class); + private final DropTableProjectMappings underTest = new DropTableProjectMappings(db.database()); + + @Test + public void execute_shouldDropTable() throws SQLException { + db.assertTableExists(TABLE_NAME); + underTest.execute(); + db.assertTableDoesNotExist(TABLE_NAME); + } + + @Test + public void execute_shouldSupportReentrantMigrationExecution() throws SQLException { + db.assertTableExists(TABLE_NAME); + underTest.execute(); + underTest.execute(); + db.assertTableDoesNotExist(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionIT.java new file mode 100644 index 00000000000..2850d7a5be9 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionIT.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FixSqaleIndexMetricDescriptionIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(FixSqaleIndexMetricDescription.class); + private final FixSqaleIndexMetricDescription underTest = new FixSqaleIndexMetricDescription(db.database()); + private final String OLD_DESCRIPTION = "Total effort (in hours) to fix all the issues on the component and therefore to comply to all the requirements."; + private final String NEW_DESCRIPTION = "Total effort (in minutes) to fix all the issues on the component and therefore to comply to all the requirements."; + + @Before + public void setUp() { + db.executeInsert("metrics", + "uuid", "uuid", + "name", "sqale_index", + "description", OLD_DESCRIPTION); + } + + @Test + public void execute_whenExecuted_shouldUpdateSqaleIndexDescription() throws SQLException { + assertThat(select()).isEqualTo(OLD_DESCRIPTION); + underTest.execute(); + assertThat(select()).isEqualTo(NEW_DESCRIPTION); + } + + @Test + public void execute_WhenExecutedTwice_shouldBeReentrant() throws SQLException { + assertThat(select()).isEqualTo(OLD_DESCRIPTION); + underTest.execute(); + underTest.execute(); + assertThat(select()).isEqualTo(NEW_DESCRIPTION); + } + + private String select() { + return (String) db.selectFirst("SELECT description FROM metrics WHERE name = 'sqale_index'").get("description"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityIT.java new file mode 100644 index 00000000000..2e1b14b13c9 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.TABLE_NAME; + +public class IncreaseIsLastKeyInCeActivityIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseIsLastKeyInCeActivity.class); + private final IncreaseIsLastKeyInCeActivity underTest = new IncreaseIsLastKeyInCeActivity(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityIT.java new file mode 100644 index 00000000000..bc8f288782a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.NEW_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.TABLE_NAME; + +public class IncreaseMainIsLastKeyInCeActivityIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseMainIsLastKeyInCeActivity.class); + private final IncreaseMainIsLastKeyInCeActivity underTest = new IncreaseMainIsLastKeyInCeActivity(db.database()); + + @Test + public void execute_increaseColumnSize() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesIT.java new file mode 100644 index 00000000000..fc9fd3d1936 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class MakeProjectUuidNullableInUserDismissedMessagesIT { + + private static final String TABLE_NAME = "user_dismissed_messages"; + private static final String COLUMN_NAME = "project_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeProjectUuidNullableInUserDismissedMessages.class); + private final MakeProjectUuidNullableInUserDismissedMessages underTest = new MakeProjectUuidNullableInUserDismissedMessages(db.database()); + + @Test + public void execute_shouldBeNullable() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); + underTest.execute(); + underTest.execute(); + + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsIT.java new file mode 100644 index 00000000000..a217aab4f0b --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.BOOLEAN; + +public class MakePurgedColumnNotNullableInSnapshotsIT { + private static final String TABLE_NAME = "snapshots"; + private static final String COLUMN_NAME = "purged"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakePurgedColumnNotNullableInSnapshots.class); + private final MakePurgedColumnNotNullableInSnapshots underTest = new MakePurgedColumnNotNullableInSnapshots(db.database()); + + @Test + public void execute_whenColumnIsNullable_shouldMakeColumnNullable() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } + + @Test + public void execute_whenExecutedTwice_shouldMakeColumnNullable() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesIT.java new file mode 100644 index 00000000000..8b452b0d119 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesIT.java @@ -0,0 +1,110 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.rules.CleanCodeAttribute; +import org.sonar.api.rules.RuleType; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +public class PopulateCleanCodeAttributeColumnInRulesIT { + + private static final String TABLE_NAME = "rules"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateCleanCodeAttributeColumnInRules.class); + private final PopulateCleanCodeAttributeColumnInRules underTest = new PopulateCleanCodeAttributeColumnInRules(db.database()); + + @Test + public void execute_whenRulesDoNotExist_shouldNotFail() { + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } + + @Test + public void execute_whenRuleWithUndefinedCleanCodeAttribute_shouldUpdate() throws SQLException { + insertRule("1", null); + underTest.execute(); + assertThat(db.select("select uuid, clean_code_attribute from rules")) + .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) + .containsExactly(CleanCodeAttribute.CONVENTIONAL.name()); + } + + @Test + public void execute_whenRuleWithUndefinedCleanCodeAttribute_shouldBeReentrant() throws SQLException { + insertRule("1", null); + underTest.execute(); + underTest.execute(); + assertThat(db.select("select uuid, clean_code_attribute from rules")) + .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) + .containsExactly(CleanCodeAttribute.CONVENTIONAL.name()); + } + + @Test + public void execute_whenRuleWithDefinedCleanCodeAttribute_shouldNotUpdate() throws SQLException { + insertRule("1", CleanCodeAttribute.FOCUSED); + underTest.execute(); + assertThat(db.select("select uuid, clean_code_attribute from rules")) + .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) + .containsExactly(CleanCodeAttribute.FOCUSED.name()); + } + + @Test + public void execute_whenRuleIsHotspot_shouldNotUpdate() throws SQLException { + insertRule("1", RuleType.SECURITY_HOTSPOT, null, null); + underTest.execute(); + assertThat(db.select("select uuid, clean_code_attribute from rules")) + .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) + .containsOnlyNulls(); + } + + @Test + public void execute_whenAdhocRuleIsHotspot_shouldNotUpdate() throws SQLException { + insertRule("1", null, RuleType.SECURITY_HOTSPOT, null); + underTest.execute(); + assertThat(db.select("select uuid, clean_code_attribute from rules")) + .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) + .containsOnlyNulls(); + } + + + private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable RuleType adhocRuleType, @Nullable CleanCodeAttribute cleanCodeAttribute) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "PLUGIN_RULE_KEY", "key", + "PLUGIN_NAME", "name", + "SCOPE", "1", + "CLEAN_CODE_ATTRIBUTE", cleanCodeAttribute != null ? cleanCodeAttribute.name() : null, + "IS_TEMPLATE", false, + "RULE_TYPE", ruleType != null ? ruleType.getDbConstant() : null, + "AD_HOC_TYPE", adhocRuleType != null ? adhocRuleType.getDbConstant() : null, + "IS_AD_HOC", false, + "IS_EXTERNAL", false); + } + + private void insertRule(String uuid, @Nullable CleanCodeAttribute cleanCodeAttribute) { + insertRule(uuid, RuleType.CODE_SMELL, null, cleanCodeAttribute); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesIT.java new file mode 100644 index 00000000000..612785612b4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesIT.java @@ -0,0 +1,221 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.batch.rule.Severity; +import org.sonar.api.issue.impact.SoftwareQuality; +import org.sonar.api.rules.RuleType; +import org.sonar.api.testfixtures.log.LogTester; +import org.sonar.core.util.Uuids; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulateDefaultImpactsInRulesIT { + private static final String TABLE_NAME = "rules"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateDefaultImpactsInRules.class); + @Rule + public LogTester logTester = new LogTester(); + + private final PopulateDefaultImpactsInRules underTest = new PopulateDefaultImpactsInRules(db.database()); + + @Test + public void execute_whenRulesDoNotExist_shouldNotFail() { + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } + + @Test + public void execute_whenRulesHasTypeAndSeverity_shouldCreateImpact() throws SQLException { + insertRuleWithType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); + } + + @Test + public void execute_shouldBeReentrant() throws SQLException { + insertRuleWithType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .hasSize(1) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); + + } + + @Test + public void execute_whenAdhocRulesHasTypeAndSeverity_shouldCreateImpact() throws SQLException { + insertRuleWithAdHocType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .hasSize(1) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); + + } + + @Test + public void execute_whenAdhocRulesHasImpactAlready_shouldNotCreateImpact() throws SQLException { + insertRuleWithAdHocType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); + insertImpact("uuid", SoftwareQuality.SECURITY, org.sonar.api.issue.impact.Severity.HIGH); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .hasSize(1) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.SECURITY.name(), org.sonar.api.issue.impact.Severity.HIGH.name())); + + } + + @Test + public void execute_whenNoTypeAndSeverityDefined_shouldNotCreateImpact() throws SQLException { + insertRuleWithType("uuid", null, null); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .isEmpty(); + + } + + @Test + public void execute_whenInvalidValueDefined_shouldNotCreateImpactAndLog() throws SQLException { + insertInvalidRule("uuid"); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .isEmpty(); + assertThat(logTester.logs()).contains("Error while mapping type to impact for rule 'uuid'"); + + } + + @Test + public void execute_whenTypeIsHotspot_shouldNotCreateImpactAndLog() throws SQLException { + insertRuleWithType("uuid", RuleType.SECURITY_HOTSPOT, Severity.MAJOR); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .isEmpty(); + assertThat(logTester.logs()).doesNotContain("Error while mapping type to impact for rule 'uuid'"); + } + + @Test + public void execute_whenRuleHasEmptyFields_shouldCreateADefaultImpact() throws SQLException { + insertPlaceholderAdhocRule("uuid"); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .hasSize(1) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); + } + + @Test + public void execute_whenStandardRuleHasBothAdhocAndStandardTypeAndSeverity_shouldCreateADefaultImpactWithAdhocTypes() throws SQLException { + insertRule("uuid", RuleType.CODE_SMELL, Severity.CRITICAL, RuleType.VULNERABILITY, Severity.MINOR, true); + underTest.execute(); + + assertThat(db.select("select software_quality, severity from rules_default_impacts")) + .hasSize(1) + .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), + stringObjectMap -> stringObjectMap.get("severity")) + .containsExactly(tuple(SoftwareQuality.SECURITY.name(), org.sonar.api.issue.impact.Severity.LOW.name())); + } + + private void insertRuleWithType(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity) { + insertRule(uuid, ruleType, severity, null, null); + } + + private void insertRuleWithAdHocType(String uuid, @Nullable RuleType adHocType, @Nullable Severity adHocseverity) { + insertRule(uuid, null, null, adHocType, adHocseverity); + } + + + private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity, @Nullable RuleType adHocType, @Nullable Severity adHocseverity) { + insertRule(uuid, ruleType, severity, adHocType, adHocseverity, adHocType != null); + } + + private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity, @Nullable RuleType adHocType, @Nullable Severity adHocseverity, boolean isAdhoc) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "PLUGIN_RULE_KEY", "key", + "PLUGIN_NAME", "name", + "SCOPE", "1", + "RULE_TYPE", ruleType != null ? ruleType.getDbConstant() : null, + "PRIORITY", severity != null ? org.sonar.api.rule.Severity.ALL.indexOf(severity.name()) : null, + "AD_HOC_TYPE", adHocType != null ? adHocType.getDbConstant() : null, + "AD_HOC_SEVERITY", adHocseverity != null ? adHocseverity.name() : null, + "IS_TEMPLATE", false, + "IS_AD_HOC", isAdhoc, + "IS_EXTERNAL", isAdhoc); + } + + private void insertInvalidRule(String uuid) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "PLUGIN_RULE_KEY", "key", + "PLUGIN_NAME", "name", + "SCOPE", "1", + "RULE_TYPE", 100, + "PRIORITY", -1, + "AD_HOC_TYPE", 100, + "AD_HOC_SEVERITY", "-1", + "IS_TEMPLATE", false, + "IS_AD_HOC", false, + "IS_EXTERNAL", false); + } + + private void insertPlaceholderAdhocRule(String uuid) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "PLUGIN_RULE_KEY", "key", + "PLUGIN_NAME", "name", + "SCOPE", "1", + "IS_TEMPLATE", false, + "IS_AD_HOC", true, + "IS_EXTERNAL", false); + } + + private void insertImpact(String ruleUuid, SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) { + db.executeInsert("RULES_DEFAULT_IMPACTS", + "UUID", Uuids.create(), + "RULE_UUID", ruleUuid, + "SOFTWARE_QUALITY", softwareQuality.name(), + "SEVERITY", severity.name()); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsIT.java new file mode 100644 index 00000000000..89ed927a7d7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsIT.java @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.tuple; + +public class PopulatePurgedColumnInSnapshotsIT { + private static final String TABLE_NAME = "snapshots"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulatePurgedColumnInSnapshots.class); + private final PopulatePurgedColumnInSnapshots underTest = new PopulatePurgedColumnInSnapshots(db.database()); + + @Test + public void execute_whenSnapshotsDoesNotExist_shouldNotFail() { + assertThatCode(underTest::execute) + .doesNotThrowAnyException(); + } + + @Test + public void execute_whenSnapshotsExist_shouldPopulatePurgedColumn() throws SQLException { + insertSnapshot("uuid-1", null); + insertSnapshot("uuid-2", 1); + insertSnapshot("uuid-3", 0); + insertSnapshot("uuid-4", null); + + underTest.execute(); + + assertThat(db.select("select uuid, purged from snapshots")) + .extracting(stringObjectMap -> stringObjectMap.get("uuid"), stringObjectMap -> stringObjectMap.get("purged")) + .containsExactlyInAnyOrder( + tuple("uuid-1", false), + tuple("uuid-2", true), + tuple("uuid-3", false), + tuple("uuid-4", false)); + } + + private void insertSnapshot(String uuid, @Nullable Integer status) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "ROOT_COMPONENT_UUID", "r_c_uuid", + "STATUS", "s", + "ISLAST", true, + "PURGE_STATUS", status, + "PURGED", null); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsIT.java new file mode 100644 index 00000000000..a2d84acebdb --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsIT.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class RenameBuildDateInSnapshotsIT { + private static final String TABLE_NAME = "snapshots"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameBuildDateInSnapshots.class); + private final RenameBuildDateInSnapshots underTest = new RenameBuildDateInSnapshots(db.database()); + + @Test + public void execute_whenExecuted_shouldRenameColumn() throws SQLException { + assertColumnExists("build_date"); + underTest.execute(); + assertColumnExists("analysis_date"); + } + + @Test + public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { + assertColumnExists("build_date"); + underTest.execute(); + underTest.execute(); + assertColumnExists("analysis_date"); + } + + private void assertColumnExists(String columnName) { + db.assertColumnDefinition(TABLE_NAME, columnName, Types.BIGINT, null, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesIT.java new file mode 100644 index 00000000000..3c4fc48d861 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameComponentUuidInGroupRolesIT { + public static final String TABLE_NAME = "group_roles"; + public static final String NEW_COLUMN_NAME = "entity_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInGroupRoles.class); + private final RenameComponentUuidInGroupRoles underTest = new RenameComponentUuidInGroupRoles(db.database()); + + @Test + public void columnIsRenamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsIT.java new file mode 100644 index 00000000000..d5c551eb076 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameComponentUuidInSnapshotsIT { + public static final String TABLE_NAME = "snapshots"; + public static final String NEW_COLUMN_NAME = "root_component_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInSnapshots.class); + private final RenameComponentUuidInSnapshots underTest = new RenameComponentUuidInSnapshots(db.database()); + + @Test + public void columnIsRenamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesIT.java new file mode 100644 index 00000000000..558851158c0 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameComponentUuidInUserRolesIT { + public static final String TABLE_NAME = "user_roles"; + public static final String NEW_COLUMN_NAME = "entity_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInUserRoles.class); + private final RenameComponentUuidInUserRoles underTest = new RenameComponentUuidInUserRoles(db.database()); + + @Test + public void columnIsRenamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesIT.java new file mode 100644 index 00000000000..afa8b7224e4 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesIT.java @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.AbstractDbTester; +import org.sonar.db.TestDb; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange; +import org.sonar.server.platform.db.migration.version.RenameVarcharColumnAbstractTest; + +public class RenameComponentUuidInWebhookDeliveriesIT extends RenameVarcharColumnAbstractTest { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInWebhookDeliveries.class); + + public RenameComponentUuidInWebhookDeliveriesIT() { + super("webhook_deliveries", "project_uuid", false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + super.verifyMigrationIsReentrant(); + } + + @Test + public void column_is_renamed() throws SQLException { + super.verifyColumnIsRenamed(); + } + + @Override + protected RenameVarcharColumnChange getClassUnderTest() { + return new RenameComponentUuidInWebhookDeliveries(db.database()); + } + + @Override + protected AbstractDbTester getDatabase() { + return db; + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityIT.java new file mode 100644 index 00000000000..b035496559d --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameMainComponentUuidInCeActivityIT { + public static final String TABLE_NAME = "ce_activity"; + public static final String NEW_COLUMN_NAME = "entity_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameMainComponentUuidInCeActivity.class); + private final RenameMainComponentUuidInCeActivity underTest = new RenameMainComponentUuidInCeActivity(db.database()); + + @Test + public void column_is_renamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueIT.java new file mode 100644 index 00000000000..12e9204f6ed --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; + +public class RenameMainComponentUuidInCeQueueIT { + public static final String TABLE_NAME = "ce_queue"; + public static final String NEW_COLUMN_NAME = "entity_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameMainComponentUuidInCeQueue.class); + private final RenameMainComponentUuidInCeQueue underTest = new RenameMainComponentUuidInCeQueue(db.database()); + + @Test + public void column_is_renamed() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsIT.java new file mode 100644 index 00000000000..74ac3499203 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsIT.java @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v102; + +import java.sql.SQLException; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsIT { + + private static final String TABLE_NAME = "new_code_periods"; + private static final String PROJECT_UUID = "project-uuid"; + private static final String BRANCH_UUID = "branch-uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods.class); + public final UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods underTest = new UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods(db.database()); + + @Test + public void execute_whenSnapshotsExist_shouldPopulatePurgedColumn() throws SQLException { + insertNewCodePeriods("uuid-1", PROJECT_UUID, BRANCH_UUID, "PREVIOUS_VERSION", null); + insertNewCodePeriods("uuid-2", PROJECT_UUID, null, "NUMBER_OF_DAYS", "90"); + insertNewCodePeriods("uuid-3", null, null, "NUMBER_OF_DAYS", "97"); + + underTest.execute(); + + assertThat(db.select("select uuid, value, previous_non_compliant_value from new_code_periods")) + .extracting(stringObjectMap -> stringObjectMap.get("uuid"), stringObjectMap -> stringObjectMap.get("value"), + stringObjectMap -> stringObjectMap.get("previous_non_compliant_value")) + .containsExactlyInAnyOrder( + tuple("uuid-1", null, null), + tuple("uuid-2", "90", null), + tuple("uuid-3", "90", "97")); + } + + private void insertNewCodePeriods(String uuid, @Nullable String projectUuid, @Nullable String branchUuid, String type, String value) { + db.executeInsert(TABLE_NAME, + "UUID", uuid, + "PROJECT_UUID", projectUuid, + "BRANCH_UUID", branchUuid, + "TYPE", type, + "VALUE", value, + "UPDATED_AT", System.currentTimeMillis(), + "CREATED_AT", System.currentTimeMillis()); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableIT.java new file mode 100644 index 00000000000..b8b129b8ff7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThatCode; + +public class AddCleanCodeAttributeColumnInIssuesTableIT { + private static final String TABLE_NAME = "issues"; + private static final String COLUMN_NAME = "clean_code_attribute"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCleanCodeAttributeColumnInIssuesTable.class); + private final AddCleanCodeAttributeColumnInIssuesTable underTest = new AddCleanCodeAttributeColumnInIssuesTable(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); + } + + @Test + public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { + underTest.execute(); + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableIT.java new file mode 100644 index 00000000000..c7afa66d0ad --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class AddCreationMethodColumnInProjectsTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCreationMethodColumnInProjectsTable.class); + private final AddCreationMethodColumnInProjectsTable underTest = new AddCreationMethodColumnInProjectsTable(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, PROJECTS_CREATION_METHOD_COLUMN_SIZE, true); + } + + @Test + public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { + underTest.execute(); + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesIT.java new file mode 100644 index 00000000000..8b5c2594c74 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThatCode; + +public class AddRuleChangesUuidColumnInQProfileChangesIT { + + private static final String TABLE_NAME = "qprofile_changes"; + private static final String COLUMN_NAME = "rule_change_uuid"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddRuleChangesUuidColumnInQProfileChanges.class); + private final AddRuleChangesUuidColumnInQProfileChanges underTest = new AddRuleChangesUuidColumnInQProfileChanges(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); + } + + @Test + public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { + underTest.execute(); + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableIT.java new file mode 100644 index 00000000000..8e3e5974cdb --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableIT.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThatCode; + +public class AddSqVersionColumnInQprofileChangesTableIT { + + private static final String TABLE_NAME = "qprofile_changes"; + private static final String COLUMN_NAME = "sq_version"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddSqVersionColumnInQprofileChangesTable.class); + private final AddSqVersionColumnInQprofileChangesTable underTest = new AddSqVersionColumnInQprofileChangesTable(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); + } + + @Test + public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { + underTest.execute(); + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableIT.java new file mode 100644 index 00000000000..6cb29f21497 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableIT.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; + +public class CreateGithubPermissionsMappingTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateGithubPermissionsMappingTable.class); + + private final DdlChange createGithubPermissionsMappingTable = new CreateGithubPermissionsMappingTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); + + createGithubPermissionsMappingTable.execute(); + + db.assertTableExists(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); + db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "github_role", Types.VARCHAR, 100, false); + db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "sonarqube_permission", Types.VARCHAR, 64, false); + db.assertPrimaryKey(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "pk_github_perms_mapping", "uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); + + createGithubPermissionsMappingTable.execute(); + // re-entrant + createGithubPermissionsMappingTable.execute(); + + db.assertTableExists(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableIT.java new file mode 100644 index 00000000000..2ba7ce6477c --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + + + +public class CreateIndexForRuleImpactChangesTableIT { + + static final String INDEX_NAME = "rule_impact_changes_r_c_uuid"; + static final String TABLE_NAME = "rule_impact_changes"; + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForRuleImpactChangesTable.class); + private final CreateIndexForRuleImpactChangesTable underTest = new CreateIndexForRuleImpactChangesTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + + underTest.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + db.assertIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid"); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableIT.java new file mode 100644 index 00000000000..63fc2e5ef41 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableIT.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; + +public class CreateRuleChangesTableIT { + + private final static String TABLE_NAME = "rule_changes"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRuleChangesTable.class); + + private final DdlChange underTest = new CreateRuleChangesTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "new_clean_code_attribute", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "old_clean_code_attribute", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "rule_uuid", Types.VARCHAR, UUID_SIZE, false); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableIT.java new file mode 100644 index 00000000000..c32da07f78c --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableIT.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; + +public class CreateRuleImpactChangesTableIT { + + + private final static String TABLE_NAME = "rule_impact_changes"; + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRuleImpactChangesTable.class); + + private final DdlChange underTest = new CreateRuleImpactChangesTable(db.database()); + + @Test + public void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "new_software_quality", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "old_software_quality", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "new_severity", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "old_severity", Types.VARCHAR, 40, true); + db.assertColumnDefinition(TABLE_NAME, "rule_change_uuid", Types.VARCHAR, UUID_SIZE, false); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableIT.java new file mode 100644 index 00000000000..8f5be5b5bc2 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableIT.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; +import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_ROLE_COLUMN; +import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.SONARQUBE_PERMISSION_COLUMN; +import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForGithubPermissionsMappingTable.INDEX_NAME; + +public class CreateUniqueIndexForGithubPermissionsMappingTableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForGithubPermissionsMappingTable.class); + private final CreateUniqueIndexForGithubPermissionsMappingTable createIndex = new CreateUniqueIndexForGithubPermissionsMappingTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertUniqueIndex(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME, GITHUB_ROLE_COLUMN, SONARQUBE_PERMISSION_COLUMN); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertUniqueIndex(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME, GITHUB_ROLE_COLUMN, SONARQUBE_PERMISSION_COLUMN); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableIT.java new file mode 100644 index 00000000000..e8a77d2be50 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableIT.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForPropertiesTable.INDEX_NAME; +import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForPropertiesTable.PROPERTIES_TABLE_NAME; + + +public class CreateUniqueIndexForPropertiesTableIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForPropertiesTable.class); + private final CreateUniqueIndexForPropertiesTable createIndex = new CreateUniqueIndexForPropertiesTable(db.database()); + + @Test + public void migration_should_create_index() throws SQLException { + db.assertIndexDoesNotExist(PROPERTIES_TABLE_NAME, INDEX_NAME); + + createIndex.execute(); + + db.assertUniqueIndex(PROPERTIES_TABLE_NAME, INDEX_NAME, "prop_key", "entity_uuid", "user_uuid"); + } + + @Test + public void migration_should_be_reentrant() throws SQLException { + createIndex.execute(); + createIndex.execute(); + + db.assertUniqueIndex(PROPERTIES_TABLE_NAME, INDEX_NAME, "prop_key", "entity_uuid", "user_uuid"); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableIT.java new file mode 100644 index 00000000000..869ef743832 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableIT.java @@ -0,0 +1,109 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import java.util.Date; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.core.util.Uuids; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class DeduplicatePropertiesTableIT { + public static final String KEY = "key"; + public static final String ENTITY = "entity"; + public static final String USER = "user"; + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DeduplicatePropertiesTable.class); + private final DeduplicatePropertiesTable underTest = new DeduplicatePropertiesTable(db.database()); + + + public void createBaseProperties() { + createProperty(KEY, null, null); + createProperty(KEY, USER, null); + createProperty(KEY, USER, ENTITY); + } + + private void createProperty(String key, @Nullable String user, @Nullable String entity) { + db.executeInsert("PROPERTIES", + "UUID", Uuids.createFast(), + "PROP_KEY", key, + "TEXT_VALUE", "value", + "ENTITY_UUID", entity, + "USER_UUID", user, + "IS_EMPTY", false, + "CREATED_AT", new Date().getTime()); + } + + @Test + public void execute_shouldDeduplicateRows_WhenOnlyKeyIsSpecified() throws SQLException { + createBaseProperties(); + createProperty(KEY, null, null); + createProperty(KEY, null, null); + underTest.execute(); + assertThat(db.select("select * from properties")) + .hasSize(3) + .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) + .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); + } + + @Test + public void execute_shouldDeduplicateRows_WhenOnlyKeyAndUserAreSpecified() throws SQLException { + createBaseProperties(); + createProperty(KEY, USER, null); + createProperty(KEY, USER, null); + underTest.execute(); + assertThat(db.select("select * from properties")) + .hasSize(3) + .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) + .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); + } + + @Test + public void execute_shouldDeduplicateRows_WhenKeyUserAndEntityAreSpecified() throws SQLException { + createBaseProperties(); + createProperty(KEY, USER, ENTITY); + createProperty(KEY, USER, ENTITY); + underTest.execute(); + assertThat(db.select("select * from properties")) + .hasSize(3) + .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) + .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); + } + + @Test + public void execute_shouldBeReentrant() throws SQLException { + createBaseProperties(); + createProperty(KEY, USER, ENTITY); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select * from properties")) + .hasSize(3) + .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) + .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableIT.java new file mode 100644 index 00000000000..0894169b2f1 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableIT.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class MakeCreationMethodColumnInProjectsNotNullableIT { + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeCreationMethodColumnInProjectsNotNullable.class); + private final MakeCreationMethodColumnInProjectsNotNullable underTest = new MakeCreationMethodColumnInProjectsNotNullable(db.database()); + + @Test + public void user_local_column_is_not_null() throws SQLException { + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableIT.java new file mode 100644 index 00000000000..693c5cae1c7 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableIT.java @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class PopulateCreationMethodColumnInProjectsTableIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateCreationMethodColumnInProjectsTable.class); + private final PopulateCreationMethodColumnInProjectsTable underTest = new PopulateCreationMethodColumnInProjectsTable(db.database()); + + @Test + public void execute_whenProjectsTableIsEmpty_shouldDoNothing() throws SQLException { + underTest.execute(); + + assertThat(db.select("select creation_method from projects")).isEmpty(); + } + + @Test + public void execute_whenProjectsExist_shouldPopulateCreationMethodColumn() throws SQLException { + insertProject("uuid-1"); + insertProject("uuid-2"); + + underTest.execute(); + + assertThat(db.select("select creation_method from projects")) + .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) + .containsExactlyInAnyOrder("UNKNOWN", "UNKNOWN"); + } + + @Test + public void execute_isReentrant() throws SQLException { + insertProject("uuid-1"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select creation_method from projects")) + .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) + .containsExactlyInAnyOrder("UNKNOWN"); + } + + private void insertProject(String uuid) { + db.executeInsert(PROJECTS_TABLE_NAME, + "UUID", uuid, + "KEE", uuid, + "QUALIFIER", "TRK", + "PRIVATE", true, + "UPDATED_AT", 1); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingIT.java new file mode 100644 index 00000000000..3a126fb535f --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingIT.java @@ -0,0 +1,99 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.testfixtures.log.LogTester; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; + +public class PopulateGithubPermissionsMappingIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateGithubPermissionsMapping.class); + @Rule + public LogTester logTester = new LogTester(); + + private final PopulateGithubPermissionsMapping migration = new PopulateGithubPermissionsMapping(db.database(), UuidFactoryFast.getInstance()); + + @Test + public void execute_whenTableAlreadyPopulated_doesNothing() throws SQLException { + db.executeInsert(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, + "UUID", UuidFactoryFast.getInstance().create(), + "github_role", "gh_role", + "sonarqube_permission", "sq_perm"); + + migration.execute(); + + assertThat(db.select("select github_role, sonarqube_permission from github_perms_mapping")) + .extracting(stringObjectMap -> stringObjectMap.get("GITHUB_ROLE"), stringObjectMap -> stringObjectMap.get("SONARQUBE_PERMISSION")) + .containsExactly(tuple("gh_role", "sq_perm")); + } + + @Test + public void execute_whenTableIsEmpty_shouldPopulate() throws SQLException { + migration.execute(); + + verifyMapping(); + } + + @Test + public void execute_isReentrant() throws SQLException { + migration.execute(); + migration.execute(); + migration.execute(); + + verifyMapping(); + } + + private void verifyMapping() { + assertThat(db.select("select github_role, sonarqube_permission from github_perms_mapping")) + .extracting(stringObjectMap -> stringObjectMap.get("GITHUB_ROLE"), stringObjectMap -> stringObjectMap.get("SONARQUBE_PERMISSION")) + .containsExactlyInAnyOrder( + tuple("read", "codeviewer"), + tuple("read", "user"), + tuple("triage", "codeviewer"), + tuple("triage", "user"), + tuple("write", "codeviewer"), + tuple("write", "user"), + tuple("write", "issueadmin"), + tuple("write", "securityhotspotadmin"), + tuple("write", "scan"), + tuple("maintain", "codeviewer"), + tuple("maintain", "user"), + tuple("maintain", "issueadmin"), + tuple("maintain", "securityhotspotadmin"), + tuple("maintain", "scan"), + tuple("admin", "codeviewer"), + tuple("admin", "user"), + tuple("admin", "issueadmin"), + tuple("admin", "securityhotspotadmin"), + tuple("admin", "scan"), + tuple("admin", "admin") + ); + } + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesIT.java new file mode 100644 index 00000000000..5b93c063c6a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesIT.java @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.impl.utils.TestSystem2; +import org.sonar.api.utils.System2; +import org.sonar.core.util.UuidFactoryFast; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SetAllowQualityProfileDisableInheritedRulesIT { + + private static final long NOW = 1; + + @Rule + public final MigrationDbTester dbTester = MigrationDbTester.createForMigrationStep(SetAllowQualityProfileDisableInheritedRules.class); + private final System2 system2 = new TestSystem2().setNow(NOW); + + private final SetAllowQualityProfileDisableInheritedRules script = new SetAllowQualityProfileDisableInheritedRules(dbTester.database(), system2, UuidFactoryFast.getInstance()); + + @Test + public void execute_shouldInsertPropertyWithFalseValue() throws SQLException { + script.execute(); + + assertThatForceAuthenticationEquals("false"); + } + + @Test + public void execute_shouldBeReentrant() throws SQLException { + script.execute(); + // re-entrant + script.execute(); + + assertThatForceAuthenticationEquals("false"); + } + + @Test + public void execute_shouldNotUpdateTheValueThatAlreadyExistsInTheDatabase() throws SQLException { + insertPropertyWithValueAsTrue(); + script.execute(); + + assertThatForceAuthenticationEquals("true"); + } + + private void assertThatForceAuthenticationEquals(String s) { + assertThat(dbTester.selectFirst("select p.text_value from properties p where p.prop_key = 'sonar.qualityProfiles.allowDisableInheritedRules'")) + .containsEntry("TEXT_VALUE", s); + } + + private void insertPropertyWithValueAsTrue() { + dbTester.executeInsert("properties", + "uuid", "uuid-1", + "prop_key", "sonar.qualityProfiles.allowDisableInheritedRules", + "is_empty", false, + "text_value", "true", + "created_at", NOW); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsIT.java new file mode 100644 index 00000000000..2695f038be1 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsIT.java @@ -0,0 +1,157 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v104; + +import java.sql.SQLException; +import java.util.Map; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DeleteRedundantFailedAlertsForApplicationsIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DeleteRedundantFailedAlertsForApplications.class); + private final DataChange underTest = new DeleteRedundantFailedAlertsForApplications(db.database()); + + @Before + public void setUp() { + // cleanup db + db.executeUpdateSql("truncate table events"); + db.executeUpdateSql("truncate table event_component_changes"); + db.executeUpdateSql("truncate table components"); + } + + @Test + public void givenFailedAlertsForApplication_whenExecuted_thenFailedAlertsAreDeleted() throws SQLException { + // given + insertComponent("app1", "appUuid1", "appUuid1", "APP"); + + // event that should be deleted + insertEvent("eventUuid1", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); + insertEventChanges("eventChangeUuid1", "eventUuid1", "appUuid1"); + insertEventChanges("eventChangeUuid2", "eventUuid1", "appUuid1"); + + // events that should not be deleted + insertEvent("eventUuid2", "appUuid1", "Passed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); + insertEventChanges("eventChangeUuid3", "eventUuid2", "appUuid1"); + insertEvent("eventUuid3", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"PASSED\" }"); + insertEventChanges("eventChangeUuid4", "eventUuid3", "appUuid1"); + + // when + underTest.execute(); + + // then + assertThat(db.countRowsOfTable("events")).isEqualTo(2); + assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isZero(); + + assertThat(db.countRowsOfTable("event_component_changes")).isEqualTo(2); + assertThat(db.countSql("select count(1) from event_component_changes where uuid = 'eventUuid1'")).isZero(); + } + + @Test + public void givenFailedAlertsForProject_whenExecute_thenTheEventsAreNotDeleted() throws SQLException { + // given + insertComponent("project1", "projectUuid1", "projectUuid1", "TRK"); + + // event that should not be deleted + insertEvent("eventUuid1", "projectUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); + insertEventChanges("eventChangeUuid1", "eventUuid1", "projectUuid1"); + insertEventChanges("eventChangeUuid2", "eventUuid1", "projectUuid1"); + + // when + underTest.execute(); + + // then + assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isEqualTo(1); + assertThat(db.countSql("select count(1) from event_component_changes where event_uuid = 'eventUuid1'")).isEqualTo(2); + } + + @Test + public void givenMigration_whenExecutedMoreThanOnce_thenNoError() throws SQLException { + // given + insertComponent("app1", "appUuid1", "appUuid1", "APP"); + + // event that should be deleted + insertEvent("eventUuid1", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); + insertEventChanges("eventChangeUuid1", "eventUuid1", "appUuid1"); + insertEventChanges("eventChangeUuid2", "eventUuid1", "appUuid1"); + + // when + underTest.execute(); + underTest.execute(); + + // then + assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isZero(); + assertThat(db.countSql("select count(1) from event_component_changes where uuid = 'eventUuid1'")).isZero(); + } + + private void insertComponent(String key, String uuid, String branchUuid, String qualifier) { + Map map = Map.ofEntries( + Map.entry("UUID", uuid), + Map.entry("KEE", key), + Map.entry("BRANCH_UUID", branchUuid), + Map.entry("UUID_PATH", "." + uuid + "."), + Map.entry("QUALIFIER", qualifier), + Map.entry("ENABLED", true), + Map.entry("PRIVATE", true) + ); + + db.executeInsert("components", map); + } + + private void insertEvent(String uuid, String componentUuid, String name, String category, String eventData) { + Map map = Map.ofEntries( + Map.entry("UUID", uuid), + Map.entry("NAME", name), + Map.entry("ANALYSIS_UUID", "analysisUuid"), + Map.entry("CATEGORY", category), + Map.entry("CREATED_AT", 1_500_000_000_000L), + Map.entry("EVENT_DATE", 1_500_000_000_000L), + Map.entry("COMPONENT_UUID", componentUuid), + Map.entry("EVENT_DATA", eventData) + ); + + db.executeInsert("events", map); + } + + private void insertEventChanges(String uuid, String eventUuid, String componentUuid) { + Map map = Map.ofEntries( + Map.entry("UUID", uuid), + Map.entry("EVENT_UUID", eventUuid), + Map.entry("EVENT_COMPONENT_UUID", componentUuid), + Map.entry("EVENT_ANALYSIS_UUID", "analysisUuid"), + Map.entry("CHANGE_CATEGORY", "FAILED_QG"), + Map.entry("COMPONENT_UUID", uuid), + Map.entry("COMPONENT_KEY", "app"), + Map.entry("COMPONENT_NAME", "app"), + Map.entry("COMPONENT_BRANCH_KEY", 1_500_000_000_000L), + Map.entry("CREATED_AT", 1_500_000_000_000L) + ); + + db.executeInsert("event_component_changes", map); + } + + +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricIT.java new file mode 100644 index 00000000000..642018ce755 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricIT.java @@ -0,0 +1,83 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.v104; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.MigrationDbTester; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class RenameWontFixIssuesMetricIT { + + @Rule + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameWontFixIssuesMetric.class); + private final RenameWontFixIssuesMetric underTest = new RenameWontFixIssuesMetric(db.database()); + + @Test + public void execute_whenMetricsTableIsEmpty_shouldDoNothing() throws SQLException { + underTest.execute(); + + assertThat(db.select("select name from metrics")).isEmpty(); + } + + @Test + public void execute_whenWontFixMetricExist_shouldRenameToAccepted() throws SQLException { + insertMetric("wont_fix_issues"); + insertMetric("other_metric"); + + underTest.execute(); + + assertThat(db.select("select name from metrics")) + .extracting(stringObjectMap -> stringObjectMap.get("NAME")) + .containsExactlyInAnyOrder("accepted_issues", "other_metric"); + } + + @Test + public void execute_isReentrant() throws SQLException { + insertMetric("wont_fix_issues"); + insertMetric("other_metric"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select name from metrics")) + .extracting(stringObjectMap -> stringObjectMap.get("NAME")) + .containsExactlyInAnyOrder("accepted_issues", "other_metric"); + } + + private void insertMetric(String name) { + db.executeInsert("metrics", + "NAME", name, + "DESCRIPTION", "description " + name, + "DIRECTION", -1, + "DOMAIN", "Issues", + "SHORT_NAME", name, + "QUALITATIVE", true, + "VAL_TYPE", "int", + "ENABLED", true, + "OPTIMIZED_BEST_VALUE", true, + "HIDDEN", false, + "DELETE_HISTORICAL_DATA", false, + "UUID", name); + } +} diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorIT/users_table.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorIT/users_table.sql new file mode 100644 index 00000000000..e86b74fd8ec --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorIT/users_table.sql @@ -0,0 +1,4 @@ +CREATE TABLE "USERS" ( + "LOGIN" VARCHAR(255), + "NAME" VARCHAR(200) +); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorIT/users_table.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorIT/users_table.sql new file mode 100644 index 00000000000..1920431bc40 --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorIT/users_table.sql @@ -0,0 +1,5 @@ +CREATE TABLE "USERS" ( + "LOGIN" VARCHAR(255), + "NAME" VARCHAR(200), + "IS_ROOT" BOOLEAN +); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT/schema_migration.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT/schema_migration.sql new file mode 100644 index 00000000000..aad2a0750a7 --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplIT/schema_migration.sql @@ -0,0 +1,4 @@ +CREATE TABLE "SCHEMA_MIGRATIONS" ( + "VERSION" VARCHAR(256) NOT NULL +); +CREATE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION"); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT/empty.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplIT/empty.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT/empty.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplIT/empty.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT/schema.sql new file mode 100644 index 00000000000..bb4ba642b4a --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderIT/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE "TEST_PRIMARY_KEY"( + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "TEST_PRIMARY_KEY" ADD CONSTRAINT "PK_TEST_PRIMARY_KEY" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/DataChangeIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/DataChangeIT/schema.sql new file mode 100644 index 00000000000..7a0e17f4e45 --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/DataChangeIT/schema.sql @@ -0,0 +1,14 @@ +CREATE TABLE "PERSONS" ( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "LOGIN" VARCHAR(50), + "AGE" INTEGER, + "ENABLED" BOOLEAN, + "UPDATED_AT" TIMESTAMP, + "COEFF" DOUBLE, + "PHONE_NUMBERS" VARCHAR(500) +); + +CREATE TABLE "PHONE_NUMBERS" ( + "PERSON_ID" INTEGER NOT NULL, + "PHONE_NUMBER" VARCHAR(100) +); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT/schema.sql new file mode 100644 index 00000000000..d51d6260dab --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsIT/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE "PLUGINS"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "KEE" CHARACTER VARYING(200) NOT NULL, + "BASE_PLUGIN_KEY" CHARACTER VARYING(200), + "FILE_HASH" CHARACTER VARYING(200) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, + "TYPE" CHARACTER VARYING(10) NOT NULL, + "REMOVED" BOOLEAN DEFAULT FALSE NOT NULL +); +ALTER TABLE "PLUGINS" ADD CONSTRAINT "PK_PLUGINS" PRIMARY KEY("UUID"); +CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE" NULLS FIRST); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT/schema.sql new file mode 100644 index 00000000000..28453ffd067 --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesIT/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "GROUP_ROLES"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "ROLE" CHARACTER VARYING(64) NOT NULL, + "COMPONENT_UUID" CHARACTER VARYING(40), + "GROUP_UUID" CHARACTER VARYING(40) +); +ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID"); +CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID" NULLS FIRST); +CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "COMPONENT_UUID" NULLS FIRST, "ROLE" NULLS FIRST); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT/schema.sql new file mode 100644 index 00000000000..f19732423ab --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesIT/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "USER_ROLES"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "ROLE" CHARACTER VARYING(64) NOT NULL, + "COMPONENT_UUID" CHARACTER VARYING(40), + "USER_UUID" CHARACTER VARYING(255) +); +ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); +CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID" NULLS FIRST); +CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT/schema.sql b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT/schema.sql new file mode 100644 index 00000000000..9b4b255b6e5 --- /dev/null +++ b/server/sonar-db-migration/src/it/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesIT/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE "WEBHOOK_DELIVERIES"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL, + "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL, + "CE_TASK_UUID" CHARACTER VARYING(40), + "ANALYSIS_UUID" CHARACTER VARYING(40), + "NAME" CHARACTER VARYING(100) NOT NULL, + "URL" CHARACTER VARYING(2000) NOT NULL, + "SUCCESS" BOOLEAN NOT NULL, + "HTTP_STATUS" INTEGER, + "DURATION_MS" BIGINT NOT NULL, + "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL, + "ERROR_STACKTRACE" CHARACTER LARGE OBJECT, + "CREATED_AT" BIGINT NOT NULL +); +ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID"); +CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST); +CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST); +CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SelectExecutorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SelectExecutorTest.java deleted file mode 100644 index b1fa7a91c92..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SelectExecutorTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.charset; - -import java.sql.Connection; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SelectExecutorTest { - - @Rule - public CoreDbTester dbTester = CoreDbTester.createForSchema(SelectExecutorTest.class, "users_table.sql"); - - SqlExecutor underTest = new SqlExecutor(); - - @Test - public void testExecuteQuery() throws Exception { - insertUser("him", "Him"); - insertUser("her", "Her"); - - try (Connection connection = dbTester.openConnection()) { - List rows = underTest.select(connection, "select login, name from users order by login", new SqlExecutor.StringsConverter(2)); - assertThat(rows).hasSize(2); - assertThat(rows.get(0)[0]).isEqualTo("her"); - assertThat(rows.get(0)[1]).isEqualTo("Her"); - assertThat(rows.get(1)[0]).isEqualTo("him"); - assertThat(rows.get(1)[1]).isEqualTo("Him"); - } - } - - private void insertUser(String login, String name) { - dbTester.executeInsert("users", - "LOGIN", login, - "NAME", name); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java deleted file mode 100644 index 260e021fa79..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.charset; - -import java.sql.Connection; -import java.util.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SqlExecutorTest { - - private static final String LOGIN_DB_COLUMN = "login"; - private static final String NAME_DB_COLUMN = "name"; - private static final String USERS_DB_TABLE = "users"; - private static final String IS_ROOT_DB_COLUMN = "is_root"; - - private SqlExecutor underTest = new SqlExecutor(); - - @Rule - public CoreDbTester dbTester = CoreDbTester.createForSchema(SqlExecutorTest.class, "users_table.sql"); - - @Test - public void executeSelect_executes_PreparedStatement() throws Exception { - dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "login1", NAME_DB_COLUMN, "name one", IS_ROOT_DB_COLUMN, false); - dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "login2", NAME_DB_COLUMN, "name two", IS_ROOT_DB_COLUMN, false); - - try (Connection connection = dbTester.openConnection()) { - List users = underTest.select(connection, "select " + LOGIN_DB_COLUMN + ", " + NAME_DB_COLUMN + " from users order by login", new SqlExecutor.StringsConverter( - 2)); - assertThat(users).hasSize(2); - assertThat(users.get(0)[0]).isEqualTo("login1"); - assertThat(users.get(0)[1]).isEqualTo("name one"); - assertThat(users.get(1)[0]).isEqualTo("login2"); - assertThat(users.get(1)[1]).isEqualTo("name two"); - } - } - - @Test - public void executeUpdate_executes_PreparedStatement() throws Exception { - dbTester.executeInsert(USERS_DB_TABLE, LOGIN_DB_COLUMN, "the_login", NAME_DB_COLUMN, "the name", IS_ROOT_DB_COLUMN, false); - - try (Connection connection = dbTester.openConnection()) { - underTest.executeDdl(connection, "update users set " + NAME_DB_COLUMN + "='new name' where " + LOGIN_DB_COLUMN + "='the_login'"); - } - Map row = dbTester.selectFirst("select " + NAME_DB_COLUMN + " from users where " + LOGIN_DB_COLUMN + "='the_login'"); - assertThat(row) - .isNotEmpty() - .containsEntry("NAME", "new name"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest.java deleted file mode 100644 index 112d7f53a65..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.history; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.server.platform.db.migration.step.MigrationStep; -import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -public class MigrationHistoryImplTest { - @Rule - public CoreDbTester dbTester = CoreDbTester.createForSchema(MigrationHistoryImplTest.class, "schema_migration.sql"); - - private MigrationHistoryMeddler migrationHistoryMeddler = mock(MigrationHistoryMeddler.class); - private MigrationHistoryImpl underTest = new MigrationHistoryImpl(dbTester.database(), migrationHistoryMeddler); - - @Test - public void start_does_not_fail_if_table_history_exists_and_calls_meddler() { - underTest.start(); - - verify(migrationHistoryMeddler).meddle(underTest); - } - - @Test - public void getLastMigrationNumber_returns_empty_if_history_table_is_empty() { - assertThat(underTest.getLastMigrationNumber()).isEmpty(); - } - - @Test - public void getLastMigrationNumber_returns_last_version_assuming_version_are_only_number() throws SQLException { - insert(12, 5, 30, 8); - - assertThat(underTest.getLastMigrationNumber()).contains(30L); - } - - @Test - public void done_fails_with_NPE_if_argument_is_null() { - assertThatThrownBy(() -> underTest.done(null)) - .isInstanceOf(NullPointerException.class); - } - - @Test - public void done_adds_migration_number_to_table() { - underTest.done(new RegisteredMigrationStep(12, "aa", MigrationStep.class)); - - assertThat(underTest.getLastMigrationNumber()).contains(12L); - } - - private void insert(int... versions) throws SQLException { - try (Connection connection = dbTester.database().getDataSource().getConnection()) { - Arrays.stream(versions).forEach(version -> insert(connection, version)); - } - } - - private void insert(Connection connection, long version) { - try (PreparedStatement statement = connection.prepareStatement("insert into schema_migrations(version) values (?)")) { - statement.setString(1, String.valueOf(version)); - statement.execute(); - connection.commit(); - } catch (SQLException e) { - throw new IllegalStateException(String.format("Failed to insert row with value %s", version), e); - } - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest.java deleted file mode 100644 index 5df392f7d80..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.history; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.dialect.MsSql; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MigrationHistoryTableImplTest { - private static final String TABLE_SCHEMA_MIGRATIONS = "schema_migrations"; - - @Rule - public MigrationDbTester dbTester = MigrationDbTester.createEmpty(); - - private MigrationHistoryTableImpl underTest = new MigrationHistoryTableImpl(dbTester.database()); - - @Test - public void start_creates_table_on_empty_schema() { - underTest.start(); - - verifyTable(); - } - - @Test - public void start_does_not_fail_if_table_exists() throws SQLException { - executeDdl(String.format("create table %s (version %s(255) not null)", TABLE_SCHEMA_MIGRATIONS, getFieldType())); - verifyTable(); - - underTest.start(); - - verifyTable(); - } - - private String getFieldType() { - if (dbTester.database().getDialect().getId().equals(MsSql.ID)) { - return "nvarchar"; - } - return "varchar"; - } - - private void executeDdl(String sql) throws SQLException { - try (Connection connection = dbTester.database().getDataSource().getConnection()) { - connection.setAutoCommit(false); - try (Statement statement = connection.createStatement()) { - statement.execute(sql); - connection.commit(); - } - } - } - - private void verifyTable() { - assertThat(dbTester.countRowsOfTable(TABLE_SCHEMA_MIGRATIONS)).isZero(); - dbTester.assertColumnDefinition(TABLE_SCHEMA_MIGRATIONS, "version", Types.VARCHAR, 255, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest.java deleted file mode 100644 index 4c85532d8fd..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.history; - -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; - -public class NoTableMigrationHistoryImplTest { - @Rule - public MigrationDbTester dbTester = MigrationDbTester.createEmpty(); - - private MigrationHistoryMeddler migrationHistoryMeddler = mock(MigrationHistoryMeddler.class); - private MigrationHistoryImpl underTest = new MigrationHistoryImpl(dbTester.database(), migrationHistoryMeddler); - - @Test - public void start_fails_with_ISE_if_table_history_does_not_exist() { - assertThatThrownBy(() -> { - underTest.start(); - verifyNoInteractions(migrationHistoryMeddler); - }) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Migration history table is missing"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java deleted file mode 100644 index 10111b0167f..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.sql; - -import java.util.Map; -import org.junit.ClassRule; -import org.junit.Test; -import org.sonar.db.dialect.Dialect; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.def.TinyIntColumnDef; -import org.sonar.server.platform.db.migration.def.VarcharColumnDef; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; -import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder; -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; -import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT; - -public class CreateTableBuilderDbTesterTest { - @ClassRule - public static final MigrationDbTester dbTester = MigrationDbTester.createEmpty(); - - private final Dialect dialect = dbTester.database().getDialect(); - private static int tableNameGenerator = 0; - - @Test - public void create_no_primary_key_table() { - newCreateTableBuilder() - .addColumn(newBooleanColumnDefBuilder().setColumnName("bool_col_1").build()) - .addColumn(newBooleanColumnDefBuilder().setColumnName("bool_col_2").setIsNullable(false).build()) - .addColumn(newIntegerColumnDefBuilder().setColumnName("i_col_1").build()) - .addColumn(newIntegerColumnDefBuilder().setColumnName("i_col_2").setIsNullable(false).build()) - .addColumn(newBigIntegerColumnDefBuilder().setColumnName("bi_col_1").build()) - .addColumn(newBigIntegerColumnDefBuilder().setColumnName("bi_col_2").setIsNullable(false).build()) - .addColumn(newClobColumnDefBuilder().setColumnName("clob_col_1").build()) - .addColumn(newClobColumnDefBuilder().setColumnName("clob_col_2").setIsNullable(false).build()) - .addColumn(newDecimalColumnDefBuilder().setColumnName("dec_col_1").build()) - .addColumn(newDecimalColumnDefBuilder().setColumnName("dec_col_2").setIsNullable(false).build()) - .addColumn(new TinyIntColumnDef.Builder().setColumnName("tiny_col_1").build()) - .addColumn(new TinyIntColumnDef.Builder().setColumnName("tiny_col_2").setIsNullable(false).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_1").setLimit(40).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) - .addColumn(newBlobColumnDefBuilder().setColumnName("blob_col_1").build()) - .addColumn(newBlobColumnDefBuilder().setColumnName("blob_col_2").setIsNullable(false).build()) - .build() - .forEach(dbTester::executeDdl); - } - - @Test - public void create_single_column_primary_key_table() { - newCreateTableBuilder() - .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_1").setIsNullable(false).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) - .build() - .forEach(dbTester::executeDdl); - } - - @Test - public void create_multi_column_primary_key_table() { - newCreateTableBuilder() - .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_1").setIsNullable(false).build()) - .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("bg_col_2").setIsNullable(false).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("varchar_col_2").setLimit(40).setIsNullable(false).build()) - .build() - .forEach(dbTester::executeDdl); - } - - @Test - public void create_autoincrement_notnullable_integer_primary_key_table() { - String tableName = createTableName(); - new CreateTableBuilder(dialect, tableName) - .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) - .addColumn(valColumnDef()) - .build() - .forEach(dbTester::executeDdl); - - verifyAutoIncrementIsWorking(tableName); - } - - @Test - public void create_autoincrement_notnullable_biginteger_primary_key_table() { - String tableName = createTableName(); - new CreateTableBuilder(dialect, tableName) - .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) - .addColumn(valColumnDef()) - .build() - .forEach(dbTester::executeDdl); - - verifyAutoIncrementIsWorking(tableName); - } - - private static VarcharColumnDef valColumnDef() { - return newVarcharColumnDefBuilder().setColumnName("val").setLimit(10).setIsNullable(false).build(); - } - - private void verifyAutoIncrementIsWorking(String tableName) { - dbTester.executeInsert(tableName, "val", "toto"); - - Map row = dbTester.selectFirst("select id as \"id\", val as \"val\" from " + tableName); - assertThat(row.get("id")).isNotNull(); - assertThat(row).containsEntry("val", "toto"); - } - - private CreateTableBuilder newCreateTableBuilder() { - return new CreateTableBuilder(dialect, createTableName()); - } - - private static String createTableName() { - return "table_" + tableNameGenerator++; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java deleted file mode 100644 index 0f73479d190..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.sql; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Optional; -import javax.sql.DataSource; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.db.Database; -import org.sonar.db.dialect.H2; -import org.sonar.db.dialect.MsSql; -import org.sonar.db.dialect.Oracle; -import org.sonar.db.dialect.PostgreSql; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class DbPrimaryKeyConstraintFinderTest { - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DbPrimaryKeyConstraintFinderTest.class, "schema.sql"); - - private final Database dbMock = mock(Database.class); - private final DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(dbMock); - - private static final PostgreSql POSTGRESQL = new PostgreSql(); - private static final MsSql MS_SQL = new MsSql(); - private static final Oracle ORACLE = new Oracle(); - private static final org.sonar.db.dialect.H2 H2 = new H2(); - - @Test - public void findConstraintName_constraint_exists() throws SQLException { - DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); - Optional constraintName = underTest.findConstraintName("TEST_PRIMARY_KEY"); - assertThat(constraintName).isPresent(); - assertThat(constraintName.get()).contains("PK_TEST_PRIMARY_KEY"); - } - - @Test - public void findConstraintName_constraint_not_exist_fails_silently() throws SQLException { - DbPrimaryKeyConstraintFinder underTest = new DbPrimaryKeyConstraintFinder(db.database()); - assertThat(underTest.findConstraintName("NOT_EXISTING_TABLE")).isNotPresent(); - } - - @Test - public void getDbVendorSpecificQuery_mssql() { - when(dbMock.getDialect()).thenReturn(MS_SQL); - - assertThat(underTest.getDbVendorSpecificQuery("my_table")) - .isEqualTo("SELECT name FROM sys.key_constraints WHERE type = 'PK' AND OBJECT_NAME(parent_object_id) = 'my_table'"); - } - - @Test - public void getDbVendorSpecificQuery_postgresql() throws SQLException { - DataSource dataSource = mock(DataSource.class); - Connection connection = mock(Connection.class); - when(dataSource.getConnection()).thenReturn(connection); - when(connection.getSchema()).thenReturn("SonarQube"); - when(dbMock.getDialect()).thenReturn(POSTGRESQL); - when(dbMock.getDataSource()).thenReturn(dataSource); - - assertThat(underTest.getDbVendorSpecificQuery("my_table")) - .isEqualTo("SELECT conname FROM pg_constraint c JOIN pg_namespace n on c.connamespace = n.oid JOIN pg_class cls on c.conrelid = cls.oid WHERE cls.relname = 'my_table' AND n.nspname = 'SonarQube'"); - } - - @Test - public void getDbVendorSpecificQuery_oracle() { - when(dbMock.getDialect()).thenReturn(ORACLE); - - assertThat(underTest.getDbVendorSpecificQuery("my_table")) - .isEqualTo("SELECT constraint_name FROM user_constraints WHERE table_name = UPPER('my_table') AND constraint_type='P'"); - } - - @Test - public void getDbVendorSpecificQuery_h2() { - when(dbMock.getDialect()).thenReturn(H2); - - assertThat(underTest.getDbVendorSpecificQuery("my_table")) - .isEqualTo("SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = 'MY_TABLE' and constraint_type = 'PRIMARY KEY'"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java deleted file mode 100644 index e7fb4663463..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java +++ /dev/null @@ -1,594 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.step; - -import java.sql.SQLException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.server.platform.db.migration.step.Select.Row; -import org.sonar.server.platform.db.migration.step.Select.RowReader; - -import static java.util.Collections.emptySet; -import static java.util.stream.Collectors.toSet; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.fail; - -public class DataChangeTest { - - private static final int MAX_BATCH_SIZE = 250; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DataChangeTest.class, "schema.sql"); - - @Before - public void setUp() { - db.executeUpdateSql("truncate table persons"); - } - - @Test - public void query() throws Exception { - insertPersons(); - - AtomicBoolean executed = new AtomicBoolean(false); - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - assertThat(context.prepareSelect("select id from persons order by id desc").list(Select.LONG_READER)) - .containsExactly(3L, 2L, 1L); - assertThat(context.prepareSelect("select id from persons where id=?").setLong(1, 2L).get(Select.LONG_READER)) - .isEqualTo(2L); - assertThat(context.prepareSelect("select id from persons where id=?").setLong(1, 12345L).get(Select.LONG_READER)) - .isNull(); - executed.set(true); - } - }.execute(); - assertThat(executed.get()).isTrue(); - } - - @Test - public void read_column_types() throws Exception { - insertPersons(); - - List persons = new ArrayList<>(); - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - persons.addAll(context - .prepareSelect("select id,login,age,enabled,updated_at,coeff from persons where id=2") - .list(new UserReader())); - } - }.execute(); - assertThat(persons).hasSize(1); - assertThat(persons.get(0)[0]).isEqualTo(2L); - assertThat(persons.get(0)[1]).isEqualTo("emmerik"); - assertThat(persons.get(0)[2]).isEqualTo(14); - assertThat(persons.get(0)[3]).isEqualTo(true); - assertThat(persons.get(0)[4]).isNotNull(); - assertThat(persons.get(0)[5]).isEqualTo(5.2); - } - - @Test - public void parameterized_query() throws Exception { - insertPersons(); - - final List ids = new ArrayList<>(); - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - ids.addAll(context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list(Select.LONG_READER)); - } - }.execute(); - assertThat(ids).containsOnly(2L, 3L); - } - - @Test - public void display_current_row_details_if_error_during_get() throws Exception { - insertPersons(); - - assertThatThrownBy(() -> { - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).get((RowReader) row -> { - throw new IllegalStateException("Unexpected error"); - }); - } - }.execute(); - }) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Error during processing of row: [id=2]"); - } - - @Test - public void display_current_row_details_if_error_during_list() throws Exception { - insertPersons(); - - assertThatThrownBy(() -> { - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list((RowReader) row -> { - throw new IllegalStateException("Unexpected error"); - }); - } - }.execute(); - }) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Error during processing of row: [id=2]"); - } - - @Test - public void bad_parameterized_query() throws Exception { - insertPersons(); - - DataChange change = new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - // parameter value is not set - context.prepareSelect("select id from persons where id>=?").list(Select.LONG_READER); - } - }; - - assertThatThrownBy(() -> change.execute()) - .isInstanceOf(SQLException.class); - } - - @Test - public void scroll() throws Exception { - insertPersons(); - - final List ids = new ArrayList<>(); - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - context.prepareSelect("select id from persons order by id desc").scroll(row -> ids.add(row.getNullableLong(1))); - } - }.execute(); - assertThat(ids).containsExactly(3L, 2L, 1L); - } - - @Test - public void insert() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)") - .setLong(1, 10L) - .setString(2, "kurt") - .setInt(3, 27) - .setBoolean(4, true) - .setDouble(5, 2.2) - .execute().commit().close(); - } - }.execute(); - - assertThat(db.select("select id as \"ID\" from persons")) - .extracting(t -> t.get("ID")) - .containsOnly(1L, 2L, 3L, 10L); - assertInitialPersons(); - assertPerson(10L, "kurt", 27L, true, null, 2.2d); - } - - @Test - public void batch_inserts() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)"); - boolean committed = upsert - .setLong(1, 10L) - .setString(2, "kurt") - .setInt(3, 27) - .setBoolean(4, true) - .setDouble(5, 2.2) - .addBatch(); - assertThat(committed).isFalse(); - - committed = upsert - .setLong(1, 11L) - .setString(2, "courtney") - .setInt(3, 25) - .setBoolean(4, false) - .setDouble(5, 2.3) - .addBatch(); - assertThat(committed).isFalse(); - - upsert.execute().commit().close(); - } - }.execute(); - - assertThat(db.select("select id as \"ID\" from persons")) - .extracting(t -> t.get("ID")) - .containsOnly(1L, 2L, 3L, 10L, 11L); - assertInitialPersons(); - assertPerson(10L, "kurt", 27L, true, null, 2.2d); - assertPerson(11L, "courtney", 25L, false, null, 2.3d); - } - - @Test - public void override_size_of_batch_inserts() throws Exception { - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)") - .setBatchSize(3); - long id = 100L; - assertThat(addBatchInsert(upsert, id++)).isFalse(); - assertThat(addBatchInsert(upsert, id++)).isFalse(); - assertThat(addBatchInsert(upsert, id++)).isTrue(); - assertThat(addBatchInsert(upsert, id++)).isFalse(); - assertThat(addBatchInsert(upsert, id++)).isFalse(); - assertThat(addBatchInsert(upsert, id++)).isTrue(); - assertThat(addBatchInsert(upsert, id)).isFalse(); - upsert.execute().commit().close(); - } - }.execute(); - assertThat(db.countRowsOfTable("persons")).isEqualTo(7); - for (int i = 100; i < 107; i++) { - assertPerson(i, "kurt", 27L, true, null, 2.2d); - } - } - - private boolean addBatchInsert(Upsert upsert, long id) throws SQLException { - return upsert - .setLong(1, id) - .setString(2, "kurt") - .setInt(3, 27) - .setBoolean(4, true) - .setDouble(5, 2.2) - .addBatch(); - } - - @Test - public void update_null() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - Upsert upsert = context.prepareUpsert("update persons set login=?,age=?,enabled=?, updated_at=?, coeff=? where id=?"); - upsert - .setString(1, null) - .setInt(2, null) - .setBoolean(3, null) - .setDate(4, null) - .setDouble(5, null) - .setLong(6, 2L) - .execute() - .commit() - .close(); - } - }.execute(); - - assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); - assertPerson(2L, null, null, null, null, null); - assertPerson(3L, "morgan", 3L, true, "2014-01-25", 5.4d); - } - - @Test - public void mass_batch_insert() throws Exception { - db.executeUpdateSql("truncate table persons"); - - final int count = MAX_BATCH_SIZE + 10; - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - Upsert upsert = context.prepareUpsert("insert into persons(id,login,age,enabled,coeff) values (?,?,?,?,?)"); - for (int i = 0; i < count; i++) { - upsert - .setLong(1, 10L + i) - .setString(2, "login" + i) - .setInt(3, 10 + i) - .setBoolean(4, true) - .setDouble(5, i + 0.5) - .addBatch(); - } - upsert.execute().commit().close(); - - } - }.execute(); - - assertThat(db.countRowsOfTable("persons")).isEqualTo(count); - } - - @Test - public void scroll_and_update() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - final Upsert upsert = context.prepareUpsert("update persons set login=?, age=? where id=?"); - context.prepareSelect("select id from persons").scroll(new Select.RowHandler() { - @Override - public void handle(Row row) throws SQLException { - long id = row.getNullableLong(1); - upsert.setString(1, "login" + id).setInt(2, 10 + (int) id).setLong(3, id); - upsert.execute(); - } - }); - upsert.commit().close(); - } - }.execute(); - - assertPerson(1L, "login1", 11L, false, "2014-01-25", 1.5d); - assertPerson(2L, "login2", 12L, true, "2014-01-25", 5.2d); - assertPerson(3L, "login3", 13L, true, "2014-01-25", 5.4d); - } - - @Test - public void display_current_row_details_if_error_during_scroll() throws Exception { - insertPersons(); - - assertThatThrownBy(() -> { - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - final Upsert upsert = context.prepareUpsert("update persons set login=?, age=? where id=?"); - context.prepareSelect("select id from persons").scroll(row -> { - throw new IllegalStateException("Unexpected error"); - }); - upsert.commit().close(); - } - }.execute(); - }) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Error during processing of row: [id=1]"); - } - - @Test - public void mass_update() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id from persons where id>=?").setLong(1, 2L); - massUpdate.update("update persons set login=?, age=? where id=?"); - massUpdate.execute((row, update) -> { - long id = row.getNullableLong(1); - update - .setString(1, "login" + id) - .setInt(2, 10 + (int) id) - .setLong(3, id); - return true; - }); - } - }.execute(); - - assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); - assertPerson(2L, "login2", 12L, true, "2014-01-25", 5.2d); - assertPerson(3L, "login3", 13L, true, "2014-01-25", 5.4d); - } - - @Test - public void row_splitter_should_split_correctly() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - MassRowSplitter massRowSplitter = context.prepareMassRowSplitter(); - massRowSplitter.select("select id, phone_numbers from persons where id>?").setLong(1, -2L); - massRowSplitter.splitRow(row -> { - try { - int personId = row.getInt(1); - String phoneNumbers = row.getString(2); - if (phoneNumbers == null) { - return emptySet(); - } - return Arrays.stream(StringUtils.split(phoneNumbers, '\n')) - .map(number -> new PhoneNumberRow(personId, number)) - .collect(toSet()); - } catch (SQLException e) { - throw new RuntimeException(e); - } - }); - - massRowSplitter.insert("insert into phone_numbers (person_id, phone_number) values (?, ?)"); - massRowSplitter.execute((row, insert) -> { - insert.setLong(1, row.personId()) - .setString(2, row.phoneNumber()); - return true; - }); - } - }.execute(); - - Set actualRows = getPhoneNumberRows(); - - assertThat(actualRows) - .containsExactlyInAnyOrder( - new PhoneNumberRow(1, "1"), - new PhoneNumberRow(1, "32234"), - new PhoneNumberRow(1, "42343"), - new PhoneNumberRow(2, "432423") - ); - } - - private Set getPhoneNumberRows() { - return db - .select("select person_id as personId, phone_number as phoneNumber from phone_numbers") - .stream() - .map(row -> new PhoneNumberRow((long) row.get("PERSONID"), (String) row.get("PHONENUMBER"))) - .collect(toSet()); - } - - private record PhoneNumberRow(long personId, String phoneNumber){} - - @Test - public void display_current_row_details_if_error_during_mass_update() throws Exception { - insertPersons(); - - assertThatThrownBy(() -> { - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id from persons where id>=?").setLong(1, 2L); - massUpdate.update("update persons set login=?, age=? where id=?"); - massUpdate.execute((row, update) -> { - throw new IllegalStateException("Unexpected error"); - }); - } - }.execute(); - }) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Error during processing of row: [id=2]"); - } - - @Test - public void mass_update_nothing() throws Exception { - insertPersons(); - - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id from persons where id>=?").setLong(1, 2L); - massUpdate.update("update persons set login=?, age=? where id=?"); - massUpdate.execute((row, update) -> false); - } - }.execute(); - - assertInitialPersons(); - } - - @Test - public void bad_mass_update() throws Exception { - insertPersons(); - - DataChange change = new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id from persons where id>=?").setLong(1, 2L); - // update is not set - massUpdate.execute((row, update) -> false); - } - }; - try { - change.execute(); - fail(); - } catch (IllegalStateException e) { - assertThat(e).hasMessage("SELECT or UPDATE requests are not defined"); - } - } - - @Test - public void read_not_null_fields() throws Exception { - insertPersons(); - - List persons = new ArrayList<>(); - new DataChange(db.database()) { - @Override - public void execute(Context context) throws SQLException { - persons.addAll(context - .prepareSelect("select id,login,age,enabled,updated_at,coeff from persons where id=2") - .list(row -> new Object[] { - // id, login, age, enabled - row.getLong(1), - row.getString(2), - row.getInt(3), - row.getBoolean(4), - row.getDate(5), - row.getDouble(6), - })); - } - }.execute(); - assertThat(persons).hasSize(1); - assertThat(persons.get(0)[0]).isEqualTo(2L); - assertThat(persons.get(0)[1]).isEqualTo("emmerik"); - assertThat(persons.get(0)[2]).isEqualTo(14); - assertThat(persons.get(0)[3]).isEqualTo(true); - assertThat(persons.get(0)[4]).isNotNull(); - assertThat(persons.get(0)[5]).isEqualTo(5.2); - } - - static class UserReader implements RowReader { - @Override - public Object[] read(Row row) throws SQLException { - return new Object[] { - // id, login, age, enabled - row.getNullableLong(1), - row.getNullableString(2), - row.getNullableInt(3), - row.getNullableBoolean(4), - row.getNullableDate(5), - row.getNullableDouble(6), - }; - } - } - - private void insertPersons() throws ParseException { - insertPerson(1, "barbara", 56, false, "2014-01-25", 1.5d, "\n1\n32234\n42343\n"); - insertPerson(2, "emmerik", 14, true, "2014-01-25", 5.2d, "432423"); - insertPerson(3, "morgan", 3, true, "2014-01-25", 5.4d, null); - } - - private void assertInitialPersons() throws ParseException { - assertPerson(1L, "barbara", 56L, false, "2014-01-25", 1.5d); - assertPerson(2L, "emmerik", 14L, true, "2014-01-25", 5.2d); - assertPerson(3L, "morgan", 3L, true, "2014-01-25", 5.4d); - } - - private void insertPerson(int id, String login, int age, boolean enabled, String updatedAt, double coeff, @Nullable String newLineSeparatedPhoneNumbers) throws ParseException { - db.executeInsert("persons", - "ID", id, - "LOGIN", login, - "AGE", age, - "ENABLED", enabled, - "UPDATED_AT", dateFormat.parse(updatedAt), - "COEFF", coeff, - "PHONE_NUMBERS", newLineSeparatedPhoneNumbers); - } - - private void assertPerson(long id, @Nullable String login, @Nullable Long age, @Nullable Boolean enabled, @Nullable String updatedAt, @Nullable Double coeff) - throws ParseException { - List> rows = db - .select("select id as \"ID\", login as \"LOGIN\", age as \"AGE\", enabled as \"ENABLED\", coeff as \"COEFF\", updated_at as \"UPDATED\" from persons where id=" + id); - assertThat(rows).describedAs("id=" + id).hasSize(1); - Map row = rows.get(0); - assertThat(row).containsEntry("ID", id); - assertThat(row).containsEntry("LOGIN", login); - assertThat(row).containsEntry("AGE", age); - assertThat(row).containsEntry("ENABLED", enabled); - assertThat(row).containsEntry("UPDATED", updatedAt == null ? null : dateFormat.parse(updatedAt)); - assertThat(row).containsEntry("COEFF", coeff); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java deleted file mode 100644 index 8bd255c6a5c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.step; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -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 static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.platform.db.migration.step.ForceReloadingOfAllPlugins.OVERWRITE_HASH; - -public class ForceReloadingOfAllPluginsTest { - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(ForceReloadingOfAllPluginsTest.class, "schema.sql"); - - private final DataChange underTest = new ForceReloadingOfAllPlugins(db.database()); - - @Test - public void migration_overwrite_file_hash_on_all_plugins() throws SQLException { - String pluginUuid1 = insertPlugin(); - String pluginUuid2 = insertPlugin(); - - underTest.execute(); - - assertPluginFileHashOverwrite(pluginUuid1); - assertPluginFileHashOverwrite(pluginUuid2); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String pluginUuid1 = insertPlugin(); - String pluginUuid2 = insertPlugin(); - - underTest.execute(); - // re-entrant - underTest.execute(); - - assertPluginFileHashOverwrite(pluginUuid1); - assertPluginFileHashOverwrite(pluginUuid2); - } - - private void assertPluginFileHashOverwrite(String pluginUuid) { - String selectSql = String.format("select file_hash from plugins where uuid='%s'", pluginUuid); - var selectResult = db.select(selectSql); - assertThat(selectResult.get(0)).containsEntry("FILE_HASH", OVERWRITE_HASH); - } - - private String insertPlugin() { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("KEE", randomAlphabetic(20)); - map.put("FILE_HASH", randomAlphabetic(32)); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("UPDATED_AT", System.currentTimeMillis()); - map.put("TYPE", "EXTERNAL"); - map.put("REMOVED", false); - db.executeInsert("plugins", map); - - return uuid; - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java deleted file mode 100644 index a4cf3d94a85..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/CreateInitialSchemaTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v00; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateInitialSchemaTest { - - private static final Set SCHEMAS_TO_IGNORE = Set.of("INFORMATION_SCHEMA", "sys", "SYS", "SYSTEM", "CTXSYS", "MDSYS", "XDB"); - - @Rule - public final MigrationDbTester dbTester = MigrationDbTester.createForMigrationStep(CreateInitialSchema.class); - - private final CreateInitialSchema underTest = new CreateInitialSchema(dbTester.database()); - - @Test - public void creates_tables_on_empty_db() throws Exception { - underTest.execute(); - - List tables = new ArrayList<>(); - try (Connection connection = dbTester.openConnection(); - ResultSet rs = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"})) { - - while (rs.next()) { - String schema = rs.getString("TABLE_SCHEM"); - if (!SCHEMAS_TO_IGNORE.contains(schema)) { - tables.add(rs.getString("TABLE_NAME").toLowerCase(Locale.ENGLISH)); - } - } - } - - assertThat(tables) - .containsOnly( - "active_rules", - "active_rule_parameters", - "app_branch_project_branch", - "alm_pats", - "app_projects", - "alm_settings", - "audits", - "project_alm_settings", - "analysis_properties", - "ce_activity", - "ce_queue", - "ce_scanner_context", - "ce_task_characteristics", - "ce_task_input", - "ce_task_message", - "components", - "default_qprofiles", - "deprecated_rule_keys", - "duplications_index", - "es_queue", - "events", - "event_component_changes", - "file_sources", - "groups", - "groups_users", - "group_roles", - "internal_component_props", - "internal_properties", - "issues", - "issue_changes", - "live_measures", - "metrics", - "new_code_periods", - "new_code_reference_issues", - "notifications", - "org_qprofiles", - "permission_templates", - "perm_templates_groups", - "perm_templates_users", - "perm_tpl_characteristics", - "plugins", - "portfolios", - "portfolio_projects", - "portfolio_proj_branches", - "portfolio_references", - "projects", - "project_badge_token", - "project_branches", - "project_links", - "project_mappings", - "project_measures", - "project_qprofiles", - "project_qgates", - "properties", - "push_events", - "qgate_group_permissions", - "qgate_user_permissions", - "qprofile_changes", - "qprofile_edit_groups", - "qprofile_edit_users", - "quality_gates", - "quality_gate_conditions", - "rules", - "rules_parameters", - "rules_profiles", - "rule_repositories", - "rule_desc_sections", - "saml_message_ids", - "scanner_analysis_cache", - "schema_migrations", - "scim_users", - "session_tokens", - "snapshots", - "users", - "user_dismissed_messages", - "user_roles", - "user_tokens", - "webhooks", - "webhook_deliveries"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java deleted file mode 100644 index 08da2eafe3c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v00; - -import java.sql.SQLException; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.Version; -import org.sonar.core.platform.SonarQubeVersion; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class PopulateInitialSchemaTest { - - private static final long NOW = 1_500L; - - private final Random random = new Random(); - private final Version version = Version.create(1 + random.nextInt(10), 1 + random.nextInt(10), random.nextInt(10)); - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - private final System2 system2 = mock(System2.class); - private final SonarQubeVersion sonarQubeVersion = mock(SonarQubeVersion.class); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateInitialSchema.class); - - private final PopulateInitialSchema underTest = new PopulateInitialSchema(db.database(), system2, uuidFactory, sonarQubeVersion); - - @Before - public void setUp() { - when(sonarQubeVersion.get()).thenReturn(version); - } - - @Test - public void migration_inserts_users_and_groups() throws SQLException { - when(system2.now()).thenReturn(NOW); - - underTest.execute(); - - verifyAdminUser(); - verifyGroup("sonar-users", "Every authenticated user automatically belongs to this group"); - verifyGroup("sonar-administrators", "System administrators"); - String qualityGateUuid = verifyQualityGate(); - verifyInternalProperties(); - verifyProperties(qualityGateUuid); - verifyRolesOfAdminsGroup(); - verifyRolesOfUsersGroup(); - verifyRolesOfAnyone(); - verifyMembershipOfAdminUser(); - } - - private void verifyAdminUser() { - Map cols = db.selectFirst("select " + - "login as \"LOGIN\", " + - "name as \"NAME\", " + - "email as \"EMAIL\", " + - "external_id as \"EXTERNAL_ID\", " + - "external_login as \"EXTERNAL_LOGIN\", " + - "external_identity_provider as \"EXT_IDENT_PROVIDER\", " + - "user_local as \"USER_LOCAL\", " + - "crypted_password as \"CRYPTED_PASSWORD\", " + - "salt as \"SALT\", " + - "hash_method as \"HASH_METHOD\", " + - "created_at as \"CREATED_AT\", " + - "updated_at as \"UPDATED_AT\", " + - "reset_password as \"RESET_PASSWORD\" " + - "from users where login='admin'"); - - assertThat(cols) - .containsEntry("LOGIN", "admin") - .containsEntry("NAME", "Administrator") - .containsEntry("EXTERNAL_ID", "admin") - .containsEntry("EXTERNAL_LOGIN", "admin") - .containsEntry("EXT_IDENT_PROVIDER", "sonarqube") - .containsEntry("USER_LOCAL", true) - .containsEntry("CRYPTED_PASSWORD", "$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi") - .containsEntry("HASH_METHOD", "BCRYPT") - .containsEntry("CREATED_AT", NOW) - .containsEntry("RESET_PASSWORD", true) - .containsEntry("UPDATED_AT", NOW); - - assertThat(cols.get("EMAIL")).isNull(); - assertThat(cols.get("SALT")).isNull(); - } - - private void verifyGroup(String expectedName, String expectedDescription) { - List> rows = db.select("select " + - "uuid as \"UUID\"," + - "name as \"name\", " + - "description as \"description\", " + - "created_at as \"CREATED_AT\", " + - "updated_at as \"UPDATED_AT\" " + - "from groups where name='" + expectedName + "'"); - assertThat(rows).hasSize(1); - - Map row = rows.get(0); - assertThat(row).containsEntry("name", expectedName); - assertThat(row).containsEntry("description", expectedDescription); - assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); - assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); - - } - - private String verifyQualityGate() { - List> rows = db.select("select " + - "uuid as \"UUID\", " + - "name as \"NAME\", " + - "is_built_in as \"BUILTIN\"," + - "created_at as \"CREATED_AT\", " + - "updated_at as \"UPDATED_AT\"" + - " from quality_gates"); - assertThat(rows).hasSize(1); - - Map row = rows.get(0); - assertThat(row).containsEntry("NAME", "Sonar way"); - assertThat(row).containsEntry("BUILTIN", true); - assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); - assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); - return (String) row.get("UUID"); - } - - private void verifyInternalProperties() { - List> rows = db.select("select " + - "kee as \"KEE\", " + - "is_empty as \"EMPTY\", " + - "text_value as \"VAL\"," + - "created_at as \"CREATED_AT\" " + - " from internal_properties"); - assertThat(rows).hasSize(2); - - Map> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("KEE"), Function.identity())); - verifyInternalProperty(rowsByKey, "installation.date", String.valueOf(system2.now())); - verifyInternalProperty(rowsByKey, "installation.version", version.toString()); - } - - private static void verifyInternalProperty(Map> rowsByKey, String key, String val) { - Map row = rowsByKey.get(key); - assertThat(row) - .containsEntry("KEE", key) - .containsEntry("EMPTY", false) - .containsEntry("VAL", val) - .containsEntry("CREATED_AT", NOW); - } - - private void verifyProperties(String qualityGateUuid) { - List> rows = db.select("select " + - "prop_key as \"PROP_KEY\", " + - "is_empty as \"EMPTY\", " + - "text_value as \"VAL\"," + - "created_at as \"CREATED_AT\" " + - " from properties"); - assertThat(rows).hasSize(4); - - Map> rowsByKey = rows.stream().collect(Collectors.toMap(t -> (String) t.get("PROP_KEY"), Function.identity())); - verifyProperty(rowsByKey, "sonar.forceAuthentication", "true"); - verifyProperty(rowsByKey, "sonar.qualityProfiles.allowDisableInheritedRules", "true"); - verifyProperty(rowsByKey, "projects.default.visibility", "public"); - verifyProperty(rowsByKey, "qualitygate.default", qualityGateUuid); - } - - private static void verifyProperty(Map> rowsByKey, String key, String val) { - Map row = rowsByKey.get(key); - assertThat(row) - .containsEntry("PROP_KEY", key) - .containsEntry("EMPTY", false) - .containsEntry("VAL", val) - .containsEntry("CREATED_AT", NOW); - } - - private void verifyRolesOfAdminsGroup() { - assertThat(selectRoles("sonar-administrators")).containsOnly("admin", "profileadmin", "gateadmin", "provisioning", "applicationcreator", "portfoliocreator"); - } - - private void verifyRolesOfUsersGroup() { - assertThat(selectRoles("sonar-users")).containsOnly("provisioning", "scan"); - } - - private void verifyRolesOfAnyone() { - List> rows = db.select("select gr.role as \"role\" " + - "from group_roles gr where gr.group_uuid is null"); - Stream roles = rows.stream() - .map(row -> (String) row.get("role")); - assertThat(roles).isEmpty(); - } - - private Stream selectRoles(String groupName) { - List> rows = db.select("select gr.role as \"role\" " + - "from group_roles gr " + - "inner join groups g on gr.group_uuid = g.uuid " + - "where g.name='" + groupName + "'"); - return rows.stream() - .map(row -> (String) row.get("role")); - } - - private void verifyMembershipOfAdminUser() { - List> rows = db.select("select g.name as \"groupName\" from groups g " + - "inner join groups_users gu on gu.group_uuid = g.uuid " + - "inner join users u on gu.user_uuid = u.uuid " + - "where u.login='admin'"); - List groupNames = rows.stream() - .map(row -> (String) row.get("groupName")) - .toList(); - assertThat(groupNames).containsOnly("sonar-administrators", "sonar-users"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsTest.java deleted file mode 100644 index 4c60bd94988..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/AddNclocToProjectsTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class AddNclocToProjectsTest { - - private static final String TABLE_NAME = "projects"; - private static final String COLUMN_NAME = "ncloc"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddNclocToProjects.class); - private final DdlChange underTest = new AddNclocToProjects(db.database()); - - @Test - public void add_column() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, true); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableTest.java deleted file mode 100644 index 9ef20dba209..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateScimGroupsTableTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v100.CreateScimGroupsTable.TABLE_NAME; - -public class CreateScimGroupsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateScimGroupsTable.class); - - private final DdlChange underTest = new CreateScimGroupsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, "scim_uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, "group_uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertPrimaryKey(TABLE_NAME, "pk_scim_groups", "scim_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidTest.java deleted file mode 100644 index 8d68b61ed6b..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuidTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.version.v100.CreateScimGroupsTable.TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v100.CreateUniqueIndexForScimGroupsUuid.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v100.CreateUniqueIndexForScimGroupsUuid.INDEX_NAME; - -public class CreateUniqueIndexForScimGroupsUuidTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForScimGroupsUuid.class); - private final DdlChange underTest = new CreateUniqueIndexForScimGroupsUuid(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - underTest.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsTest.java deleted file mode 100644 index 7d340d9f21c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropBModuleUuidInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "b_module_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropBModuleUuidInComponents.class); - private final DdlChange underTest = new DropBModuleUuidInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsTest.java deleted file mode 100644 index 3007800f3b8..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropBModuleUuidPathInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropBModuleUuidPathInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "b_module_uuid_path"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropBModuleUuidPathInComponents.class); - private final DdlChange underTest = new DropBModuleUuidPathInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsTest.java deleted file mode 100644 index c5e221bebdf..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsModuleUuidInComponentsTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexProjectsModuleUuidInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "module_uuid"; - private static final String INDEX_NAME = "projects_module_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexProjectsModuleUuidInComponents.class); - private final DdlChange underTest = new DropIndexProjectsModuleUuidInComponents(db.database()); - - @Test - public void drops_index() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } - - @Test - public void execute_whenIndexNameWithPrefix_shouldStillDelete() throws SQLException { - String alteredIndexName = "idx_1234567891345678916456789_" + INDEX_NAME; - db.renameIndex(TABLE_NAME, INDEX_NAME, alteredIndexName); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - db.assertIndex(TABLE_NAME, alteredIndexName, COLUMN_NAME); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, alteredIndexName); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsTest.java deleted file mode 100644 index a020f6b7636..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropIndexProjectsRootUuidInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexProjectsRootUuidInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "root_uuid"; - private static final String INDEX_NAME = "projects_root_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexProjectsRootUuidInComponents.class); - private final DdlChange underTest = new DropIndexProjectsRootUuidInComponents(db.database()); - - @Test - public void drops_index() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsTest.java deleted file mode 100644 index afe3854ee48..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropModuleUuidInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "module_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropModuleUuidInComponents.class); - private final DdlChange underTest = new DropModuleUuidInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsTest.java deleted file mode 100644 index 20b1fdd851b..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropModuleUuidPathInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropModuleUuidPathInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "module_uuid_path"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropModuleUuidPathInComponents.class); - private final DdlChange underTest = new DropModuleUuidPathInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 1500, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsTest.java deleted file mode 100644 index 0abca87daa9..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropRootUuidInComponentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropRootUuidInComponentsTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "root_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropRootUuidInComponents.class); - private final DdlChange underTest = new DropRootUuidInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, false); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java deleted file mode 100644 index 85e7a04a7d2..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DropScimUserProvisioningTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropScimUserProvisioning.class); - private final DataChange underTest = new DropScimUserProvisioning(db.database()); - - @Test - public void migration_should_truncate_scim_users_table() throws SQLException { - insertScimUser(1); - insertScimUser(2); - - underTest.execute(); - - assertThat(db.select("select * from scim_users")).isEmpty(); - } - - private void insertScimUser(long id) { - db.executeInsert("scim_users", - "scim_uuid", "any-scim-uuid-" + id, - "user_uuid", "any-user-uuid-" + id - ); - } - - @Test - public void migration_is_reentrant() throws SQLException { - insertScimUser(1); - insertScimUser(2); - - underTest.execute(); - underTest.execute(); - assertThat(db.select("select * from scim_users")).isEmpty(); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java deleted file mode 100644 index d8a0db1e548..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -public class DropSonarScimEnabledPropertyTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropSonarScimEnabledProperty.class); - private final DataChange underTest = new DropSonarScimEnabledProperty(db.database()); - - @Test - public void migration_should_remove_scim_property() throws SQLException { - insertScimProperty(db); - - underTest.execute(); - - Assertions.assertThat(db.select("select * from properties")).isEmpty(); - } - - @Test - public void migration_is_reentrant() throws SQLException { - insertScimProperty(db); - - underTest.execute(); - underTest.execute(); - - Assertions.assertThat(db.select("select * from properties")).isEmpty(); - } - - private void insertScimProperty(MigrationDbTester db) { - db.executeInsert("properties ", - "prop_key", "sonar.scim.enabled", - "is_empty", false, - "text_value", "true", - "created_at", 100_000L, - "uuid", "some-random-uuid" - ); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java deleted file mode 100644 index 13e18222a68..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogTester; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.platform.db.migration.version.v100.LogMessageIfSonarScimEnabledPresentProperty.SONAR_SCIM_ENABLED; - -public class LogMessageIfSonarScimEnabledPresentPropertyTest { - - @Rule - public LogTester logger = new LogTester(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(LogMessageIfSonarScimEnabledPresentProperty.class); - private final DataChange underTest = new LogMessageIfSonarScimEnabledPresentProperty(db.database()); - - @Before - public void before() { - logger.clear(); - } - - @Test - public void migration_should_log_message_when_scim_property() throws SQLException { - db.executeInsert("properties ", - "prop_key", "sonar.scim.enabled", - "is_empty", false, - "text_value", "true", - "created_at", 100_000L, - "uuid", "some-random-uuid" - ); - - underTest.execute(); - - assertThat(logger.logs(Level.WARN)) - .hasSize(1) - .containsExactly("'" + SONAR_SCIM_ENABLED + "' property is defined but not read anymore. Please read the upgrade notes" + - " for the instruction to upgrade. User provisioning is deactivated until reactivated from the SonarQube" + - " Administration Interface (\"General->Authentication\"). " - + "See documentation: https://docs.sonarsource.com/sonarqube/10.1/instance-administration/authentication/saml/scim/overview/"); - } - - @Test - public void migration_should_not_log_if_no_scim_property() throws SQLException { - - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).isEmpty(); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.executeInsert("properties ", - "prop_key", "sonar.scim.enabled", - "is_empty", false, - "text_value", "true", - "created_at", 100_000L, - "uuid", "some-random-uuid" - ); - - underTest.execute(); - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).hasSize(2); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersTest.java deleted file mode 100644 index 56352082e16..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/MakeColumnUserLocalNotNullableInUsersTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.BOOLEAN; - -public class MakeColumnUserLocalNotNullableInUsersTest { - private static final String TABLE_NAME = "users"; - private static final String COLUMN_NAME = "user_local"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeColumnUserLocalNotNullableInUsers.class); - private final MakeColumnUserLocalNotNullableInUsers underTest = new MakeColumnUserLocalNotNullableInUsers(db.database()); - - @Test - public void user_local_column_is_not_null() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsTest.java deleted file mode 100644 index 1f889830536..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; -import static org.assertj.core.api.Assertions.assertThat; - -public class PopulateNclocForForProjectsTest { - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateNclocForForProjects.class); - - private final DataChange underTest = new PopulateNclocForForProjects(db.database()); - - @Test - public void migration_populates_ncloc_for_projects() throws SQLException { - Map expectedNclocByProjectUuid = populateData(); - underTest.execute(); - verifyNclocCorrectlyPopulatedForProjects(expectedNclocByProjectUuid); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - Map expectedNclocByProjectUuid = populateData(); - underTest.execute(); - // re-entrant - underTest.execute(); - verifyNclocCorrectlyPopulatedForProjects(expectedNclocByProjectUuid); - } - - private Map populateData() { - String nclocMetricUuid = insertMetric("ncloc"); - - String projectUuid1 = insertProject(); - String project1Branch1 = insertProjectBranch(projectUuid1); - String project1Branch2 = insertProjectBranch(projectUuid1); - - long project1maxNcloc = 100; - insertLiveMeasure(nclocMetricUuid, projectUuid1, project1Branch1, 80L); - insertLiveMeasure(nclocMetricUuid, projectUuid1, project1Branch2, project1maxNcloc); - - String otherMetricUuid = insertMetric("other"); - insertLiveMeasure(otherMetricUuid, projectUuid1, project1Branch1, 5000L); - insertLiveMeasure(otherMetricUuid, projectUuid1, project1Branch2, 6000L); - - String projectUuid2 = insertProject(); - String project2Branch1 = insertProjectBranch(projectUuid2); - String project2Branch2 = insertProjectBranch(projectUuid2); - String project2Branch3 = insertProjectBranch(projectUuid2); - - long project2maxNcloc = 60; - insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch1, 20L); - insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch2, 50L); - insertLiveMeasure(nclocMetricUuid, projectUuid2, project2Branch3, project2maxNcloc); - - return Map.of(projectUuid1, project1maxNcloc, projectUuid2, project2maxNcloc); - } - - private void verifyNclocCorrectlyPopulatedForProjects(Map expectedNclocByProjectUuid) { - for (Map.Entry entry : expectedNclocByProjectUuid.entrySet()) { - String query = String.format("select ncloc from projects where uuid='%s'", entry.getKey()); - Long nclocFromProject = (Long) db.selectFirst(query).get("NCLOC"); - assertThat(nclocFromProject).isEqualTo(entry.getValue()); - } - } - - private String insertMetric(String name) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("NAME", name); - db.executeInsert("metrics", map); - return uuid; - } - - private String insertProject() { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("KEE", randomAlphabetic(20)); - map.put("QUALIFIER", "TRK"); - map.put("PRIVATE", true); - map.put("UPDATED_AT", System.currentTimeMillis()); - db.executeInsert("projects", map); - return uuid; - } - - private String insertProjectBranch(String projectUuid) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("PROJECT_UUID", projectUuid); - map.put("KEE", randomAlphabetic(20)); - map.put("BRANCH_TYPE", "PULL_REQUEST"); - map.put("UPDATED_AT", System.currentTimeMillis()); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("NEED_ISSUE_SYNC", false); - db.executeInsert("project_branches", map); - return uuid; - } - - private void insertLiveMeasure(String metricUuid, String projectUuid, String componentUuid, Long value) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("PROJECT_UUID", projectUuid); - map.put("COMPONENT_UUID", componentUuid); - map.put("METRIC_UUID", metricUuid); - map.put("VALUE", value); - map.put("UPDATED_AT", System.currentTimeMillis()); - map.put("CREATED_AT", System.currentTimeMillis()); - db.executeInsert("live_measures", map); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesTest.java deleted file mode 100644 index 98c062f3e8a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfilesTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.core.util.SequenceUuidFactory; -import org.sonar.core.util.UuidFactory; -import org.sonar.db.MigrationDbTester; -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.Mockito.mock; -import static org.mockito.Mockito.when; - -public class RemoveOrphanRulesFromQualityProfilesTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveOrphanRulesFromQualityProfiles.class); - private final System2 system2 = mock(System2.class); - private final UuidFactory instance = new SequenceUuidFactory(); - private final DataChange underTest = new RemoveOrphanRulesFromQualityProfiles(db.database(), instance, system2); - - @Before - public void before() { - when(system2.now()).thenReturn(1L); - } - - @Test - public void migration_should_remove_orphans() throws SQLException { - insertData(); - - underTest.execute(); - - assertOrphanRuleRemoved(); - assertQualityProfileChanges(); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - insertData(); - - // re-entrant - underTest.execute(); - underTest.execute(); - - assertOrphanRuleRemoved(); - assertQualityProfileChanges(); - } - - private void insertData() { - insertRule("uuid-rule-1", "language-1", "rule1"); - insertRule("uuid-rule-2", "language-2", "rule2"); - insertProfile("uuid-profile-1", "language-1"); - insertProfile("uuid-profile-2", "language-2"); - activateRule("uuid-active-rule-1", "uuid-profile-1", "uuid-rule-1"); - activateRule("uuid-active-rule-2", "uuid-profile-1", "uuid-rule-2"); - activateRule("uuid-active-rule-3", "uuid-profile-2", "uuid-rule-2"); - } - - private void insertRule(String uuid, String language, String ruleKey) { - Map rule = new HashMap<>(); - rule.put("uuid", uuid); - rule.put("plugin_rule_key", language + ":" + ruleKey); - rule.put("plugin_name", "plugin-name-1"); - rule.put("scope", "MAIN"); - rule.put("language", language); - rule.put("is_template", false); - rule.put("is_ad_hoc", false); - rule.put("is_external", false); - db.executeInsert("rules", rule); - } - - private void insertProfile(String uuid, String language) { - Map profile = new HashMap<>(); - profile.put("uuid", uuid); - profile.put("name", "profile-name-1"); - profile.put("language", language); - profile.put("is_built_in", false); - db.executeInsert("rules_profiles", profile); - } - - private void activateRule(String activeRuleUuid, String profileUuid, String ruleUuid) { - Map active_rule = new HashMap<>(); - active_rule.put("uuid", activeRuleUuid); - active_rule.put("failure_level", 3); - active_rule.put("profile_uuid", profileUuid); - active_rule.put("rule_uuid", ruleUuid); - db.executeInsert("active_rules", active_rule); - } - - private void assertOrphanRuleRemoved() { - assertThat(db.select("SELECT * from active_rules")) - .extracting(r -> r.get("UUID")) - .containsExactly("uuid-active-rule-1", "uuid-active-rule-3"); - } - - private void assertQualityProfileChanges() { - assertThat(db.select("SELECT * from qprofile_changes")) - .extracting(r -> r.get("KEE"), r -> r.get("RULES_PROFILE_UUID"), r -> r.get("CHANGE_TYPE"), r -> r.get("USER_UUID"), r -> r.get("CHANGE_DATA"), r -> r.get("CREATED_AT")) - .containsExactly(tuple("1", "uuid-profile-1", "DEACTIVATED", null, "ruleUuid=uuid-rule-2", 1L)); - } - - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersTest.java deleted file mode 100644 index 8d4b9f3811f..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/UpdateUserLocalValueInUsersTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v100; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang.RandomStringUtils.randomNumeric; -import static org.assertj.core.api.Assertions.assertThat; - -public class UpdateUserLocalValueInUsersTest { - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateUserLocalValueInUsers.class); - - private final DataChange underTest = new UpdateUserLocalValueInUsers(db.database()); - - @Test - public void migration_updates_user_local_if_null() throws SQLException { - String userUuid1 = insertUser(true); - String userUuid2 = insertUser(false); - String userUuid3 = insertUser(null); - - underTest.execute(); - - assertUserLocalIsUpdatedCorrectly(userUuid1, true); - assertUserLocalIsUpdatedCorrectly(userUuid2, false); - assertUserLocalIsUpdatedCorrectly(userUuid3, true); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String userUuid1 = insertUser(true); - String userUuid2 = insertUser(false); - String userUuid3 = insertUser(null); - - underTest.execute(); - // re-entrant - underTest.execute(); - - assertUserLocalIsUpdatedCorrectly(userUuid1, true); - assertUserLocalIsUpdatedCorrectly(userUuid2, false); - assertUserLocalIsUpdatedCorrectly(userUuid3, true); - } - - private void assertUserLocalIsUpdatedCorrectly(String userUuid, boolean expected) { - String selectSql = String.format("select user_local from users where uuid='%s'", userUuid); - assertThat(db.select(selectSql).stream() - .map(row -> row.get("USER_LOCAL")) - .toList()) - .containsExactlyInAnyOrder(expected); - } - - private String insertUser(Boolean userLocal) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("LOGIN", randomAlphabetic(20)); - map.put("EXTERNAL_LOGIN", randomAlphabetic(20)); - map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube"); - map.put("EXTERNAL_ID", randomNumeric(5)); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("USER_LOCAL", userLocal); - map.put("RESET_PASSWORD", false); - db.executeInsert("users", map); - return uuid; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableTest.java deleted file mode 100644 index 5ff81a9f979..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddCodeVariantsColumnInIssuesTableTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class AddCodeVariantsColumnInIssuesTableTest { - - private static final String TABLE_NAME = "issues"; - private static final String COLUMN_NAME = "code_variants"; - private static final int COLUMN_SIZE = 4000; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCodeVariantsColumnInIssuesTable.class); - private final AddCodeVariantsColumnInIssuesTable underTest = new AddCodeVariantsColumnInIssuesTable(db.database()); - - @Test - public void migration_should_add_column() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, COLUMN_SIZE, true); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, COLUMN_SIZE, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesTest.java deleted file mode 100644 index b8be2e52805..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddIsMainColumnInProjectBranchesTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.BOOLEAN; - -public class AddIsMainColumnInProjectBranchesTest { - - private static final String TABLE_NAME = "project_branches"; - private static final String COLUMN_NAME = "is_main"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddIsMainColumnInProjectBranches.class); - private final AddIsMainColumnInProjectBranches underTest = new AddIsMainColumnInProjectBranches(db.database()); - - @Test - public void is_main_column_exists_with_null_value() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableTest.java deleted file mode 100644 index 92753a09a82..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSchedulesTableTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.AddReportSchedulesTable.TABLE_NAME; - -public class AddReportSchedulesTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddReportSchedulesTable.class); - - private final DdlChange underTest = new AddReportSchedulesTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, "portfolio_uuid", Types.VARCHAR, UUID_SIZE, true); - db.assertColumnDefinition(TABLE_NAME, "branch_uuid", Types.VARCHAR, UUID_SIZE, true); - db.assertColumnDefinition(TABLE_NAME, "last_send_time_in_ms", Types.BIGINT, null, false); - db.assertPrimaryKey(TABLE_NAME, "pk_report_schedules", "uuid"); - - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - } - - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableTest.java deleted file mode 100644 index e91f406f6be..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AddReportSubscriptionsTableTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.AddReportSubscriptionsTable.TABLE_NAME; - -public class AddReportSubscriptionsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddReportSubscriptionsTable.class); - - private final DdlChange underTest = new AddReportSubscriptionsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, "portfolio_uuid", Types.VARCHAR, UUID_SIZE, true); - db.assertColumnDefinition(TABLE_NAME, "branch_uuid", Types.VARCHAR, UUID_SIZE, true); - db.assertColumnDefinition(TABLE_NAME, "user_uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertPrimaryKey(TABLE_NAME, "pk_report_subscriptions", "uuid"); - - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesTest.java deleted file mode 100644 index 6a535290628..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/AlterIsMainColumnInProjectBranchesTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.BOOLEAN; - -public class AlterIsMainColumnInProjectBranchesTest { - - private static final String TABLE_NAME = "project_branches"; - private static final String COLUMN_NAME = "is_main"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AlterIsMainColumnInProjectBranches.class); - private final AlterIsMainColumnInProjectBranches underTest = new AlterIsMainColumnInProjectBranches(db.database()); - - @Test - public void execute_shouldNotBeNullable() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableTest.java deleted file mode 100644 index 9ce026c62a8..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateExternalGroupsTableTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_GROUP_ID_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.GROUP_UUID_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.TABLE_NAME; - -public class CreateExternalGroupsTableTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateExternalGroupsTable.class); - - private final DdlChange createExternalGroupsTable = new CreateExternalGroupsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - createExternalGroupsTable.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, GROUP_UUID_COLUMN_NAME, Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME, Types.VARCHAR, 255, false); - db.assertColumnDefinition(TABLE_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, Types.VARCHAR, 100, false); - db.assertPrimaryKey(TABLE_NAME, "pk_external_groups", GROUP_UUID_COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - createExternalGroupsTable.execute(); - // re-entrant - createExternalGroupsTable.execute(); - - db.assertTableExists(TABLE_NAME); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java deleted file mode 100644 index daaf33ea5ab..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForEmailOnUsersTableTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.INDEX_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForEmailOnUsersTable.TABLE_NAME; - -public class CreateIndexForEmailOnUsersTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForEmailOnUsersTable.class); - private final CreateIndexForEmailOnUsersTable createIndexForEmailOnUsersTable = new CreateIndexForEmailOnUsersTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndexForEmailOnUsersTable.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndexForEmailOnUsersTable.execute(); - createIndexForEmailOnUsersTable.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java deleted file mode 100644 index 95b41149862..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTableTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v101.CreateIndexForScmAccountOnScmAccountsTable.INDEX_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNTS_TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME; - -public class CreateIndexForScmAccountOnScmAccountsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForScmAccountOnScmAccountsTable.class); - private final CreateIndexForScmAccountOnScmAccountsTable createIndexForScmAccountOnScmAccountsTable = new CreateIndexForScmAccountOnScmAccountsTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME); - - createIndexForScmAccountOnScmAccountsTable.execute(); - - db.assertIndex(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndexForScmAccountOnScmAccountsTable.execute(); - createIndexForScmAccountOnScmAccountsTable.execute(); - - db.assertIndex(SCM_ACCOUNTS_TABLE_NAME, INDEX_NAME, SCM_ACCOUNT_COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableTest.java deleted file mode 100644 index e64fb1beeea..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_GROUP_ID_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateExternalGroupsTable.TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.INDEX_NAME; - -public class CreateIndexOnExternalIdAndIdentityOnExternalGroupsTableTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.class); - private final CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable createIndexOnExternalIdAndIdentityOnExternalGroupsTable = new CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable( - db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); - createIndexOnExternalIdAndIdentityOnExternalGroupsTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, EXTERNAL_GROUP_ID_COLUMN_NAME); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensTest.java deleted file mode 100644 index f778472f259..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateProjectUuidInUserTokensTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class CreateProjectUuidInUserTokensTest { - private static final String TABLE_NAME = "user_tokens"; - private static final String COLUMN_NAME = "project_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateProjectUuidInUserTokens.class); - private final CreateProjectUuidInUserTokens underTest = new CreateProjectUuidInUserTokens(db.database()); - - @Test - public void migration_creates_new_column() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, null); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, null); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java deleted file mode 100644 index 34e98672ac0..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateScmAccountsTableTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNTS_TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.SCM_ACCOUNT_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.CreateScmAccountsTable.USER_UUID_COLUMN_NAME; - -public class CreateScmAccountsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateScmAccountsTable.class); - - private final DdlChange createScmAccountsTable = new CreateScmAccountsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(SCM_ACCOUNTS_TABLE_NAME); - - createScmAccountsTable.execute(); - - db.assertTableExists(SCM_ACCOUNTS_TABLE_NAME); - db.assertColumnDefinition(SCM_ACCOUNTS_TABLE_NAME, USER_UUID_COLUMN_NAME, Types.VARCHAR, USER_UUID_SIZE, false); - db.assertColumnDefinition(SCM_ACCOUNTS_TABLE_NAME, SCM_ACCOUNT_COLUMN_NAME, Types.VARCHAR, SCM_ACCOUNT_SIZE, false); - db.assertPrimaryKey(SCM_ACCOUNTS_TABLE_NAME, "pk_scm_accounts", USER_UUID_COLUMN_NAME, SCM_ACCOUNT_COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(SCM_ACCOUNTS_TABLE_NAME); - - createScmAccountsTable.execute(); - // re-entrant - createScmAccountsTable.execute(); - - db.assertTableExists(SCM_ACCOUNTS_TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableTest.java deleted file mode 100644 index 6dc33a750c0..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTableTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v101.AddReportSchedulesTable.TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.COLUMN_NAME_BRANCH; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.COLUMN_NAME_PORTFOLIO; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSchedulesTable.INDEX_NAME; - - -public class CreateUniqueIndexForReportSchedulesTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForReportSchedulesTable.class); - private final CreateUniqueIndexForReportSchedulesTable createUniqueIndexForReportSchedulesTable = new CreateUniqueIndexForReportSchedulesTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createUniqueIndexForReportSchedulesTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createUniqueIndexForReportSchedulesTable.execute(); - createUniqueIndexForReportSchedulesTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableTest.java deleted file mode 100644 index 7a76d46b6aa..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTableTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v101.AddReportSubscriptionsTable.TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_BRANCH; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_PORTFOLIO; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.COLUMN_NAME_USER; -import static org.sonar.server.platform.db.migration.version.v101.CreateUniqueIndexForReportSubscriptionsTable.INDEX_NAME; - - -public class CreateUniqueIndexForReportSubscriptionsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForReportSubscriptionsTable.class); - private final CreateUniqueIndexForReportSubscriptionsTable createUniqueIndexForReportSubscriptionsTable = new CreateUniqueIndexForReportSubscriptionsTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createUniqueIndexForReportSubscriptionsTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH, COLUMN_NAME_USER); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createUniqueIndexForReportSubscriptionsTable.execute(); - createUniqueIndexForReportSubscriptionsTable.execute(); - - db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME_PORTFOLIO, COLUMN_NAME_BRANCH, COLUMN_NAME_USER); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensTest.java deleted file mode 100644 index 82bcdddbb55..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropProjectKeyInUserTokensTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.version.v101.DropProjectKeyInUserTokens.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.DropProjectKeyInUserTokens.TABLE_NAME; - -public class DropProjectKeyInUserTokensTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropProjectKeyInUserTokens.class); - private final DdlChange underTest = new DropProjectKeyInUserTokens(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 255, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java deleted file mode 100644 index aad4e6aa763..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/DropScmAccountsInUsersTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.version.v101.DropScmAccountsInUsers.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.DropScmAccountsInUsers.TABLE_NAME; - -public class DropScmAccountsInUsersTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropScmAccountsInUsers.class); - private final DdlChange dropScmAccountsInUsers = new DropScmAccountsInUsers(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); - dropScmAccountsInUsers.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 4000, true); - dropScmAccountsInUsers.execute(); - dropScmAccountsInUsers.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosTest.java deleted file mode 100644 index a320804c413..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/FixDifferentUuidsForSubportfoliosTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.resources.Qualifiers; -import org.sonar.db.MigrationDbTester; - -import static java.util.stream.Collectors.toSet; - -public class FixDifferentUuidsForSubportfoliosTest { - private static final String OLD_UUID = "differentSubPfUuid"; - private static final String SUB_PF_KEY = "subPfKey"; - private static final String NEW_SUBPF_UUID = "subPfUuid"; - private static final String PF_UUID = "pfUuid"; - private static final String NEW_CHILD_SUBPF_UUID = "childsubpfUuid"; - private static final String OLD_CHILD_SUBPF_UUID = "old_child_subpf_uuid"; - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(FixDifferentUuidsForSubportfolios.class); - private final FixDifferentUuidsForSubportfolios underTest = new FixDifferentUuidsForSubportfolios(db.database()); - - @Test - public void execute_shouldUpdatePortfoliosAndPortfolioProjectsAndPortfolioReferenceTable() throws SQLException { - insertPortfolio("pfKey", PF_UUID); - insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); - insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); - insertPortfolioProject("projUuid", OLD_UUID); - insertPortfolioReference("refUuid", OLD_UUID); - - underTest.execute(); - - Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); - } - - @Test - public void execute_shouldBeRentrant() throws SQLException { - insertPortfolio("pfKey", PF_UUID); - insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); - insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); - insertPortfolioProject("projUuid", OLD_UUID); - insertPortfolioReference("refUuid", OLD_UUID); - - underTest.execute(); - underTest.execute(); - - Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_SUBPF_UUID); - } - - @Test - public void execute_shouldFixUuidForSubPortfolioAtDifferentLevels() throws SQLException { - insertPortfolio("pfKey", PF_UUID); - - insertComponent(SUB_PF_KEY, NEW_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); - insertComponent("child_subpfkey", NEW_CHILD_SUBPF_UUID, PF_UUID, Qualifiers.SUBVIEW); - - insertSubPortfolio(SUB_PF_KEY, PF_UUID, PF_UUID, OLD_UUID); - insertSubPortfolio("child_subpfkey", OLD_UUID, PF_UUID, OLD_CHILD_SUBPF_UUID); - insertPortfolioProject("projUuid", OLD_CHILD_SUBPF_UUID); - insertPortfolioReference("refUuid", OLD_CHILD_SUBPF_UUID); - - underTest.execute(); - - Assertions.assertThat(findValueIn("portfolios", "uuid")).containsExactlyInAnyOrder(PF_UUID, NEW_SUBPF_UUID, NEW_CHILD_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolios", "parent_uuid")).containsExactlyInAnyOrder(null, PF_UUID, NEW_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_projects", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_CHILD_SUBPF_UUID); - Assertions.assertThat(findValueIn("portfolio_references", "portfolio_uuid")).containsExactlyInAnyOrder(NEW_CHILD_SUBPF_UUID); - } - - private Set findValueIn(String table, String field) { - return db.select(String.format("select %s FROM %s", field, table)) - .stream() - .map(row -> (String) row.get(field)) - .collect(toSet()); - } - - - private String insertComponent(String key, String uuid, String branchUuid, String qualifier) { - Map map = new HashMap<>(); - map.put("UUID", uuid); - map.put("KEE", key); - map.put("BRANCH_UUID", branchUuid); - map.put("UUID_PATH", "." + uuid + "."); - map.put("QUALIFIER", qualifier); - map.put("ENABLED", true); - map.put("PRIVATE", true); - - db.executeInsert("components", map); - return uuid; - } - - private String insertPortfolio(String kee, String uuid) { - return insertSubPortfolio(kee, uuid, uuid); - } - - private String insertSubPortfolio(String kee, String rootUuid, String uuid) { - return insertSubPortfolio(kee, null, rootUuid, uuid); - } - - private String insertSubPortfolio(String kee, @Nullable String parentUuid, String rootUuid, String uuid) { - Map map = new HashMap<>(); - map.put("UUID", uuid); - map.put("KEE", kee); - map.put("NAME", uuid); - map.put("ROOT_UUID", rootUuid); - map.put("PRIVATE", false); - map.put("SELECTION_MODE", "MANUAL"); - map.put("PARENT_UUID", parentUuid); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("UPDATED_AT", System.currentTimeMillis()); - - - db.executeInsert("portfolios", map); - return uuid; - } - - private String insertPortfolioReference(String uuid, String portfolioUuid) { - Map map = new HashMap<>(); - map.put("UUID", uuid); - map.put("PORTFOLIO_UUID", portfolioUuid); - map.put("REFERENCE_UUID", "reference"); - map.put("CREATED_AT", System.currentTimeMillis()); - - db.executeInsert("portfolio_references", map); - return uuid; - } - - private String insertPortfolioProject(String uuid, String portfolioUuid) { - Map map = new HashMap<>(); - map.put("UUID", uuid); - map.put("PORTFOLIO_UUID", portfolioUuid); - map.put("PROJECT_UUID", portfolioUuid); - map.put("CREATED_AT", System.currentTimeMillis()); - - db.executeInsert("portfolio_projects", map); - return uuid; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java deleted file mode 100644 index 85b0a3fcba5..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseKeeColumnSizeInInternalPropertiesTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.NEW_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseKeeColumnSizeInInternalProperties.TABLE_NAME; - -public class IncreaseKeeColumnSizeInInternalPropertiesTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseKeeColumnSizeInInternalProperties.class); - private final IncreaseKeeColumnSizeInInternalProperties underTest = new IncreaseKeeColumnSizeInInternalProperties(db.database()); - - @Test - public void execute_increaseColumnSize() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 20, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 20, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java deleted file mode 100644 index 9a339bdf102..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeActivityTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.NEW_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeActivity.TABLE_NAME; - -public class IncreaseTaskTypeColumnSizeInCeActivityTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseTaskTypeColumnSizeInCeActivity.class); - private final IncreaseTaskTypeColumnSizeInCeActivity underTest = new IncreaseTaskTypeColumnSizeInCeActivity(db.database()); - - @Test - public void execute_increaseColumnSize() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java deleted file mode 100644 index d609734a5db..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/IncreaseTaskTypeColumnSizeInCeQueueTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.NEW_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v101.IncreaseTaskTypeColumnSizeInCeQueue.TABLE_NAME; - -public class IncreaseTaskTypeColumnSizeInCeQueueTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseTaskTypeColumnSizeInCeQueue.class); - private final IncreaseTaskTypeColumnSizeInCeQueue underTest = new IncreaseTaskTypeColumnSizeInCeQueue(db.database()); - - @Test - public void execute_increaseColumnSize() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 15, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java deleted file mode 100644 index f9988ef088b..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/MigrateScmAccountsFromUsersToScmAccountsTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; -import org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.ScmAccountRow; - -import static java.lang.String.format; -import static java.util.stream.Collectors.toSet; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNoException; -import static org.sonar.server.platform.db.migration.version.v101.MigrateScmAccountsFromUsersToScmAccounts.SCM_ACCOUNTS_SEPARATOR_CHAR; - -public class MigrateScmAccountsFromUsersToScmAccountsTest { - - private static final UuidFactory UUID_FACTORY = UuidFactoryFast.getInstance(); - private static final String SCM_ACCOUNT1 = "scmaccount"; - private static final String SCM_ACCOUNT2 = "scmaccount2"; - private static final String SCM_ACCOUNT_CAMELCASE = "scmAccount3"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MigrateScmAccountsFromUsersToScmAccounts.class); - private final DataChange migrateScmAccountsFromUsersToScmAccounts = new MigrateScmAccountsFromUsersToScmAccounts(db.database()); - - @Test - public void execute_whenUserHasNullScmAccounts_doNotInsertInScmAccounts() throws SQLException { - insertUserAndGetUuid(null); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).isEmpty(); - } - - @Test - public void execute_whenUserHasEmptyScmAccounts_doNotInsertInScmAccounts() throws SQLException { - insertUserAndGetUuid(""); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).isEmpty(); - } - - @Test - public void execute_whenUserHasEmptyScmAccountsWithOneSeparator_doNotInsertInScmAccounts() throws SQLException { - insertUserAndGetUuid(String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR)); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).isEmpty(); - } - - @Test - public void execute_whenUserHasEmptyScmAccountsWithTwoSeparators_doNotInsertInScmAccounts() throws SQLException { - insertUserAndGetUuid(SCM_ACCOUNTS_SEPARATOR_CHAR + String.valueOf(SCM_ACCOUNTS_SEPARATOR_CHAR)); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).isEmpty(); - } - - @Test - public void execute_whenUserHasOneScmAccountWithoutSeparator_insertsInScmAccounts() throws SQLException { - String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); - } - - @Test - public void execute_whenUserHasOneScmAccountWithSeparators_insertsInScmAccounts() throws SQLException { - String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR)); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); - } - - @Test - public void execute_whenUserHasOneScmAccountWithMixedCase_insertsInScmAccountsInLowerCase() throws SQLException { - String userUuid = insertUserAndGetUuid(format("%s%s%s", SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT_CAMELCASE, SCM_ACCOUNTS_SEPARATOR_CHAR)); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT_CAMELCASE.toLowerCase(Locale.ENGLISH))); - } - - @Test - public void execute_whenUserHasTwoScmAccount_insertsInScmAccounts() throws SQLException { - String userUuid = insertUserAndGetUuid(format("%s%s%s%s%s", - SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT1, SCM_ACCOUNTS_SEPARATOR_CHAR, SCM_ACCOUNT2, SCM_ACCOUNTS_SEPARATOR_CHAR)); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).containsExactlyInAnyOrder( - new ScmAccountRow(userUuid, SCM_ACCOUNT1), - new ScmAccountRow(userUuid, SCM_ACCOUNT2) - ); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String userUuid = insertUserAndGetUuid(SCM_ACCOUNT1); - - migrateScmAccountsFromUsersToScmAccounts.execute(); - migrateScmAccountsFromUsersToScmAccounts.execute(); - - Set scmAccounts = findAllScmAccounts(); - assertThat(scmAccounts).containsExactly(new ScmAccountRow(userUuid, SCM_ACCOUNT1)); - } - - @Test - public void migration_should_be_reentrant_if_scm_account_column_dropped() { - db.executeDdl("alter table users drop column scm_accounts"); - - assertThatNoException().isThrownBy(migrateScmAccountsFromUsersToScmAccounts::execute); - } - - - private Set findAllScmAccounts() { - Set scmAccounts = db.select("select user_uuid, scm_account from scm_accounts") - .stream() - .map(row -> new ScmAccountRow((String) row.get("user_uuid"), (String) row.get("scm_account"))) - .collect(toSet()); - return scmAccounts; - } - - private String insertUserAndGetUuid(@Nullable String scmAccounts) { - - Map map = new HashMap<>(); - String uuid = UUID_FACTORY.create(); - String login = "login_" + uuid; - map.put("UUID", uuid); - map.put("LOGIN", login); - map.put("HASH_METHOD", "tagada"); - map.put("EXTERNAL_LOGIN", login); - map.put("EXTERNAL_IDENTITY_PROVIDER", "sonarqube"); - map.put("EXTERNAL_ID", login); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("RESET_PASSWORD", false); - map.put("USER_LOCAL", true); - map.put("SCM_ACCOUNTS", scmAccounts); - db.executeInsert("users", map); - return uuid; - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensTest.java deleted file mode 100644 index cf34d995487..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateProjectUuidInUserTokensTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.groups.Tuple.tuple; - -public class PopulateProjectUuidInUserTokensTest { - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateProjectUuidInUserTokens.class); - - private final DataChange underTest = new PopulateProjectUuidInUserTokens(db.database()); - - @Test - public void migration_populates_project_uuid_for_tokens() throws SQLException { - String project1Uuid = insertProject("project1"); - String project2Uuid = insertProject("project2"); - - String token1Uuid = insertUserToken("project1"); - String token2Uuid = insertUserToken("project1"); - String token3Uuid = insertUserToken("project2"); - String token4Uuid = insertUserToken(null); - - underTest.execute(); - assertThat(db.select("select * from user_tokens")) - .extracting(r -> r.get("UUID"), r -> r.get("PROJECT_UUID")) - .containsOnly( - tuple(token1Uuid, project1Uuid), - tuple(token2Uuid, project1Uuid), - tuple(token3Uuid, project2Uuid), - tuple(token4Uuid, null)); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String project1Uuid = insertProject("project1"); - String project2Uuid = insertProject("project2"); - - String token1Uuid = insertUserToken("project1"); - String token2Uuid = insertUserToken("project1"); - String token3Uuid = insertUserToken("project2"); - String token4Uuid = insertUserToken(null); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from user_tokens")) - .extracting(r -> r.get("UUID"), r -> r.get("PROJECT_UUID")) - .containsOnly( - tuple(token1Uuid, project1Uuid), - tuple(token2Uuid, project1Uuid), - tuple(token3Uuid, project2Uuid), - tuple(token4Uuid, null)); - } - - private String insertUserToken(@Nullable String projectKey) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("USER_UUID", "user" + uuid); - map.put("NAME", "name" + uuid); - map.put("TOKEN_HASH", "token" + uuid); - map.put("CREATED_AT", 1); - map.put("PROJECT_KEY", projectKey); - map.put("TYPE", "PROJECT_ANALYSIS_TOKEN"); - - db.executeInsert("user_tokens", map); - return uuid; - } - - private String insertProject(String projectKey) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("KEE", projectKey); - map.put("QUALIFIER", "TRK"); - map.put("PRIVATE", true); - map.put("UPDATED_AT", System.currentTimeMillis()); - db.executeInsert("projects", map); - return uuid; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesTest.java deleted file mode 100644 index 50a25d72cad..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSchedulesTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -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; - -public class PopulateReportSchedulesTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateReportSchedules.class); - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - private final DataChange underTest = new PopulateReportSchedules(db.database()); - - @Test - public void execute_shouldPopulateFromPortfolioProperties() throws SQLException { - insertPortfolio("uuid1"); - insertPortfolioProperty("uuid1", "1234"); - - underTest.execute(); - - assertThat(db.select("select * from report_schedules")) - .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS")) - .containsOnly(tuple("uuid1", null, 1234L)); - } - - @Test - public void execute_shouldPopulateFromBranchProperties() throws SQLException { - insertBranch("uuid1"); - insertProjectBranchProperty("uuid1", "1234"); - - underTest.execute(); - - assertThat(db.select("select * from report_schedules")) - .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("LAST_SEND_TIME_IN_MS")) - .containsOnly(tuple(null, "uuid1", 1234L)); - } - - @Test - public void execute_whenPropertyMatchesBothBranchAndPortfolio_shouldNotPopulate() throws SQLException { - insertBranch("uuid1"); - insertPortfolio("uuid1"); - insertProjectBranchProperty("uuid1", "1234"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from report_schedules")).isEmpty(); - } - - private void insertPortfolio(String uuid) { - db.executeInsert("portfolios", - "uuid", uuid, - "kee", "kee_" + uuid, - "name", "name_" + uuid, - "root_uuid", uuid, - "private", true, - "selection_mode", "manual", - "created_at", 1000, - "updated_at", 1000 - ); - } - - private void insertProjectBranchProperty(String portfolioUuid, String value) { - db.executeInsert("properties", - "uuid", uuidFactory.create(), - "prop_key", "sonar.governance.report.project.branch.lastSendTimeInMs", - "is_empty", false, - "text_value", value, - "created_at", 1000, - "entity_uuid", portfolioUuid - ); - } - - private void insertPortfolioProperty(String portfolioUuid, String value) { - db.executeInsert("properties", - "uuid", uuidFactory.create(), - "prop_key", "sonar.governance.report.lastSendTimeInMs", - "is_empty", false, - "text_value", value, - "created_at", 1000, - "entity_uuid", portfolioUuid - ); - } - - private void insertBranch(String uuid) { - db.executeInsert("project_branches", - "uuid", uuid, - "project_uuid", "project_" + uuid, - "kee", "kee_" + uuid, - "branch_type", "BRANCH", - "created_at", 1000, - "updated_at", 1000, - "need_issue_sync", false, - "is_main", true - ); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsTest.java deleted file mode 100644 index 0a003a9536d..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/PopulateReportSubscriptionsTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -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; - -public class PopulateReportSubscriptionsTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateReportSubscriptions.class); - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - private final DataChange underTest = new PopulateReportSubscriptions(db.database()); - - @Test - public void execute_shouldPopulateFromPortfolioProperties() throws SQLException { - insertPortfolio("uuid1"); - insertPortfolioProperty("uuid1", "1234"); - - underTest.execute(); - - assertThat(db.select("select * from report_subscriptions")) - .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("USER_UUID")) - .containsOnly(tuple("uuid1", null, "1234")); - } - - @Test - public void execute_shouldPopulateFromBranchProperties() throws SQLException { - insertBranch("uuid1"); - insertBranchProperty("uuid1", "1234"); - - underTest.execute(); - - assertThat(db.select("select * from report_subscriptions")) - .extracting(m -> m.get("PORTFOLIO_UUID"), m -> m.get("BRANCH_UUID"), m -> m.get("USER_UUID")) - .containsOnly(tuple(null, "uuid1", "1234")); - } - - @Test - public void execute_whenPropertyMatchesBothBranchAndPortfolio_shouldNotPopulate() throws SQLException { - insertBranch("uuid1"); - insertPortfolio("uuid1"); - insertBranchProperty("uuid1", "1234"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from report_subscriptions")).isEmpty(); - } - - private void insertPortfolio(String uuid) { - db.executeInsert("portfolios", - "uuid", uuid, - "kee", "kee_" + uuid, - "name", "name_" + uuid, - "root_uuid", uuid, - "private", true, - "selection_mode", "manual", - "created_at", 1000, - "updated_at", 1000 - ); - } - - private void insertBranchProperty(String branchUuid, String userUuid){ - insertProperty( branchUuid, userUuid, "sonar.governance.report.userNotification"); - } - - private void insertPortfolioProperty(String branchUuid, String userUuid){ - insertProperty( branchUuid, userUuid, "sonar.governance.report.project.branch.userNotification"); - } - - private void insertProperty(String componentUuid, String userUuid, String propertyKey) { - db.executeInsert("properties", - "uuid", uuidFactory.create(), - "prop_key", propertyKey, - "is_empty", false, - "text_value", "true", - "created_at", 1000, - "entity_uuid", componentUuid, - "user_uuid", userUuid - ); - } - - private void insertBranch(String uuid) { - db.executeInsert("project_branches", - "uuid", uuid, - "project_uuid", "project_" + uuid, - "kee", "kee_" + uuid, - "branch_type", "BRANCH", - "created_at", 1000, - "updated_at", 1000, - "need_issue_sync", false, - "is_main", true - ); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensTest.java deleted file mode 100644 index dd3cafed866..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveOrphanUserTokensTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RemoveOrphanUserTokensTest { - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveOrphanUserTokens.class); - - private final DataChange underTest = new RemoveOrphanUserTokens(db.database()); - - @Test - public void migration_deletes_orphan_tokens() throws SQLException { - String project1Uuid = insertProject("project1"); - - String token1Uuid = insertUserToken("project1"); - String token2Uuid = insertUserToken("orphan"); - String token3Uuid = insertUserToken(null); - - underTest.execute(); - assertThat(db.select("select * from user_tokens")) - .extracting(r -> r.get("UUID")) - .containsOnly(token1Uuid, token3Uuid); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String project1Uuid = insertProject("project1"); - - String token1Uuid = insertUserToken("project1"); - String token2Uuid = insertUserToken("orphan"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from user_tokens")) - .extracting(r -> r.get("UUID")) - .containsOnly(token1Uuid); - } - - private String insertUserToken( @Nullable String projectKey) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("USER_UUID", "user" + uuid); - map.put("NAME", "name" + uuid); - map.put("TOKEN_HASH", "token" + uuid); - map.put("CREATED_AT", 1); - map.put("PROJECT_KEY", projectKey); - map.put("TYPE", "PROJECT_ANALYSIS_TOKEN"); - - db.executeInsert("user_tokens", map); - return uuid; - } - - private String insertProject(String projectKey) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - map.put("KEE", projectKey); - map.put("QUALIFIER", "TRK"); - map.put("PRIVATE", true); - map.put("UPDATED_AT", System.currentTimeMillis()); - db.executeInsert("projects", map); - return uuid; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesTest.java deleted file mode 100644 index 3b6bc15ff74..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RemoveReportPropertiesTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RemoveReportPropertiesTest { - - private static final String SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION = "sonar.governance.report.userNotification"; - private static final String SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION = "sonar.governance.report.project.branch.userNotification"; - private static final String SONAR_GOVERNANCE_REPORT_LAST_SEND_TIME_IN_MS = "sonar.governance.report.lastSendTimeInMs"; - private static final String SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_LAST_SEND_TIME_IN_MS = "sonar.governance.report.project.branch.lastSendTimeInMs"; - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RemoveReportProperties.class); - - private final DataChange underTest = new RemoveReportProperties(db.database()); - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Test - public void execute_shouldRemoveRelevantPropertiesFromTable() throws SQLException { - insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION, "true"); - insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION, "true"); - insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_LAST_SEND_TIME_IN_MS, "12"); - insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_LAST_SEND_TIME_IN_MS, "123"); - insertProperty( "portfolio_uuid", "user_uuid", "sonar.other.property", "123"); - - underTest.execute(); - - assertThat(db.select("select * from properties")).hasSize(1) - .extracting(r->r.get("PROP_KEY")).containsExactly("sonar.other.property"); - } - - @Test - public void execute_shouldBeIdempotent() throws SQLException { - insertProperty( "branch_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_USER_NOTIFICATION, "true"); - insertProperty( "portfolio_uuid", "user_uuid", SONAR_GOVERNANCE_REPORT_PROJECT_BRANCH_USER_NOTIFICATION, "true"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from properties")).isEmpty(); - } - - private void insertProperty(String componentUuid, String userUuid, String propertyKey, String value) { - db.executeInsert("properties", - "uuid", uuidFactory.create(), - "prop_key", propertyKey, - "is_empty", false, - "text_value", value, - "created_at", 1000, - "entity_uuid", componentUuid, - "user_uuid", userUuid - ); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesTest.java deleted file mode 100644 index ed6a9d81e4e..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/RenameColumnComponentUuidInPropertiesTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameColumnComponentUuidInPropertiesTest { - - public static final String TABLE_NAME = "properties"; - public static final String NEW_COLUMN_NAME = "entity_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameColumnComponentUuidInProperties.class); - private final RenameColumnComponentUuidInProperties underTest = new RenameColumnComponentUuidInProperties(db.database()); - - @Test - public void columnIsRenamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesTest.java deleted file mode 100644 index e2fed55d384..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v101/UpdateIsMainColumnInProjectBranchesTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v101; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.UuidFactory; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; - -public class UpdateIsMainColumnInProjectBranchesTest { - - private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateIsMainColumnInProjectBranches.class); - - private final DataChange underTest = new UpdateIsMainColumnInProjectBranches(db.database()); - - private static int not_random_value_always_incremented = 0; - - @Test - public void migration_updates_is_main_if_row_has_the_same_uuids() throws SQLException { - String branchUuid1 = insertProjectBranch(true); - String branchUuid2 = insertProjectBranch(false); - - underTest.execute(); - - assertBranchIsMain(branchUuid1); - assertBranchIsNotMain(branchUuid2); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - String branchUuid1 = insertProjectBranch(true); - String branchUuid2 = insertProjectBranch(false); - - underTest.execute(); - // re-entrant - underTest.execute(); - - assertBranchIsMain(branchUuid1); - assertBranchIsNotMain(branchUuid2); - } - - private void assertBranchIsMain(String branchUuid) { - assertBranchIs(branchUuid, true); - } - - private void assertBranchIsNotMain(String branchUuid) { - assertBranchIs(branchUuid, false); - } - - private void assertBranchIs(String branchUuid, boolean isMain) { - String selectSql = String.format("select is_main from project_branches where uuid='%s'", branchUuid); - assertThat(db.select(selectSql).stream() - .map(row -> row.get("IS_MAIN")) - .toList()) - .containsExactlyInAnyOrder(isMain); - } - - private String insertProjectBranch(boolean sameUuids) { - Map map = new HashMap<>(); - String uuid = uuidFactory.create(); - map.put("UUID", uuid); - if(sameUuids) { - map.put("PROJECT_UUID", uuid); - } else { - map.put("PROJECT_UUID", "uuid" + not_random_value_always_incremented++); - } - map.put("KEE", "randomKey"); - map.put("BRANCH_TYPE", "BRANCH"); - map.put("MERGE_BRANCH_UUID", null); - map.put("CREATED_AT", System.currentTimeMillis()); - map.put("UPDATED_AT", System.currentTimeMillis()); - map.put("PULL_REQUEST_BINARY", null); - map.put("EXCLUDE_FROM_PURGE", true); - map.put("NEED_ISSUE_SYNC", false); - db.executeInsert("project_branches", map); - return uuid; - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesTest.java deleted file mode 100644 index f7606a598e4..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCleanCodeAttributeInRulesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -public class AddCleanCodeAttributeInRulesTest { - private static final String TABLE_NAME = "rules"; - private static final String COLUMN_NAME = "clean_code_attribute"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCleanCodeAttributeInRules.class); - - private final AddCleanCodeAttributeInRules underTest = new AddCleanCodeAttributeInRules(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); - } - - @Test - public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledTest.java deleted file mode 100644 index a64c82b065a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddUserConsentRequiredIfGithubAutoProvisioningEnabledTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogTester; -import org.sonar.api.utils.System2; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.platform.db.migration.version.v102.AddUserConsentRequiredIfGithubAutoProvisioningEnabled.PROP_KEY; -import static org.sonar.server.platform.db.migration.version.v102.AddUserConsentRequiredIfGithubAutoProvisioningEnabled.PROVISIONING_GITHUB_ENABLED_PROP_KEY; - -public class AddUserConsentRequiredIfGithubAutoProvisioningEnabledTest { - - @Rule - public LogTester logger = new LogTester(); - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddUserConsentRequiredIfGithubAutoProvisioningEnabled.class); - private final DataChange underTest = new AddUserConsentRequiredIfGithubAutoProvisioningEnabled(db.database(), new System2(), UuidFactoryFast.getInstance()); - - @Before - public void before() { - logger.clear(); - } - - @Test - public void migration_whenGitHubAutoProvisioningPropertyNotPresent_shouldNotRequireConsent() throws SQLException { - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).isEmpty(); - assertThat(isConsentRequired()).isFalse(); - } - - @Test - public void migration_whenGitHubAutoProvisioningDisabled_shouldNotRequireConsent() throws SQLException { - disableGithubProvisioning(); - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).isEmpty(); - assertThat(isConsentRequired()).isFalse(); - } - - @Test - public void migration_whenGitHubAutoProvisioningEnabled_shouldRequireConsent() throws SQLException { - enableGithubProvisioning(); - - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).containsExactly("Automatic synchronization was previously activated for GitHub. It requires user consent to continue working as new" - + " features were added with the synchronization. Please read the upgrade notes."); - assertThat(isConsentRequired()).isTrue(); - } - - @Test - public void migration_is_reentrant() throws SQLException { - enableGithubProvisioning(); - - underTest.execute(); - underTest.execute(); - - assertThat(logger.logs(Level.WARN)).containsExactly("Automatic synchronization was previously activated for GitHub. It requires user consent to continue working as new" - + " features were added with the synchronization. Please read the upgrade notes."); - assertThat(isConsentRequired()).isTrue(); - } - - private void disableGithubProvisioning() { - toggleGithubProvisioning(false); - } - private void enableGithubProvisioning() { - toggleGithubProvisioning(true); - } - - private boolean isConsentRequired() { - return db.countSql("select count(*) from properties where prop_key = '" + PROP_KEY + "'") >= 1; - } - - private void toggleGithubProvisioning(boolean enabled) { - db.executeInsert("internal_properties", "kee", PROVISIONING_GITHUB_ENABLED_PROP_KEY, "text_value", String.valueOf(enabled), "is_empty", true, "created_at", 0); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableTest.java deleted file mode 100644 index 312d47653d7..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateAnticipatedTransitionsTableTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE; -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.USER_UUID_SIZE; -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v102.CreateAnticipatedTransitionsTable.ANTICIPATED_TRANSITIONS_TABLE_NAME; - -public class CreateAnticipatedTransitionsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateAnticipatedTransitionsTable.class); - - private final DdlChange createAnticipatedTransitionsTable = new CreateAnticipatedTransitionsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME); - - createAnticipatedTransitionsTable.execute(); - - db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "project_uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "user_uuid", Types.VARCHAR, USER_UUID_SIZE, false); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition", Types.VARCHAR, 20, false); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "transition_comment", Types.VARCHAR, MAX_SIZE, true); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line", Types.INTEGER, null, true); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "message", Types.VARCHAR, MAX_SIZE, true); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "line_hash", Types.VARCHAR, 255, true); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "rule_key", Types.VARCHAR, 200, false); - db.assertColumnDefinition(ANTICIPATED_TRANSITIONS_TABLE_NAME, "file_path", Types.VARCHAR, 1500, false); - db.assertPrimaryKey(ANTICIPATED_TRANSITIONS_TABLE_NAME, "pk_anticipated_transitions", "uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(ANTICIPATED_TRANSITIONS_TABLE_NAME); - - createAnticipatedTransitionsTable.execute(); - // re-entrant - createAnticipatedTransitionsTable.execute(); - - db.assertTableExists(ANTICIPATED_TRANSITIONS_TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsTest.java deleted file mode 100644 index 233a60d60d7..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateBooleanPurgedColumnInSnapshotsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.BOOLEAN; - -public class CreateBooleanPurgedColumnInSnapshotsTest { - - private static final String TABLE_NAME = "snapshots"; - private static final String COLUMN_NAME = "purged"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateBooleanPurgedColumnInSnapshots.class); - - private final CreateBooleanPurgedColumnInSnapshots underTest = new CreateBooleanPurgedColumnInSnapshots(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreatePurgedColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); - } - - @Test - public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, null); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java deleted file mode 100644 index 037e2b8f250..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.GROUP_UUID_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.ORGANIZATION_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.TABLE_NAME; - -public class CreateGithubOrganizationsGroupsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateGithubOrganizationsGroupsTable.class); - private final DdlChange createGithubOrganizationsGroupsTable = new CreateGithubOrganizationsGroupsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - createGithubOrganizationsGroupsTable.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, GROUP_UUID_COLUMN_NAME, Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, ORGANIZATION_COLUMN_NAME, Types.VARCHAR, 100, false); - db.assertPrimaryKey(TABLE_NAME, "pk_github_orgs_groups", GROUP_UUID_COLUMN_NAME); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - createGithubOrganizationsGroupsTable.execute(); - // re-entrant - createGithubOrganizationsGroupsTable.execute(); - - db.assertTableExists(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesTest.java deleted file mode 100644 index cba75946536..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexCreatedAtInWebhookDeliveriesTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class CreateIndexCreatedAtInWebhookDeliveriesTest { - - public static final String TABLE_NAME = "webhook_deliveries"; - public static final String INDEX_NAME = "wd_created_at"; - public static final String EXPECTED_COLUMN = "created_at"; - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexCreatedAtInWebhookDeliveries.class); - private final DdlChange createIndex = new CreateIndexCreatedAtInWebhookDeliveries(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, EXPECTED_COLUMN); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, EXPECTED_COLUMN); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityTest.java deleted file mode 100644 index 985467477b2..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeActivityTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -public class CreateIndexEntityUuidInCeActivityTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInCeActivity.class); - private final CreateIndexEntityUuidInCeActivity createIndex = new CreateIndexEntityUuidInCeActivity(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("ce_activity", "ce_activity_entity_uuid"); - - createIndex.execute(); - - db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("ce_activity", "ce_activity_entity_uuid", "entity_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueTest.java deleted file mode 100644 index f9823a4b887..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInCeQueueTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -public class CreateIndexEntityUuidInCeQueueTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInCeQueue.class); - private final CreateIndexEntityUuidInCeQueue createIndex = new CreateIndexEntityUuidInCeQueue(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("ce_queue", "ce_queue_entity_uuid"); - - createIndex.execute(); - - db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("ce_queue", "ce_queue_entity_uuid", "entity_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesTest.java deleted file mode 100644 index 0bbf74a34d1..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInGroupRolesTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -public class CreateIndexEntityUuidInGroupRolesTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInGroupRoles.class); - private final CreateIndexEntityUuidInGroupRoles createIndex = new CreateIndexEntityUuidInGroupRoles(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("group_roles", "group_roles_entity_uuid"); - - createIndex.execute(); - - db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("group_roles", "group_roles_entity_uuid", "entity_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesTest.java deleted file mode 100644 index 5bcba341adc..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexEntityUuidInUserRolesTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -public class CreateIndexEntityUuidInUserRolesTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexEntityUuidInUserRoles.class); - private final CreateIndexEntityUuidInUserRoles createIndex = new CreateIndexEntityUuidInUserRoles(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("user_roles", "user_roles_entity_uuid"); - - createIndex.execute(); - - db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("user_roles", "user_roles_entity_uuid", "entity_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java deleted file mode 100644 index dd7d32ccd2e..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class CreateIndexProjectUuidCreatedAtInWebhookDeliveriesTest { - - public static final String TABLE_NAME = "webhook_deliveries"; - public static final String INDEX_NAME = "wd_project_uuid_created_at"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexProjectUuidCreatedAtInWebhookDeliveries.class); - private final DdlChange createIndex = new CreateIndexProjectUuidCreatedAtInWebhookDeliveries(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "project_uuid", "created_at"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesTest.java deleted file mode 100644 index 050f215b139..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexProjectUuidInProjectBranchesTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class CreateIndexProjectUuidInProjectBranchesTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexProjectUuidInProjectBranches.class); - private final CreateIndexProjectUuidInProjectBranches createIndex = new CreateIndexProjectUuidInProjectBranches(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("project_branches", "project_branches_project_uuid"); - - createIndex.execute(); - - db.assertIndex("project_branches", "project_branches_project_uuid", "project_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("project_branches", "project_branches_project_uuid", "project_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java deleted file mode 100644 index 35651df72fd..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class CreateIndexRootComponentUuidInSnapshotsTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexRootComponentUuidInSnapshots.class); - private final CreateIndexRootComponentUuidInSnapshots createIndex = new CreateIndexRootComponentUuidInSnapshots(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("snapshots", "snapshots_root_component_uuid"); - - createIndex.execute(); - - db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java deleted file mode 100644 index 8f22537d299..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class CreateIndexTaskUuidCreatedAtInWebhookDeliveriesTest { - - public static final String TABLE_NAME = "webhook_deliveries"; - public static final String INDEX_NAME = "wd_ce_task_uuid_created_at"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexTaskUuidCreatedAtInWebhookDeliveries.class); - private final DdlChange createIndex = new CreateIndexTaskUuidCreatedAtInWebhookDeliveries(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "ce_task_uuid", "created_at"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java deleted file mode 100644 index 1d31a4bb1af..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class CreateIndexWebhookUuidCreatedAtInWebhookDeliveriesTest { - - public static final String TABLE_NAME = "webhook_deliveries"; - public static final String INDEX_NAME = "wd_webhook_uuid_created_at"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexWebhookUuidCreatedAtInWebhookDeliveries.class); - private final DdlChange createIndex = new CreateIndexWebhookUuidCreatedAtInWebhookDeliveries(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "webhook_uuid", "created_at"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableTest.java deleted file mode 100644 index f5e15c8a932..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIssueImpactsTableTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class CreateIssueImpactsTableTest { - private static final String EXPECTED_TABLE_NAME = "issues_impacts"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIssueImpactsTable.class); - - private final DdlChange underTest = new CreateIssueImpactsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(EXPECTED_TABLE_NAME); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "issue_key", Types.VARCHAR, 40, false); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false); - db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(EXPECTED_TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsTest.java deleted file mode 100644 index cd07919da36..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreatePreviousNonCompliantValueInNewCodePeriodsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class CreatePreviousNonCompliantValueInNewCodePeriodsTest { - - private static final String COLUMN_NAME= "previous_non_compliant_value"; - - private static final String TABLE_NAME = "new_code_periods"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreatePreviousNonCompliantValueInNewCodePeriods.class); - private final CreatePreviousNonCompliantValueInNewCodePeriods underTest = new CreatePreviousNonCompliantValueInNewCodePeriods(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreatePurgedColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, null); - } - - @Test - public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 255, null); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableTest.java deleted file mode 100644 index d4c254716f3..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateRulesDefaultImpactsTableTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - - -public class CreateRulesDefaultImpactsTableTest { - private static final String EXPECTED_TABLE_NAME = "rules_default_impacts"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRulesDefaultImpactsTable.class); - - private final DdlChange underTest = new CreateRulesDefaultImpactsTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(EXPECTED_TABLE_NAME); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "rule_uuid", Types.VARCHAR, 40, false); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false); - db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false); - db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(EXPECTED_TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsTest.java deleted file mode 100644 index 8ca49f8c071..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpactsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class CreateUniqueConstraintOnIssuesImpactsTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueConstraintOnIssuesImpacts.class); - private final CreateUniqueConstraintOnIssuesImpacts underTest = new CreateUniqueConstraintOnIssuesImpacts(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("issues_impacts", "uniq_iss_key_sof_qual"); - - underTest.execute(); - - db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - underTest.execute(); - underTest.execute(); - - db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsTest.java deleted file mode 100644 index b64e50e414c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpactsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - - -public class CreateUniqueConstraintOnRulesDefaultImpactsTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueConstraintOnRulesDefaultImpacts.class); - private final CreateUniqueConstraintOnRulesDefaultImpacts underTest = new CreateUniqueConstraintOnRulesDefaultImpacts(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist("rules_default_impacts", "uniq_rul_uuid_sof_qual"); - - underTest.execute(); - - db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - underTest.execute(); - underTest.execute(); - - db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java deleted file mode 100644 index 8959c0f329d..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexComponentUuidInGroupRolesTest { - - private static final String TABLE_NAME = "group_roles"; - private static final String COLUMN_NAME = "component_uuid"; - private static final String INDEX_NAME = "group_roles_component_uuid"; - - /** - * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid - * also updated the index - */ - @Rule - public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInGroupRolesTest.class, "schema.sql"); - private final DropIndexComponentUuidInGroupRoles underTest = new DropIndexComponentUuidInGroupRoles(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java deleted file mode 100644 index 49bbe07d058..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexComponentUuidInSnapshotsTest { - - private static final String TABLE_NAME = "snapshots"; - private static final String COLUMN_NAME = "component_uuid"; - private static final String INDEX_NAME = "snapshot_component"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexComponentUuidInSnapshots.class); - private final DropIndexComponentUuidInSnapshots underTest = new DropIndexComponentUuidInSnapshots(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java deleted file mode 100644 index f3da16e7f1e..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexComponentUuidInUserRolesTest { - - private static final String TABLE_NAME = "user_roles"; - private static final String COLUMN_NAME = "component_uuid"; - private static final String INDEX_NAME = "user_roles_component_uuid"; - - /** - * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid - * also updated the index - */ - @Rule - public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInUserRolesTest.class, "schema.sql"); - private final DropIndexComponentUuidInUserRoles underTest = new DropIndexComponentUuidInUserRoles(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java deleted file mode 100644 index 73bdd332da0..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInWebhookDeliveriesTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexComponentUuidInWebhookDeliveriesTest { - - private static final String TABLE_NAME = "webhook_deliveries"; - private static final String COLUMN_NAME = "component_uuid"; - private static final String INDEX_NAME = "component_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexComponentUuidInWebhookDeliveries.class); - private final DropIndexComponentUuidInWebhookDeliveries underTest = new DropIndexComponentUuidInWebhookDeliveries(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityTest.java deleted file mode 100644 index a7f27a00497..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeActivityTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexMainComponentUuidInCeActivityTest { - - private static final String TABLE_NAME = "ce_activity"; - private static final String COLUMN_NAME = "main_component_uuid"; - private static final String INDEX_NAME = "ce_activity_main_component"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexMainComponentUuidInCeActivity.class); - private final DropIndexMainComponentUuidInCeActivity underTest = new DropIndexMainComponentUuidInCeActivity(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueTest.java deleted file mode 100644 index ae6d8429bd6..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexMainComponentUuidInCeQueueTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropIndexMainComponentUuidInCeQueueTest { - - private static final String TABLE_NAME = "ce_queue"; - private static final String COLUMN_NAME = "main_component_uuid"; - private static final String INDEX_NAME = "ce_queue_main_component"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexMainComponentUuidInCeQueue.class); - private final DropIndexMainComponentUuidInCeQueue underTest = new DropIndexMainComponentUuidInCeQueue(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java deleted file mode 100644 index 3848fb78e2a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexOnMainBranchProjectUuidTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexOnMainBranchProjectUuidTest { - private static final String TABLE_NAME = "components"; - private static final String COLUMN_NAME = "main_branch_project_uuid"; - private static final String INDEX_NAME = "idx_main_branch_prj_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexOnMainBranchProjectUuid.class); - private final DdlChange underTest = new DropIndexOnMainBranchProjectUuid(db.database()); - - @Test - public void drops_index() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java deleted file mode 100644 index b7f33fc7add..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.CoreDbTester; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexProjectUuidInWebhookDeliveriesTest { - - private static final String TABLE_NAME = "webhook_deliveries"; - private static final String COLUMN_NAME = "project_uuid"; - private static final String INDEX_NAME = "wd_project_uuid"; - - /** - * {@link MigrationDbTester} is not used because we are expecting index with component_uuid to exist. However, renaming the column component_uuid to entity_uuid - * also updated the index - */ - @Rule - public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexProjectUuidInWebhookDeliveriesTest.class, "schema.sql"); - private final DdlChange underTest = new DropIndexProjectUuidInWebhookDeliveries(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java deleted file mode 100644 index dc1d926c50f..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexTaskUuidInWebhookDeliveriesTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexTaskUuidInWebhookDeliveriesTest { - - private static final String TABLE_NAME = "webhook_deliveries"; - private static final String COLUMN_NAME = "ce_task_uuid"; - private static final String INDEX_NAME = "ce_task_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexTaskUuidInWebhookDeliveries.class); - private final DdlChange underTest = new DropIndexTaskUuidInWebhookDeliveries(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java deleted file mode 100644 index bf422d9da0b..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexWebhookUuidInWebhookDeliveriesTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -public class DropIndexWebhookUuidInWebhookDeliveriesTest { - - private static final String TABLE_NAME = "webhook_deliveries"; - private static final String COLUMN_NAME = "webhook_uuid"; - private static final String INDEX_NAME = "idx_wbhk_dlvrs_wbhk_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexWebhookUuidInWebhookDeliveries.class); - private final DdlChange underTest = new DropIndexWebhookUuidInWebhookDeliveries(db.database()); - - @Test - public void index_is_dropped() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); - - underTest.execute(); - underTest.execute(); - - db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java deleted file mode 100644 index f8878f4b1c8..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropMainBranchProjectUuidInComponentsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v102.DropMainBranchProjectUuidInComponents.TABLE_NAME; - -public class DropMainBranchProjectUuidInComponentsTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropMainBranchProjectUuidInComponents.class); - private final DdlChange underTest = new DropMainBranchProjectUuidInComponents(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 50, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsTest.java deleted file mode 100644 index 054745a5d6a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropPurgeStatusColumnInSnapshotsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropPurgeStatusColumnInSnapshotsTest { - - private static final String TABLE_NAME = "snapshots"; - private static final String COLUMN_NAME = "purge_status"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropPurgeStatusColumnInSnapshots.class); - private final DropPurgeStatusColumnInSnapshots underTest = new DropPurgeStatusColumnInSnapshots(db.database()); - - @Test - public void drops_column() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.INTEGER, null, null); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.INTEGER, null, null); - underTest.execute(); - underTest.execute(); - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java deleted file mode 100644 index 8c908eae891..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropTableProjectMappingsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class DropTableProjectMappingsTest { - public static final String TABLE_NAME = "project_mappings"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropTableProjectMappings.class); - private final DropTableProjectMappings underTest = new DropTableProjectMappings(db.database()); - - @Test - public void execute_shouldDropTable() throws SQLException { - db.assertTableExists(TABLE_NAME); - underTest.execute(); - db.assertTableDoesNotExist(TABLE_NAME); - } - - @Test - public void execute_shouldSupportReentrantMigrationExecution() throws SQLException { - db.assertTableExists(TABLE_NAME); - underTest.execute(); - underTest.execute(); - db.assertTableDoesNotExist(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionTest.java deleted file mode 100644 index 3d836dc199c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/FixSqaleIndexMetricDescriptionTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class FixSqaleIndexMetricDescriptionTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(FixSqaleIndexMetricDescription.class); - private final FixSqaleIndexMetricDescription underTest = new FixSqaleIndexMetricDescription(db.database()); - private final String OLD_DESCRIPTION = "Total effort (in hours) to fix all the issues on the component and therefore to comply to all the requirements."; - private final String NEW_DESCRIPTION = "Total effort (in minutes) to fix all the issues on the component and therefore to comply to all the requirements."; - - @Before - public void setUp() { - db.executeInsert("metrics", - "uuid", "uuid", - "name", "sqale_index", - "description", OLD_DESCRIPTION); - } - - @Test - public void execute_whenExecuted_shouldUpdateSqaleIndexDescription() throws SQLException { - assertThat(select()).isEqualTo(OLD_DESCRIPTION); - underTest.execute(); - assertThat(select()).isEqualTo(NEW_DESCRIPTION); - } - - @Test - public void execute_WhenExecutedTwice_shouldBeReentrant() throws SQLException { - assertThat(select()).isEqualTo(OLD_DESCRIPTION); - underTest.execute(); - underTest.execute(); - assertThat(select()).isEqualTo(NEW_DESCRIPTION); - } - - private String select() { - return (String) db.selectFirst("SELECT description FROM metrics WHERE name = 'sqale_index'").get("description"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java deleted file mode 100644 index 088ca308103..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseIsLastKeyInCeActivityTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.NEW_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseIsLastKeyInCeActivity.TABLE_NAME; - -public class IncreaseIsLastKeyInCeActivityTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseIsLastKeyInCeActivity.class); - private final IncreaseIsLastKeyInCeActivity underTest = new IncreaseIsLastKeyInCeActivity(db.database()); - - @Test - public void execute_increaseColumnSize() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java deleted file mode 100644 index 03cfd188eb9..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/IncreaseMainIsLastKeyInCeActivityTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.NEW_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v102.IncreaseMainIsLastKeyInCeActivity.TABLE_NAME; - -public class IncreaseMainIsLastKeyInCeActivityTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(IncreaseMainIsLastKeyInCeActivity.class); - private final IncreaseMainIsLastKeyInCeActivity underTest = new IncreaseMainIsLastKeyInCeActivity(db.database()); - - @Test - public void execute_increaseColumnSize() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 55, false); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, NEW_COLUMN_SIZE, false); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java deleted file mode 100644 index 2dc4e8bc640..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakeProjectUuidNullableInUserDismissedMessagesTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class MakeProjectUuidNullableInUserDismissedMessagesTest { - - private static final String TABLE_NAME = "user_dismissed_messages"; - private static final String COLUMN_NAME = "project_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeProjectUuidNullableInUserDismissedMessages.class); - private final MakeProjectUuidNullableInUserDismissedMessages underTest = new MakeProjectUuidNullableInUserDismissedMessages(db.database()); - - @Test - public void execute_shouldBeNullable() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, false); - underTest.execute(); - underTest.execute(); - - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsTest.java deleted file mode 100644 index 84f9cd4befc..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/MakePurgedColumnNotNullableInSnapshotsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.BOOLEAN; - -public class MakePurgedColumnNotNullableInSnapshotsTest { - private static final String TABLE_NAME = "snapshots"; - private static final String COLUMN_NAME = "purged"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakePurgedColumnNotNullableInSnapshots.class); - private final MakePurgedColumnNotNullableInSnapshots underTest = new MakePurgedColumnNotNullableInSnapshots(db.database()); - - @Test - public void execute_whenColumnIsNullable_shouldMakeColumnNullable() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } - - @Test - public void execute_whenExecutedTwice_shouldMakeColumnNullable() throws SQLException { - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, BOOLEAN, null, false); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesTest.java deleted file mode 100644 index b9ac4edfacc..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCleanCodeAttributeColumnInRulesTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.rules.CleanCodeAttribute; -import org.sonar.api.rules.RuleType; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - -public class PopulateCleanCodeAttributeColumnInRulesTest { - - private static final String TABLE_NAME = "rules"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateCleanCodeAttributeColumnInRules.class); - private final PopulateCleanCodeAttributeColumnInRules underTest = new PopulateCleanCodeAttributeColumnInRules(db.database()); - - @Test - public void execute_whenRulesDoNotExist_shouldNotFail() { - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } - - @Test - public void execute_whenRuleWithUndefinedCleanCodeAttribute_shouldUpdate() throws SQLException { - insertRule("1", null); - underTest.execute(); - assertThat(db.select("select uuid, clean_code_attribute from rules")) - .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) - .containsExactly(CleanCodeAttribute.CONVENTIONAL.name()); - } - - @Test - public void execute_whenRuleWithUndefinedCleanCodeAttribute_shouldBeReentrant() throws SQLException { - insertRule("1", null); - underTest.execute(); - underTest.execute(); - assertThat(db.select("select uuid, clean_code_attribute from rules")) - .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) - .containsExactly(CleanCodeAttribute.CONVENTIONAL.name()); - } - - @Test - public void execute_whenRuleWithDefinedCleanCodeAttribute_shouldNotUpdate() throws SQLException { - insertRule("1", CleanCodeAttribute.FOCUSED); - underTest.execute(); - assertThat(db.select("select uuid, clean_code_attribute from rules")) - .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) - .containsExactly(CleanCodeAttribute.FOCUSED.name()); - } - - @Test - public void execute_whenRuleIsHotspot_shouldNotUpdate() throws SQLException { - insertRule("1", RuleType.SECURITY_HOTSPOT, null, null); - underTest.execute(); - assertThat(db.select("select uuid, clean_code_attribute from rules")) - .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) - .containsOnlyNulls(); - } - - @Test - public void execute_whenAdhocRuleIsHotspot_shouldNotUpdate() throws SQLException { - insertRule("1", null, RuleType.SECURITY_HOTSPOT, null); - underTest.execute(); - assertThat(db.select("select uuid, clean_code_attribute from rules")) - .extracting(stringObjectMap -> stringObjectMap.get("clean_code_attribute")) - .containsOnlyNulls(); - } - - - private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable RuleType adhocRuleType, @Nullable CleanCodeAttribute cleanCodeAttribute) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "PLUGIN_RULE_KEY", "key", - "PLUGIN_NAME", "name", - "SCOPE", "1", - "CLEAN_CODE_ATTRIBUTE", cleanCodeAttribute != null ? cleanCodeAttribute.name() : null, - "IS_TEMPLATE", false, - "RULE_TYPE", ruleType != null ? ruleType.getDbConstant() : null, - "AD_HOC_TYPE", adhocRuleType != null ? adhocRuleType.getDbConstant() : null, - "IS_AD_HOC", false, - "IS_EXTERNAL", false); - } - - private void insertRule(String uuid, @Nullable CleanCodeAttribute cleanCodeAttribute) { - insertRule(uuid, RuleType.CODE_SMELL, null, cleanCodeAttribute); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesTest.java deleted file mode 100644 index 986b78cdc53..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateDefaultImpactsInRulesTest.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.issue.impact.SoftwareQuality; -import org.sonar.api.rules.RuleType; -import org.sonar.api.testfixtures.log.LogTester; -import org.sonar.core.util.Uuids; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.tuple; - -public class PopulateDefaultImpactsInRulesTest { - private static final String TABLE_NAME = "rules"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateDefaultImpactsInRules.class); - @Rule - public LogTester logTester = new LogTester(); - - private final PopulateDefaultImpactsInRules underTest = new PopulateDefaultImpactsInRules(db.database()); - - @Test - public void execute_whenRulesDoNotExist_shouldNotFail() { - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } - - @Test - public void execute_whenRulesHasTypeAndSeverity_shouldCreateImpact() throws SQLException { - insertRuleWithType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); - } - - @Test - public void execute_shouldBeReentrant() throws SQLException { - insertRuleWithType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .hasSize(1) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); - - } - - @Test - public void execute_whenAdhocRulesHasTypeAndSeverity_shouldCreateImpact() throws SQLException { - insertRuleWithAdHocType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .hasSize(1) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); - - } - - @Test - public void execute_whenAdhocRulesHasImpactAlready_shouldNotCreateImpact() throws SQLException { - insertRuleWithAdHocType("uuid", RuleType.CODE_SMELL, Severity.MAJOR); - insertImpact("uuid", SoftwareQuality.SECURITY, org.sonar.api.issue.impact.Severity.HIGH); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .hasSize(1) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.SECURITY.name(), org.sonar.api.issue.impact.Severity.HIGH.name())); - - } - - @Test - public void execute_whenNoTypeAndSeverityDefined_shouldNotCreateImpact() throws SQLException { - insertRuleWithType("uuid", null, null); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .isEmpty(); - - } - - @Test - public void execute_whenInvalidValueDefined_shouldNotCreateImpactAndLog() throws SQLException { - insertInvalidRule("uuid"); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .isEmpty(); - assertThat(logTester.logs()).contains("Error while mapping type to impact for rule 'uuid'"); - - } - - @Test - public void execute_whenTypeIsHotspot_shouldNotCreateImpactAndLog() throws SQLException { - insertRuleWithType("uuid", RuleType.SECURITY_HOTSPOT, Severity.MAJOR); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .isEmpty(); - assertThat(logTester.logs()).doesNotContain("Error while mapping type to impact for rule 'uuid'"); - } - - @Test - public void execute_whenRuleHasEmptyFields_shouldCreateADefaultImpact() throws SQLException { - insertPlaceholderAdhocRule("uuid"); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .hasSize(1) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY.name(), org.sonar.api.issue.impact.Severity.MEDIUM.name())); - } - - @Test - public void execute_whenStandardRuleHasBothAdhocAndStandardTypeAndSeverity_shouldCreateADefaultImpactWithAdhocTypes() throws SQLException { - insertRule("uuid", RuleType.CODE_SMELL, Severity.CRITICAL, RuleType.VULNERABILITY, Severity.MINOR, true); - underTest.execute(); - - assertThat(db.select("select software_quality, severity from rules_default_impacts")) - .hasSize(1) - .extracting(stringObjectMap -> stringObjectMap.get("software_quality"), - stringObjectMap -> stringObjectMap.get("severity")) - .containsExactly(tuple(SoftwareQuality.SECURITY.name(), org.sonar.api.issue.impact.Severity.LOW.name())); - } - - private void insertRuleWithType(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity) { - insertRule(uuid, ruleType, severity, null, null); - } - - private void insertRuleWithAdHocType(String uuid, @Nullable RuleType adHocType, @Nullable Severity adHocseverity) { - insertRule(uuid, null, null, adHocType, adHocseverity); - } - - - private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity, @Nullable RuleType adHocType, @Nullable Severity adHocseverity) { - insertRule(uuid, ruleType, severity, adHocType, adHocseverity, adHocType != null); - } - - private void insertRule(String uuid, @Nullable RuleType ruleType, @Nullable Severity severity, @Nullable RuleType adHocType, @Nullable Severity adHocseverity, boolean isAdhoc) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "PLUGIN_RULE_KEY", "key", - "PLUGIN_NAME", "name", - "SCOPE", "1", - "RULE_TYPE", ruleType != null ? ruleType.getDbConstant() : null, - "PRIORITY", severity != null ? org.sonar.api.rule.Severity.ALL.indexOf(severity.name()) : null, - "AD_HOC_TYPE", adHocType != null ? adHocType.getDbConstant() : null, - "AD_HOC_SEVERITY", adHocseverity != null ? adHocseverity.name() : null, - "IS_TEMPLATE", false, - "IS_AD_HOC", isAdhoc, - "IS_EXTERNAL", isAdhoc); - } - - private void insertInvalidRule(String uuid) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "PLUGIN_RULE_KEY", "key", - "PLUGIN_NAME", "name", - "SCOPE", "1", - "RULE_TYPE", 100, - "PRIORITY", -1, - "AD_HOC_TYPE", 100, - "AD_HOC_SEVERITY", "-1", - "IS_TEMPLATE", false, - "IS_AD_HOC", false, - "IS_EXTERNAL", false); - } - - private void insertPlaceholderAdhocRule(String uuid) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "PLUGIN_RULE_KEY", "key", - "PLUGIN_NAME", "name", - "SCOPE", "1", - "IS_TEMPLATE", false, - "IS_AD_HOC", true, - "IS_EXTERNAL", false); - } - - private void insertImpact(String ruleUuid, SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) { - db.executeInsert("RULES_DEFAULT_IMPACTS", - "UUID", Uuids.create(), - "RULE_UUID", ruleUuid, - "SOFTWARE_QUALITY", softwareQuality.name(), - "SEVERITY", severity.name()); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsTest.java deleted file mode 100644 index 155d55fd07a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulatePurgedColumnInSnapshotsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.tuple; - -public class PopulatePurgedColumnInSnapshotsTest { - private static final String TABLE_NAME = "snapshots"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulatePurgedColumnInSnapshots.class); - private final PopulatePurgedColumnInSnapshots underTest = new PopulatePurgedColumnInSnapshots(db.database()); - - @Test - public void execute_whenSnapshotsDoesNotExist_shouldNotFail() { - assertThatCode(underTest::execute) - .doesNotThrowAnyException(); - } - - @Test - public void execute_whenSnapshotsExist_shouldPopulatePurgedColumn() throws SQLException { - insertSnapshot("uuid-1", null); - insertSnapshot("uuid-2", 1); - insertSnapshot("uuid-3", 0); - insertSnapshot("uuid-4", null); - - underTest.execute(); - - assertThat(db.select("select uuid, purged from snapshots")) - .extracting(stringObjectMap -> stringObjectMap.get("uuid"), stringObjectMap -> stringObjectMap.get("purged")) - .containsExactlyInAnyOrder( - tuple("uuid-1", false), - tuple("uuid-2", true), - tuple("uuid-3", false), - tuple("uuid-4", false)); - } - - private void insertSnapshot(String uuid, @Nullable Integer status) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "ROOT_COMPONENT_UUID", "r_c_uuid", - "STATUS", "s", - "ISLAST", true, - "PURGE_STATUS", status, - "PURGED", null); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsTest.java deleted file mode 100644 index e7cd21a0627..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameBuildDateInSnapshotsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class RenameBuildDateInSnapshotsTest { - private static final String TABLE_NAME = "snapshots"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameBuildDateInSnapshots.class); - private final RenameBuildDateInSnapshots underTest = new RenameBuildDateInSnapshots(db.database()); - - @Test - public void execute_whenExecuted_shouldRenameColumn() throws SQLException { - assertColumnExists("build_date"); - underTest.execute(); - assertColumnExists("analysis_date"); - } - - @Test - public void execute_whenExecutedTwice_shouldNotFail() throws SQLException { - assertColumnExists("build_date"); - underTest.execute(); - underTest.execute(); - assertColumnExists("analysis_date"); - } - - private void assertColumnExists(String columnName) { - db.assertColumnDefinition(TABLE_NAME, columnName, Types.BIGINT, null, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java deleted file mode 100644 index 426c89f4de1..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameComponentUuidInGroupRolesTest { - public static final String TABLE_NAME = "group_roles"; - public static final String NEW_COLUMN_NAME = "entity_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInGroupRoles.class); - private final RenameComponentUuidInGroupRoles underTest = new RenameComponentUuidInGroupRoles(db.database()); - - @Test - public void columnIsRenamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java deleted file mode 100644 index 2b2edad145e..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameComponentUuidInSnapshotsTest { - public static final String TABLE_NAME = "snapshots"; - public static final String NEW_COLUMN_NAME = "root_component_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInSnapshots.class); - private final RenameComponentUuidInSnapshots underTest = new RenameComponentUuidInSnapshots(db.database()); - - @Test - public void columnIsRenamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java deleted file mode 100644 index 20f23c3baec..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameComponentUuidInUserRolesTest { - public static final String TABLE_NAME = "user_roles"; - public static final String NEW_COLUMN_NAME = "entity_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInUserRoles.class); - private final RenameComponentUuidInUserRoles underTest = new RenameComponentUuidInUserRoles(db.database()); - - @Test - public void columnIsRenamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java deleted file mode 100644 index bbe364a08fd..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInWebhookDeliveriesTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.AbstractDbTester; -import org.sonar.db.TestDb; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange; -import org.sonar.server.platform.db.migration.version.RenameVarcharColumnAbstractTest; - -public class RenameComponentUuidInWebhookDeliveriesTest extends RenameVarcharColumnAbstractTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameComponentUuidInWebhookDeliveries.class); - - public RenameComponentUuidInWebhookDeliveriesTest() { - super("webhook_deliveries", "project_uuid", false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - super.verifyMigrationIsReentrant(); - } - - @Test - public void column_is_renamed() throws SQLException { - super.verifyColumnIsRenamed(); - } - - @Override - protected RenameVarcharColumnChange getClassUnderTest() { - return new RenameComponentUuidInWebhookDeliveries(db.database()); - } - - @Override - protected AbstractDbTester getDatabase() { - return db; - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java deleted file mode 100644 index 45c9494c675..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeActivityTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameMainComponentUuidInCeActivityTest { - public static final String TABLE_NAME = "ce_activity"; - public static final String NEW_COLUMN_NAME = "entity_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameMainComponentUuidInCeActivity.class); - private final RenameMainComponentUuidInCeActivity underTest = new RenameMainComponentUuidInCeActivity(db.database()); - - @Test - public void column_is_renamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java deleted file mode 100644 index f7e64b072a8..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameMainComponentUuidInCeQueueTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; - -public class RenameMainComponentUuidInCeQueueTest { - public static final String TABLE_NAME = "ce_queue"; - public static final String NEW_COLUMN_NAME = "entity_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameMainComponentUuidInCeQueue.class); - private final RenameMainComponentUuidInCeQueue underTest = new RenameMainComponentUuidInCeQueue(db.database()); - - @Test - public void column_is_renamed() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsTest.java deleted file mode 100644 index 74a94b36e5b..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v102; - -import java.sql.SQLException; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; - -public class UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriodsTest { - - private static final String TABLE_NAME = "new_code_periods"; - private static final String PROJECT_UUID = "project-uuid"; - private static final String BRANCH_UUID = "branch-uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods.class); - public final UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods underTest = new UpdateValueAndPopulatePreviousNonCompliantValueInNewCodePeriods(db.database()); - - @Test - public void execute_whenSnapshotsExist_shouldPopulatePurgedColumn() throws SQLException { - insertNewCodePeriods("uuid-1", PROJECT_UUID, BRANCH_UUID, "PREVIOUS_VERSION", null); - insertNewCodePeriods("uuid-2", PROJECT_UUID, null, "NUMBER_OF_DAYS", "90"); - insertNewCodePeriods("uuid-3", null, null, "NUMBER_OF_DAYS", "97"); - - underTest.execute(); - - assertThat(db.select("select uuid, value, previous_non_compliant_value from new_code_periods")) - .extracting(stringObjectMap -> stringObjectMap.get("uuid"), stringObjectMap -> stringObjectMap.get("value"), - stringObjectMap -> stringObjectMap.get("previous_non_compliant_value")) - .containsExactlyInAnyOrder( - tuple("uuid-1", null, null), - tuple("uuid-2", "90", null), - tuple("uuid-3", "90", "97")); - } - - private void insertNewCodePeriods(String uuid, @Nullable String projectUuid, @Nullable String branchUuid, String type, String value) { - db.executeInsert(TABLE_NAME, - "UUID", uuid, - "PROJECT_UUID", projectUuid, - "BRANCH_UUID", branchUuid, - "TYPE", type, - "VALUE", value, - "UPDATED_AT", System.currentTimeMillis(), - "CREATED_AT", System.currentTimeMillis()); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableTest.java deleted file mode 100644 index 05905706ce5..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCleanCodeAttributeColumnInIssuesTableTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThatCode; - -public class AddCleanCodeAttributeColumnInIssuesTableTest { - private static final String TABLE_NAME = "issues"; - private static final String COLUMN_NAME = "clean_code_attribute"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCleanCodeAttributeColumnInIssuesTable.class); - private final AddCleanCodeAttributeColumnInIssuesTable underTest = new AddCleanCodeAttributeColumnInIssuesTable(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); - } - - @Test - public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { - underTest.execute(); - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java deleted file mode 100644 index 9650b160c61..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_SIZE; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; - -public class AddCreationMethodColumnInProjectsTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddCreationMethodColumnInProjectsTable.class); - private final AddCreationMethodColumnInProjectsTable underTest = new AddCreationMethodColumnInProjectsTable(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { - db.assertColumnDoesNotExist(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, PROJECTS_CREATION_METHOD_COLUMN_SIZE, true); - } - - @Test - public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { - underTest.execute(); - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java deleted file mode 100644 index 2e9a2f5a0c4..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThatCode; - -public class AddRuleChangesUuidColumnInQProfileChangesTest { - - private static final String TABLE_NAME = "qprofile_changes"; - private static final String COLUMN_NAME = "rule_change_uuid"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddRuleChangesUuidColumnInQProfileChanges.class); - private final AddRuleChangesUuidColumnInQProfileChanges underTest = new AddRuleChangesUuidColumnInQProfileChanges(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); - } - - @Test - public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { - underTest.execute(); - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableTest.java deleted file mode 100644 index 7bbb739be79..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddSqVersionColumnInQprofileChangesTableTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThatCode; - -public class AddSqVersionColumnInQprofileChangesTableTest { - - private static final String TABLE_NAME = "qprofile_changes"; - private static final String COLUMN_NAME = "sq_version"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddSqVersionColumnInQprofileChangesTable.class); - private final AddSqVersionColumnInQprofileChangesTable underTest = new AddSqVersionColumnInQprofileChangesTable(db.database()); - - @Test - public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { - db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); - underTest.execute(); - db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true); - } - - @Test - public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { - underTest.execute(); - assertThatCode(underTest::execute).doesNotThrowAnyException(); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableTest.java deleted file mode 100644 index b988f46d663..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateGithubPermissionsMappingTableTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; -import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; - -public class CreateGithubPermissionsMappingTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateGithubPermissionsMappingTable.class); - - private final DdlChange createGithubPermissionsMappingTable = new CreateGithubPermissionsMappingTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); - - createGithubPermissionsMappingTable.execute(); - - db.assertTableExists(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); - db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "github_role", Types.VARCHAR, 100, false); - db.assertColumnDefinition(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "sonarqube_permission", Types.VARCHAR, 64, false); - db.assertPrimaryKey(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, "pk_github_perms_mapping", "uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); - - createGithubPermissionsMappingTable.execute(); - // re-entrant - createGithubPermissionsMappingTable.execute(); - - db.assertTableExists(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableTest.java deleted file mode 100644 index 808aaf679a6..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTableTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - - - -public class CreateIndexForRuleImpactChangesTableTest { - - static final String INDEX_NAME = "rule_impact_changes_r_c_uuid"; - static final String TABLE_NAME = "rule_impact_changes"; - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateIndexForRuleImpactChangesTable.class); - private final CreateIndexForRuleImpactChangesTable underTest = new CreateIndexForRuleImpactChangesTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); - - underTest.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - underTest.execute(); - underTest.execute(); - - db.assertIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid"); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java deleted file mode 100644 index 505bef45ef4..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; - -public class CreateRuleChangesTableTest { - - private final static String TABLE_NAME = "rule_changes"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRuleChangesTable.class); - - private final DdlChange underTest = new CreateRuleChangesTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); - db.assertColumnDefinition(TABLE_NAME, "new_clean_code_attribute", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "old_clean_code_attribute", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "rule_uuid", Types.VARCHAR, UUID_SIZE, false); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java deleted file mode 100644 index c4c74b21365..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; - -public class CreateRuleImpactChangesTableTest { - - - private final static String TABLE_NAME = "rule_impact_changes"; - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateRuleImpactChangesTable.class); - - private final DdlChange underTest = new CreateRuleImpactChangesTable(db.database()); - - @Test - public void migration_should_create_a_table() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - db.assertColumnDefinition(TABLE_NAME, "new_software_quality", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "old_software_quality", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "new_severity", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "old_severity", Types.VARCHAR, 40, true); - db.assertColumnDefinition(TABLE_NAME, "rule_change_uuid", Types.VARCHAR, UUID_SIZE, false); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - db.assertTableDoesNotExist(TABLE_NAME); - - underTest.execute(); - // re-entrant - underTest.execute(); - - db.assertTableExists(TABLE_NAME); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableTest.java deleted file mode 100644 index a88d9013736..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTableTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; -import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_ROLE_COLUMN; -import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.SONARQUBE_PERMISSION_COLUMN; -import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForGithubPermissionsMappingTable.INDEX_NAME; - -public class CreateUniqueIndexForGithubPermissionsMappingTableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForGithubPermissionsMappingTable.class); - private final CreateUniqueIndexForGithubPermissionsMappingTable createIndex = new CreateUniqueIndexForGithubPermissionsMappingTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertUniqueIndex(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME, GITHUB_ROLE_COLUMN, SONARQUBE_PERMISSION_COLUMN); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertUniqueIndex(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, INDEX_NAME, GITHUB_ROLE_COLUMN, SONARQUBE_PERMISSION_COLUMN); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableTest.java deleted file mode 100644 index 4eb1b82a472..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForPropertiesTableTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForPropertiesTable.INDEX_NAME; -import static org.sonar.server.platform.db.migration.version.v103.CreateUniqueIndexForPropertiesTable.PROPERTIES_TABLE_NAME; - - -public class CreateUniqueIndexForPropertiesTableTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateUniqueIndexForPropertiesTable.class); - private final CreateUniqueIndexForPropertiesTable createIndex = new CreateUniqueIndexForPropertiesTable(db.database()); - - @Test - public void migration_should_create_index() throws SQLException { - db.assertIndexDoesNotExist(PROPERTIES_TABLE_NAME, INDEX_NAME); - - createIndex.execute(); - - db.assertUniqueIndex(PROPERTIES_TABLE_NAME, INDEX_NAME, "prop_key", "entity_uuid", "user_uuid"); - } - - @Test - public void migration_should_be_reentrant() throws SQLException { - createIndex.execute(); - createIndex.execute(); - - db.assertUniqueIndex(PROPERTIES_TABLE_NAME, INDEX_NAME, "prop_key", "entity_uuid", "user_uuid"); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableTest.java deleted file mode 100644 index 756f64cb7f6..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/DeduplicatePropertiesTableTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import java.util.Date; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.core.util.Uuids; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; - -public class DeduplicatePropertiesTableTest { - public static final String KEY = "key"; - public static final String ENTITY = "entity"; - public static final String USER = "user"; - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DeduplicatePropertiesTable.class); - private final DeduplicatePropertiesTable underTest = new DeduplicatePropertiesTable(db.database()); - - - public void createBaseProperties() { - createProperty(KEY, null, null); - createProperty(KEY, USER, null); - createProperty(KEY, USER, ENTITY); - } - - private void createProperty(String key, @Nullable String user, @Nullable String entity) { - db.executeInsert("PROPERTIES", - "UUID", Uuids.createFast(), - "PROP_KEY", key, - "TEXT_VALUE", "value", - "ENTITY_UUID", entity, - "USER_UUID", user, - "IS_EMPTY", false, - "CREATED_AT", new Date().getTime()); - } - - @Test - public void execute_shouldDeduplicateRows_WhenOnlyKeyIsSpecified() throws SQLException { - createBaseProperties(); - createProperty(KEY, null, null); - createProperty(KEY, null, null); - underTest.execute(); - assertThat(db.select("select * from properties")) - .hasSize(3) - .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) - .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); - } - - @Test - public void execute_shouldDeduplicateRows_WhenOnlyKeyAndUserAreSpecified() throws SQLException { - createBaseProperties(); - createProperty(KEY, USER, null); - createProperty(KEY, USER, null); - underTest.execute(); - assertThat(db.select("select * from properties")) - .hasSize(3) - .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) - .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); - } - - @Test - public void execute_shouldDeduplicateRows_WhenKeyUserAndEntityAreSpecified() throws SQLException { - createBaseProperties(); - createProperty(KEY, USER, ENTITY); - createProperty(KEY, USER, ENTITY); - underTest.execute(); - assertThat(db.select("select * from properties")) - .hasSize(3) - .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) - .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); - } - - @Test - public void execute_shouldBeReentrant() throws SQLException { - createBaseProperties(); - createProperty(KEY, USER, ENTITY); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select * from properties")) - .hasSize(3) - .extracting(str -> str.get("PROP_KEY"), str -> str.get("USER_UUID"), str -> str.get("ENTITY_UUID")) - .containsExactlyInAnyOrder(tuple(KEY, null, null), tuple(KEY, USER, null), tuple(KEY, USER, ENTITY)); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java deleted file mode 100644 index b2d2cbcfc5c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static java.sql.Types.VARCHAR; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; - -public class MakeCreationMethodColumnInProjectsNotNullableTest { - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(MakeCreationMethodColumnInProjectsNotNullable.class); - private final MakeCreationMethodColumnInProjectsNotNullable underTest = new MakeCreationMethodColumnInProjectsNotNullable(db.database()); - - @Test - public void user_local_column_is_not_null() throws SQLException { - db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); - underTest.execute(); - db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); - } - - @Test - public void migration_is_reentrant() throws SQLException { - db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); - underTest.execute(); - underTest.execute(); - db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java deleted file mode 100644 index fc5668fd43c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; - -public class PopulateCreationMethodColumnInProjectsTableTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateCreationMethodColumnInProjectsTable.class); - private final PopulateCreationMethodColumnInProjectsTable underTest = new PopulateCreationMethodColumnInProjectsTable(db.database()); - - @Test - public void execute_whenProjectsTableIsEmpty_shouldDoNothing() throws SQLException { - underTest.execute(); - - assertThat(db.select("select creation_method from projects")).isEmpty(); - } - - @Test - public void execute_whenProjectsExist_shouldPopulateCreationMethodColumn() throws SQLException { - insertProject("uuid-1"); - insertProject("uuid-2"); - - underTest.execute(); - - assertThat(db.select("select creation_method from projects")) - .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) - .containsExactlyInAnyOrder("UNKNOWN", "UNKNOWN"); - } - - @Test - public void execute_isReentrant() throws SQLException { - insertProject("uuid-1"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select creation_method from projects")) - .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) - .containsExactlyInAnyOrder("UNKNOWN"); - } - - private void insertProject(String uuid) { - db.executeInsert(PROJECTS_TABLE_NAME, - "UUID", uuid, - "KEE", uuid, - "QUALIFIER", "TRK", - "PRIVATE", true, - "UPDATED_AT", 1); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingTest.java deleted file mode 100644 index e7130ed6e31..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateGithubPermissionsMappingTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.testfixtures.log.LogTester; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; -import static org.sonar.server.platform.db.migration.version.v103.CreateGithubPermissionsMappingTable.GITHUB_PERMISSIONS_MAPPING_TABLE_NAME; - -public class PopulateGithubPermissionsMappingTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(PopulateGithubPermissionsMapping.class); - @Rule - public LogTester logTester = new LogTester(); - - private final PopulateGithubPermissionsMapping migration = new PopulateGithubPermissionsMapping(db.database(), UuidFactoryFast.getInstance()); - - @Test - public void execute_whenTableAlreadyPopulated_doesNothing() throws SQLException { - db.executeInsert(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME, - "UUID", UuidFactoryFast.getInstance().create(), - "github_role", "gh_role", - "sonarqube_permission", "sq_perm"); - - migration.execute(); - - assertThat(db.select("select github_role, sonarqube_permission from github_perms_mapping")) - .extracting(stringObjectMap -> stringObjectMap.get("GITHUB_ROLE"), stringObjectMap -> stringObjectMap.get("SONARQUBE_PERMISSION")) - .containsExactly(tuple("gh_role", "sq_perm")); - } - - @Test - public void execute_whenTableIsEmpty_shouldPopulate() throws SQLException { - migration.execute(); - - verifyMapping(); - } - - @Test - public void execute_isReentrant() throws SQLException { - migration.execute(); - migration.execute(); - migration.execute(); - - verifyMapping(); - } - - private void verifyMapping() { - assertThat(db.select("select github_role, sonarqube_permission from github_perms_mapping")) - .extracting(stringObjectMap -> stringObjectMap.get("GITHUB_ROLE"), stringObjectMap -> stringObjectMap.get("SONARQUBE_PERMISSION")) - .containsExactlyInAnyOrder( - tuple("read", "codeviewer"), - tuple("read", "user"), - tuple("triage", "codeviewer"), - tuple("triage", "user"), - tuple("write", "codeviewer"), - tuple("write", "user"), - tuple("write", "issueadmin"), - tuple("write", "securityhotspotadmin"), - tuple("write", "scan"), - tuple("maintain", "codeviewer"), - tuple("maintain", "user"), - tuple("maintain", "issueadmin"), - tuple("maintain", "securityhotspotadmin"), - tuple("maintain", "scan"), - tuple("admin", "codeviewer"), - tuple("admin", "user"), - tuple("admin", "issueadmin"), - tuple("admin", "securityhotspotadmin"), - tuple("admin", "scan"), - tuple("admin", "admin") - ); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesTest.java deleted file mode 100644 index 9b13313acce..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/SetAllowQualityProfileDisableInheritedRulesTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v103; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.impl.utils.TestSystem2; -import org.sonar.api.utils.System2; -import org.sonar.core.util.UuidFactoryFast; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SetAllowQualityProfileDisableInheritedRulesTest { - - private static final long NOW = 1; - - @Rule - public final MigrationDbTester dbTester = MigrationDbTester.createForMigrationStep(SetAllowQualityProfileDisableInheritedRules.class); - private final System2 system2 = new TestSystem2().setNow(NOW); - - private final SetAllowQualityProfileDisableInheritedRules script = new SetAllowQualityProfileDisableInheritedRules(dbTester.database(), system2, UuidFactoryFast.getInstance()); - - @Test - public void execute_shouldInsertPropertyWithFalseValue() throws SQLException { - script.execute(); - - assertThatForceAuthenticationEquals("false"); - } - - @Test - public void execute_shouldBeReentrant() throws SQLException { - script.execute(); - // re-entrant - script.execute(); - - assertThatForceAuthenticationEquals("false"); - } - - @Test - public void execute_shouldNotUpdateTheValueThatAlreadyExistsInTheDatabase() throws SQLException { - insertPropertyWithValueAsTrue(); - script.execute(); - - assertThatForceAuthenticationEquals("true"); - } - - private void assertThatForceAuthenticationEquals(String s) { - assertThat(dbTester.selectFirst("select p.text_value from properties p where p.prop_key = 'sonar.qualityProfiles.allowDisableInheritedRules'")) - .containsEntry("TEXT_VALUE", s); - } - - private void insertPropertyWithValueAsTrue() { - dbTester.executeInsert("properties", - "uuid", "uuid-1", - "prop_key", "sonar.qualityProfiles.allowDisableInheritedRules", - "is_empty", false, - "text_value", "true", - "created_at", NOW); - } -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsTest.java deleted file mode 100644 index cf1322bd774..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/DeleteRedundantFailedAlertsForApplicationsTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v104; - -import java.sql.SQLException; -import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; -import org.sonar.server.platform.db.migration.step.DataChange; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DeleteRedundantFailedAlertsForApplicationsTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DeleteRedundantFailedAlertsForApplications.class); - private final DataChange underTest = new DeleteRedundantFailedAlertsForApplications(db.database()); - - @Before - public void setUp() { - // cleanup db - db.executeUpdateSql("truncate table events"); - db.executeUpdateSql("truncate table event_component_changes"); - db.executeUpdateSql("truncate table components"); - } - - @Test - public void givenFailedAlertsForApplication_whenExecuted_thenFailedAlertsAreDeleted() throws SQLException { - // given - insertComponent("app1", "appUuid1", "appUuid1", "APP"); - - // event that should be deleted - insertEvent("eventUuid1", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); - insertEventChanges("eventChangeUuid1", "eventUuid1", "appUuid1"); - insertEventChanges("eventChangeUuid2", "eventUuid1", "appUuid1"); - - // events that should not be deleted - insertEvent("eventUuid2", "appUuid1", "Passed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); - insertEventChanges("eventChangeUuid3", "eventUuid2", "appUuid1"); - insertEvent("eventUuid3", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"PASSED\" }"); - insertEventChanges("eventChangeUuid4", "eventUuid3", "appUuid1"); - - // when - underTest.execute(); - - // then - assertThat(db.countRowsOfTable("events")).isEqualTo(2); - assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isZero(); - - assertThat(db.countRowsOfTable("event_component_changes")).isEqualTo(2); - assertThat(db.countSql("select count(1) from event_component_changes where uuid = 'eventUuid1'")).isZero(); - } - - @Test - public void givenFailedAlertsForProject_whenExecute_thenTheEventsAreNotDeleted() throws SQLException { - // given - insertComponent("project1", "projectUuid1", "projectUuid1", "TRK"); - - // event that should not be deleted - insertEvent("eventUuid1", "projectUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); - insertEventChanges("eventChangeUuid1", "eventUuid1", "projectUuid1"); - insertEventChanges("eventChangeUuid2", "eventUuid1", "projectUuid1"); - - // when - underTest.execute(); - - // then - assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isEqualTo(1); - assertThat(db.countSql("select count(1) from event_component_changes where event_uuid = 'eventUuid1'")).isEqualTo(2); - } - - @Test - public void givenMigration_whenExecutedMoreThanOnce_thenNoError() throws SQLException { - // given - insertComponent("app1", "appUuid1", "appUuid1", "APP"); - - // event that should be deleted - insertEvent("eventUuid1", "appUuid1", "Failed", "Alert", "{ stillFailing: false, status: \"ERROR\" }"); - insertEventChanges("eventChangeUuid1", "eventUuid1", "appUuid1"); - insertEventChanges("eventChangeUuid2", "eventUuid1", "appUuid1"); - - // when - underTest.execute(); - underTest.execute(); - - // then - assertThat(db.countSql("select count(1) from events where uuid = 'eventUuid1'")).isZero(); - assertThat(db.countSql("select count(1) from event_component_changes where uuid = 'eventUuid1'")).isZero(); - } - - private void insertComponent(String key, String uuid, String branchUuid, String qualifier) { - Map map = Map.ofEntries( - Map.entry("UUID", uuid), - Map.entry("KEE", key), - Map.entry("BRANCH_UUID", branchUuid), - Map.entry("UUID_PATH", "." + uuid + "."), - Map.entry("QUALIFIER", qualifier), - Map.entry("ENABLED", true), - Map.entry("PRIVATE", true) - ); - - db.executeInsert("components", map); - } - - private void insertEvent(String uuid, String componentUuid, String name, String category, String eventData) { - Map map = Map.ofEntries( - Map.entry("UUID", uuid), - Map.entry("NAME", name), - Map.entry("ANALYSIS_UUID", "analysisUuid"), - Map.entry("CATEGORY", category), - Map.entry("CREATED_AT", 1_500_000_000_000L), - Map.entry("EVENT_DATE", 1_500_000_000_000L), - Map.entry("COMPONENT_UUID", componentUuid), - Map.entry("EVENT_DATA", eventData) - ); - - db.executeInsert("events", map); - } - - private void insertEventChanges(String uuid, String eventUuid, String componentUuid) { - Map map = Map.ofEntries( - Map.entry("UUID", uuid), - Map.entry("EVENT_UUID", eventUuid), - Map.entry("EVENT_COMPONENT_UUID", componentUuid), - Map.entry("EVENT_ANALYSIS_UUID", "analysisUuid"), - Map.entry("CHANGE_CATEGORY", "FAILED_QG"), - Map.entry("COMPONENT_UUID", uuid), - Map.entry("COMPONENT_KEY", "app"), - Map.entry("COMPONENT_NAME", "app"), - Map.entry("COMPONENT_BRANCH_KEY", 1_500_000_000_000L), - Map.entry("CREATED_AT", 1_500_000_000_000L) - ); - - db.executeInsert("event_component_changes", map); - } - - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricTest.java deleted file mode 100644 index 94a28aca8eb..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v104/RenameWontFixIssuesMetricTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.v104; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.db.MigrationDbTester; - -import static org.assertj.core.api.Assertions.assertThat; - - -public class RenameWontFixIssuesMetricTest { - - @Rule - public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(RenameWontFixIssuesMetric.class); - private final RenameWontFixIssuesMetric underTest = new RenameWontFixIssuesMetric(db.database()); - - @Test - public void execute_whenMetricsTableIsEmpty_shouldDoNothing() throws SQLException { - underTest.execute(); - - assertThat(db.select("select name from metrics")).isEmpty(); - } - - @Test - public void execute_whenWontFixMetricExist_shouldRenameToAccepted() throws SQLException { - insertMetric("wont_fix_issues"); - insertMetric("other_metric"); - - underTest.execute(); - - assertThat(db.select("select name from metrics")) - .extracting(stringObjectMap -> stringObjectMap.get("NAME")) - .containsExactlyInAnyOrder("accepted_issues", "other_metric"); - } - - @Test - public void execute_isReentrant() throws SQLException { - insertMetric("wont_fix_issues"); - insertMetric("other_metric"); - - underTest.execute(); - underTest.execute(); - - assertThat(db.select("select name from metrics")) - .extracting(stringObjectMap -> stringObjectMap.get("NAME")) - .containsExactlyInAnyOrder("accepted_issues", "other_metric"); - } - - private void insertMetric(String name) { - db.executeInsert("metrics", - "NAME", name, - "DESCRIPTION", "description " + name, - "DIRECTION", -1, - "DOMAIN", "Issues", - "SHORT_NAME", name, - "QUALITATIVE", true, - "VAL_TYPE", "int", - "ENABLED", true, - "OPTIMIZED_BEST_VALUE", true, - "HIDDEN", false, - "DELETE_HISTORICAL_DATA", false, - "UUID", name); - } -} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/AutoDbMigrationH2Test/schema_migrations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/AutoDbMigrationH2Test/schema_migrations.sql deleted file mode 100644 index aad2a0750a7..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/AutoDbMigrationH2Test/schema_migrations.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "SCHEMA_MIGRATIONS" ( - "VERSION" VARCHAR(256) NOT NULL -); -CREATE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorTest/users_table.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorTest/users_table.sql deleted file mode 100644 index e86b74fd8ec..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SelectExecutorTest/users_table.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "USERS" ( - "LOGIN" VARCHAR(255), - "NAME" VARCHAR(200) -); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorTest/users_table.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorTest/users_table.sql deleted file mode 100644 index 1920431bc40..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/charset/SqlExecutorTest/users_table.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE "USERS" ( - "LOGIN" VARCHAR(255), - "NAME" VARCHAR(200), - "IS_ROOT" BOOLEAN -); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest/schema_migration.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest/schema_migration.sql deleted file mode 100644 index aad2a0750a7..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryImplTest/schema_migration.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "SCHEMA_MIGRATIONS" ( - "VERSION" VARCHAR(256) NOT NULL -); -CREATE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/MigrationHistoryTableImplTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/history/NoTableMigrationHistoryImplTest/empty.sql deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql deleted file mode 100644 index bb4ba642b4a..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/sql/DbPrimaryKeyConstraintFinderTest/schema.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "TEST_PRIMARY_KEY"( - "UUID" VARCHAR(40) NOT NULL -); -ALTER TABLE "TEST_PRIMARY_KEY" ADD CONSTRAINT "PK_TEST_PRIMARY_KEY" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/DataChangeTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/DataChangeTest/schema.sql deleted file mode 100644 index 7a0e17f4e45..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/DataChangeTest/schema.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE "PERSONS" ( - "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), - "LOGIN" VARCHAR(50), - "AGE" INTEGER, - "ENABLED" BOOLEAN, - "UPDATED_AT" TIMESTAMP, - "COEFF" DOUBLE, - "PHONE_NUMBERS" VARCHAR(500) -); - -CREATE TABLE "PHONE_NUMBERS" ( - "PERSON_ID" INTEGER NOT NULL, - "PHONE_NUMBER" VARCHAR(100) -); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql deleted file mode 100644 index d51d6260dab..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE "PLUGINS"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "KEE" CHARACTER VARYING(200) NOT NULL, - "BASE_PLUGIN_KEY" CHARACTER VARYING(200), - "FILE_HASH" CHARACTER VARYING(200) NOT NULL, - "CREATED_AT" BIGINT NOT NULL, - "UPDATED_AT" BIGINT NOT NULL, - "TYPE" CHARACTER VARYING(10) NOT NULL, - "REMOVED" BOOLEAN DEFAULT FALSE NOT NULL -); -ALTER TABLE "PLUGINS" ADD CONSTRAINT "PK_PLUGINS" PRIMARY KEY("UUID"); -CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql deleted file mode 100644 index 28453ffd067..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest/schema.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE "GROUP_ROLES"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "ROLE" CHARACTER VARYING(64) NOT NULL, - "COMPONENT_UUID" CHARACTER VARYING(40), - "GROUP_UUID" CHARACTER VARYING(40) -); -ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID"); -CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID" NULLS FIRST); -CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "COMPONENT_UUID" NULLS FIRST, "ROLE" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest/schema.sql deleted file mode 100644 index f19732423ab..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest/schema.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE "USER_ROLES"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "ROLE" CHARACTER VARYING(64) NOT NULL, - "COMPONENT_UUID" CHARACTER VARYING(40), - "USER_UUID" CHARACTER VARYING(255) -); -ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID"); -CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID" NULLS FIRST); -CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql deleted file mode 100644 index 9b4b255b6e5..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexProjectUuidInWebhookDeliveriesTest/schema.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE "WEBHOOK_DELIVERIES"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL, - "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL, - "CE_TASK_UUID" CHARACTER VARYING(40), - "ANALYSIS_UUID" CHARACTER VARYING(40), - "NAME" CHARACTER VARYING(100) NOT NULL, - "URL" CHARACTER VARYING(2000) NOT NULL, - "SUCCESS" BOOLEAN NOT NULL, - "HTTP_STATUS" INTEGER, - "DURATION_MS" BIGINT NOT NULL, - "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL, - "ERROR_STACKTRACE" CHARACTER LARGE OBJECT, - "CREATED_AT" BIGINT NOT NULL -); -ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID"); -CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST); -CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST); -CREATE INDEX "WD_WEBHOOK_UUID_CREATED_AT" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID", "CREATED_AT" NULLS FIRST); -- cgit v1.2.3