From 85249a5a2a2de92eb547be3825520a9dd5fd8ddf Mon Sep 17 00:00:00 2001 From: Aurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com> Date: Wed, 4 May 2022 09:28:10 +0200 Subject: [PATCH] SONAR-16302 remove RuleDefinitionDto and put information in RuleDto --- .../issue/AdHocRuleCreator.java | 50 +- .../SiblingComponentsWithOpenIssuesTest.java | 8 +- .../issue/AdHocRuleCreatorTest.java | 11 +- .../issue/ComponentIssuesLoaderTest.java | 10 +- .../ProjectTrackerBaseLazyInputTest.java | 4 +- .../PullRequestSourceBranchMergerTest.java | 4 +- .../issue/RuleRepositoryImplTest.java | 5 +- .../issue/SiblingsIssueMergerTest.java | 4 +- .../step/PersistAdHocRulesStepTest.java | 8 +- .../step/PersistIssuesStepTest.java | 24 +- .../step/SendIssueNotificationsStepTest.java | 12 +- .../issue/ExportIssuesStepTest.java | 2 +- .../rule/ExportAdHocRulesStepTest.java | 3 +- .../java/org/sonar/db/issue/IssueDto.java | 10 +- .../java/org/sonar/db/issue/IssueTesting.java | 9 +- .../db/qualityprofile/ActiveRuleDto.java | 4 +- .../main/java/org/sonar/db/rule/RuleDao.java | 91 +--- .../org/sonar/db/rule/RuleDefinitionDto.java | 489 ------------------ .../db/rule/RuleDescriptionSectionDto.java | 18 - .../main/java/org/sonar/db/rule/RuleDto.java | 419 ++++++++------- .../java/org/sonar/db/rule/RuleMapper.java | 25 +- .../org/sonar/db/rule/RuleMetadataDto.java | 11 +- .../java/org/sonar/db/rule/RuleParamDto.java | 2 +- .../QualityProfileExportMapper.xml | 4 +- .../org/sonar/db/rule/RuleMapper.xml | 177 ++----- .../sonar/db/component/ComponentDaoTest.java | 6 +- .../java/org/sonar/db/issue/IssueDaoTest.java | 15 +- .../java/org/sonar/db/issue/IssueDtoTest.java | 4 +- .../org/sonar/db/issue/IssueMapperTest.java | 11 +- .../org/sonar/db/purge/PurgeCommandsTest.java | 10 +- .../java/org/sonar/db/purge/PurgeDaoTest.java | 24 +- .../db/qualityprofile/ActiveRuleDaoTest.java | 20 +- .../qualityprofile/QualityProfileDaoTest.java | 6 +- .../QualityProfileExportDaoTest.java | 38 +- .../java/org/sonar/db/rule/RuleDaoTest.java | 365 ++++++------- .../sonar/db/rule/RuleDefinitionDtoTest.java | 59 --- .../rule/RuleDescriptionSectionDtoTest.java | 13 - .../java/org/sonar/db/rule/RuleDtoTest.java | 32 ++ .../org/sonar/db/issue/IssueDbTester.java | 18 +- .../QualityProfileDbTester.java | 6 +- .../java/org/sonar/db/rule/RuleDbTester.java | 77 ++- .../java/org/sonar/db/rule/RuleTesting.java | 67 +-- .../db/migration/def/VarcharColumnDef.java | 1 + .../v95/CreateRuleDescSectionsTable.java | 6 +- .../index/IssueIteratorForSingleChunk.java | 2 +- .../qualityprofile/ActiveRuleChange.java | 10 +- .../sonar/server/rule/DefaultRuleFinder.java | 13 +- .../server/rule/HotspotRuleDescription.java | 4 +- .../server/rule/RuleDescriptionFormatter.java | 13 +- .../sonar/server/rule/ServerRuleFinder.java | 8 +- .../server/issue/index/IssueIndexerTest.java | 24 +- .../issue/index/IssueIteratorFactoryTest.java | 12 +- .../NewIssuesNotificationTest.java | 40 +- .../qualityprofile/ActiveRuleChangeTest.java | 4 +- .../index/ActiveRuleIndexerTest.java | 8 +- .../server/rule/DefaultRuleFinderTest.java | 15 +- .../rule/HotspotRuleDescriptionTest.java | 22 +- .../rule/RuleDescriptionFormatterTest.java | 9 +- .../server/rule/index/RuleIndexTest.java | 166 +++--- .../server/rule/index/RuleIndexerTest.java | 18 +- ...suesChangesNotificationBuilderTesting.java | 5 - .../server/qualityprofile/QProfileRules.java | 4 +- .../sonar/server/rule/CachingRuleFinder.java | 77 ++- .../server/rule/WebServerRuleFinderImpl.java | 8 +- .../server/rule/CachingRuleFinderTest.java | 91 ++-- .../org/sonar/server/rule/RegisterRules.java | 205 ++++---- .../sonar/server/rule/RegisterRulesTest.java | 135 +++-- .../sonar/server/issue/index/IssueQuery.java | 10 +- .../server/issue/index/IssueQueryFactory.java | 14 +- .../issue/index/IssueIndexFacetsTest.java | 4 +- .../issue/index/IssueIndexFiltersTest.java | 6 +- .../server/issue/index/IssueIndexTest.java | 6 +- .../issue/index/IssueQueryFactoryTest.java | 6 +- .../server/issue/index/IssueQueryTest.java | 4 +- ...lityProfileChangeEventServiceImplTest.java | 9 +- .../sonar/server/hotspot/ws/SearchAction.java | 12 +- .../sonar/server/hotspot/ws/ShowAction.java | 10 +- .../sonar/server/issue/WebIssueStorage.java | 4 +- .../server/issue/ws/BulkChangeAction.java | 10 +- .../sonar/server/issue/ws/IssueUpdater.java | 16 +- .../server/issue/ws/SearchResponseData.java | 8 +- .../server/issue/ws/SearchResponseFormat.java | 10 +- .../server/issue/ws/SearchResponseLoader.java | 38 +- .../qualityprofile/QProfileBackuperImpl.java | 38 +- .../qualityprofile/QProfileExporters.java | 14 +- .../qualityprofile/QProfileRulesImpl.java | 18 +- .../builtin/BuiltInQProfileInsertImpl.java | 6 +- .../BuiltInQProfileRepositoryImpl.java | 26 +- .../builtin/RuleActivationContext.java | 14 +- .../qualityprofile/builtin/RuleActivator.java | 8 +- .../qualityprofile/ws/ActivateRuleAction.java | 8 +- .../qualityprofile/ws/ChangelogAction.java | 14 +- .../qualityprofile/ws/CompareAction.java | 18 +- .../ws/DeactivateRuleAction.java | 4 +- .../qualityprofile/ws/QProfileWsSupport.java | 8 +- .../org/sonar/server/rule/RuleCreator.java | 34 +- .../org/sonar/server/rule/RuleUpdater.java | 8 +- .../server/rule/ws/ActiveRuleCompleter.java | 3 +- .../sonar/server/rule/ws/CreateAction.java | 8 +- .../sonar/server/rule/ws/DeleteAction.java | 4 +- .../org/sonar/server/rule/ws/ListAction.java | 4 +- .../org/sonar/server/rule/ws/RuleMapper.java | 63 ++- .../sonar/server/rule/ws/SearchAction.java | 13 +- .../org/sonar/server/rule/ws/ShowAction.java | 9 +- .../sonar/server/rule/ws/UpdateAction.java | 9 +- .../sonar/server/batch/IssuesActionTest.java | 24 +- .../server/branch/pr/ws/ListActionTest.java | 4 +- .../server/branch/ws/ListActionTest.java | 6 +- .../ComponentCleanerServiceTest.java | 4 +- .../ws/SearchEventsActionNewIssuesTest.java | 6 +- .../hotspot/ws/AddCommentActionTest.java | 14 +- .../server/hotspot/ws/AssignActionTest.java | 14 +- .../hotspot/ws/ChangeStatusActionTest.java | 18 +- .../server/hotspot/ws/SearchActionTest.java | 132 ++--- .../server/hotspot/ws/ShowActionTest.java | 84 +-- .../sonar/server/issue/RulesAggregation.java | 4 +- .../server/issue/RulesAggregationTest.java | 6 +- .../server/issue/TransitionActionTest.java | 4 +- .../server/issue/TransitionServiceTest.java | 14 +- .../server/issue/WebIssueStorageTest.java | 10 +- .../server/issue/ws/AddCommentActionTest.java | 4 +- .../server/issue/ws/AuthorsActionTest.java | 16 +- .../server/issue/ws/BulkChangeActionTest.java | 40 +- .../server/issue/ws/ChangelogActionTest.java | 3 +- .../issue/ws/DoTransitionActionTest.java | 16 +- .../server/issue/ws/IssueUpdaterTest.java | 20 +- .../issue/ws/SearchActionComponentsTest.java | 58 +-- .../issue/ws/SearchActionFacetsTest.java | 26 +- .../server/issue/ws/SearchActionTest.java | 85 ++- .../issue/ws/SetSeverityActionTest.java | 4 +- .../server/issue/ws/SetTagsActionTest.java | 8 +- .../server/issue/ws/SetTypeActionTest.java | 6 +- .../sonar/server/issue/ws/TagsActionTest.java | 46 +- .../QProfileBackuperImplTest.java | 24 +- .../QProfileComparisonTest.java | 10 +- .../qualityprofile/QProfileExportersTest.java | 4 +- .../QProfileFactoryImplTest.java | 4 +- .../qualityprofile/QProfileResetImplTest.java | 14 +- .../qualityprofile/QProfileRuleImplTest.java | 114 ++-- .../qualityprofile/QProfileRulesImplTest.java | 6 +- .../qualityprofile/QProfileTreeImplTest.java | 36 +- ...gisterQualityProfilesNotificationTest.java | 42 +- .../RegisterQualityProfilesTest.java | 6 +- .../BuiltInQProfileInsertImplTest.java | 10 +- .../BuiltInQProfileRepositoryImplTest.java | 10 +- .../BuiltInQProfileRepositoryRule.java | 14 +- .../BuiltInQProfileUpdateImplTest.java | 56 +- ...ltInQualityProfilesUpdateListenerTest.java | 6 +- .../builtin/RuleActivatorTest.java | 12 +- .../ws/ActivateRuleActionTest.java | 6 +- .../ws/ChangeParentActionTest.java | 26 +- .../ws/ChangelogActionTest.java | 22 +- .../qualityprofile/ws/CompareActionTest.java | 41 +- .../qualityprofile/ws/CreateActionTest.java | 9 +- .../ws/DeactivateRuleActionTest.java | 8 +- .../ws/InheritanceActionTest.java | 24 +- .../ws/QProfileWsSupportTest.java | 4 +- .../ws/QProfilesWsMediumTest.java | 38 +- .../qualityprofile/ws/SearchActionTest.java | 20 +- .../qualityprofile/ws/ShowActionTest.java | 22 +- .../sonar/server/rule/RuleCreatorTest.java | 41 +- .../sonar/server/rule/RuleUpdaterTest.java | 55 +- .../rule/ws/ActiveRuleCompleterTest.java | 4 +- .../server/rule/ws/CreateActionTest.java | 11 +- .../server/rule/ws/DeleteActionTest.java | 10 +- .../server/rule/ws/SearchActionTest.java | 120 ++--- .../sonar/server/rule/ws/ShowActionTest.java | 35 +- .../sonar/server/rule/ws/TagsActionTest.java | 6 +- .../server/rule/ws/UpdateActionTest.java | 18 +- .../source/ws/IssueSnippetsActionTest.java | 4 +- 170 files changed, 2202 insertions(+), 2939 deletions(-) delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java delete mode 100644 server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java index bdfd8070c4c..c03ddef9fbf 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java @@ -28,7 +28,6 @@ import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.server.rule.index.RuleIndexer; @@ -60,29 +59,12 @@ public class AdHocRuleCreator { */ public RuleDto persistAndIndex(DbSession dbSession, NewAdHocRule adHoc) { RuleDao dao = dbClient.ruleDao(); - Optional existingRuleDtoOpt = dao.selectByKey(dbSession, adHoc.getKey()); RuleMetadataDto metadata; long now = system2.now(); - if (!existingRuleDtoOpt.isPresent()) { - RuleDefinitionDto dto = new RuleDefinitionDto() - .setUuid(uuidFactory.create()) - .setRuleKey(adHoc.getKey()) - .setIsExternal(true) - .setIsAdHoc(true) - .setName(adHoc.getEngineId() + ":" + adHoc.getRuleId()) - .setScope(ALL) - .setStatus(READY) - .setCreatedAt(now) - .setUpdatedAt(now); - dao.insert(dbSession, dto); - metadata = new RuleMetadataDto().setRuleUuid(dto.getUuid()); - } else { - // No need to update the rule, only org specific metadata - RuleDto ruleDto = existingRuleDtoOpt.get(); - Preconditions.checkState(ruleDto.isExternal() && ruleDto.isAdHoc()); - metadata = ruleDto.getMetadata(); - } + RuleDto ruleDtoToUpdate = findOrCreateRuleDto(dbSession, adHoc, dao, now); + + metadata = ruleDtoToUpdate.getMetadata(); if (adHoc.hasDetails()) { boolean changed = false; if (!Objects.equals(metadata.getAdHocName(), adHoc.getName())) { @@ -104,8 +86,8 @@ public class AdHocRuleCreator { } if (changed) { metadata.setUpdatedAt(now); - metadata.setCreatedAt(now); - dao.insertOrUpdate(dbSession, metadata); + metadata.setCreatedAt(ruleDtoToUpdate.getCreatedAt()); + dao.update(dbSession, ruleDtoToUpdate); } } @@ -115,4 +97,26 @@ public class AdHocRuleCreator { return ruleDto; } + private RuleDto findOrCreateRuleDto(DbSession dbSession, NewAdHocRule adHoc, RuleDao dao, long now) { + Optional existingRuleDtoOpt = dbClient.ruleDao().selectByKey(dbSession, adHoc.getKey()); + if (existingRuleDtoOpt.isEmpty()) { + RuleDto ruleDto = new RuleDto() + .setUuid(uuidFactory.create()) + .setRuleKey(adHoc.getKey()) + .setIsExternal(true) + .setIsAdHoc(true) + .setName(adHoc.getEngineId() + ":" + adHoc.getRuleId()) + .setScope(ALL) + .setStatus(READY) + .setCreatedAt(now) + .setUpdatedAt(now); + dao.insert(dbSession, ruleDto); + return ruleDto; + } else { + RuleDto ruleDto = existingRuleDtoOpt.get(); + Preconditions.checkState(ruleDto.isExternal() && ruleDto.isAdHoc()); + return ruleDto; + } + } + } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java index e565f866622..c3d0c03d4df 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java @@ -30,7 +30,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.project.Project; import static org.assertj.core.api.Assertions.assertThat; @@ -79,7 +79,7 @@ public class SiblingComponentsWithOpenIssuesTest { fileWithNoIssuesOnBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1, null)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); fileWithOneOpenIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null)); db.issues().insert(rule, branch1pr1, fileWithOneOpenIssueOnBranch1Pr1); @@ -167,7 +167,7 @@ public class SiblingComponentsWithOpenIssuesTest { b -> b.setBranchType(BranchType.PULL_REQUEST), b -> b.setMergeBranchUuid(project.uuid())); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto fileWithResolvedIssueOnPullrequest = db.components().insertComponent(ComponentTesting.newFileDto(pullRequest, null)); db.issues().insert(rule, pullRequest, fileWithResolvedIssueOnPullrequest, i -> i.setStatus("RESOLVED")); @@ -186,7 +186,7 @@ public class SiblingComponentsWithOpenIssuesTest { b -> b.setBranchType(BranchType.BRANCH), b -> b.setMergeBranchUuid(project.uuid())); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto fileWithResolvedIssueOnDerivedBranch = db.components().insertComponent(ComponentTesting.newFileDto(derivedBranch, null)); db.issues().insert(rule, derivedBranch, fileWithResolvedIssueOnDerivedBranch, i -> i.setStatus("RESOLVED")); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java index e9582b0ae18..680a1e675b1 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java @@ -27,7 +27,6 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.scanner.protocol.Constants; @@ -151,14 +150,14 @@ public class AdHocRuleCreatorTest { assertThat(ruleUpdated.getMetadata().getAdHocDescription()).isEqualTo("A description updated"); assertThat(ruleUpdated.getMetadata().getAdHocSeverity()).isEqualTo(Severity.CRITICAL); assertThat(ruleUpdated.getMetadata().getAdHocType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); - assertThat(ruleUpdated.getDefinition().getCreatedAt()).isEqualTo(creationDate); + assertThat(ruleUpdated.getCreatedAt()).isEqualTo(creationDate); assertThat(ruleUpdated.getMetadata().getCreatedAt()).isEqualTo(creationDate); assertThat(ruleUpdated.getMetadata().getUpdatedAt()).isGreaterThan(creationDate); } @Test public void does_not_update_rule_when_no_change() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_eslint").setIsExternal(true).setIsAdHoc(true)); + RuleDto rule = db.rules().insert(r -> r.setRepositoryKey("external_eslint").setIsExternal(true).setIsAdHoc(true)); RuleMetadataDto ruleMetadata = db.rules().insertOrUpdateMetadata(rule); RuleDto ruleUpdated = underTest.persistAndIndex(dbSession, new NewAdHocRule(ScannerReport.AdHocRule.newBuilder() @@ -178,15 +177,15 @@ public class AdHocRuleCreatorTest { assertThat(ruleUpdated.getRuleDescriptionSectionDtos()).usingRecursiveFieldByFieldElementComparator().isEqualTo(rule.getRuleDescriptionSectionDtos()); assertThat(ruleUpdated.getSeverity()).isEqualTo(rule.getSeverity()); assertThat(ruleUpdated.getType()).isEqualTo(rule.getType()); - assertThat(ruleUpdated.getDefinition().getCreatedAt()).isEqualTo(rule.getCreatedAt()); - assertThat(ruleUpdated.getDefinition().getUpdatedAt()).isEqualTo(rule.getUpdatedAt()); + assertThat(ruleUpdated.getCreatedAt()).isEqualTo(rule.getCreatedAt()); + assertThat(ruleUpdated.getUpdatedAt()).isEqualTo(ruleMetadata.getUpdatedAt()); assertThat(ruleUpdated.getMetadata().getAdHocName()).isEqualTo(ruleMetadata.getAdHocName()); assertThat(ruleUpdated.getMetadata().getAdHocDescription()).isEqualTo(ruleMetadata.getAdHocDescription()); assertThat(ruleUpdated.getMetadata().getAdHocSeverity()).isEqualTo(ruleMetadata.getAdHocSeverity()); assertThat(ruleUpdated.getMetadata().getAdHocType()).isEqualTo(ruleMetadata.getAdHocType()); assertThat(ruleUpdated.getMetadata().getCreatedAt()).isEqualTo(rule.getCreatedAt()); - assertThat(ruleUpdated.getMetadata().getUpdatedAt()).isEqualTo(rule.getUpdatedAt()); + assertThat(ruleUpdated.getMetadata().getUpdatedAt()).isEqualTo(ruleMetadata.getUpdatedAt()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java index 97c05b04114..c64cff004ca 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderTest.java @@ -48,7 +48,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static java.util.Collections.emptyList; import static java.util.Collections.singleton; @@ -79,7 +79,7 @@ public class ComponentIssuesLoaderTest { public void loadClosedIssues_returns_single_DefaultIssue_by_issue_based_on_first_row() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); + RuleDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); IssueDto issue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL)); db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); @@ -98,7 +98,7 @@ public class ComponentIssuesLoaderTest { public void loadClosedIssues_returns_single_DefaultIssue_with_null_line_if_first_row_has_no_line_diff() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); + RuleDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); IssueDto issue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL)); db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(issueDate, 10)); @@ -117,7 +117,7 @@ public class ComponentIssuesLoaderTest { public void loadClosedIssues_returns_only_closed_issues_with_close_date() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); + RuleDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date issueDate = addDays(NOW, -10); IssueDto closedIssue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL)); db.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10)); @@ -185,7 +185,7 @@ public class ComponentIssuesLoaderTest { private void loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(ComponentIssuesLoader underTest) { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); + RuleDto rule = db.rules().insert(t -> t.setType(CODE_SMELL)); Date[] issueDates = new Date[] { addDays(NOW, -10), addDays(NOW, -31), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java index 9b93522b552..db85e27e3da 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java @@ -37,7 +37,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.IssueFieldsSetter; import static org.assertj.core.api.Assertions.assertThat; @@ -64,7 +64,7 @@ public class ProjectTrackerBaseLazyInputTest { private DbClient dbClient = dbTester.getDbClient(); private ProjectTrackerBaseLazyInput underTest; - private RuleDefinitionDto rule; + private RuleDto rule; private ComponentDto rootProjectDto; private ComponentIssuesLoader issuesLoader = new ComponentIssuesLoader(dbTester.getDbClient(), ruleRepositoryRule, activeRulesHolderRule, new MapSettings().asConfig(), System2.INSTANCE, mock(IssueChangesToDeleteRepository.class)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java index 106eb680e37..763986106e3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java @@ -36,7 +36,7 @@ import org.sonar.core.issue.tracking.Tracker; import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; @@ -76,7 +76,7 @@ public class PullRequestSourceBranchMergerTest { public DbTester db = DbTester.create(); private PullRequestSourceBranchMerger underTest; - private RuleDefinitionDto rule; + private RuleDto rule; private DefaultIssue rawIssue; private Input rawIssuesInput; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java index 2a8549b04fb..2cc15705de1 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java @@ -35,7 +35,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.rule.DeprecatedRuleKeyDto; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.server.rule.index.RuleIndexer; @@ -258,7 +257,7 @@ public class RuleRepositoryImplTest { assertThat(underTest.getByKey(ruleKey).getType()).isNull(); RuleDao ruleDao = dbClient.ruleDao(); - Optional ruleDefinitionDto = ruleDao.selectDefinitionByKey(dbClient.openSession(false), ruleKey); + Optional ruleDefinitionDto = ruleDao.selectByKey(dbClient.openSession(false), ruleKey); assertThat(ruleDefinitionDto).isNotPresent(); } @@ -272,7 +271,7 @@ public class RuleRepositoryImplTest { underTest.saveOrUpdateAddHocRules(db.getSession()); db.commit(); - Optional ruleDefinitionDto = db.getDbClient().ruleDao().selectDefinitionByKey(db.getSession(), ruleKey); + Optional ruleDefinitionDto = db.getDbClient().ruleDao().selectByKey(db.getSession(), ruleKey); assertThat(ruleDefinitionDto).isPresent(); Rule rule = underTest.getByKey(ruleKey); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java index 776b24352f0..b7d6758719d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java @@ -44,7 +44,7 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.project.Project; @@ -95,7 +95,7 @@ public class SiblingsIssueMergerTest { private ComponentDto branch1Dto; private ComponentDto branch2Dto; private ComponentDto branch3Dto; - private RuleDefinitionDto rule; + private RuleDto rule; @Before public void setUp() { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java index 2b3239c50ed..75da3c3a548 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java @@ -34,7 +34,7 @@ import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.server.es.EsTester; import org.sonar.server.rule.index.RuleIndexDefinition; @@ -78,10 +78,10 @@ public class PersistAdHocRulesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); RuleDao ruleDao = dbClient.ruleDao(); - Optional ruleDefinitionDtoOptional = ruleDao.selectDefinitionByKey(dbClient.openSession(false), ruleKey); + Optional ruleDefinitionDtoOptional = ruleDao.selectByKey(dbClient.openSession(false), ruleKey); assertThat(ruleDefinitionDtoOptional).isPresent(); - RuleDefinitionDto reloaded = ruleDefinitionDtoOptional.get(); + RuleDto reloaded = ruleDefinitionDtoOptional.get(); assertThat(reloaded.getRuleKey()).isEqualTo("no-cond-assign"); assertThat(reloaded.getRepositoryKey()).isEqualTo("external_eslint"); assertThat(reloaded.isExternal()).isTrue(); @@ -104,7 +104,7 @@ public class PersistAdHocRulesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); RuleDao ruleDao = dbClient.ruleDao(); - assertThat(ruleDao.selectAllDefinitions(dbClient.openSession(false))).hasSize(1); + assertThat(ruleDao.selectAll(dbClient.openSession(false))).hasSize(1); assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isZero(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java index a3b66907a9b..c63c640925b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java @@ -53,7 +53,7 @@ import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueMapper; import org.sonar.db.newcodeperiod.NewCodePeriodType; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.server.issue.IssueStorage; @@ -118,7 +118,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void insert_copied_issue() { - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -182,7 +182,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void insert_copied_issue_with_minimal_info() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -228,7 +228,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void insert_merged_issue() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -287,7 +287,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void update_conflicting_issue() { - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -322,7 +322,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void insert_new_issue() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -364,7 +364,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void close_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN) .setResolution(null) @@ -394,7 +394,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void handle_no_longer_new_issue() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -447,7 +447,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void handle_existing_new_code_issue_migration() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -496,7 +496,7 @@ public class PersistIssuesStepTest extends BaseStepTest { @Test public void handle_existing_without_need_for_new_code_issue_migration() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "master", null)); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); + RuleDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01")); db.rules().insert(rule); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); @@ -551,7 +551,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void add_comment() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN) .setResolution(null) @@ -592,7 +592,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public void add_change() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN) .setResolution(null) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java index b173eff874a..338d7516a28 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -60,7 +60,7 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.notification.DistributedMetricStatsInt; import org.sonar.server.issue.notification.IssuesChangesNotification; @@ -499,7 +499,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { UserDto user = db.users().insertUser(); ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT); analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList())); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); @@ -526,7 +526,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { .addChildren( builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()) .build()); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot); IssuesChangesNotification issuesChangesNotification = mock(IssuesChangesNotification.class); @@ -546,7 +546,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { verifyNoMoreInteractions(notificationService); } - private DefaultIssue prepareIssue(long issueCreatedAt, UserDto user, ComponentDto project, ComponentDto file, RuleDefinitionDto ruleDefinitionDto, RuleType type) { + private DefaultIssue prepareIssue(long issueCreatedAt, UserDto user, ComponentDto project, ComponentDto file, RuleDto ruleDefinitionDto, RuleType type) { DefaultIssue issue = newIssue(ruleDefinitionDto, project, file).setType(type).toDefaultIssue() .setNew(false).setChanged(true).setSendNotifications(true).setCreationDate(new Date(issueCreatedAt)).setAssigneeUuid(user.getUuid()); protoIssueCache.newAppender().append(issue).close(); @@ -571,7 +571,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); analysisMetadataHolder.setProject(Project.from(project)); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = newIssue(ruleDefinitionDto, branch, file).setType(randomTypeExceptHotspot).toDefaultIssue() .setNew(false) @@ -601,7 +601,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { UserDto user = db.users().insertUser(); ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; List issues = IntStream.range(0, 2001 + new Random().nextInt(10)) .mapToObj(i -> newIssue(ruleDefinitionDto, project, file).setKee("uuid_" + i).setType(randomTypeExceptHotspot).toDefaultIssue() diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java index 2a3214ae047..0eccab91c48 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java @@ -378,7 +378,7 @@ public class ExportIssuesStepTest { private RuleDto insertRule(String ruleKey1) { RuleDto dto = new RuleDto().setRepositoryKey(SOME_REPO).setScope(Scope.MAIN).setRuleKey(ruleKey1).setStatus(RuleStatus.READY); - dbTester.rules().insert(dto.getDefinition()); + dbTester.rules().insert(dto); dbSession.commit(); return dto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java index 8507f576880..b93ceeb324c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java @@ -43,7 +43,6 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; @@ -210,7 +209,7 @@ public class ExportAdHocRulesStepTest { private RuleDto insertRule(RuleKey ruleKey, boolean isExternal, boolean isAdHoc) { dbTester.rules().insert( - new RuleDefinitionDto() + new RuleDto() .setRuleKey(ruleKey) .setIsExternal(isExternal) .setIsAdHoc(isAdHoc) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index a4a97c4c7de..512624b3841 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -39,7 +39,7 @@ import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; import org.sonar.db.component.ComponentDto; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.api.utils.DateUtils.dateToLong; @@ -366,7 +366,7 @@ public final class IssueDto implements Serializable { } public Set getSecurityStandards() { - return RuleDefinitionDto.deserializeSecurityStandardsString(securityStandards); + return RuleDto.deserializeSecurityStandardsString(securityStandards); } /** @@ -451,7 +451,7 @@ public final class IssueDto implements Serializable { return ruleKey; } - public IssueDto setRule(RuleDefinitionDto rule) { + public IssueDto setRule(RuleDto rule) { Preconditions.checkNotNull(rule.getUuid(), "Rule must be persisted."); this.ruleUuid = rule.getUuid(); this.ruleKey = rule.getRuleKey(); @@ -476,7 +476,7 @@ public final class IssueDto implements Serializable { /** * Should only be used to persist in E/S *

- * Please use {@link #setRule(RuleDefinitionDto)} instead + * Please use {@link #setRule(RuleDto)} instead */ public IssueDto setLanguage(String language) { this.language = language; @@ -600,7 +600,7 @@ public final class IssueDto implements Serializable { /** * Should only be used to persist in E/S *

- * Please use {@link #setRule(RuleDefinitionDto)} instead + * Please use {@link #setRule(RuleDto)} instead */ public IssueDto setRuleKey(String repo, String rule) { this.ruleRepo = repo; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java index 8f806ef1a8b..0577ae6452b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java @@ -30,7 +30,6 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.core.util.Uuids; import org.sonar.db.component.ComponentDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import static com.google.common.base.Preconditions.checkArgument; @@ -46,16 +45,16 @@ public class IssueTesting { // only statics } - public static IssueDto newIssue(RuleDefinitionDto rule, ComponentDto project, ComponentDto file) { + public static IssueDto newIssue(RuleDto rule, ComponentDto project, ComponentDto file) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT), "Second parameter should be a project"); return newIssue(rule, project.uuid(), project.getDbKey(), file); } - public static IssueDto newIssue(RuleDefinitionDto rule, ProjectDto project, ComponentDto file) { + public static IssueDto newIssue(RuleDto rule, ProjectDto project, ComponentDto file) { return newIssue(rule, project.getUuid(), project.getKey(), file); } - public static IssueDto newIssue(RuleDefinitionDto rule, String projectUuid, String projectKey, ComponentDto file) { + public static IssueDto newIssue(RuleDto rule, String projectUuid, String projectKey, ComponentDto file) { checkArgument(file.projectUuid().equals(projectUuid), "The file doesn't belong to the project"); return new IssueDto() @@ -103,7 +102,7 @@ public class IssueTesting { public static IssueDto newDto(RuleDto rule, ComponentDto file, ComponentDto project) { return new IssueDto() .setKee(Uuids.createFast()) - .setRule(rule.getDefinition()) + .setRule(rule) .setType(RuleType.CODE_SMELL) .setComponent(file) .setProject(project) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java index 2048d29ad7a..c867aa778dd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java @@ -26,7 +26,7 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.ActiveRule; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.SeverityUtil; import static java.util.Objects.requireNonNull; @@ -160,7 +160,7 @@ public class ActiveRuleDto { return this; } - public static ActiveRuleDto createFor(QProfileDto profile, RuleDefinitionDto ruleDto) { + public static ActiveRuleDto createFor(QProfileDto profile, RuleDto ruleDto) { requireNonNull(profile.getRulesProfileUuid(), "Profile is not persisted"); requireNonNull(ruleDto.getUuid(), "Rule is not persisted"); ActiveRuleDto dto = new ActiveRuleDto(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index e5709520abe..9678de4dbfa 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -19,6 +19,7 @@ */ package org.sonar.db.rule; +import com.google.common.annotations.VisibleForTesting; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -55,53 +56,26 @@ public class RuleDao implements Dao { return Optional.ofNullable(mapper(session).selectByKey(key)); } - public Optional selectDefinitionByKey(DbSession session, RuleKey key) { - return Optional.ofNullable(mapper(session).selectDefinitionByKey(key)); - } - public Optional selectMetadataByKey(DbSession session, RuleKey key) { return Optional.ofNullable(mapper(session).selectMetadataByKey(key)); } - public List selectMetadataByKeys(DbSession session, Collection keys) { - if (keys.isEmpty()) { - return emptyList(); - } - return executeLargeInputs(keys, mapper(session)::selectMetadataByKeys); - } - public RuleDto selectOrFailByKey(DbSession session, RuleKey key) { return Optional.ofNullable(mapper(session).selectByKey(key)) .orElseThrow(() -> new RowNotFoundException(String.format("Rule with key '%s' does not exist", key))); } - public RuleDefinitionDto selectOrFailDefinitionByKey(DbSession session, RuleKey key) { - return Optional.ofNullable(mapper(session).selectDefinitionByKey(key)) - .orElseThrow(() -> new RowNotFoundException(String.format("Rule with key '%s' does not exist", key))); - } - public Optional selectByUuid(String uuid, DbSession session) { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); } - public Optional selectDefinitionByUuid(String uuid, DbSession session) { - return Optional.ofNullable(mapper(session).selectDefinitionByUuid(uuid)); - } - - public List selectByUuids(DbSession session, List uuids) { + public List selectByUuids(DbSession session, Collection uuids) { if (uuids.isEmpty()) { return emptyList(); } return executeLargeInputs(uuids, chunk -> mapper(session).selectByUuids(chunk)); } - public List selectDefinitionByUuids(DbSession session, Collection uuids) { - if (uuids.isEmpty()) { - return emptyList(); - } - return executeLargeInputs(uuids, mapper(session)::selectDefinitionByUuids); - } - public List selectByKeys(DbSession session, Collection keys) { if (keys.isEmpty()) { return emptyList(); @@ -109,14 +83,7 @@ public class RuleDao implements Dao { return executeLargeInputs(keys, chunk -> mapper(session).selectByKeys(chunk)); } - public List selectDefinitionByKeys(DbSession session, Collection keys) { - if (keys.isEmpty()) { - return emptyList(); - } - return executeLargeInputs(keys, mapper(session)::selectDefinitionByKeys); - } - - public List selectEnabled(DbSession session) { + public List selectEnabled(DbSession session) { return mapper(session).selectEnabled(); } @@ -124,10 +91,6 @@ public class RuleDao implements Dao { return mapper(session).selectAll(); } - public List selectAllDefinitions(DbSession session) { - return mapper(session).selectAllDefinitions(); - } - public List selectByTypeAndLanguages(DbSession session, List types, List languages) { return executeLargeInputs(languages, chunk -> mapper(session).selectByTypeAndLanguages(types, chunk)); } @@ -136,39 +99,39 @@ public class RuleDao implements Dao { return mapper(session).selectByQuery(ruleQuery); } - public void insert(DbSession session, RuleDefinitionDto ruleDefinitionDto) { - checkNotNull(ruleDefinitionDto.getUuid(), "RuleDefinitionDto has no 'uuid'."); + public void insert(DbSession session, RuleDto ruleDto) { + checkNotNull(ruleDto.getUuid(), "RuleDto has no 'uuid'."); RuleMapper mapper = mapper(session); - mapper.insertDefinition(ruleDefinitionDto); - insertRuleDescriptionSectionDtos(ruleDefinitionDto, mapper); - } - - public void insert(DbSession session, RuleMetadataDto dto) { - checkNotNull(dto.getRuleUuid(), "RuleMetadataDto has no 'ruleUuid'."); - mapper(session).insertMetadata(dto); + mapper.insertRule(ruleDto); + insertOrUpdateRuleMetadata(session, ruleDto.getMetadata()); + updateRuleDescriptionSectionDtos(ruleDto, mapper); } - public void update(DbSession session, RuleDefinitionDto ruleDefinitionDto) { + public void update(DbSession session, RuleDto ruleDto) { RuleMapper mapper = mapper(session); - mapper.updateDefinition(ruleDefinitionDto); - updateRuleDescriptionDtos(ruleDefinitionDto, mapper); + mapper.updateRule(ruleDto); + insertOrUpdateRuleMetadata(session, ruleDto.getMetadata()); + updateRuleDescriptionSectionDtos(ruleDto, mapper); } - private void updateRuleDescriptionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) { - mapper.deleteRuleDescriptionSection(ruleDefinitionDto.getUuid()); - insertRuleDescriptionSectionDtos(ruleDefinitionDto, mapper); + private static void updateRuleDescriptionSectionDtos(RuleDto ruleDto, RuleMapper mapper) { + mapper.deleteRuleDescriptionSection(ruleDto.getUuid()); + insertRuleDescriptionSectionDtos(ruleDto, mapper); } - private static void insertRuleDescriptionSectionDtos(RuleDefinitionDto ruleDefinitionDto, RuleMapper mapper) { - ruleDefinitionDto.getRuleDescriptionSectionDtos() - .forEach(section -> mapper.insertRuleDescriptionSection(ruleDefinitionDto.getUuid(), section)); + private static void insertRuleDescriptionSectionDtos(RuleDto ruleDto, RuleMapper mapper) { + ruleDto.getRuleDescriptionSectionDtos() + .forEach(section -> mapper.insertRuleDescriptionSection(ruleDto.getUuid(), section)); } - public void insertOrUpdate(DbSession session, RuleMetadataDto dto) { - if (mapper(session).countMetadata(dto) > 0) { - mapper(session).updateMetadata(dto); + @VisibleForTesting + void insertOrUpdateRuleMetadata(DbSession session, RuleMetadataDto ruleMetadataDto) { + if (ruleMetadataDto.isUndefined()) { + mapper(session).deleteMetadata(ruleMetadataDto.getRuleUuid()); + } else if (mapper(session).countMetadata(ruleMetadataDto) > 0) { + mapper(session).updateMetadata(ruleMetadataDto); } else { - mapper(session).insertMetadata(dto); + mapper(session).insertMetadata(ruleMetadataDto); } } @@ -248,7 +211,7 @@ public class RuleDao implements Dao { return executeLargeInputs(ruleUuids, mapper(dbSession)::selectParamsByRuleUuids); } - public void insertRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) { + public void insertRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { checkNotNull(rule.getUuid(), "Rule uuid must be set"); param.setRuleUuid(rule.getUuid()); @@ -256,7 +219,7 @@ public class RuleDao implements Dao { mapper(session).insertParameter(param); } - public RuleParamDto updateRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) { + public RuleParamDto updateRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { checkNotNull(rule.getUuid(), "Rule uuid must be set"); checkNotNull(param.getUuid(), "Rule parameter is not yet persisted must be set"); param.setRuleUuid(rule.getUuid()); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java deleted file mode 100644 index 2347e80f8f5..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java +++ /dev/null @@ -1,489 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.db.rule; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import java.util.HashSet; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rules.RuleType; -import org.sonar.db.rule.RuleDto.Scope; - -import static com.google.common.base.Preconditions.checkArgument; -import static org.sonar.db.rule.RuleDescriptionSectionDto.DEFAULT_KEY; - -public class RuleDefinitionDto { - - private static final Splitter SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); - - private String uuid; - private String repositoryKey; - private String ruleKey; - - private Set ruleDescriptionSectionDtos = new HashSet<>(); - - /** - * Description format can be null on external rule, otherwise it should never be null - */ - private RuleDto.Format descriptionFormat; - private RuleStatus status; - private String name; - private String configKey; - - /** - * Severity can be null on external rule, otherwise it should never be null - */ - private Integer severity; - - private boolean isTemplate; - - /** - * This flag specify that this is an external rule, meaning that generated issues from this rule will be provided by the analyzer without being activated on a quality profile. - */ - private boolean isExternal; - - /** - * When an external rule is defined as ad hoc, it means that it's not defined using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}. - * As the opposite, an external rule not being defined as ad hoc is declared by using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}. - * This flag is only used for external rules (it can only be set to true for when {@link #isExternal()} is true) - */ - private boolean isAdHoc; - - private String language; - private String templateUuid; - private String defRemediationFunction; - private String defRemediationGapMultiplier; - private String defRemediationBaseEffort; - private String gapDescription; - private String systemTags; - private String securityStandards; - private int type; - private Scope scope; - - private RuleKey key; - - private String pluginKey; - - private long createdAt; - private long updatedAt; - - public RuleDefinitionDto() { - // nothing to do here - } - - public static Set deserializeTagsString(@Nullable String tags) { - return deserializeStringSet(tags); - } - - public static Set deserializeSecurityStandardsString(@Nullable String securityStandards) { - return deserializeStringSet(securityStandards); - } - - private static Set deserializeStringSet(@Nullable String str) { - if (str == null || str.isEmpty()) { - return ImmutableSet.of(); - } - - return ImmutableSet.copyOf(SPLITTER.split(str)); - } - - private static String serializeStringSet(@Nullable Set strings) { - return strings == null || strings.isEmpty() ? null : StringUtils.join(strings, ','); - } - - public RuleKey getKey() { - if (key == null) { - key = RuleKey.of(getRepositoryKey(), getRuleKey()); - } - return key; - } - - RuleDefinitionDto setKey(RuleKey key) { - this.key = key; - setRepositoryKey(key.repository()); - setRuleKey(key.rule()); - return this; - } - - public String getUuid() { - return uuid; - } - - public RuleDefinitionDto setUuid(String uuid) { - this.uuid = uuid; - return this; - } - - public String getRepositoryKey() { - return repositoryKey; - } - - public RuleDefinitionDto setRepositoryKey(String s) { - checkArgument(s.length() <= 255, "Rule repository is too long: %s", s); - this.repositoryKey = s; - return this; - } - - public String getRuleKey() { - return ruleKey; - } - - public RuleDefinitionDto setRuleKey(String s) { - checkArgument(s.length() <= 200, "Rule key is too long: %s", s); - this.ruleKey = s; - return this; - } - - public RuleDefinitionDto setRuleKey(RuleKey ruleKey) { - this.repositoryKey = ruleKey.repository(); - this.ruleKey = ruleKey.rule(); - this.key = ruleKey; - return this; - } - - @CheckForNull - public RuleDescriptionSectionDto getRuleDescriptionSectionDto(String ruleDescriptionSectionKey) { - return findExistingSectionWithSameKey(ruleDescriptionSectionKey).orElse(null); - } - - @CheckForNull - public RuleDescriptionSectionDto getDefaultRuleDescriptionSectionDto() { - return findExistingSectionWithSameKey(DEFAULT_KEY).orElse(null); - } - - public RuleDefinitionDto addRuleDescriptionSectionDto(RuleDescriptionSectionDto ruleDescriptionSectionDto) { - checkArgument(sectionWithSameKeyShouldNotExist(ruleDescriptionSectionDto), - "A section with key %s already exists", ruleDescriptionSectionDto.getKey()); - ruleDescriptionSectionDtos.add(ruleDescriptionSectionDto); - return this; - } - - private boolean sectionWithSameKeyShouldNotExist(RuleDescriptionSectionDto ruleDescriptionSectionDto) { - return findExistingSectionWithSameKey(ruleDescriptionSectionDto.getKey()).isEmpty(); - } - - public RuleDefinitionDto addOrReplaceRuleDescriptionSectionDto(RuleDescriptionSectionDto ruleDescriptionSectionDto) { - Optional existingSectionWithSameKey = findExistingSectionWithSameKey(ruleDescriptionSectionDto.getKey()); - existingSectionWithSameKey.ifPresent(ruleDescriptionSectionDtos::remove); - ruleDescriptionSectionDtos.add(ruleDescriptionSectionDto); - return this; - } - - private Optional findExistingSectionWithSameKey(String ruleDescriptionSectionKey) { - return ruleDescriptionSectionDtos.stream().filter(section -> section.getKey().equals(ruleDescriptionSectionKey)).findAny(); - } - - @CheckForNull - public RuleDto.Format getDescriptionFormat() { - return descriptionFormat; - } - - public RuleDefinitionDto setDescriptionFormat(@Nullable RuleDto.Format descriptionFormat) { - this.descriptionFormat = descriptionFormat; - return this; - } - - public RuleStatus getStatus() { - return status; - } - - public RuleDefinitionDto setStatus(@Nullable RuleStatus s) { - this.status = s; - return this; - } - - public String getName() { - return name; - } - - public RuleDefinitionDto setName(@Nullable String s) { - checkArgument(s == null || s.length() <= 255, "Rule name is too long: %s", s); - this.name = s; - return this; - } - - public String getConfigKey() { - return configKey; - } - - public RuleDefinitionDto setConfigKey(@Nullable String configKey) { - this.configKey = configKey; - return this; - } - - @CheckForNull - public Integer getSeverity() { - return severity; - } - - @CheckForNull - public String getSeverityString() { - return severity != null ? SeverityUtil.getSeverityFromOrdinal(severity) : null; - } - - public RuleDefinitionDto setSeverity(@Nullable String severity) { - return this.setSeverity(severity != null ? SeverityUtil.getOrdinalFromSeverity(severity) : null); - } - - public RuleDefinitionDto setSeverity(@Nullable Integer severity) { - this.severity = severity; - return this; - } - - public boolean isTemplate() { - return isTemplate; - } - - public RuleDefinitionDto setIsTemplate(boolean isTemplate) { - this.isTemplate = isTemplate; - return this; - } - - public boolean isExternal() { - return isExternal; - } - - public RuleDefinitionDto setIsExternal(boolean isExternal) { - this.isExternal = isExternal; - return this; - } - - public boolean isAdHoc() { - return isAdHoc; - } - - public RuleDefinitionDto setIsAdHoc(boolean isAdHoc) { - this.isAdHoc = isAdHoc; - return this; - } - - @CheckForNull - public String getLanguage() { - return language; - } - - public RuleDefinitionDto setLanguage(String language) { - this.language = language; - return this; - } - - @CheckForNull - public String getTemplateUuid() { - return templateUuid; - } - - public boolean isCustomRule() { - return getTemplateUuid() != null; - } - - public RuleDefinitionDto setTemplateUuid(@Nullable String templateUuid) { - this.templateUuid = templateUuid; - return this; - } - - @CheckForNull - public String getDefRemediationFunction() { - return defRemediationFunction; - } - - public RuleDefinitionDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) { - this.defRemediationFunction = defaultRemediationFunction; - return this; - } - - @CheckForNull - public String getDefRemediationGapMultiplier() { - return defRemediationGapMultiplier; - } - - public RuleDefinitionDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) { - this.defRemediationGapMultiplier = defaultRemediationGapMultiplier; - return this; - } - - @CheckForNull - public String getDefRemediationBaseEffort() { - return defRemediationBaseEffort; - } - - public RuleDefinitionDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) { - this.defRemediationBaseEffort = defaultRemediationBaseEffort; - return this; - } - - @CheckForNull - public String getGapDescription() { - return gapDescription; - } - - public RuleDefinitionDto setGapDescription(@Nullable String s) { - this.gapDescription = s; - return this; - } - - public Set getSystemTags() { - return deserializeTagsString(systemTags); - } - - private String getSystemTagsField() { - return systemTags; - } - - void setSystemTagsField(String s) { - systemTags = s; - } - - public RuleDefinitionDto setSystemTags(Set tags) { - this.systemTags = serializeStringSet(tags); - return this; - } - - public Set getSecurityStandards() { - return deserializeSecurityStandardsString(securityStandards); - } - - private String getSecurityStandardsField() { - return securityStandards; - } - - void setSecurityStandardsField(String s) { - securityStandards = s; - } - - public RuleDefinitionDto setSecurityStandards(Set standards) { - this.securityStandards = serializeStringSet(standards); - return this; - } - - public int getType() { - return type; - } - - public RuleDefinitionDto setType(int type) { - this.type = type; - return this; - } - - public RuleDefinitionDto setType(RuleType type) { - this.type = type.getDbConstant(); - return this; - } - - public long getCreatedAt() { - return createdAt; - } - - public RuleDefinitionDto setCreatedAt(long createdAt) { - this.createdAt = createdAt; - return this; - } - - public long getUpdatedAt() { - return updatedAt; - } - - public RuleDefinitionDto setUpdatedAt(long updatedAt) { - this.updatedAt = updatedAt; - return this; - } - - public Scope getScope() { - return this.scope; - } - - public RuleDefinitionDto setScope(Scope scope) { - this.scope = scope; - return this; - } - - @CheckForNull - public String getPluginKey() { - return pluginKey; - } - - public RuleDefinitionDto setPluginKey(@Nullable String pluginKey) { - this.pluginKey = pluginKey; - return this; - } - - public Set getRuleDescriptionSectionDtos() { - return ruleDescriptionSectionDtos; - } - - void setRuleDescriptionSectionDtos(Set ruleDescriptionSectionDtos) { - this.ruleDescriptionSectionDtos = ruleDescriptionSectionDtos; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof RuleDefinitionDto)) { - return false; - } - if (this == obj) { - return true; - } - RuleDefinitionDto other = (RuleDefinitionDto) obj; - return Objects.equals(this.uuid, other.uuid); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(this.uuid) - .toHashCode(); - } - - @Override - public String toString() { - return "RuleDefinitionDto{" + - "uuid=" + uuid + - ", repositoryKey='" + repositoryKey + '\'' + - ", ruleKey='" + ruleKey + '\'' + - ", ruleDescriptionSections='" + ruleDescriptionSectionDtos + '\'' + - ", descriptionFormat=" + descriptionFormat + - ", status=" + status + - ", name='" + name + '\'' + - ", configKey='" + configKey + '\'' + - ", severity=" + severity + - ", isTemplate=" + isTemplate + - ", language='" + language + '\'' + - ", templateUuid=" + templateUuid + - ", defRemediationFunction='" + defRemediationFunction + '\'' + - ", defRemediationGapMultiplier='" + defRemediationGapMultiplier + '\'' + - ", defRemediationBaseEffort='" + defRemediationBaseEffort + '\'' + - ", gapDescription='" + gapDescription + '\'' + - ", systemTags='" + systemTags + '\'' + - ", type=" + type + - ", key=" + key + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", scope=" + scope + - '}'; - } - -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java index ae91fe2bbe7..b1da5553845 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java @@ -19,7 +19,6 @@ */ package org.sonar.db.rule; -import java.util.Objects; import java.util.StringJoiner; import static org.sonar.api.utils.Preconditions.checkArgument; @@ -74,23 +73,6 @@ public class RuleDescriptionSectionDto { .toString(); } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - RuleDescriptionSectionDto that = (RuleDescriptionSectionDto) o; - return Objects.equals(uuid, that.uuid) && Objects.equals(key, that.key) && Objects.equals(content, that.content); - } - - @Override - public int hashCode() { - return Objects.hash(uuid, key, content); - } - public static final class RuleDescriptionSectionDtoBuilder { private String uuid; private String key = null; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java index 12f4d4e4625..61f95d0d481 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java @@ -19,16 +19,24 @@ */ package org.sonar.db.rule; -import java.util.Collection; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.HashCodeBuilder; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Collections.emptySet; +import static org.sonar.db.rule.RuleDescriptionSectionDto.DEFAULT_KEY; + public class RuleDto { public enum Format { @@ -39,176 +47,253 @@ public class RuleDto { MAIN, TEST, ALL } - private final RuleDefinitionDto definition; + private static final Splitter SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); + + private String uuid; + private String repositoryKey; + private String ruleKey; + + private Set ruleDescriptionSectionDtos = new HashSet<>(); + + /** + * Description format can be null on external rule, otherwise it should never be null + */ + private RuleDto.Format descriptionFormat; + private RuleStatus status; + private String name; + private String configKey; + + /** + * Severity can be null on external rule, otherwise it should never be null + */ + private Integer severity; + + private boolean isTemplate; + + /** + * This flag specify that this is an external rule, meaning that generated issues from this rule will be provided by the analyzer without being activated on a quality profile. + */ + private boolean isExternal; + + /** + * When an external rule is defined as ad hoc, it means that it's not defined using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}. + * As the opposite, an external rule not being defined as ad hoc is declared by using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}. + * This flag is only used for external rules (it can only be set to true for when {@link #isExternal()} is true) + */ + private boolean isAdHoc; + + private String language; + private String templateUuid; + private String defRemediationFunction; + private String defRemediationGapMultiplier; + private String defRemediationBaseEffort; + private String gapDescription; + private String systemTagsField; + private String securityStandardsField; + private int type; + private Scope scope; + + private RuleKey key; + + private String pluginKey; + + private long createdAt; + private long updatedAt; + private final RuleMetadataDto metadata; public RuleDto() { - this(new RuleDefinitionDto(), new RuleMetadataDto()); + this(new RuleMetadataDto()); } - public RuleDto(RuleDefinitionDto definition, RuleMetadataDto metadata) { - this.definition = definition; + public RuleDto(RuleMetadataDto metadata) { this.metadata = metadata; } - public RuleDefinitionDto getDefinition() { - return definition; - } public RuleMetadataDto getMetadata() { return metadata; } public RuleKey getKey() { - return definition.getKey(); + if (key == null) { + key = RuleKey.of(getRepositoryKey(), getRuleKey()); + } + return key; + } + + RuleDto setKey(RuleKey key) { + this.key = key; + setRepositoryKey(key.repository()); + setRuleKey(key.rule()); + return this; } public String getUuid() { - return definition.getUuid(); + return uuid; } public RuleDto setUuid(String uuid) { - definition.setUuid(uuid); + this.uuid = uuid; metadata.setRuleUuid(uuid); return this; } public String getRepositoryKey() { - return definition.getRepositoryKey(); + return repositoryKey; } - public RuleDto setRepositoryKey(String s) { - definition.setRepositoryKey(s); + public RuleDto setRepositoryKey(String repositoryKey) { + checkArgument(repositoryKey.length() <= 255, "Rule repository is too long: %s", repositoryKey); + this.repositoryKey = repositoryKey; return this; } public String getRuleKey() { - return definition.getRuleKey(); + return ruleKey; } - public RuleDto setRuleKey(String s) { - definition.setRuleKey(s); + public RuleDto setRuleKey(String ruleKey) { + checkArgument(ruleKey.length() <= 200, "Rule key is too long: %s", ruleKey); + this.ruleKey = ruleKey; + return this; + } + + public RuleDto setRuleKey(RuleKey ruleKey) { + this.repositoryKey = ruleKey.repository(); + this.ruleKey = ruleKey.rule(); + this.key = ruleKey; return this; } @CheckForNull public String getPluginKey() { - return definition.getPluginKey(); + return pluginKey; } - public RuleDto setPluginKey(@Nullable String s) { - definition.setPluginKey(s); + public RuleDto setPluginKey(@Nullable String pluginKey) { + this.pluginKey = pluginKey; return this; } - @CheckForNull - public RuleDescriptionSectionDto getRuleDescriptionSection(String ruleDescriptionSectionKey) { - return definition.getRuleDescriptionSectionDto(ruleDescriptionSectionKey); + public Set getRuleDescriptionSectionDtos() { + return ruleDescriptionSectionDtos; } @CheckForNull - public RuleDescriptionSectionDto getDefaultRuleDescriptionSection() { - return definition.getDefaultRuleDescriptionSectionDto(); + public RuleDescriptionSectionDto getRuleDescriptionSectionDto(String ruleDescriptionSectionKey) { + return findExistingSectionWithSameKey(ruleDescriptionSectionKey).orElse(null); } - public Collection getRuleDescriptionSectionDtos() { - return definition.getRuleDescriptionSectionDtos(); + @CheckForNull + public RuleDescriptionSectionDto getDefaultRuleDescriptionSection() { + return findExistingSectionWithSameKey(DEFAULT_KEY).orElse(null); } public RuleDto addRuleDescriptionSectionDto(RuleDescriptionSectionDto ruleDescriptionSectionDto) { - definition.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); + checkArgument(sectionWithSameKeyShouldNotExist(ruleDescriptionSectionDto), + "A section with key %s already exists", ruleDescriptionSectionDto.getKey()); + ruleDescriptionSectionDtos.add(ruleDescriptionSectionDto); return this; } + private boolean sectionWithSameKeyShouldNotExist(RuleDescriptionSectionDto ruleDescriptionSectionDto) { + return findExistingSectionWithSameKey(ruleDescriptionSectionDto.getKey()).isEmpty(); + } + public RuleDto addOrReplaceRuleDescriptionSectionDto(RuleDescriptionSectionDto ruleDescriptionSectionDto) { - definition.addOrReplaceRuleDescriptionSectionDto(ruleDescriptionSectionDto); + Optional existingSectionWithSameKey = findExistingSectionWithSameKey(ruleDescriptionSectionDto.getKey()); + existingSectionWithSameKey.ifPresent(ruleDescriptionSectionDtos::remove); + ruleDescriptionSectionDtos.add(ruleDescriptionSectionDto); return this; } - void setRuleDescriptionSectionDtos(Set ruleDescriptionSectionDtos) { - definition.setRuleDescriptionSectionDtos(ruleDescriptionSectionDtos); + private Optional findExistingSectionWithSameKey(String ruleDescriptionSectionKey) { + return ruleDescriptionSectionDtos.stream().filter(section -> section.getKey().equals(ruleDescriptionSectionKey)).findAny(); } + + @CheckForNull public Format getDescriptionFormat() { - return definition.getDescriptionFormat(); + return descriptionFormat; } public RuleDto setDescriptionFormat(Format descriptionFormat) { - definition.setDescriptionFormat(descriptionFormat); + this.descriptionFormat = descriptionFormat; return this; } public RuleStatus getStatus() { - return definition.getStatus(); + return status; } - public RuleDto setStatus(@Nullable RuleStatus s) { - definition.setStatus(s); + public RuleDto setStatus(@Nullable RuleStatus status) { + this.status = status; return this; } public String getName() { - return definition.getName(); + return name; } - public RuleDto setName(@Nullable String s) { - definition.setName(s); + public RuleDto setName(@Nullable String name) { + checkArgument(name == null || name.length() <= 255, "Rule name is too long: %s", name); + this.name = name; return this; } public String getConfigKey() { - return definition.getConfigKey(); + return configKey; } public RuleDto setConfigKey(@Nullable String configKey) { - definition.setConfigKey(configKey); + this.configKey = configKey; return this; } public Scope getScope() { - return definition.getScope(); + return scope; } public RuleDto setScope(Scope scope) { - definition.setScope(scope); + this.scope = scope; return this; } @CheckForNull public Integer getSeverity() { - return definition.getSeverity(); + return severity; } @CheckForNull public String getSeverityString() { - return definition.getSeverityString(); + return severity != null ? SeverityUtil.getSeverityFromOrdinal(severity) : null; } public RuleDto setSeverity(@Nullable String severity) { - definition.setSeverity(severity); - return this; + return this.setSeverity(severity != null ? SeverityUtil.getOrdinalFromSeverity(severity) : null); } public RuleDto setSeverity(@Nullable Integer severity) { - definition.setSeverity(severity); + this.severity = severity; return this; } public boolean isExternal() { - return definition.isExternal(); + return isExternal; } public RuleDto setIsExternal(boolean isExternal) { - definition.setIsExternal(isExternal); + this.isExternal = isExternal; return this; } public boolean isAdHoc() { - return definition.isAdHoc(); + return isAdHoc; } public RuleDto setIsAdHoc(boolean isAdHoc) { - definition.setIsAdHoc(isAdHoc); + this.isAdHoc = isAdHoc; return this; } @@ -258,174 +343,93 @@ public class RuleDto { } public boolean isTemplate() { - return definition.isTemplate(); + return isTemplate; } public RuleDto setIsTemplate(boolean isTemplate) { - definition.setIsTemplate(isTemplate); + this.isTemplate = isTemplate; return this; } @CheckForNull public String getLanguage() { - return definition.getLanguage(); + return language; } public RuleDto setLanguage(String language) { - definition.setLanguage(language); + this.language = language; return this; } @CheckForNull public String getTemplateUuid() { - return definition.getTemplateUuid(); + return templateUuid; } public RuleDto setTemplateUuid(@Nullable String templateUuid) { - definition.setTemplateUuid(templateUuid); + this.templateUuid = templateUuid; return this; } - @CheckForNull - public String getDefRemediationFunction() { - return definition.getDefRemediationFunction(); + public boolean isCustomRule() { + return getTemplateUuid() != null; } - public RuleDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) { - definition.setDefRemediationFunction(defaultRemediationFunction); - return this; - } - - @CheckForNull - public String getDefRemediationGapMultiplier() { - return definition.getDefRemediationGapMultiplier(); - } - - public RuleDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) { - definition.setDefRemediationGapMultiplier(defaultRemediationGapMultiplier); - return this; - } - - @CheckForNull - public String getDefRemediationBaseEffort() { - return definition.getDefRemediationBaseEffort(); - } - - public RuleDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) { - definition.setDefRemediationBaseEffort(defaultRemediationBaseEffort); + public RuleDto setSystemTags(Set tags) { + this.systemTagsField = serializeStringSet(tags); return this; } - @CheckForNull - public String getGapDescription() { - return definition.getGapDescription(); - } - - public RuleDto setGapDescription(@Nullable String s) { - definition.setGapDescription(s); + public RuleDto setSecurityStandards(Set standards) { + this.securityStandardsField = serializeStringSet(standards); return this; } - public RuleDto setSystemTags(Set tags) { - this.definition.setSystemTags(tags); - return this; + public Set getSystemTags() { + return deserializeTagsString(systemTagsField); } - public RuleDto setSecurityStandards(Set standards) { - this.definition.setSecurityStandards(standards); - return this; + public Set getSecurityStandards() { + return deserializeSecurityStandardsString(securityStandardsField); } public int getType() { - return definition.getType(); + return type; } public RuleDto setType(int type) { - definition.setType(type); + this.type = type; return this; } public RuleDto setType(RuleType type) { - definition.setType(type); + this.type = type.getDbConstant(); return this; } - public Set getSystemTags() { - return definition.getSystemTags(); - } - - /** - * Used in MyBatis mapping. - */ - private void setSystemTagsField(String s) { - definition.setSystemTagsField(s); - } - - public Set getSecurityStandards() { - return definition.getSecurityStandards(); - } - - /** - * Used in MyBatis mapping. - */ - private void setSecurityStandardsField(String s) { - definition.setSecurityStandardsField(s); - } public long getCreatedAt() { - return definition.getCreatedAt(); - } - - public RuleDto setCreatedAt(long createdAt) { - definition.setCreatedAt(createdAt); - metadata.setCreatedAt(createdAt); - return this; - } - - /** - * Used in MyBatis mapping. - */ - private void setCreatedAtFromDefinition(@Nullable Long createdAt) { - if (createdAt != null && createdAt > definition.getCreatedAt()) { - setCreatedAt(createdAt); - } + return createdAt; } - /** - * Used in MyBatis mapping. - */ - private void setCreatedAtFromMetadata(@Nullable Long createdAt) { - if (createdAt != null && createdAt > definition.getCreatedAt()) { - setCreatedAt(createdAt); + public RuleDto setCreatedAt(@Nullable Long createdAt) { + if ((this.createdAt == 0 && createdAt != null) || (createdAt != null && createdAt < this.createdAt)) { + this.createdAt = createdAt; + metadata.setCreatedAt(createdAt); } - } - - public long getUpdatedAt() { - return definition.getUpdatedAt(); - } - - public RuleDto setUpdatedAt(long updatedAt) { - definition.setUpdatedAt(updatedAt); - metadata.setUpdatedAt(updatedAt); return this; } - /** - * Used in MyBatis mapping. - */ - private void setUpdatedAtFromDefinition(@Nullable Long updatedAt) { - if (updatedAt != null && updatedAt > definition.getUpdatedAt()) { - setUpdatedAt(updatedAt); - } + public long getUpdatedAt() { + return updatedAt; } - /** - * Used in MyBatis mapping. - */ - private void setUpdatedAtFromMetadata(@Nullable Long updatedAt) { - if (updatedAt != null && updatedAt > definition.getUpdatedAt()) { - setUpdatedAt(updatedAt); + public RuleDto setUpdatedAt(@Nullable Long updatedAt) { + if (updatedAt != null && updatedAt > this.updatedAt) { + this.updatedAt = updatedAt; + metadata.setUpdatedAt(updatedAt); } + return this; } @CheckForNull @@ -468,6 +472,48 @@ public class RuleDto { return this; } + + @CheckForNull + public String getDefRemediationFunction() { + return defRemediationFunction; + } + + public RuleDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) { + this.defRemediationFunction = defaultRemediationFunction; + return this; + } + + @CheckForNull + public String getDefRemediationGapMultiplier() { + return defRemediationGapMultiplier; + } + + public RuleDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) { + this.defRemediationGapMultiplier = defaultRemediationGapMultiplier; + return this; + } + + @CheckForNull + public String getDefRemediationBaseEffort() { + return defRemediationBaseEffort; + } + + public RuleDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) { + this.defRemediationBaseEffort = defaultRemediationBaseEffort; + return this; + } + + @CheckForNull + public String getGapDescription() { + return gapDescription; + } + + public RuleDto setGapDescription(@Nullable String s) { + this.gapDescription = s; + return this; + } + + @CheckForNull public String getRemediationFunction() { return metadata.getRemediationFunction(); @@ -509,12 +555,31 @@ public class RuleDto { metadata.setTagsField(s); } + + public static Set deserializeTagsString(@Nullable String tags) { + return deserializeStringSet(tags); + } + + public static Set deserializeSecurityStandardsString(@Nullable String securityStandards) { + return deserializeStringSet(securityStandards); + } + + private static Set deserializeStringSet(@Nullable String str) { + if (str == null || str.isEmpty()) { + return emptySet(); + } + + return ImmutableSet.copyOf(SPLITTER.split(str)); + } + public RuleDto setTags(Set tags) { this.metadata.setTags(tags); return this; } - + private static String serializeStringSet(@Nullable Set strings) { + return strings == null || strings.isEmpty() ? null : StringUtils.join(strings, ','); + } @Override public boolean equals(Object obj) { @@ -525,32 +590,14 @@ public class RuleDto { return true; } RuleDto other = (RuleDto) obj; - return new EqualsBuilder() - .append(getRepositoryKey(), other.getRepositoryKey()) - .append(getRuleKey(), other.getRuleKey()) - .isEquals(); + return Objects.equals(this.uuid, other.uuid); } @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(getRepositoryKey()) - .append(getRuleKey()) + .append(this.uuid) .toHashCode(); } - @Override - public String toString() { - return "RuleDto{" + - "definition=" + definition + - ", metadata=" + metadata + - '}'; - } - - public static RuleDto createFor(RuleKey key) { - return new RuleDto() - .setRepositoryKey(key.repository()) - .setRuleKey(key.rule()); - } - } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java index 74f67110746..56ce1bbdd41 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.session.ResultHandler; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleQuery; @@ -31,45 +30,29 @@ public interface RuleMapper { List selectAll(); - List selectAllDefinitions(); - - List selectEnabled(); + List selectEnabled(); RuleDto selectByUuid(@Param("uuid") String uuid); - RuleDefinitionDto selectDefinitionByUuid(String uuid); - List selectByUuids(@Param("uuids") List uuids); - List selectDefinitionByUuids(@Param("uuids") List uuids); - RuleDto selectByKey(@Param("ruleKey") RuleKey ruleKey); - RuleDefinitionDto selectDefinitionByKey(RuleKey ruleKey); - RuleMetadataDto selectMetadataByKey(@Param("ruleKey") RuleKey ruleKey); - List selectMetadataByKeys(@Param("ruleKeys") List keys); - List selectByKeys(@Param("ruleKeys") List keys); - List selectDefinitionByKeys(@Param("ruleKeys") List keys); - - void scrollIndexingRules(ResultHandler handler); - - List selectIndexingRulesByUuids(@Param("ruleUuids") List ruleUuids); - List selectIndexingRuleExtensionsByIds(@Param("ruleExtensionIds") List ruleExtensionIds); List selectByQuery(@Param("query") RuleQuery ruleQuery); List selectByTypeAndLanguages(@Param("types") List types, @Param("languages") List languages); - void insertDefinition(RuleDefinitionDto ruleDefinitionDto); + void insertRule(RuleDto ruleDefinitionDto); void insertRuleDescriptionSection(@Param("ruleUuid") String ruleUuid, @Param("dto") RuleDescriptionSectionDto ruleDescriptionSectionDto); - void updateDefinition(RuleDefinitionDto ruleDefinitionDto); + void updateRule(RuleDto ruleDefinitionDto); void deleteRuleDescriptionSection(String ruleUuid); @@ -77,6 +60,8 @@ public interface RuleMapper { void insertMetadata(RuleMetadataDto ruleMetadataDto); + void deleteMetadata(@Param("uuid") String uuid); + void updateMetadata(RuleMetadataDto ruleMetadataDto); List selectParamsByRuleUuids(@Param("ruleUuids") List ruleUuids); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java index e6c641ce3a3..2ed35d03f6f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java @@ -43,7 +43,6 @@ public class RuleMetadataDto { /** * Name of on ad hoc rule. - * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set */ private String adHocName; @@ -54,13 +53,13 @@ public class RuleMetadataDto { /** * Severity of on ad hoc rule. - * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set + * When {@link RuleDto#isAdHoc()} is true, this field should always be set */ private String adHocSeverity; /** * Type of on ad hoc rule. - * When {@link RuleDefinitionDto#isAdHoc} is true, this field should always be set + * When {@link RuleDto#isAdHoc()} is true, this field should always be set */ private Integer adHocType; @@ -252,4 +251,10 @@ public class RuleMetadataDto { ", updatedAt=" + updatedAt + '}'; } + + public boolean isUndefined() { + return StringUtils.isEmpty(noteData) && StringUtils.isEmpty(noteUserUuid) && noteCreatedAt == null && noteUpdatedAt == null && StringUtils.isEmpty(remediationFunction) && + StringUtils.isEmpty(remediationGapMultiplier) && StringUtils.isEmpty(remediationBaseEffort) && StringUtils.isEmpty(tags) + && StringUtils.isEmpty(adHocName) && StringUtils.isEmpty(adHocDescription) && StringUtils.isEmpty(adHocSeverity) && adHocType == null; + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java index 4071b05eb33..229e6a6a435 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java @@ -102,7 +102,7 @@ public class RuleParamDto { return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); } - public static RuleParamDto createFor(RuleDefinitionDto rule) { + public static RuleParamDto createFor(RuleDto rule) { // Should eventually switch to RuleKey (RuleKey is available before insert) return new RuleParamDto().setRuleUuid(rule.getUuid()); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml index ed94cc4598a..d323a166cf0 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileExportMapper.xml @@ -35,7 +35,7 @@ p.value as value - + @@ -55,7 +55,7 @@ - select from active_rules a diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml index ad74a26fab4..02ada782137 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -3,19 +3,15 @@ - - rds.uuid as "rds_uuid", - rds.kee as "rds_kee", - rds.content as "rds_content", - - left outer join rule_desc_sections rds on rds.rule_uuid = r.uuid - - + + rds.uuid as "rds_uuid", + rds.kee as "rds_kee", + rds.content as "rds_content", r.uuid as "r_uuid", r.plugin_rule_key as "ruleKey", r.plugin_name as "repositoryKey", @@ -38,18 +34,6 @@ r.rule_type as "type", r.plugin_key as "pluginKey", r.scope, - - - - - r.created_at as "createdAt", - r.updated_at as "updatedAt" - - - - - r.created_at as "createdAtFromDefinition", - r.updated_at as "updatedAtFromDefinition", rm.note_data as "noteData", rm.note_user_uuid as "noteUserUuid", rm.note_created_at as "noteCreatedAt", @@ -62,8 +46,18 @@ rm.ad_hoc_description as "adHocDescription", rm.ad_hoc_severity as "adHocSeverity", rm.ad_hoc_type as "adHocType", - rm.created_at as "createdAtFromMetadata", - rm.updated_at as "updatedAtFromMetadata" + case + when rm.created_at is null then r.created_at + else case + when r.created_at < rm.created_at then r.created_at + else rm.created_at + end end as "createdAt", + case + when rm.updated_at is null then r.updated_at + else case + when r.updated_at < rm.updated_at then rm.updated_at + else r.updated_at + end end as "updatedAt" @@ -83,8 +77,8 @@ - - + + @@ -97,8 +91,6 @@ - - @@ -121,8 +113,6 @@ - - @@ -131,53 +121,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select - + from rules r + where r.status != 'REMOVED' @@ -194,16 +145,6 @@ r.uuid=#{uuid,jdbcType=VARCHAR} - - - - - - - - - - @@ -568,6 +448,13 @@ rule_uuid=#{ruleUuid,jdbcType=VARCHAR} + + delete from + rules_metadata + where + rule_uuid=#{uuid,jdbcType=INTEGER} + + delete from active_rule_parameters diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index ab4e8ee6cb7..e47fd35065b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -55,7 +55,7 @@ import org.sonar.db.audit.model.ComponentNewValue; import org.sonar.db.issue.IssueDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.source.FileSourceDto; import static com.google.common.collect.ImmutableSet.of; @@ -1885,7 +1885,7 @@ public class ComponentDaoTest { ComponentDto branch2 = db.components().insertProjectBranch(project, ComponentTesting.newBranchDto(project.getUuid(), BRANCH).setKey("branch2")); ComponentDto fileBranch2 = db.components().insertComponent(ComponentTesting.newFileDto(branch2)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.issues().insert(new IssueDto().setKee("i1").setComponent(fileBranch1).setProject(branch1).setRule(rule).setStatus(STATUS_CONFIRMED)); db.issues().insert(new IssueDto().setKee("i2").setComponent(fileBranch2).setProject(branch2).setRule(rule).setStatus(STATUS_CLOSED)); db.issues().insert(new IssueDto().setKee("i3").setComponent(fileBranch2).setProject(branch2).setRule(rule).setStatus(STATUS_OPEN)); @@ -1900,7 +1900,7 @@ public class ComponentDaoTest { final ProjectDto project = db.components().insertPrivateProjectDto(b -> b.setName("foo")); ComponentDto branch1 = db.components().insertProjectBranch(project, ComponentTesting.newBranchDto(project.getUuid(), BRANCH).setKey("branch1")); ComponentDto fileBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.issues().insert(new IssueDto().setKee("i").setComponent(fileBranch1).setProject(branch1).setRule(rule).setStatus(STATUS_CLOSED)); List result = underTest.selectComponentsFromBranchesThatHaveOpenIssues(db.getSession(), singleton(branch1.uuid())); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 094d5023745..f6fe4d569fd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -37,7 +37,6 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ComponentUpdateDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; @@ -152,7 +151,7 @@ public class IssueDaoTest { @Test public void scrollNonClosedByComponentUuid() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto openIssue1OnFile = db.issues().insert(rule, project, file, i -> i.setStatus("OPEN").setResolution(null).setType(randomRuleTypeExceptHotspot())); @@ -162,7 +161,7 @@ public class IssueDaoTest { IssueDto securityHotspot = db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT)); - RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); + RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot())); assertThat(underTest.selectNonClosedByComponentUuidExcludingExternalsAndSecurityHotspots(db.getSession(), file.uuid())) @@ -178,7 +177,7 @@ public class IssueDaoTest { @Test public void scrollNonClosedByModuleOrProject() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); @@ -193,7 +192,7 @@ public class IssueDaoTest { IssueDto securityHotspot = db.issues().insert(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT)); - RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); + RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot())); assertThat(underTest.selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(db.getSession(), project)) @@ -211,7 +210,7 @@ public class IssueDaoTest { @Test public void selectOpenByComponentUuid() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo") @@ -233,7 +232,7 @@ public class IssueDaoTest { @Test public void selectOpenByComponentUuid_should_correctly_map_required_fields() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo") @@ -306,7 +305,7 @@ public class IssueDaoTest { public void selectGroupsOfComponentTreeOnLeak_on_file() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto fpBug = db.issues().insert(rule, project, file, i -> i.setStatus("RESOLVED").setResolution("FALSE-POSITIVE").setSeverity("MAJOR").setType(RuleType.BUG).setIssueCreationTime(1_500L)); IssueDto criticalBug1 = db.issues().insert(rule, project, file, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java index bd153ec25ce..6032ed1e573 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java @@ -32,7 +32,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -103,7 +103,7 @@ public class IssueDtoTest { public void set_rule() { IssueDto dto = new IssueDto() .setKee("100") - .setRule(new RuleDefinitionDto().setUuid("uuid-1").setRuleKey("AvoidCycle").setRepositoryKey("squid").setIsExternal(true)) + .setRule(new RuleDto().setUuid("uuid-1").setRuleKey("AvoidCycle").setRepositoryKey("squid").setIsExternal(true)) .setLanguage("xoo"); assertThat(dto.getRuleUuid()).isEqualTo("uuid-1"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java index b50f7de1d43..48eec38af1b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java @@ -47,7 +47,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; @@ -263,7 +262,7 @@ public class IssueMapperTest { ComponentDto component = randomComponent(); IssueDto issueWithRule = insertNewClosedIssue(component, ruleType); IssueChangeDto issueChange = insertToClosedDiff(issueWithRule); - IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setUuid("uuid-50")); + IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDto().setType(ruleType).setUuid("uuid-50")); insertToClosedDiff(issueWithoutRule); RecorderResultHandler resultHandler = new RecorderResultHandler(); @@ -350,7 +349,7 @@ public class IssueMapperTest { public void scrollClosedByComponentUuid_returns_closed_issues_which_close_date_is_greater_or_equal_to_requested() { RuleType ruleType = randomSupportedRuleType(); ComponentDto component = randomComponent(); - RuleDefinitionDto rule1 = dbTester.rules().insert(t -> t.setType(ruleType)); + RuleDto rule1 = dbTester.rules().insert(t -> t.setType(ruleType)); IssueDto[] issues = new IssueDto[] { insertNewClosedIssue(component, rule1, 1_999_999L), insertNewClosedIssue(component, rule1, 3_999_999L), @@ -471,17 +470,17 @@ public class IssueMapperTest { @SafeVarargs private final IssueDto insertNewClosedIssue(ComponentDto component, RuleType ruleType, Consumer... consumers) { - RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(ruleType)); + RuleDto rule = dbTester.rules().insert(t -> t.setType(ruleType)); return insertNewClosedIssue(component, rule, system2.now(), consumers); } @SafeVarargs - private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDefinitionDto rule, Consumer... consumers) { + private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDto rule, Consumer... consumers) { return insertNewClosedIssue(component, rule, system2.now(), consumers); } @SafeVarargs - private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDefinitionDto rule, long issueCloseTime, Consumer... consumers) { + private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDto rule, long issueCloseTime, Consumer... consumers) { IssueDto res = new IssueDto() .setKee(UuidFactoryFast.getInstance().create()) .setRuleUuid(rule.getUuid()) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 5321db94f83..5700ff9b356 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -51,7 +51,7 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.portfolio.PortfolioProjectDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; @@ -495,8 +495,8 @@ public class PurgeCommandsTest { @Test @UseDataProvider("projectsAndViews") public void deleteIssues_deletes_all_issues_of_specified_root_component(ComponentDto projectOrView) { - RuleDefinitionDto rule1 = dbTester.rules().insert(); - RuleDefinitionDto rule2 = dbTester.rules().insert(); + RuleDto rule1 = dbTester.rules().insert(); + RuleDto rule2 = dbTester.rules().insert(); dbTester.components().insertComponent(projectOrView); ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView)); ComponentDto otherProject = dbTester.components().insertPrivateProject(); @@ -520,7 +520,7 @@ public class PurgeCommandsTest { @Test @UseDataProvider("projectsAndViews") public void deleteIssues_deletes_issue_changes(ComponentDto projectOrView) { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); dbTester.components().insertComponent(projectOrView); ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView)); int count = 5; @@ -539,7 +539,7 @@ public class PurgeCommandsTest { @Test @UseDataProvider("projectsAndViews") public void deleteIssues_deletes_new_code_reference_issues(ComponentDto projectOrView) { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); dbTester.components().insertComponent(projectOrView); ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView)); List issueKeys = new ArrayList<>(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 24f0862791c..a8bbfc379c6 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -75,7 +75,7 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType; import org.sonar.db.portfolio.PortfolioProjectDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.property.PropertyDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.source.FileSourceDto; import org.sonar.db.user.UserDismissedMessageDto; import org.sonar.db.user.UserDto; @@ -138,7 +138,7 @@ public class PurgeDaoTest { @Test public void purge_inactive_branches() { when(system2.now()).thenReturn(new Date().getTime()); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto branch1 = db.components().insertProjectBranch(project); ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); @@ -177,7 +177,7 @@ public class PurgeDaoTest { @Test public void purge_inactive_pull_request() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto nonMainBranch = db.components().insertProjectBranch(project); db.components().insertSnapshot(nonMainBranch); @@ -203,7 +203,7 @@ public class PurgeDaoTest { @Test public void purge_inactive_branches_when_analyzing_non_main_branch() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto nonMainBranch = db.components().insertProjectBranch(project); db.components().insertSnapshot(nonMainBranch); @@ -236,7 +236,7 @@ public class PurgeDaoTest { @Test public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); db.components().insertSnapshot(project); db.components().insertSnapshot(project); @@ -518,7 +518,7 @@ public class PurgeDaoTest { @Test public void delete_project_and_associated_data() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "a/b")); @@ -558,7 +558,7 @@ public class PurgeDaoTest { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); BranchDto projectBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid()).get(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto app = db.components().insertPrivateApplication(); ComponentDto appBranch = db.components().insertProjectBranch(app); @@ -597,7 +597,7 @@ public class PurgeDaoTest { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); BranchDto projectBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid()).get(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto app = db.components().insertPrivateApplication(); ComponentDto appBranch = db.components().insertProjectBranch(app); @@ -1035,7 +1035,7 @@ public class PurgeDaoTest { } private ComponentDto insertProjectWithBranchAndRelatedData() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); @@ -1097,7 +1097,7 @@ public class PurgeDaoTest { @Test public void should_delete_old_closed_issues() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); @@ -1147,7 +1147,7 @@ public class PurgeDaoTest { ComponentDto enabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(true)); ComponentDto disabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(false)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto closed1 = db.issues().insert(rule, project, enabledFileWithIssues, issue -> { issue.setStatus("CLOSED"); issue.setResolution(Issue.RESOLUTION_FIXED); @@ -1853,7 +1853,7 @@ public class PurgeDaoTest { .map(t -> (String) t.get("UUID")); } - private void addComponentsSnapshotsAndIssuesToBranch(ComponentDto branch, RuleDefinitionDto rule, int branchAge) { + private void addComponentsSnapshotsAndIssuesToBranch(ComponentDto branch, RuleDto rule, int branchAge) { db.components().insertSnapshot(branch, dto -> dto.setCreatedAt(DateUtils.addDays(new Date(), -branchAge).getTime())); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 9a168075d2c..9a83f626dca 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -34,7 +34,7 @@ import org.sonar.api.server.rule.RuleParamType; import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import static com.google.common.collect.Lists.newArrayList; @@ -61,10 +61,10 @@ public class ActiveRuleDaoTest { private QProfileDto profile1; private QProfileDto profile2; - private RuleDefinitionDto rule1; - private RuleDefinitionDto rule2; - private RuleDefinitionDto rule3; - private RuleDefinitionDto removedRule; + private RuleDto rule1; + private RuleDto rule2; + private RuleDto rule3; + private RuleDto removedRule; private RuleParamDto rule1Param1; private RuleParamDto rule1Param2; private RuleParamDto rule2Param1; @@ -159,7 +159,7 @@ public class ActiveRuleDaoTest { @Test public void selectByTypeAndProfileUuids() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); + RuleDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); underTest.insert(dbSession, activeRule1); @@ -171,7 +171,7 @@ public class ActiveRuleDaoTest { @Test public void selectByTypeAndProfileUuids_ignores_rules_in_other_profiles() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); + RuleDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); ActiveRuleDto activeRule1 = createFor(profile2, rule1).setSeverity(BLOCKER); underTest.insert(dbSession, activeRule1); @@ -182,7 +182,7 @@ public class ActiveRuleDaoTest { @Test public void selectByTypeAndProfileUuids_ignores_rules_with_another_rule_type() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); + RuleDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant())); ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); underTest.insert(dbSession, activeRule1); @@ -410,7 +410,7 @@ public class ActiveRuleDaoTest { assertThat(db.countRowsOfTable(dbSession, "active_rules")).isOne(); } - private static ActiveRuleDto newRow(QProfileDto profile, RuleDefinitionDto rule) { + private static ActiveRuleDto newRow(QProfileDto profile, RuleDto rule) { return createFor(profile, rule).setSeverity(BLOCKER); } @@ -612,7 +612,7 @@ public class ActiveRuleDaoTest { @Test public void countActiveRulesByQuery_filter_by_rule_status() { - RuleDefinitionDto betaRule = db.rules().insert(r -> r.setStatus(BETA)); + RuleDto betaRule = db.rules().insert(r -> r.setStatus(BETA)); db.qualityProfiles().activateRule(profile1, rule1); db.qualityProfiles().activateRule(profile1, rule2); db.qualityProfiles().activateRule(profile1, betaRule); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 566c971a45e..45d0290e2dd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -38,7 +38,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static com.google.common.collect.ImmutableList.of; import static com.google.common.collect.Lists.newArrayList; @@ -505,7 +505,7 @@ public class QualityProfileDaoTest { // a built-in quality profile with active rules QProfileDto builtInQPWithActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true)); - RuleDefinitionDto ruleDefinitionDto = db.rules().insert(); + RuleDto ruleDefinitionDto = db.rules().insert(); db.qualityProfiles().activateRule(builtInQPWithActiveRules, ruleDefinitionDto); dbSession.commit(); @@ -546,7 +546,7 @@ public class QualityProfileDaoTest { // a built-in quality profile with active rules QProfileDto builtInQPWithActiveRules = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage("java")); - RuleDefinitionDto ruleDefinitionDto = db.rules().insert(); + RuleDto ruleDefinitionDto = db.rules().insert(); db.qualityProfiles().activateRule(builtInQPWithActiveRules, ruleDefinitionDto); dbSession.commit(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java index 3806c062f8f..9c1f9c09261 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java @@ -35,7 +35,7 @@ import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.rule.RuleParamDto; @@ -52,9 +52,9 @@ public class QualityProfileExportDaoTest { @Test public void selectRulesByProfile_ready_rules_only() { String language = "java"; - RuleDefinitionDto rule1 = createRule(language); - RuleDefinitionDto rule2 = createRule(language); - RuleDefinitionDto rule3 = createRule(language); + RuleDto rule1 = createRule(language); + RuleDto rule2 = createRule(language); + RuleDto rule3 = createRule(language); createRule(language, RuleStatus.REMOVED); QProfileDto profile = createProfile(language); @@ -71,16 +71,16 @@ public class QualityProfileExportDaoTest { @Test public void selectRulesByProfile_verify_columns() { String language = "java"; - RuleDefinitionDto ruleTemplate = createRule(language); - RuleDefinitionDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getUuid()); - var customRuleContent = customRule.getDefaultRuleDescriptionSectionDto().getContent(); + RuleDto ruleTemplate = createRule(language); + RuleDto customRule = createRule(language, RuleStatus.READY, ruleTemplate.getUuid()); + var customRuleContent = customRule.getDefaultRuleDescriptionSection().getContent(); RuleMetadataDto customRuleMetadata = createRuleMetadata(new RuleMetadataDto() .setRuleUuid(customRule.getUuid()) .setNoteData("Extended description") .setTags(Sets.newHashSet("tag1", "tag2", "tag3"))); - RuleDefinitionDto rule = createRule(language, RuleStatus.READY, null); - var ruleContent = rule.getDefaultRuleDescriptionSectionDto().getContent(); + RuleDto rule = createRule(language, RuleStatus.READY, null); + var ruleContent = rule.getDefaultRuleDescriptionSection().getContent(); RuleMetadataDto ruleMetadata = createRuleMetadata(new RuleMetadataDto() .setRuleUuid(rule.getUuid())); QProfileDto profile = createProfile(language); @@ -126,7 +126,7 @@ public class QualityProfileExportDaoTest { public void selectRulesByProfile_verify_rows_over_1000() { String language = "java"; int numberOfParamsToCreate = 1005; - RuleDefinitionDto rule = createRule(language); + RuleDto rule = createRule(language); List ruleParams = addParamsToRule(rule, numberOfParamsToCreate); QProfileDto profile = createProfile(language); @@ -146,14 +146,14 @@ public class QualityProfileExportDaoTest { @Test public void selectRulesByProfile_params_assigned_correctly() { String language = "java"; - RuleDefinitionDto firstRule = createRule(language); + RuleDto firstRule = createRule(language); List ruleParamsOfFirstRule = addParamsToRule(firstRule, 2); - RuleDefinitionDto secondRule = createRule(language); + RuleDto secondRule = createRule(language); List ruleParamsOfSecondRule = addParamsToRule(secondRule, 3); String otherLanguage = "js"; - RuleDefinitionDto thirdRule = createRule(otherLanguage); + RuleDto thirdRule = createRule(otherLanguage); List ruleParamsOfThirdRule = addParamsToRule(thirdRule, 4); QProfileDto profile = createProfile(language); @@ -199,22 +199,22 @@ public class QualityProfileExportDaoTest { return found.get(); } - private List addParamsToRule(RuleDefinitionDto firstRule, int numberOfParams) { + private List addParamsToRule(RuleDto firstRule, int numberOfParams) { return IntStream.range(0, numberOfParams) .mapToObj(value -> db.rules().insertRuleParam(firstRule, ruleParamDto -> ruleParamDto.setName("name_" + firstRule.getUuid() + "_" + value))) .collect(Collectors.toList()); } - private RuleDefinitionDto createRule(String language) { + private RuleDto createRule(String language) { return createRule(language, RuleStatus.READY); } - private RuleDefinitionDto createRule(String language, RuleStatus status) { + private RuleDto createRule(String language, RuleStatus status) { return createRule(language, status, null); } - private RuleDefinitionDto createRule(String language, RuleStatus status, @Nullable String templateUuid) { + private RuleDto createRule(String language, RuleStatus status, @Nullable String templateUuid) { return db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setRepositoryKey("repoKey").setLanguage(language).setStatus(status) .setTemplateUuid(templateUuid)); } @@ -227,13 +227,13 @@ public class QualityProfileExportDaoTest { return db.qualityProfiles().insert(p -> p.setLanguage(lanugage)); } - private List activate(QProfileDto profile, RuleDefinitionDto... rules) { + private List activate(QProfileDto profile, RuleDto... rules) { return Stream.of(rules) .map(ruleDefinitionDto -> db.qualityProfiles().activateRule(profile, ruleDefinitionDto)) .collect(Collectors.toList()); } - private ActiveRuleDto activate(QProfileDto profile, RuleDefinitionDto rule, Collection params) { + private ActiveRuleDto activate(QProfileDto profile, RuleDto rule, Collection params) { ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile, rule); params.forEach(ruleParamDto -> { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java index 849392b92d7..21a26e8ee8f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -68,87 +68,84 @@ public class RuleDaoTest { @Test public void selectByKey() { - RuleDefinitionDto ruleDefinition = db.rules().insert(); - RuleMetadataDto metadata = newRuleMetadata(ruleDefinition); - db.rules().insertRule(ruleDefinition, metadata); + RuleDto ruleDto = db.rules().insert(); + RuleMetadataDto metadata = newRuleMetadata(ruleDto); + db.rules().insertRule(ruleDto, metadata); assertThat(underTest.selectByKey(db.getSession(), RuleKey.of("foo", "bar"))) .isEmpty(); - RuleDto rule = underTest.selectByKey(db.getSession(), ruleDefinition.getKey()).get(); - assertEquals(rule.getDefinition(), ruleDefinition); + RuleDto rule = underTest.selectByKey(db.getSession(), ruleDto.getKey()).get(); + assertEquals(rule, ruleDto); verifyMetadata(rule.getMetadata(), metadata); } @Test public void selectByKey_return_rule() { - RuleDefinitionDto ruleDefinition = db.rules().insert(); + RuleDto ruleDto = db.rules().insert(); - assertThat(underTest.selectByKey(db.getSession(), ruleDefinition.getKey())).isNotEmpty(); + assertThat(underTest.selectByKey(db.getSession(), ruleDto.getKey())).isNotEmpty(); } @Test public void selectByKey_returns_metadata() { - RuleDefinitionDto ruleDefinition = db.rules().insert(); - RuleMetadataDto ruleMetadata = newRuleMetadata(ruleDefinition); - db.rules().insertRule(ruleDefinition, ruleMetadata); + RuleDto ruleDto = db.rules().insert(); + RuleMetadataDto ruleMetadata = newRuleMetadata(ruleDto); + db.rules().insertRule(ruleDto, ruleMetadata); - RuleDto rule = underTest.selectByKey(db.getSession(), ruleDefinition.getKey()).get(); + RuleDto rule = underTest.selectByKey(db.getSession(), ruleDto.getKey()).get(); verifyMetadata(rule.getMetadata(), ruleMetadata); } @Test public void selectDefinitionByKey() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); - assertThat(underTest.selectDefinitionByKey(db.getSession(), RuleKey.of("NOT", "FOUND"))).isEmpty(); + assertThat(underTest.selectByKey(db.getSession(), RuleKey.of("NOT", "FOUND"))).isEmpty(); - Optional reloaded = underTest.selectDefinitionByKey(db.getSession(), rule.getKey()); + Optional reloaded = underTest.selectByKey(db.getSession(), rule.getKey()); assertThat(reloaded).isPresent(); } @Test - public void selectMetadataByKeys() { - RuleDefinitionDto rule1 = db.rules().insert(); + public void selectMetadataByKey() { + RuleDto rule1 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule1); - assertThat(underTest.selectMetadataByKeys(db.getSession(), Collections.emptyList())).isEmpty(); - assertThat(underTest.selectMetadataByKeys(db.getSession(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty(); + assertThat(underTest.selectByKeys(db.getSession(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty(); - List rulesMetadata = underTest.selectMetadataByKeys(db.getSession(), asList(rule1.getKey(), - RuleKey.of("java", "OTHER"))); - assertThat(rulesMetadata).hasSize(1); - assertThat(rulesMetadata.get(0).getRuleUuid()).isEqualTo(rule1.getUuid()); + Optional rulesMetadata = underTest.selectMetadataByKey(db.getSession(), rule1.getKey()); + assertThat(rulesMetadata).isPresent(); + assertThat(rulesMetadata.get().getRuleUuid()).isEqualTo(rule1.getUuid()); } @Test public void selectByUuid() { - RuleDefinitionDto ruleDefinition = db.rules().insert(); - RuleMetadataDto metadata = newRuleMetadata(ruleDefinition); - RuleDto expected = db.rules().insertRule(ruleDefinition, metadata); + RuleDto ruleDto = db.rules().insert(); + RuleMetadataDto metadata = newRuleMetadata(ruleDto); + RuleDto expected = db.rules().insertRule(ruleDto, metadata); - assertThat(underTest.selectByUuid(expected.getUuid() + 500, db.getSession())) - .isEmpty(); + assertThat(underTest.selectByUuid(expected.getUuid() + 500, db.getSession())).isEmpty(); RuleDto rule = underTest.selectByUuid(expected.getUuid(), db.getSession()).get(); - assertEquals(rule.getDefinition(), ruleDefinition); + assertEquals(rule, ruleDto); verifyMetadata(rule.getMetadata(), metadata); } @Test public void selectDefinitionByUuid() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); - assertThat(underTest.selectDefinitionByUuid(UNKNOWN_RULE_UUID, db.getSession())).isEmpty(); - Optional ruleDtoOptional = underTest.selectDefinitionByUuid(rule.getUuid(), db.getSession()); + assertThat(underTest.selectByUuid(UNKNOWN_RULE_UUID, db.getSession())).isEmpty(); + Optional ruleDtoOptional = underTest.selectByUuid(rule.getUuid(), db.getSession()); assertThat(ruleDtoOptional).isPresent(); } @Test public void selectByUuids() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule2); - RuleDefinitionDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); + RuleDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); db.rules().insertOrUpdateMetadata(removedRule); assertThat(underTest.selectByUuids(db.getSession(), singletonList(rule1.getUuid()))).hasSize(1); @@ -160,18 +157,18 @@ public class RuleDaoTest { @Test public void selectDefinitionByUuids() { - RuleDefinitionDto rule1 = db.rules().insert(); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); - assertThat(underTest.selectDefinitionByUuids(db.getSession(), singletonList(rule1.getUuid()))).hasSize(1); - assertThat(underTest.selectDefinitionByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid()))).hasSize(2); - assertThat(underTest.selectDefinitionByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid(), UNKNOWN_RULE_UUID))).hasSize(2); - assertThat(underTest.selectDefinitionByUuids(db.getSession(), singletonList(UNKNOWN_RULE_UUID))).isEmpty(); + assertThat(underTest.selectByUuids(db.getSession(), singletonList(rule1.getUuid()))).hasSize(1); + assertThat(underTest.selectByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid()))).hasSize(2); + assertThat(underTest.selectByUuids(db.getSession(), asList(rule1.getUuid(), rule2.getUuid(), UNKNOWN_RULE_UUID))).hasSize(2); + assertThat(underTest.selectByUuids(db.getSession(), singletonList(UNKNOWN_RULE_UUID))).isEmpty(); } @Test public void selectOrFailByKey() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insert(); RuleDto rule = underTest.selectOrFailByKey(db.getSession(), rule1.getKey()); @@ -187,16 +184,16 @@ public class RuleDaoTest { @Test public void selectOrFailDefinitionByKey_fails_if_rule_not_found() { - assertThatThrownBy(() -> underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of("NOT", "FOUND"))) + assertThatThrownBy(() -> underTest.selectOrFailByKey(db.getSession(), RuleKey.of("NOT", "FOUND"))) .isInstanceOf(RowNotFoundException.class) .hasMessage("Rule with key 'NOT:FOUND' does not exist"); } @Test public void selectByKeys() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule2); assertThat(underTest.selectByKeys(db.getSession(), Collections.emptyList())).isEmpty(); @@ -209,12 +206,12 @@ public class RuleDaoTest { @Test public void selectDefinitionByKeys() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); - assertThat(underTest.selectDefinitionByKeys(db.getSession(), Collections.emptyList())).isEmpty(); - assertThat(underTest.selectDefinitionByKeys(db.getSession(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty(); + assertThat(underTest.selectByKeys(db.getSession(), Collections.emptyList())).isEmpty(); + assertThat(underTest.selectByKeys(db.getSession(), singletonList(RuleKey.of("NOT", "FOUND")))).isEmpty(); - List rules = underTest.selectDefinitionByKeys(db.getSession(), asList(rule.getKey(), RuleKey.of("java", "OTHER"))); + List rules = underTest.selectByKeys(db.getSession(), asList(rule.getKey(), RuleKey.of("java", "OTHER"))); assertThat(rules).hasSize(1); assertThat(rules.get(0).getUuid()).isEqualTo(rule.getUuid()); } @@ -232,9 +229,9 @@ public class RuleDaoTest { @Test public void selectAll_returns_metadata() { - RuleDefinitionDto ruleDefinition = db.rules().insert(); - RuleMetadataDto expected = newRuleMetadata(ruleDefinition); - db.rules().insertRule(ruleDefinition, expected); + RuleDto ruleDto = db.rules().insert(); + RuleMetadataDto expected = newRuleMetadata(ruleDto); + db.rules().insertRule(ruleDto, expected); List rules = underTest.selectAll(db.getSession()); assertThat(rules).hasSize(1); @@ -242,7 +239,7 @@ public class RuleDaoTest { verifyMetadata(rules.iterator().next().getMetadata(), expected); } - private void assertEquals(RuleDefinitionDto actual, RuleDefinitionDto expected) { + private void assertEquals(RuleDto actual, RuleDto expected) { assertThat(actual.getUuid()).isEqualTo(expected.getUuid()); assertThat(actual.getRepositoryKey()).isEqualTo(expected.getRepositoryKey()); assertThat(actual.getRuleKey()).isEqualTo(expected.getRuleKey()); @@ -284,37 +281,37 @@ public class RuleDaoTest { @Test public void selectAllDefinitions() { - RuleDefinitionDto rule1 = db.rules().insert(); - RuleDefinitionDto rule2 = db.rules().insert(); - RuleDefinitionDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); + RuleDto rule1 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); + RuleDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); - List ruleDtos = underTest.selectAllDefinitions(db.getSession()); + List ruleDtos = underTest.selectAll(db.getSession()); - assertThat(ruleDtos).extracting(RuleDefinitionDto::getUuid).containsOnly(rule1.getUuid(), rule2.getUuid(), removedRule.getUuid()); + assertThat(ruleDtos).extracting(RuleDto::getUuid).containsOnly(rule1.getUuid(), rule2.getUuid(), removedRule.getUuid()); } @Test public void selectEnabled_with_ResultHandler() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.rules().insert(r -> r.setStatus(REMOVED)); - List rules = underTest.selectEnabled(db.getSession()); + List rules = underTest.selectEnabled(db.getSession()); assertThat(rules.size()).isOne(); - RuleDefinitionDto ruleDto = rules.get(0); + RuleDto ruleDto = rules.get(0); assertThat(ruleDto.getUuid()).isEqualTo(rule.getUuid()); } @Test public void selectByTypeAndLanguages() { - RuleDefinitionDto rule1 = db.rules().insert( + RuleDto rule1 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S001")) .setConfigKey("S1") .setType(RuleType.VULNERABILITY) .setLanguage("java")); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert( + RuleDto rule2 = db.rules().insert( r -> r.setKey(RuleKey.of("js", "S002")) .setType(RuleType.SECURITY_HOTSPOT) .setLanguage("js")); @@ -334,14 +331,14 @@ public class RuleDaoTest { @Test public void selectByTypeAndLanguages_return_nothing_when_no_rule_on_languages() { - RuleDefinitionDto rule1 = db.rules().insert( + RuleDto rule1 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S001")) .setConfigKey("S1") .setType(RuleType.VULNERABILITY) .setLanguage("java")); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert( + RuleDto rule2 = db.rules().insert( r -> r.setKey(RuleKey.of("js", "S002")) .setType(RuleType.VULNERABILITY) .setLanguage("js")); @@ -353,20 +350,20 @@ public class RuleDaoTest { @Test public void selectByTypeAndLanguages_return_nothing_when_no_rule_with_type() { - RuleDefinitionDto rule1 = db.rules().insert( + RuleDto rule1 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S001")) .setConfigKey("S1") .setType(RuleType.VULNERABILITY) .setLanguage("java")); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert( + RuleDto rule2 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S002")) .setType(RuleType.SECURITY_HOTSPOT) .setLanguage("java")); db.rules().insertOrUpdateMetadata(rule2); - RuleDefinitionDto rule3 = db.rules().insert( + RuleDto rule3 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S003")) .setType(RuleType.CODE_SMELL) .setLanguage("java")); @@ -378,7 +375,7 @@ public class RuleDaoTest { @Test public void selectByTypeAndLanguages_ignores_external_rules() { - RuleDefinitionDto rule1 = db.rules().insert( + RuleDto rule1 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S001")) .setConfigKey("S1") .setType(RuleType.VULNERABILITY) @@ -393,7 +390,7 @@ public class RuleDaoTest { @Test public void selectByTypeAndLanguages_ignores_template_rules() { - RuleDefinitionDto rule1 = db.rules().insert( + RuleDto rule1 = db.rules().insert( r -> r.setKey(RuleKey.of("java", "S001")) .setConfigKey("S1") .setType(RuleType.VULNERABILITY) @@ -408,11 +405,11 @@ public class RuleDaoTest { @Test public void select_by_query() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setKey(RuleKey.of("java", "S001")).setConfigKey("S1")); + RuleDto rule1 = db.rules().insert(r -> r.setKey(RuleKey.of("java", "S001")).setConfigKey("S1")); db.rules().insertOrUpdateMetadata(rule1); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setKey(RuleKey.of("java", "S002"))); + RuleDto rule2 = db.rules().insert(r -> r.setKey(RuleKey.of("java", "S002"))); db.rules().insertOrUpdateMetadata(rule2); - RuleDefinitionDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); + RuleDto removedRule = db.rules().insert(r -> r.setStatus(REMOVED)); assertThat(underTest.selectByQuery(db.getSession(), RuleQuery.create())).hasSize(2); assertThat(underTest.selectByQuery(db.getSession(), RuleQuery.create().withKey("S001"))).hasSize(1); @@ -425,7 +422,7 @@ public class RuleDaoTest { @Test public void insert() { RuleDescriptionSectionDto sectionDto = createDefaultRuleDescriptionSection(); - RuleDefinitionDto newRule = new RuleDefinitionDto() + RuleDto newRule = new RuleDto() .setUuid("rule-uuid") .setRuleKey("NewRuleKey") .setRepositoryKey("plugin") @@ -453,7 +450,7 @@ public class RuleDaoTest { underTest.insert(db.getSession(), newRule); db.getSession().commit(); - RuleDefinitionDto ruleDto = underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of("plugin", "NewRuleKey")); + RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), RuleKey.of("plugin", "NewRuleKey")); assertThat(ruleDto.getUuid()).isNotNull(); assertThat(ruleDto.getName()).isEqualTo("new name"); assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED); @@ -483,9 +480,9 @@ public class RuleDaoTest { @Test public void update_RuleDefinitionDto() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleDescriptionSectionDto sectionDto = createDefaultRuleDescriptionSection(); - RuleDefinitionDto ruleToUpdate = new RuleDefinitionDto() + RuleDto ruleToUpdate = new RuleDto() .setUuid(rule.getUuid()) .setRuleKey("NewRuleKey") .setRepositoryKey("plugin") @@ -513,7 +510,7 @@ public class RuleDaoTest { underTest.update(db.getSession(), ruleToUpdate); db.getSession().commit(); - RuleDefinitionDto ruleDto = underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of("plugin", "NewRuleKey")); + RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), RuleKey.of("plugin", "NewRuleKey")); assertThat(ruleDto.getName()).isEqualTo("new name"); assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED); assertThat(ruleDto.getRuleKey()).isEqualTo("NewRuleKey"); @@ -543,7 +540,7 @@ public class RuleDaoTest { @Test public void update_rule_sections_add_new_section() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleDescriptionSectionDto existingSection = rule.getRuleDescriptionSectionDtos().iterator().next(); RuleDescriptionSectionDto newSection = RuleDescriptionSectionDto.builder() .uuid(randomAlphanumeric(20)) @@ -556,7 +553,7 @@ public class RuleDaoTest { underTest.update(db.getSession(), rule); db.getSession().commit(); - RuleDefinitionDto ruleDto = underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey())); + RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey())); assertThat(ruleDto.getRuleDescriptionSectionDtos()) .usingRecursiveFieldByFieldElementComparator() @@ -565,7 +562,7 @@ public class RuleDaoTest { @Test public void update_rule_sections_replaces_section() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleDescriptionSectionDto existingSection = rule.getRuleDescriptionSectionDtos().iterator().next(); RuleDescriptionSectionDto replacingSection = RuleDescriptionSectionDto.builder() .uuid(randomAlphanumeric(20)) @@ -578,7 +575,7 @@ public class RuleDaoTest { underTest.update(db.getSession(), rule); db.getSession().commit(); - RuleDefinitionDto ruleDto = underTest.selectOrFailDefinitionByKey(db.getSession(), RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey())); + RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey())); assertThat(ruleDto.getRuleDescriptionSectionDtos()) .usingRecursiveFieldByFieldElementComparator() @@ -587,26 +584,24 @@ public class RuleDaoTest { @Test public void update_RuleMetadataDto_inserts_row_in_RULE_METADATA_if_not_exists_yet() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); + + rule.setNoteData("My note"); + rule.setNoteUserUuid("admin"); + rule.setNoteCreatedAt(DateUtils.parseDate("2013-12-19").getTime()); + rule.setNoteUpdatedAt(DateUtils.parseDate("2013-12-20").getTime()); + rule.setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()); + rule.setRemediationGapMultiplier("1h"); + rule.setRemediationBaseEffort("5min"); + rule.setTags(newHashSet("tag1", "tag2")); + rule.setAdHocName("ad hoc name"); + rule.setAdHocDescription("ad hoc desc"); + rule.setAdHocSeverity(Severity.BLOCKER); + rule.setAdHocType(RuleType.CODE_SMELL); + rule.setCreatedAt(3_500_000_000_000L); + rule.setUpdatedAt(4_000_000_000_000L); - RuleMetadataDto metadataToUpdate = new RuleMetadataDto() - .setRuleUuid(rule.getUuid()) - .setNoteData("My note") - .setNoteUserUuid("admin") - .setNoteCreatedAt(DateUtils.parseDate("2013-12-19").getTime()) - .setNoteUpdatedAt(DateUtils.parseDate("2013-12-20").getTime()) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setRemediationGapMultiplier("1h") - .setRemediationBaseEffort("5min") - .setTags(newHashSet("tag1", "tag2")) - .setAdHocName("ad hoc name") - .setAdHocDescription("ad hoc desc") - .setAdHocSeverity(Severity.BLOCKER) - .setAdHocType(RuleType.CODE_SMELL) - .setCreatedAt(3_500_000_000_000L) - .setUpdatedAt(4_000_000_000_000L); - - underTest.insertOrUpdate(db.getSession(), metadataToUpdate); + underTest.update(db.getSession(), rule); db.getSession().commit(); RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), rule.getKey()); @@ -623,7 +618,7 @@ public class RuleDaoTest { assertThat(ruleDto.getAdHocSeverity()).isEqualTo(Severity.BLOCKER); assertThat(ruleDto.getAdHocType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); assertThat(ruleDto.getSecurityStandards()).isEmpty(); - assertThat(ruleDto.getCreatedAt()).isEqualTo(3_500_000_000_000L); + assertThat(ruleDto.getCreatedAt()).isEqualTo(rule.getCreatedAt()); assertThat(ruleDto.getUpdatedAt()).isEqualTo(4_000_000_000_000L); // Info from rule definition assertThat(ruleDto.getDefRemediationFunction()).isEqualTo(rule.getDefRemediationFunction()); @@ -636,29 +631,13 @@ public class RuleDaoTest { @Test public void update_RuleMetadataDto_updates_row_in_RULE_METADATA_if_already_exists() { - RuleDefinitionDto rule = db.rules().insert(); - RuleMetadataDto metadataV1 = new RuleMetadataDto() - .setRuleUuid(rule.getUuid()) - .setCreatedAt(3_500_000_000_000L) - .setUpdatedAt(4_000_000_000_000L); - RuleMetadataDto metadataV2 = new RuleMetadataDto() - .setRuleUuid(rule.getUuid()) - .setNoteData("My note") - .setNoteUserUuid("admin") - .setNoteCreatedAt(DateUtils.parseDate("2013-12-19").getTime()) - .setNoteUpdatedAt(DateUtils.parseDate("2013-12-20").getTime()) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setRemediationGapMultiplier("1h") - .setRemediationBaseEffort("5min") - .setTags(newHashSet("tag1", "tag2")) - .setAdHocName("ad hoc name") - .setAdHocDescription("ad hoc desc") - .setAdHocSeverity(Severity.BLOCKER) - .setAdHocType(RuleType.CODE_SMELL) - .setCreatedAt(6_500_000_000_000L) - .setUpdatedAt(7_000_000_000_000L); - - underTest.insertOrUpdate(db.getSession(), metadataV1); + RuleDto rule = db.rules().insert(); + rule.setAdHocDescription("ad-hoc-desc"); + rule.setCreatedAt(3_500_000_000_000L); + rule.setUpdatedAt(4_000_000_000_000L); + + + underTest.update(db.getSession(), rule); db.commit(); assertThat(db.countRowsOfTable("RULES_METADATA")).isOne(); @@ -672,14 +651,30 @@ public class RuleDaoTest { assertThat(ruleDto.getRemediationBaseEffort()).isNull(); assertThat(ruleDto.getTags()).isEmpty(); assertThat(ruleDto.getAdHocName()).isNull(); - assertThat(ruleDto.getAdHocDescription()).isNull(); + assertThat(ruleDto.getAdHocDescription()).isEqualTo("ad-hoc-desc"); assertThat(ruleDto.getAdHocSeverity()).isNull(); assertThat(ruleDto.getAdHocType()).isNull(); assertThat(ruleDto.getSecurityStandards()).isEmpty(); - assertThat(ruleDto.getCreatedAt()).isEqualTo(3_500_000_000_000L); + assertThat(ruleDto.getCreatedAt()).isEqualTo(rule.getCreatedAt()); + assertThat(ruleDto.getMetadata().getCreatedAt()).isEqualTo(rule.getCreatedAt()); assertThat(ruleDto.getUpdatedAt()).isEqualTo(4_000_000_000_000L); - - underTest.insertOrUpdate(db.getSession(), metadataV2); + assertThat(ruleDto.getMetadata().getUpdatedAt()).isEqualTo(4_000_000_000_000L); + + rule.setNoteData("My note"); + rule.setNoteUserUuid("admin"); + rule.setNoteCreatedAt(DateUtils.parseDate("2013-12-19").getTime()); + rule.setNoteUpdatedAt(DateUtils.parseDate("2013-12-20").getTime()); + rule.setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()); + rule.setRemediationGapMultiplier("1h"); + rule.setRemediationBaseEffort("5min"); + rule.setTags(newHashSet("tag1", "tag2")); + rule.setAdHocName("ad hoc name"); + rule.setAdHocDescription("ad hoc desc"); + rule.setAdHocSeverity(Severity.BLOCKER); + rule.setAdHocType(RuleType.CODE_SMELL); + rule.setCreatedAt(6_500_000_000_000L); + rule.setUpdatedAt(7_000_000_000_000L); + underTest.update(db.getSession(), rule); db.commit(); ruleDto = underTest.selectOrFailByKey(db.getSession(), rule.getKey()); @@ -696,20 +691,22 @@ public class RuleDaoTest { assertThat(ruleDto.getAdHocSeverity()).isEqualTo(Severity.BLOCKER); assertThat(ruleDto.getAdHocType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); assertThat(ruleDto.getSecurityStandards()).isEmpty(); - assertThat(ruleDto.getCreatedAt()).isEqualTo(3_500_000_000_000L); + assertThat(ruleDto.getCreatedAt()).isEqualTo(rule.getCreatedAt()); + assertThat(ruleDto.getMetadata().getCreatedAt()).isEqualTo(rule.getCreatedAt()); assertThat(ruleDto.getUpdatedAt()).isEqualTo(7_000_000_000_000L); + assertThat(ruleDto.getMetadata().getUpdatedAt()).isEqualTo(7_000_000_000_000L); } @Test public void select_all_rule_params() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); RuleParamDto ruleParam1 = db.rules().insertRuleParam(rule1); RuleParamDto ruleParam12 = db.rules().insertRuleParam(rule1); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); RuleParamDto ruleParam2 = db.rules().insertRuleParam(rule2); - RuleDefinitionDto rule3 = db.rules().insert(); + RuleDto rule3 = db.rules().insert(); RuleParamDto ruleParam3 = db.rules().insertRuleParam(rule3); List ruleDtos = underTest.selectAllRuleParams(db.getSession()); @@ -722,7 +719,7 @@ public class RuleDaoTest { @Test public void select_parameters_by_rule_key() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule); List ruleDtos = underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey()); @@ -738,9 +735,9 @@ public class RuleDaoTest { @Test public void select_parameters_by_rule_keys() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insertRuleParam(rule1); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); db.rules().insertRuleParam(rule2); assertThat(underTest.selectRuleParamsByRuleKeys(db.getSession(), @@ -752,7 +749,7 @@ public class RuleDaoTest { @Test public void insert_parameter() { - RuleDefinitionDto ruleDefinitionDto = db.rules().insert(); + RuleDto ruleDefinitionDto = db.rules().insert(); RuleParamDto orig = RuleParamDto.createFor(ruleDefinitionDto) .setName("max") @@ -775,7 +772,7 @@ public class RuleDaoTest { @Test public void should_fail_to_insert_duplicate_parameter() { - RuleDefinitionDto ruleDefinitionDto = db.rules().insert(); + RuleDto ruleDefinitionDto = db.rules().insert(); RuleParamDto param = RuleParamDto.createFor(ruleDefinitionDto) .setName("max") @@ -791,7 +788,7 @@ public class RuleDaoTest { @Test public void update_parameter() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule); List params = underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey()); @@ -814,7 +811,7 @@ public class RuleDaoTest { @Test public void delete_parameter() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule); assertThat(underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey())).hasSize(1); @@ -840,10 +837,10 @@ public class RuleDaoTest { .uuid("uuid") .content("my description") .build(); - RuleDefinitionDto r1 = db.rules().insert(r -> { + RuleDto r1 = db.rules().insert(r -> { r.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); }); - RuleDefinitionDto r2 = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto r2 = db.rules().insert(r -> r.setIsExternal(true)); underTest.selectIndexingRules(db.getSession(), accumulator); @@ -862,6 +859,7 @@ public class RuleDaoTest { assertThat(firstRule.getRuleDescriptionSectionsDtos().stream() .filter(s -> s.getKey().equals(ruleDescriptionSectionDto.getKey())) .collect(MoreCollectors.onlyElement())) + .usingRecursiveComparison() .isEqualTo(ruleDescriptionSectionDto); assertThat(firstRule.getDescriptionFormat()).isEqualTo(r1.getDescriptionFormat()); assertThat(firstRule.getSeverity()).isEqualTo(r1.getSeverity()); @@ -884,9 +882,12 @@ public class RuleDaoTest { @Test public void scrollIndexingRules_maps_rule_definition_fields_for_regular_rule_and_template_rule() { Accumulator accumulator = new Accumulator<>(); - RuleDefinitionDto r1 = db.rules().insert(); - RuleMetadataDto r1Metadatas = db.rules().insertOrUpdateMetadata(r1, r -> r.setTagsField("t1,t2")); - RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1.getUuid())); + RuleDto r1 = db.rules().insert(); + r1.setTags(Set.of("t1", "t2")); + r1 = db.rules().update(r1); + + String r1Uuid = r1.getUuid(); + RuleDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1Uuid)); underTest.selectIndexingRules(db.getSession(), accumulator); @@ -894,11 +895,11 @@ public class RuleDaoTest { RuleForIndexingDto firstRule = findRuleForIndexingWithUuid(accumulator, r1.getUuid()); RuleForIndexingDto secondRule = findRuleForIndexingWithUuid(accumulator, r2.getUuid()); - assertRuleDefinitionFieldsAreEquals(r1, firstRule); - assertRuleMetadataFieldsAreEquals(r1Metadatas, firstRule); + assertRuleDefinitionFieldsAreEquals(r1, r1.getMetadata().getUpdatedAt(), firstRule); + assertRuleMetadataFieldsAreEquals(r1.getMetadata(), firstRule); assertThat(firstRule.getTemplateRuleKey()).isNull(); assertThat(firstRule.getTemplateRepository()).isNull(); - assertRuleDefinitionFieldsAreEquals(r2, secondRule); + assertRuleDefinitionFieldsAreEquals(r2, r2.getUpdatedAt(), secondRule); assertThat(secondRule.getTemplateRuleKey()).isEqualTo(r1.getRuleKey()); assertThat(secondRule.getTemplateRepository()).isEqualTo(r1.getRepositoryKey()); } @@ -914,7 +915,7 @@ public class RuleDaoTest { @Test public void scrollIndexingRulesByKeys() { Accumulator accumulator = new Accumulator<>(); - RuleDefinitionDto r1 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); db.rules().insert(); underTest.selectIndexingRulesByKeys(db.getSession(), singletonList(r1.getUuid()), accumulator); @@ -927,8 +928,8 @@ public class RuleDaoTest { @Test public void scrollIndexingRulesByKeys_maps_rule_definition_fields_for_regular_rule_and_template_rule() { Accumulator accumulator = new Accumulator<>(); - RuleDefinitionDto r1 = db.rules().insert(); - RuleDefinitionDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1.getUuid())); + RuleDto r1 = db.rules().insert(); + RuleDto r2 = db.rules().insert(rule -> rule.setTemplateUuid(r1.getUuid())); underTest.selectIndexingRulesByKeys(db.getSession(), Arrays.asList(r1.getUuid(), r2.getUuid()), accumulator); @@ -936,34 +937,36 @@ public class RuleDaoTest { RuleForIndexingDto firstRule = accumulator.list.stream().filter(t -> t.getUuid().equals(r1.getUuid())).findFirst().get(); RuleForIndexingDto secondRule = accumulator.list.stream().filter(t -> t.getUuid().equals(r2.getUuid())).findFirst().get(); - assertRuleDefinitionFieldsAreEquals(r1, firstRule); + assertRuleDefinitionFieldsAreEquals(r1, r1.getMetadata().getUpdatedAt(), firstRule); assertThat(firstRule.getTemplateRuleKey()).isNull(); assertThat(firstRule.getTemplateRepository()).isNull(); - assertRuleDefinitionFieldsAreEquals(r2, secondRule); + assertRuleDefinitionFieldsAreEquals(r2, r2.getUpdatedAt(), secondRule); assertThat(secondRule.getTemplateRuleKey()).isEqualTo(r1.getRuleKey()); assertThat(secondRule.getTemplateRepository()).isEqualTo(r1.getRepositoryKey()); } - private void assertRuleDefinitionFieldsAreEquals(RuleDefinitionDto r1, RuleForIndexingDto firstRule) { - assertThat(firstRule.getUuid()).isEqualTo(r1.getUuid()); - assertThat(firstRule.getRuleKey()).isEqualTo(r1.getKey()); - assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey()); - assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey()); - assertThat(firstRule.getName()).isEqualTo(r1.getName()); - assertThat(firstRule.getRuleDescriptionSectionsDtos()).isEqualTo(r1.getRuleDescriptionSectionDtos()); - assertThat(firstRule.getDescriptionFormat()).isEqualTo(r1.getDescriptionFormat()); - assertThat(firstRule.getSeverity()).isEqualTo(r1.getSeverity()); - assertThat(firstRule.getSeverityAsString()).isEqualTo(SeverityUtil.getSeverityFromOrdinal(r1.getSeverity())); - assertThat(firstRule.getStatus()).isEqualTo(r1.getStatus()); - assertThat(firstRule.isTemplate()).isEqualTo(r1.isTemplate()); - assertThat(firstRule.getSystemTags()).isEqualTo(r1.getSystemTags()); - assertThat(firstRule.getSecurityStandards()).isEqualTo(r1.getSecurityStandards()); - assertThat(firstRule.getInternalKey()).isEqualTo(r1.getConfigKey()); - assertThat(firstRule.getLanguage()).isEqualTo(r1.getLanguage()); - assertThat(firstRule.getType()).isEqualTo(r1.getType()); - assertThat(firstRule.getTypeAsRuleType()).isEqualTo(RuleType.valueOf(r1.getType())); - assertThat(firstRule.getCreatedAt()).isEqualTo(r1.getCreatedAt()); - assertThat(firstRule.getUpdatedAt()).isEqualTo(r1.getUpdatedAt()); + private void assertRuleDefinitionFieldsAreEquals(RuleDto r1, long updatedAt, RuleForIndexingDto ruleForIndexing) { + assertThat(ruleForIndexing.getUuid()).isEqualTo(r1.getUuid()); + assertThat(ruleForIndexing.getRuleKey()).isEqualTo(r1.getKey()); + assertThat(ruleForIndexing.getRepository()).isEqualTo(r1.getRepositoryKey()); + assertThat(ruleForIndexing.getPluginRuleKey()).isEqualTo(r1.getRuleKey()); + assertThat(ruleForIndexing.getName()).isEqualTo(r1.getName()); + assertThat(ruleForIndexing.getRuleDescriptionSectionsDtos()) + .usingRecursiveComparison() + .isEqualTo(r1.getRuleDescriptionSectionDtos()); + assertThat(ruleForIndexing.getDescriptionFormat()).isEqualTo(r1.getDescriptionFormat()); + assertThat(ruleForIndexing.getSeverity()).isEqualTo(r1.getSeverity()); + assertThat(ruleForIndexing.getSeverityAsString()).isEqualTo(SeverityUtil.getSeverityFromOrdinal(r1.getSeverity())); + assertThat(ruleForIndexing.getStatus()).isEqualTo(r1.getStatus()); + assertThat(ruleForIndexing.isTemplate()).isEqualTo(r1.isTemplate()); + assertThat(ruleForIndexing.getSystemTags()).isEqualTo(r1.getSystemTags()); + assertThat(ruleForIndexing.getSecurityStandards()).isEqualTo(r1.getSecurityStandards()); + assertThat(ruleForIndexing.getInternalKey()).isEqualTo(r1.getConfigKey()); + assertThat(ruleForIndexing.getLanguage()).isEqualTo(r1.getLanguage()); + assertThat(ruleForIndexing.getType()).isEqualTo(r1.getType()); + assertThat(ruleForIndexing.getTypeAsRuleType()).isEqualTo(RuleType.valueOf(r1.getType())); + assertThat(ruleForIndexing.getCreatedAt()).isEqualTo(r1.getCreatedAt()); + assertThat(ruleForIndexing.getUpdatedAt()).isEqualTo(updatedAt); } private static void assertRuleMetadataFieldsAreEquals(RuleMetadataDto r1Metadatas, RuleForIndexingDto firstRule) { @@ -984,9 +987,9 @@ public class RuleDaoTest { @Test public void scrollIndexingRuleExtensionsByIds() { Accumulator accumulator = new Accumulator<>(); - RuleDefinitionDto r1 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); RuleMetadataDto r1Extension = db.rules().insertOrUpdateMetadata(r1, r -> r.setTagsField("t1,t2")); - RuleDefinitionDto r2 = db.rules().insert(); + RuleDto r2 = db.rules().insert(); db.rules().insertOrUpdateMetadata(r2, r -> r.setTagsField("t1,t3")); underTest.scrollIndexingRuleExtensionsByIds(db.getSession(), singletonList(r1.getUuid()), accumulator); @@ -999,8 +1002,8 @@ public class RuleDaoTest { @Test public void selectAllDeprecatedRuleKeys() { - RuleDefinitionDto r1 = db.rules().insert(); - RuleDefinitionDto r2 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); + RuleDto r2 = db.rules().insert(); db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r1.getUuid())); db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r2.getUuid())); @@ -1013,10 +1016,10 @@ public class RuleDaoTest { @Test public void selectDeprecatedRuleKeysByRuleUuids() { - RuleDefinitionDto r1 = db.rules().insert(); - RuleDefinitionDto r2 = db.rules().insert(); - RuleDefinitionDto r3 = db.rules().insert(); - RuleDefinitionDto r4 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); + RuleDto r2 = db.rules().insert(); + RuleDto r3 = db.rules().insert(); + RuleDto r4 = db.rules().insert(); DeprecatedRuleKeyDto drk1 = db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r1.getUuid())); DeprecatedRuleKeyDto drk2 = db.rules().insertDeprecatedKey(r -> r.setRuleUuid(r1.getUuid())); @@ -1083,7 +1086,7 @@ public class RuleDaoTest { @Test public void insertDeprecatedRuleKey() { - RuleDefinitionDto r1 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); DeprecatedRuleKeyDto deprecatedRuleKeyDto = db.rules().insertDeprecatedKey(d -> d.setRuleUuid(r1.getUuid())); db.getSession().commit(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java deleted file mode 100644 index 9c743478a98..00000000000 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.db.rule; - -import org.junit.Test; -import org.sonar.core.util.Uuids; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.db.rule.RuleTesting.newRule; - -public class RuleDefinitionDtoTest { - - @Test - public void equals_is_based_on_uuid() { - String uuid = Uuids.createFast(); - RuleDefinitionDto dto = newRule().setUuid(uuid); - - assertThat(dto) - .isEqualTo(dto) - .isEqualTo(newRule().setUuid(uuid)) - .isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)) - .isNotNull() - .isNotEqualTo(new Object()) - .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast())) - .isNotEqualTo(newRule().setUuid(Uuids.createFast())); - } - - @Test - public void hashcode_is_based_on_uuid() { - String uuid = Uuids.createFast(); - RuleDefinitionDto dto = newRule().setUuid(uuid); - - assertThat(dto) - .hasSameHashCodeAs(dto) - .hasSameHashCodeAs(newRule().setUuid(uuid)) - .hasSameHashCodeAs(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)); - assertThat(dto.hashCode()) - .isNotEqualTo(new Object().hashCode()) - .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()).hashCode()) - .isNotEqualTo(newRule().setUuid(Uuids.createFast()).hashCode()); - } -} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java index 229a1860930..6696b22547b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java @@ -28,19 +28,6 @@ public class RuleDescriptionSectionDtoTest { .uuid("uuid") .content("desc").build(); - @Test - public void testEquals() { - - Assertions.assertThat(RuleDescriptionSectionDto.builder() - .key("key") - .uuid("uuid") - .content("desc") - .build()) - .isEqualTo(SECTION); - - Assertions.assertThat(SECTION).isEqualTo(SECTION); - } - @Test public void testToString() { Assertions.assertThat(SECTION).hasToString("RuleDescriptionSectionDto[uuid='uuid', key='key', content='desc']"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java index 09a6fd6f4f1..6f7ed24fa85 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java @@ -23,10 +23,12 @@ import com.google.common.collect.ImmutableSet; import java.util.Collections; import java.util.Set; import org.junit.Test; +import org.sonar.core.util.Uuids; import static org.apache.commons.lang.StringUtils.repeat; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.sonar.db.rule.RuleTesting.newRule; public class RuleDtoTest { @@ -60,4 +62,34 @@ public class RuleDtoTest { RuleDto dto = new RuleDto().setTags(Collections.emptySet()); assertThat(dto.getTags()).isEmpty(); } + + @Test + public void equals_is_based_on_uuid() { + String uuid = Uuids.createFast(); + RuleDto dto = newRule().setUuid(uuid); + + assertThat(dto) + .isEqualTo(dto) + .isEqualTo(newRule().setUuid(uuid)) + .isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast())) + .isNotEqualTo(newRule().setUuid(Uuids.createFast())); + } + + @Test + public void hashcode_is_based_on_uuid() { + String uuid = Uuids.createFast(); + RuleDto dto = newRule().setUuid(uuid); + + assertThat(dto) + .hasSameHashCodeAs(dto) + .hasSameHashCodeAs(newRule().setUuid(uuid)) + .hasSameHashCodeAs(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)); + assertThat(dto.hashCode()) + .isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()).hashCode()) + .isNotEqualTo(newRule().setUuid(Uuids.createFast()).hashCode()); + } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java index fcf97674806..595183d387d 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java @@ -31,7 +31,7 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import static com.google.common.base.Preconditions.checkArgument; @@ -55,7 +55,7 @@ public class IssueDbTester { * Inserts an issue or a security hotspot. */ @SafeVarargs - public final IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { + public final IssueDto insert(RuleDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { IssueDto issue = newIssue(rule, project, file); stream(populators).forEach(p -> p.accept(issue)); return insert(issue); @@ -66,7 +66,7 @@ public class IssueDbTester { */ @SafeVarargs public final IssueDto insert(Consumer... populators) { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file); @@ -89,7 +89,7 @@ public class IssueDbTester { * @throws AssertionError if rule is a Security Hotspot */ @SafeVarargs - public final IssueDto insertIssue(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { + public final IssueDto insertIssue(RuleDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { assertThat(rule.getType()) .describedAs("rule must not be a Security Hotspot type") .isNotEqualTo(SECURITY_HOTSPOT.getDbConstant()); @@ -100,7 +100,7 @@ public class IssueDbTester { } @SafeVarargs - public final IssueDto insert(RuleDefinitionDto rule, ProjectDto project, ComponentDto file, Consumer... populators) { + public final IssueDto insert(RuleDto rule, ProjectDto project, ComponentDto file, Consumer... populators) { IssueDto issue = newIssue(rule, project, file); stream(populators).forEach(p -> p.accept(issue)); return insert(issue); @@ -125,7 +125,7 @@ public class IssueDbTester { */ @SafeVarargs public final IssueDto insertIssue(Consumer... populators) { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file) @@ -140,7 +140,7 @@ public class IssueDbTester { * @throws AssertionError if rule is not Security Hotspot */ @SafeVarargs - public final IssueDto insertHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { + public final IssueDto insertHotspot(RuleDto rule, ComponentDto project, ComponentDto file, Consumer... populators) { checkArgument(rule.getType() == RuleType.SECURITY_HOTSPOT.getDbConstant(), "rule must be a hotspot rule"); IssueDto issue = newIssue(rule, project, file) @@ -156,7 +156,7 @@ public class IssueDbTester { */ @SafeVarargs public final IssueDto insertHotspot(ComponentDto project, ComponentDto file, Consumer... populators) { - RuleDefinitionDto rule = db.rules().insertHotspotRule(); + RuleDto rule = db.rules().insertHotspotRule(); IssueDto issue = newIssue(rule, project, file) .setType(SECURITY_HOTSPOT) .setStatus(Issue.STATUS_TO_REVIEW) @@ -182,7 +182,7 @@ public class IssueDbTester { */ @SafeVarargs public final IssueDto insertHotspot(Consumer... populators) { - RuleDefinitionDto rule = db.rules().insertHotspotRule(); + RuleDto rule = db.rules().insertHotspotRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java index 688744b1295..afc0584eeef 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java @@ -28,7 +28,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; @@ -87,12 +87,12 @@ public class QualityProfileDbTester { return this; } - public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule) { + public ActiveRuleDto activateRule(QProfileDto profile, RuleDto rule) { return activateRule(profile, rule, ar -> { }); } - public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule, Consumer consumer) { + public ActiveRuleDto activateRule(QProfileDto profile, RuleDto rule, Consumer consumer) { ActiveRuleDto activeRule = createFor(profile, rule) .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) .setCreatedAt(nextLong()) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java index 89136c070d6..0c09ee46243 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java @@ -24,13 +24,11 @@ import java.util.Random; import java.util.function.Consumer; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; -import org.sonar.api.server.rule.RuleParamType; import org.sonar.core.util.Uuids; import org.sonar.db.DbTester; import org.sonar.db.user.UserDto; import static java.util.Arrays.asList; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.db.rule.RuleTesting.newDeprecatedRuleKey; import static org.sonar.db.rule.RuleTesting.newRule; @@ -46,72 +44,72 @@ public class RuleDbTester { this.db = db; } - public RuleDefinitionDto insert() { + public RuleDto insert() { return insert(newRule()); } - public RuleDefinitionDto insert(RuleKey key) { + public RuleDto insert(RuleKey key) { return insert(newRule(key)); } @SafeVarargs - public final RuleDefinitionDto insert(Consumer... populaters) { - RuleDefinitionDto rule = newRule(); + public final RuleDto insert(Consumer... populaters) { + RuleDto rule = newRule(); asList(populaters).forEach(populater -> populater.accept(rule)); return insert(rule); } - public RuleDefinitionDto insert(RuleKey key, Consumer populater) { - RuleDefinitionDto rule = newRule(key); + public RuleDto insert(RuleKey key, Consumer populater) { + RuleDto rule = newRule(key); populater.accept(rule); return insert(rule); } - public RuleDefinitionDto insertIssueRule() { + public RuleDto insertIssueRule() { return insert(newIssueRule()); } - public RuleDefinitionDto insertIssueRule(RuleKey key) { + public RuleDto insertIssueRule(RuleKey key) { return insert(newIssueRule(key)); } @SafeVarargs - public final RuleDefinitionDto insertIssueRule(Consumer... populaters) { - RuleDefinitionDto rule = newIssueRule(); + public final RuleDto insertIssueRule(Consumer... populaters) { + RuleDto rule = newIssueRule(); asList(populaters).forEach(populater -> populater.accept(rule)); return insert(rule); } - public RuleDefinitionDto insertIssueRule(RuleKey key, Consumer populater) { - RuleDefinitionDto rule = newIssueRule(key); + public RuleDto insertIssueRule(RuleKey key, Consumer populater) { + RuleDto rule = newIssueRule(key); populater.accept(rule); return insert(rule); } - private static RuleDefinitionDto newIssueRule(RuleKey key) { + private static RuleDto newIssueRule(RuleKey key) { return newRule(key).setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]); } - private static RuleDefinitionDto newIssueRule() { + private static RuleDto newIssueRule() { return newRule().setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]); } - public RuleDefinitionDto insertHotspotRule() { + public RuleDto insertHotspotRule() { return insert(newHotspotRule()); } @SafeVarargs - public final RuleDefinitionDto insertHotspotRule(Consumer... populaters) { - RuleDefinitionDto rule = newHotspotRule(); + public final RuleDto insertHotspotRule(Consumer... populaters) { + RuleDto rule = newHotspotRule(); asList(populaters).forEach(populater -> populater.accept(rule)); return insert(rule); } - private static RuleDefinitionDto newHotspotRule() { + private static RuleDto newHotspotRule() { return newRule().setType(SECURITY_HOTSPOT); } - public RuleDefinitionDto insert(RuleDefinitionDto rule) { + public RuleDto insert(RuleDto rule) { if (rule.getUuid() == null) { rule.setUuid(Uuids.createFast()); } @@ -121,39 +119,34 @@ public class RuleDbTester { return rule; } - public RuleDefinitionDto update(RuleDefinitionDto rule) { + public RuleDto update(RuleDto rule) { db.getDbClient().ruleDao().update(db.getSession(), rule); db.commit(); return rule; } @SafeVarargs - public final RuleMetadataDto insertOrUpdateMetadata(RuleDefinitionDto rule, Consumer... populaters) { + public final RuleMetadataDto insertOrUpdateMetadata(RuleDto rule, Consumer... populaters) { RuleMetadataDto dto = RuleTesting.newRuleMetadata(rule); asList(populaters).forEach(populater -> populater.accept(dto)); return insertOrUpdateMetadata(dto); } @SafeVarargs - public final RuleMetadataDto insertOrUpdateMetadata(RuleDefinitionDto rule, UserDto noteUser, Consumer... populaters) { + public final RuleMetadataDto insertOrUpdateMetadata(RuleDto rule, UserDto noteUser, Consumer... populaters) { RuleMetadataDto dto = RuleTesting.newRuleMetadata(rule, noteUser); asList(populaters).forEach(populater -> populater.accept(dto)); return insertOrUpdateMetadata(dto); } public RuleMetadataDto insertOrUpdateMetadata(RuleMetadataDto metadata) { - db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), metadata); + db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), metadata); db.commit(); - return metadata; - } - - public RuleParamDto insertRuleParam(RuleDefinitionDto rule) { - return insertRuleParam(rule, p -> { - }); + return db.getDbClient().ruleDao().selectByUuid(metadata.getRuleUuid(), db.getSession()).get().getMetadata(); } @SafeVarargs - public final RuleParamDto insertRuleParam(RuleDefinitionDto rule, Consumer... populaters) { + public final RuleParamDto insertRuleParam(RuleDto rule, Consumer... populaters) { RuleParamDto param = RuleTesting.newRuleParam(rule); asList(populaters).forEach(populater -> populater.accept(param)); db.getDbClient().ruleDao().insertRuleParam(db.getSession(), rule, param); @@ -166,9 +159,9 @@ public class RuleDbTester { ruleDto.setUuid(Uuids.createFast()); } - insert(ruleDto.getDefinition()); + insert(ruleDto); RuleMetadataDto metadata = ruleDto.getMetadata(); - db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), metadata.setRuleUuid(ruleDto.getUuid())); + db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), metadata.setRuleUuid(ruleDto.getUuid())); db.commit(); return ruleDto; } @@ -207,19 +200,9 @@ public class RuleDbTester { return deprecatedRuleKeyDto; } - public RuleParamDto insertRuleParam(RuleDto rule) { - RuleParamDto param = new RuleParamDto(); - param.setRuleUuid(rule.getUuid()); - param.setName(randomAlphabetic(10)); - param.setType(RuleParamType.STRING.type()); - db.getDbClient().ruleDao().insertRuleParam(db.getSession(), rule.getDefinition(), param); - db.commit(); - return param; - } - - public RuleDto insertRule(RuleDefinitionDto ruleDefinition, RuleMetadataDto ruleMetadata) { - db.getDbClient().ruleDao().insertOrUpdate(db.getSession(), ruleMetadata.setRuleUuid(ruleDefinition.getUuid())); + public RuleDto insertRule(RuleDto ruleDto, RuleMetadataDto ruleMetadata) { + db.getDbClient().ruleDao().insertOrUpdateRuleMetadata(db.getSession(), ruleMetadata.setRuleUuid(ruleDto.getUuid())); db.commit(); - return new RuleDto(ruleDefinition, ruleMetadata); + return db.getDbClient().ruleDao().selectOrFailByKey(db.getSession(), ruleDto.getKey()); } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java index d2c72d2ef46..c511d78af71 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java @@ -60,23 +60,23 @@ public class RuleTesting { // only static helpers } - public static RuleDefinitionDto newRule() { + public static RuleDto newRule() { return newRule(randomRuleKey()); } - public static RuleDefinitionDto newRule(RuleKey key) { - RuleDefinitionDto ruleDefinitionDto = newRuleWithoutDescriptionSection(key); - ruleDefinitionDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "description_" + randomAlphabetic(5))); - return ruleDefinitionDto; + public static RuleDto newRule(RuleKey key) { + RuleDto ruleDto = newRuleWithoutDescriptionSection(key); + ruleDto.addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "description_" + randomAlphabetic(5))); + return ruleDto; } - public static RuleDefinitionDto newRuleWithoutDescriptionSection() { + public static RuleDto newRuleWithoutDescriptionSection() { return newRuleWithoutDescriptionSection(randomRuleKey()); } - public static RuleDefinitionDto newRuleWithoutDescriptionSection(RuleKey ruleKey) { + public static RuleDto newRuleWithoutDescriptionSection(RuleKey ruleKey) { long currentTimeMillis = System.currentTimeMillis(); - return new RuleDefinitionDto() + return new RuleDto() .setRepositoryKey(ruleKey.repository()) .setRuleKey(ruleKey.rule()) .setUuid("rule_uuid_" + randomAlphanumeric(5)) @@ -116,20 +116,20 @@ public class RuleTesting { .setAdHocDescription("adHocDescription_" + randomAlphanumeric(5)) .setAdHocSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) .setAdHocType(RuleType.values()[nextInt(RuleType.values().length - 1)]) - .setCreatedAt(System.currentTimeMillis() - 100) - .setUpdatedAt(System.currentTimeMillis() - 50); + .setCreatedAt(System.currentTimeMillis()) + .setUpdatedAt(System.currentTimeMillis() + 50); } - public static RuleMetadataDto newRuleMetadata(RuleDefinitionDto rule) { + public static RuleMetadataDto newRuleMetadata(RuleDto rule) { return newRuleMetadata() .setRuleUuid(rule.getUuid()); } - public static RuleMetadataDto newRuleMetadata(RuleDefinitionDto rule, UserDto noteUser) { + public static RuleMetadataDto newRuleMetadata(RuleDto rule, UserDto noteUser) { return newRuleMetadata(rule).setNoteUserUuid(noteUser.getUuid()); } - public static RuleParamDto newRuleParam(RuleDefinitionDto rule) { + public static RuleParamDto newRuleParam(RuleDto rule) { return new RuleParamDto() .setRuleUuid(rule.getUuid()) .setName("name_" + randomAlphabetic(5)) @@ -216,19 +216,8 @@ public class RuleTesting { .setIsTemplate(true); } - /** - * @deprecated use {@link #newCustomRule(RuleDefinitionDto)} - */ - @Deprecated - public static RuleDto newCustomRule(RuleDto templateRule) { - checkNotNull(templateRule.getUuid(), "The template rule need to be persisted before creating this custom rule."); - return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis())) - .setLanguage(templateRule.getLanguage()) - .setTemplateUuid(templateRule.getUuid()) - .setType(templateRule.getType()); - } - public static RuleDefinitionDto newCustomRule(RuleDefinitionDto templateRule) { + public static RuleDto newCustomRule(RuleDto templateRule) { checkNotNull(templateRule.getUuid(), "The template rule need to be persisted before creating this custom rule."); return newRule(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis())) .setLanguage(templateRule.getLanguage()) @@ -244,59 +233,59 @@ public class RuleTesting { return RuleKey.of(randomAlphabetic(255), randomAlphabetic(200)); } - public static Consumer setRepositoryKey(String repositoryKey) { + public static Consumer setRepositoryKey(String repositoryKey) { return rule -> rule.setRepositoryKey(repositoryKey); } - public static Consumer setCreatedAt(long createdAt) { + public static Consumer setCreatedAt(long createdAt) { return rule -> rule.setCreatedAt(createdAt); } - public static Consumer setUpdatedAt(long updatedtAt) { + public static Consumer setUpdatedAt(long updatedtAt) { return rule -> rule.setUpdatedAt(updatedtAt); } - public static Consumer setRuleKey(String ruleKey) { + public static Consumer setRuleKey(String ruleKey) { return rule -> rule.setRuleKey(ruleKey); } - public static Consumer setName(String name) { + public static Consumer setName(String name) { return rule -> rule.setName(name); } - public static Consumer setLanguage(String language) { + public static Consumer setLanguage(String language) { return rule -> rule.setLanguage(language); } - public static Consumer setSeverity(String severity) { + public static Consumer setSeverity(String severity) { return rule -> rule.setSeverity(severity); } - public static Consumer setStatus(RuleStatus status) { + public static Consumer setStatus(RuleStatus status) { return rule -> rule.setStatus(status); } - public static Consumer setType(RuleType type) { + public static Consumer setType(RuleType type) { return rule -> rule.setType(type); } - public static Consumer setIsExternal(boolean isExternal) { + public static Consumer setIsExternal(boolean isExternal) { return rule -> rule.setIsExternal(isExternal); } - public static Consumer setSecurityStandards(Set securityStandards) { + public static Consumer setSecurityStandards(Set securityStandards) { return rule -> rule.setSecurityStandards(securityStandards); } - public static Consumer setIsTemplate(boolean isTemplate) { + public static Consumer setIsTemplate(boolean isTemplate) { return rule -> rule.setIsTemplate(isTemplate); } - public static Consumer setTemplateId(@Nullable String templateUuid) { + public static Consumer setTemplateId(@Nullable String templateUuid) { return rule -> rule.setTemplateUuid(templateUuid); } - public static Consumer setSystemTags(String... tags) { + public static Consumer setSystemTags(String... tags) { return rule -> rule.setSystemTags(copyOf(tags)); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/VarcharColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/VarcharColumnDef.java index f7bfff8887c..56982a3f551 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/VarcharColumnDef.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/VarcharColumnDef.java @@ -43,6 +43,7 @@ public class VarcharColumnDef extends AbstractColumnDef { public static final int UUID_VARCHAR_SIZE = 50; public static final int UUID_SIZE = 40; + public static final int DESCRIPTION_SECTION_KEY_SIZE = 50; /** * UUID length of the USERS table is not using the standard UUID length. * The reason of this is because when the UUID column was introduced in the USERS table, existing rows were fed with the login, which has a length of 255. diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java index b9bf5f88018..b96b83267df 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/CreateRuleDescSectionsTable.java @@ -25,6 +25,7 @@ import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; import org.sonar.server.platform.db.migration.step.CreateTableChange; import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.DESCRIPTION_SECTION_KEY_SIZE; import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; @@ -32,6 +33,7 @@ public class CreateRuleDescSectionsTable extends CreateTableChange { static final String RULE_DESCRIPTION_SECTIONS_TABLE = "rule_desc_sections"; + public CreateRuleDescSectionsTable(Database db) { super(db, RULE_DESCRIPTION_SECTIONS_TABLE); } @@ -40,8 +42,8 @@ public class CreateRuleDescSectionsTable extends CreateTableChange { public void execute(Context context, String tableName) throws SQLException { context.execute(new CreateTableBuilder(getDialect(), tableName) .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(40).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setIsNullable(false).setLimit(50).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(UUID_SIZE).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setIsNullable(false).setLimit(DESCRIPTION_SECTION_KEY_SIZE).build()) .addColumn(newClobColumnDefBuilder().setColumnName("content").setIsNullable(false).build()) .build()); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java index ce9604beae7..925c3392828 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java @@ -45,7 +45,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static org.elasticsearch.common.Strings.isNullOrEmpty; import static org.sonar.api.utils.DateUtils.longToDate; import static org.sonar.db.DatabaseUtils.getLong; -import static org.sonar.db.rule.RuleDefinitionDto.deserializeSecurityStandardsString; +import static org.sonar.db.rule.RuleDto.deserializeSecurityStandardsString; import static org.sonar.server.security.SecurityStandards.fromSecurityStandards; /** diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java index 8a0a2f176e9..f73a48241aa 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java @@ -28,7 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.QProfileChangeDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; public class ActiveRuleChange { @@ -45,17 +45,17 @@ public class ActiveRuleChange { private ActiveRuleInheritance inheritance = null; private final Map parameters = new HashMap<>(); - public ActiveRuleChange(Type type, ActiveRuleDto activeRule, RuleDefinitionDto ruleDefinition) { + public ActiveRuleChange(Type type, ActiveRuleDto activeRule, RuleDto ruleDto) { this.type = type; this.key = activeRule.getKey(); - this.ruleUuid = ruleDefinition.getUuid(); + this.ruleUuid = ruleDto.getUuid(); this.activeRule = activeRule; } - public ActiveRuleChange(Type type, ActiveRuleKey key, RuleDefinitionDto ruleDefinition) { + public ActiveRuleChange(Type type, ActiveRuleKey key, RuleDto ruleDto) { this.type = type; this.key = key; - this.ruleUuid = ruleDefinition.getUuid(); + this.ruleUuid = ruleDto.getUuid(); } public ActiveRuleKey getKey() { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java index d423396f329..84edc168bdb 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java @@ -37,7 +37,6 @@ import org.sonar.api.rules.RulePriority; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; @@ -57,23 +56,23 @@ public class DefaultRuleFinder implements ServerRuleFinder { } @Override - public Optional findDtoByKey(RuleKey key) { + public Optional findDtoByKey(RuleKey key) { try (DbSession dbSession = dbClient.openSession(false)) { - return ruleDao.selectDefinitionByKey(dbSession, key) + return ruleDao.selectByKey(dbSession, key) .filter(r -> r.getStatus() != RuleStatus.REMOVED); } } @Override - public Optional findDtoByUuid(String uuid) { + public Optional findDtoByUuid(String uuid) { try (DbSession dbSession = dbClient.openSession(false)) { - return ruleDao.selectDefinitionByUuid(uuid, dbSession) + return ruleDao.selectByUuid(uuid, dbSession) .filter(r -> r.getStatus() != RuleStatus.REMOVED); } } @Override - public Collection findAll() { + public Collection findAll() { try (DbSession dbSession = dbClient.openSession(false)) { return ruleDao.selectEnabled(dbSession); } @@ -149,7 +148,7 @@ public class DefaultRuleFinder implements ServerRuleFinder { .setStatus(rule.getStatus().name()) .setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()])) .setTags(rule.getTags().toArray(new String[rule.getTags().size()])) - .setDescription(getDescriptionAsHtml(rule.getDefinition())); + .setDescription(getDescriptionAsHtml(rule)); List apiParams = new ArrayList<>(); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java index c59cb3cb362..8b09f8ca59b 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java @@ -22,7 +22,7 @@ package org.sonar.server.rule; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleForIndexingDto; import static java.util.Optional.ofNullable; @@ -47,7 +47,7 @@ public class HotspotRuleDescription { this.fixIt = fixIt; } - public static HotspotRuleDescription from(RuleDefinitionDto dto) { + public static HotspotRuleDescription from(RuleDto dto) { String description = RuleDescriptionFormatter.getDescriptionAsHtml(dto); return from(description); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java index 0bfb7851a1a..e4f7aced088 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java @@ -22,7 +22,6 @@ package org.sonar.server.rule; import java.util.Collection; import java.util.Objects; import java.util.Optional; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleForIndexingDto; @@ -35,12 +34,12 @@ public class RuleDescriptionFormatter { private RuleDescriptionFormatter() { /* static helpers */ } - public static String getDescriptionAsHtml(RuleDefinitionDto ruleDefinitionDto) { - if (ruleDefinitionDto.getDescriptionFormat() == null) { + public static String getDescriptionAsHtml(RuleDto ruleDto) { + if (ruleDto.getDescriptionFormat() == null) { return null; } - Collection ruleDescriptionSectionDtos = ruleDefinitionDto.getRuleDescriptionSectionDtos(); - return retrieveDescription(ruleDescriptionSectionDtos, ruleDefinitionDto.getRuleKey(), ruleDefinitionDto.getDescriptionFormat()); + Collection ruleDescriptionSectionDtos = ruleDto.getRuleDescriptionSectionDtos(); + return retrieveDescription(ruleDescriptionSectionDtos, ruleDto.getRuleKey(), Objects.requireNonNull(ruleDto.getDescriptionFormat())); } public static String getDescriptionAsHtml(RuleForIndexingDto ruleForIndexingDto) { @@ -67,9 +66,7 @@ public class RuleDescriptionFormatter { } private static String toHtml(String ruleKey, RuleDto.Format descriptionFormat, RuleDescriptionSectionDto ruleDescriptionSectionDto) { - RuleDto.Format nonNullDescriptionFormat = Objects.requireNonNull(descriptionFormat, - "Rule " + descriptionFormat + " contains section(s) but has no format set"); - switch (nonNullDescriptionFormat) { + switch (descriptionFormat) { case MARKDOWN: return Markdown.convertToHtml(ruleDescriptionSectionDto.getContent()); case HTML: diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java index 4301642c317..eb258ce0384 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/ServerRuleFinder.java @@ -23,13 +23,13 @@ import java.util.Collection; import java.util.Optional; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleFinder; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; public interface ServerRuleFinder extends RuleFinder { - Optional findDtoByKey(RuleKey key); + Optional findDtoByKey(RuleKey key); - Optional findDtoByUuid(String uuid); + Optional findDtoByUuid(String uuid); - Collection findAll(); + Collection findAll(); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java index adee556ce05..9f88638c7a7 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java @@ -40,7 +40,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.es.EsQueueDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.IndexingResult; import org.sonar.server.es.ProjectIndexer; @@ -104,7 +104,7 @@ public class IssueIndexerTest { @Test public void verify_indexed_fields() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo")); ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1")); @@ -138,7 +138,7 @@ public class IssueIndexerTest { @Test public void verify_security_standards_indexation() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setSecurityStandards(new HashSet<>(Arrays.asList("cwe:123", "owaspTop10:a3", "cwe:863")))); + RuleDto rule = db.rules().insert(r -> r.setSecurityStandards(new HashSet<>(Arrays.asList("cwe:123", "owaspTop10:a3", "cwe:863")))); ComponentDto project = db.components().insertPrivateProject(); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo")); ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1")); @@ -170,7 +170,7 @@ public class IssueIndexerTest { @Test public void indexOnAnalysis_indexes_the_issues_of_project() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = db.issues().insert(rule, project, file); @@ -184,7 +184,7 @@ public class IssueIndexerTest { @Test public void indexOnAnalysis_does_not_delete_orphan_docs() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = db.issues().insert(rule, project, file); @@ -289,7 +289,7 @@ public class IssueIndexerTest { @Test public void commitAndIndexIssues_commits_db_transaction_and_adds_issues_to_index() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); @@ -322,7 +322,7 @@ public class IssueIndexerTest { @Test public void indexing_errors_during_commitAndIndexIssues_are_recovered() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); @@ -390,7 +390,7 @@ public class IssueIndexerTest { @Test public void indexing_recovers_multiple_errors_on_the_same_project() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue1 = db.issues().insert(rule, project, file); @@ -480,7 +480,7 @@ public class IssueIndexerTest { @Test public void index_issue_in_non_main_branch() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo")); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(branch, "src/main/java/foo")); @@ -500,7 +500,7 @@ public class IssueIndexerTest { @Test public void issue_on_test_file_has_test_scope() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo")); ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1").setQualifier("UTS")); @@ -516,7 +516,7 @@ public class IssueIndexerTest { @Test public void issue_on_directory_has_main_code_scope() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo")); IssueDto issue = db.issues().insert(rule, project, dir); @@ -531,7 +531,7 @@ public class IssueIndexerTest { @Test public void issue_on_project_has_main_code_scope() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); IssueDto issue = db.issues().insert(rule, project, project); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index b43eb7bc89c..db30320ff42 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -31,7 +31,7 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.component.ComponentTesting.newDirectory; @@ -46,7 +46,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_one_issue() { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project) .setPath("src/main/java/Action.java")); @@ -97,7 +97,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issues() { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, "src/main/java")); @@ -129,7 +129,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issue_from_project() { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project1 = dbTester.components().insertPrivateProject(); ComponentDto module1 = dbTester.components().insertComponent(newModuleDto(project1)); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(module1)); @@ -153,7 +153,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_directory_path() { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); @@ -174,7 +174,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_file_path() { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java index ba166a5ff04..d764d0e24cb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java @@ -30,7 +30,7 @@ import org.sonar.api.utils.Durations; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier; import org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition; @@ -144,8 +144,8 @@ public class NewIssuesNotificationTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "path")); ComponentDto file = db.components().insertComponent(newFileDto(directory)); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); + RuleDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); + RuleDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); IssueDto issue1 = db.issues().insert(rule1, project, file, i -> i.setType(BUG).setAssigneeUuid(maynard.getUuid()).setTags(asList("bug", "owasp"))); IssueDto issue2 = db.issues().insert(rule2, project, directory, i -> i.setType(CODE_SMELL).setAssigneeUuid(keenan.getUuid()).setTags(singletonList("owasp"))); @@ -186,8 +186,8 @@ public class NewIssuesNotificationTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "path")); ComponentDto file = db.components().insertComponent(newFileDto(directory)); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); + RuleDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); + RuleDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); IssueDto issue1 = db.issues().insert(rule1, project, file, i -> i.setType(BUG).setAssigneeUuid(maynard.getUuid()).setTags(asList("bug", "owasp"))); IssueDto issue2 = db.issues().insert(rule2, project, directory, i -> i.setType(CODE_SMELL).setAssigneeUuid(keenan.getUuid()).setTags(singletonList("owasp"))); @@ -229,8 +229,8 @@ public class NewIssuesNotificationTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "path")); ComponentDto file = db.components().insertComponent(newFileDto(directory)); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); + RuleDto rule1 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-world").setName("Rule the World").setLanguage("Java")); + RuleDto rule2 = db.rules().insert(r -> r.setRepositoryKey("SonarQube").setRuleKey("rule1-the-universe").setName("Rule the Universe").setLanguage("Clojure")); IssueDto issue1 = db.issues().insert(rule1, project, file, i -> i.setType(BUG).setAssigneeUuid(maynard.getUuid()).setTags(asList("bug", "owasp"))); IssueDto issue2 = db.issues().insert(rule2, project, directory, i -> i.setType(CODE_SMELL).setAssigneeUuid(keenan.getUuid()).setTags(singletonList("owasp"))); @@ -270,8 +270,8 @@ public class NewIssuesNotificationTest { } } - private void mockDetailsSupplierRules(RuleDefinitionDto... rules) { - for (RuleDefinitionDto rule : rules) { + private void mockDetailsSupplierRules(RuleDto... rules) { + for (RuleDto rule : rules) { when(detailsSupplier.getRuleDefinitionByRuleKey(rule.getKey())) .thenReturn(Optional.of(new RuleDefinition(rule.getName(), rule.getLanguage()))); } @@ -287,7 +287,7 @@ public class NewIssuesNotificationTest { public void set_assignee() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(user.getUuid())); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); @@ -314,7 +314,7 @@ public class NewIssuesNotificationTest { UserDto user8 = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user1.getUuid())).toDefaultIssue())); IntStream.rangeClosed(1, 9).forEach(i -> stats.add(db.issues().insert(rule, project, file, issue -> issue.setAssigneeUuid(user2.getUuid())).toDefaultIssue())); @@ -347,7 +347,7 @@ public class NewIssuesNotificationTest { @Test public void add_only_5_components_with_biggest_issue_counts() { ComponentDto project = db.components().insertPrivateProject(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); ComponentDto file1 = db.components().insertComponent(newFileDto(project)); IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule, project, file1).toDefaultIssue())); @@ -389,21 +389,21 @@ public class NewIssuesNotificationTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 10).forEach(i -> stats.add(db.issues().insert(rule1, project, file).toDefaultIssue())); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 9).forEach(i -> stats.add(db.issues().insert(rule2, project, file).toDefaultIssue())); - RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule3 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 8).forEach(i -> stats.add(db.issues().insert(rule3, project, file).toDefaultIssue())); - RuleDefinitionDto rule4 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule4 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 7).forEach(i -> stats.add(db.issues().insert(rule4, project, file).toDefaultIssue())); - RuleDefinitionDto rule5 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule5 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 6).forEach(i -> stats.add(db.issues().insert(rule5, project, file).toDefaultIssue())); - RuleDefinitionDto rule6 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule6 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 5).forEach(i -> stats.add(db.issues().insert(rule6, project, file).toDefaultIssue())); - RuleDefinitionDto rule7 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule7 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 4).forEach(i -> stats.add(db.issues().insert(rule7, project, file).toDefaultIssue())); - RuleDefinitionDto rule8 = db.rules().insert(r -> r.setLanguage("Java")); + RuleDto rule8 = db.rules().insert(r -> r.setLanguage("Java")); IntStream.rangeClosed(1, 3).forEach(i -> stats.add(db.issues().insert(rule8, project, file).toDefaultIssue())); mockDetailsSupplierComponents(project, file); mockDetailsSupplierRules(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java index 0c239acb830..a3b4ec124f6 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java @@ -25,7 +25,7 @@ import org.sonar.core.util.Uuids; import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto; @@ -40,7 +40,7 @@ public class ActiveRuleChangeTest { QProfileDto profile = newQualityProfileDto(); ActiveRuleKey key = ActiveRuleKey.of(profile, RuleKey.of("P1", "R1")); String ruleUuid = Uuids.createFast(); - ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setUuid(ruleUuid)); + ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDto().setUuid(ruleUuid)); QProfileChangeDto result = underTest.toDto(A_USER_UUID); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index eb15f1c8343..1be83a831ff 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -32,7 +32,7 @@ import org.sonar.db.DbTester; import org.sonar.db.es.EsQueueDto; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.qualityprofile.ActiveRuleChange; @@ -53,8 +53,8 @@ public class ActiveRuleIndexerTest { public EsTester es = EsTester.create(); private ActiveRuleIndexer underTest = new ActiveRuleIndexer(db.getDbClient(), es.client()); - private RuleDefinitionDto rule1; - private RuleDefinitionDto rule2; + private RuleDto rule1; + private RuleDto rule2; private QProfileDto profile1; private QProfileDto profile2; @@ -194,7 +194,7 @@ public class ActiveRuleIndexerTest { .containsExactlyInAnyOrder(Tuple.tuple(expected.getDocId(), expected.getDocIdType(), expected.getDocRouting())); } - private void commitAndIndex(RuleDefinitionDto rule, ActiveRuleDto... ar) { + private void commitAndIndex(RuleDto rule, ActiveRuleDto... ar) { underTest.commitAndIndex(db.getSession(), stream(ar) .map(a -> new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, a, rule)) .collect(Collectors.toList())); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java index 43eccf270ad..8b83e2d5811 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java @@ -30,7 +30,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -111,7 +110,7 @@ public class DefaultRuleFinderTest { assertThat(underTest.findAll(RuleQuery.create())).extracting(Rule::ruleKey).containsOnly(rule1.getKey(), rule3.getKey(), rule4.getKey()); // find_all - assertThat(underTest.findAll()).extracting(RuleDefinitionDto::getRuleKey).containsOnly(rule1.getKey().rule(), rule3.getKey().rule(), rule4.getKey().rule()); + assertThat(underTest.findAll()).extracting(RuleDto::getRuleKey).containsOnly(rule1.getKey().rule(), rule3.getKey().rule(), rule4.getKey().rule()); // do_not_find_disabled_rules assertThat(underTest.findByKey("checkstyle", "DisabledCheck")).isNull(); @@ -133,23 +132,23 @@ public class DefaultRuleFinderTest { public void find_all_not_include_removed_rule() { // rule 3 is REMOVED assertThat(underTest.findAll(RuleQuery.create())).extracting(Rule::ruleKey).containsOnly(rule1.getKey(), rule3.getKey(), rule4.getKey()); - assertThat(underTest.findAll()).extracting(RuleDefinitionDto::getRuleKey).containsOnly(rule1.getKey().rule(), rule3.getKey().rule(), rule4.getKey().rule()); + assertThat(underTest.findAll()).extracting(RuleDto::getRuleKey).containsOnly(rule1.getKey().rule(), rule3.getKey().rule(), rule4.getKey().rule()); } @Test public void findByKey_populates_system_tags_but_not_tags() { - RuleDefinitionDto ruleDefinition = dbTester.rules() + RuleDto ruleDto = dbTester.rules() .insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6)))); dbTester.rules().insertRule(); - Rule rule = underTest.findByKey(ruleDefinition.getKey()); + Rule rule = underTest.findByKey(ruleDto.getKey()); assertThat(rule.getSystemTags()) - .containsOnlyElementsOf(ruleDefinition.getSystemTags()); + .containsOnlyElementsOf(ruleDto.getSystemTags()); assertThat(rule.getTags()).isEmpty(); - rule = underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey()); + rule = underTest.findByKey(ruleDto.getRepositoryKey(), ruleDto.getRuleKey()); assertThat(rule.getSystemTags()) - .containsOnlyElementsOf(ruleDefinition.getSystemTags()); + .containsOnlyElementsOf(ruleDto.getSystemTags()); assertThat(rule.getTags()).isEmpty(); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java index 03983cb664c..07f9045ee5a 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java @@ -24,21 +24,19 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; -import static org.sonar.db.rule.RuleTesting.newRuleWithoutDescriptionSection; @RunWith(DataProviderRunner.class) public class HotspotRuleDescriptionTest { @Test public void parse_returns_all_empty_fields_when_no_description() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection(); + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection(); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -49,7 +47,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_returns_all_empty_fields_when_empty_description() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", "")); + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", "")); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -61,7 +59,7 @@ public class HotspotRuleDescriptionTest { @Test @UseDataProvider("descriptionsWithoutTitles") public void parse_to_risk_description_fields_when_desc_contains_no_section(String description) { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", description)); + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", description)); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -82,7 +80,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_return_null_risk_when_desc_starts_with_ask_yourself_title() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( createDefaultRuleDescriptionSection("uuid", (ASKATRISK + RECOMMENTEDCODINGPRACTICE))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -94,7 +92,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_return_null_vulnerable_when_no_ask_yourself_whether_title() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection() + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection() .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", (DESCRIPTION + RECOMMENTEDCODINGPRACTICE))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -106,7 +104,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_return_null_fixIt_when_desc_has_no_Recommended_Secure_Coding_Practices_title() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection() + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection() .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection("uuid", (DESCRIPTION + ASKATRISK))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -118,7 +116,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_with_noncompliant_section_not_removed() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( createDefaultRuleDescriptionSection("uuid", (DESCRIPTION + NONCOMPLIANTCODE + COMPLIANTCODE))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -130,7 +128,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_moved_noncompliant_code() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( createDefaultRuleDescriptionSection("uuid", (DESCRIPTION + RECOMMENTEDCODINGPRACTICE + NONCOMPLIANTCODE + SEE))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -144,7 +142,7 @@ public class HotspotRuleDescriptionTest { @Test public void parse_moved_sensitivecode_code() { - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection().addRuleDescriptionSectionDto( createDefaultRuleDescriptionSection("uuid", (DESCRIPTION + ASKATRISK + RECOMMENTEDCODINGPRACTICE + SENSITIVECODE + SEE))); HotspotRuleDescription result = HotspotRuleDescription.from(dto); @@ -161,7 +159,7 @@ public class HotspotRuleDescriptionTest { String askContent = "This is the ask section content"; String recommendedContent = "This is the recommended section content"; - RuleDefinitionDto dto = RuleTesting.newRuleWithoutDescriptionSection() + RuleDto dto = RuleTesting.newRuleWithoutDescriptionSection() .setTemplateUuid("123") .setDescriptionFormat(RuleDto.Format.MARKDOWN) .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection( diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java index e550548cbdf..c63f3ebbe8b 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.Set; import org.jetbrains.annotations.NotNull; import org.junit.Test; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleForIndexingDto; @@ -39,21 +38,21 @@ public class RuleDescriptionFormatterTest { @Test public void getMarkdownDescriptionAsHtml() { - RuleDefinitionDto rule = new RuleDefinitionDto().setDescriptionFormat(RuleDto.Format.MARKDOWN).addRuleDescriptionSectionDto(MARKDOWN_SECTION); + RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.MARKDOWN).addRuleDescriptionSectionDto(MARKDOWN_SECTION); String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule); assertThat(html).isEqualTo("md description"); } @Test public void getHtmlDescriptionAsIs() { - RuleDefinitionDto rule = new RuleDefinitionDto().setDescriptionFormat(RuleDto.Format.HTML).addRuleDescriptionSectionDto(HTML_SECTION); + RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.HTML).addRuleDescriptionSectionDto(HTML_SECTION); String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule); assertThat(html).isEqualTo(HTML_SECTION.getContent()); } @Test public void handleEmptyDescription() { - RuleDefinitionDto rule = new RuleDefinitionDto().setDescriptionFormat(RuleDto.Format.HTML); + RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.HTML); String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule); assertThat(result).isNull(); } @@ -61,7 +60,7 @@ public class RuleDescriptionFormatterTest { @Test public void handleNullDescriptionFormat() { RuleDescriptionSectionDto sectionWithNullFormat = createDefaultRuleDescriptionSection("uuid", "whatever"); - RuleDefinitionDto rule = new RuleDefinitionDto().addRuleDescriptionSectionDto(sectionWithNullFormat); + RuleDto rule = new RuleDto().addRuleDescriptionSectionDto(sectionWithNullFormat); String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule); assertThat(result).isNull(); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java index d617fd46c29..f276fb08843 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java @@ -37,7 +37,7 @@ import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; @@ -121,10 +121,10 @@ public class RuleIndexTest { @Test public void search_by_key() { - RuleDefinitionDto js1 = createRule( + RuleDto js1 = createRule( setRepositoryKey("javascript"), setRuleKey("X001")); - RuleDefinitionDto cobol1 = createRule( + RuleDto cobol1 = createRule( setRepositoryKey("cobol"), setRuleKey("X001")); createRule( @@ -147,7 +147,7 @@ public class RuleIndexTest { @Test public void search_by_case_insensitive_key() { - RuleDefinitionDto ruleDto = createRule( + RuleDto ruleDto = createRule( setRepositoryKey("javascript"), setRuleKey("X001")); index(); @@ -203,7 +203,7 @@ public class RuleIndexTest { @Test public void search_name_with_protected_chars() { - RuleDefinitionDto rule = createRule(setName("ja#va&sc\"r:ipt")); + RuleDto rule = createRule(setName("ja#va&sc\"r:ipt")); index(); RuleQuery protectedCharsQuery = new RuleQuery().setQueryText(rule.getName()); @@ -215,20 +215,20 @@ public class RuleIndexTest { public void search_content_by_query() { // it's important to set all the fields being used by the search (name, desc, key, lang, ...), // otherwise the generated random values may raise false-positives - RuleDefinitionDto rule1 = createJavaRule(rule -> rule.setRuleKey("123") + RuleDto rule1 = createJavaRule(rule -> rule.setRuleKey("123") .setName("rule 123") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "My great rule CWE-123 which makes your code 1000 times better!"))); - RuleDefinitionDto rule2 = createJavaRule(rule -> rule.setRuleKey("124") + RuleDto rule2 = createJavaRule(rule -> rule.setRuleKey("124") .setName("rule 124") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Another great and shiny rule CWE-124"))); - RuleDefinitionDto rule3 = createJavaRule(rule -> rule.setRuleKey("1000") + RuleDto rule3 = createJavaRule(rule -> rule.setRuleKey("1000") .setName("rule 1000") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Another great rule CWE-1000"))); - RuleDefinitionDto rule4 = createJavaRule(rule -> rule.setRuleKey("404") + RuleDto rule4 = createJavaRule(rule -> rule.setRuleKey("404") .setName("rule 404") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "

HTML-Geeks

special formatting!

insidetables
"))); - RuleDefinitionDto rule5 = createJavaRule(rule -> rule.setRuleKey("405") + RuleDto rule5 = createJavaRule(rule -> rule.setRuleKey("405") .setName("rule 405") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "internationalization missunderstandings alsdkjfnadklsjfnadkdfnsksdjfn"))); index(); @@ -272,10 +272,10 @@ public class RuleIndexTest { @Test public void search_by_any_of_repositories() { - RuleDefinitionDto findbugs = createRule( + RuleDto findbugs = createRule( setRepositoryKey("findbugs"), setRuleKey("S001")); - RuleDefinitionDto pmd = createRule( + RuleDto pmd = createRule( setRepositoryKey("pmd"), setRuleKey("S002")); index(); @@ -295,9 +295,9 @@ public class RuleIndexTest { @Test public void filter_by_tags() { - RuleDefinitionDto rule1 = createRule(setSystemTags("tag1s")); + RuleDto rule1 = createRule(setSystemTags("tag1s")); createRuleMetadata(rule1, setTags("tag1")); - RuleDefinitionDto rule2 = createRule(setSystemTags("tag2s")); + RuleDto rule2 = createRule(setSystemTags("tag2s")); createRuleMetadata(rule2, setTags("tag2")); index(); @@ -321,7 +321,7 @@ public class RuleIndexTest { @Test public void tags_facet_supports_selected_value_with_regexp_special_characters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); createRuleMetadata(rule, setTags("misra++")); index(); @@ -336,9 +336,9 @@ public class RuleIndexTest { @Test public void search_by_types() { createRule(setType(CODE_SMELL)); - RuleDefinitionDto vulnerability = createRule(setType(VULNERABILITY)); - RuleDefinitionDto bug1 = createRule(setType(BUG)); - RuleDefinitionDto bug2 = createRule(setType(BUG)); + RuleDto vulnerability = createRule(setType(VULNERABILITY)); + RuleDto bug1 = createRule(setType(BUG)); + RuleDto bug2 = createRule(setType(BUG)); index(); // find all @@ -367,8 +367,8 @@ public class RuleIndexTest { @Test public void search_by_is_template() { - RuleDefinitionDto ruleNoTemplate = createRule(setIsTemplate(false)); - RuleDefinitionDto ruleIsTemplate = createRule(setIsTemplate(true)); + RuleDto ruleNoTemplate = createRule(setIsTemplate(false)); + RuleDto ruleIsTemplate = createRule(setIsTemplate(true)); index(); // find all @@ -394,8 +394,8 @@ public class RuleIndexTest { @Test public void search_by_is_external() { - RuleDefinitionDto ruleIsNotExternal = createRule(setIsExternal(false)); - RuleDefinitionDto ruleIsExternal = createRule(setIsExternal(true)); + RuleDto ruleIsNotExternal = createRule(setIsExternal(false)); + RuleDto ruleIsExternal = createRule(setIsExternal(true)); index(); // Only external @@ -411,8 +411,8 @@ public class RuleIndexTest { @Test public void search_by_template_key() { - RuleDefinitionDto template = createRule(setIsTemplate(true)); - RuleDefinitionDto customRule = createRule(setTemplateId(template.getUuid())); + RuleDto template = createRule(setIsTemplate(true)); + RuleDto customRule = createRule(setTemplateId(template.getUuid())); index(); // find all @@ -433,7 +433,7 @@ public class RuleIndexTest { @Test public void search_by_any_of_languages() { createRule(setLanguage("java")); - RuleDefinitionDto javascript = createRule(setLanguage("js")); + RuleDto javascript = createRule(setLanguage("js")); index(); RuleQuery query = new RuleQuery().setLanguages(asList("cobol", "js")); @@ -455,8 +455,8 @@ public class RuleIndexTest { @Test public void search_by_security_cwe_return_vulnerabilities_and_hotspots_only() { - RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("cwe:543", "cwe:123", "owaspTop10:a1")), r -> r.setType(VULNERABILITY)); - RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("cwe:543", "owaspTop10:a1")), r -> r.setType(SECURITY_HOTSPOT)); + RuleDto rule1 = createRule(setSecurityStandards(of("cwe:543", "cwe:123", "owaspTop10:a1")), r -> r.setType(VULNERABILITY)); + RuleDto rule2 = createRule(setSecurityStandards(of("cwe:543", "owaspTop10:a1")), r -> r.setType(SECURITY_HOTSPOT)); createRule(setSecurityStandards(of("owaspTop10:a1")), r -> r.setType(CODE_SMELL)); index(); @@ -467,8 +467,8 @@ public class RuleIndexTest { @Test public void search_by_security_owaspTop10_2017_return_vulnerabilities_and_hotspots_only() { - RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10:a10", "cwe:543")), r -> r.setType(VULNERABILITY)); - RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:543")), r -> r.setType(SECURITY_HOTSPOT)); + RuleDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10:a10", "cwe:543")), r -> r.setType(VULNERABILITY)); + RuleDto rule2 = createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:543")), r -> r.setType(SECURITY_HOTSPOT)); createRule(setSecurityStandards(of("cwe:543")), r -> r.setType(CODE_SMELL)); index(); @@ -479,8 +479,8 @@ public class RuleIndexTest { @Test public void search_by_security_owaspTop10_2021_return_vulnerabilities_and_hotspots_only() { - RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("owaspTop10-2021:a1", "owaspTop10-2021:a10", "cwe:543")), r -> r.setType(VULNERABILITY)); - RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("owaspTop10-2021:a10", "cwe:543")), r -> r.setType(SECURITY_HOTSPOT)); + RuleDto rule1 = createRule(setSecurityStandards(of("owaspTop10-2021:a1", "owaspTop10-2021:a10", "cwe:543")), r -> r.setType(VULNERABILITY)); + RuleDto rule2 = createRule(setSecurityStandards(of("owaspTop10-2021:a10", "cwe:543")), r -> r.setType(SECURITY_HOTSPOT)); createRule(setSecurityStandards(of("cwe:543")), r -> r.setType(CODE_SMELL)); index(); @@ -491,8 +491,8 @@ public class RuleIndexTest { @Test public void search_by_security_sansTop25_return_vulnerabilities_and_hotspots_only() { - RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10:a10", "cwe:89")), r -> r.setType(VULNERABILITY)); - RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:829")), r -> r.setType(SECURITY_HOTSPOT)); + RuleDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10:a10", "cwe:89")), r -> r.setType(VULNERABILITY)); + RuleDto rule2 = createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:829")), r -> r.setType(SECURITY_HOTSPOT)); createRule(setSecurityStandards(of("cwe:306")), r -> r.setType(CODE_SMELL)); index(); @@ -503,9 +503,9 @@ public class RuleIndexTest { @Test public void search_by_security_sonarsource_return_vulnerabilities_and_hotspots_only() { - RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10-2021:a10", "cwe:89")), r -> r.setType(VULNERABILITY)); + RuleDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10-2021:a10", "cwe:89")), r -> r.setType(VULNERABILITY)); createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:829")), r -> r.setType(CODE_SMELL)); - RuleDefinitionDto rule3 = createRule(setSecurityStandards(of("cwe:601")), r -> r.setType(SECURITY_HOTSPOT)); + RuleDto rule3 = createRule(setSecurityStandards(of("cwe:601")), r -> r.setType(SECURITY_HOTSPOT)); index(); RuleQuery query = new RuleQuery().setSonarsourceSecurity(of("sql-injection", "open-redirect")); @@ -516,7 +516,7 @@ public class RuleIndexTest { @Test public void search_by_security_sonarsource_return_complete_list_of_facets() { - List rules = new ArrayList<>(); + List rules = new ArrayList<>(); //Creation of one rule for each standard security category defined (except other) for (Map.Entry> sqCategorySetEntry : SecurityStandards.CWES_BY_SQ_CATEGORY.entrySet()) { @@ -537,12 +537,12 @@ public class RuleIndexTest { String xoo = "xoo"; QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(xoo)); QProfileDto anotherProfile = db.qualityProfiles().insert(p -> p.setLanguage(xoo)); - RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); - RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); - RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); - RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); - RuleDefinitionDto anotherProfileRule1 = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); - RuleDefinitionDto anotherProfileRule2 = db.rules().insertRule(r -> r.setLanguage(xoo)).getDefinition(); + RuleDto commonRule = db.rules().insertRule(r -> r.setLanguage(xoo)); + RuleDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(xoo)); + RuleDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(xoo)); + RuleDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(xoo)); + RuleDto anotherProfileRule1 = db.rules().insertRule(r -> r.setLanguage(xoo)); + RuleDto anotherProfileRule2 = db.rules().insertRule(r -> r.setLanguage(xoo)); db.qualityProfiles().activateRule(profile, commonRule); db.qualityProfiles().activateRule(profile, profileRule1); db.qualityProfiles().activateRule(profile, profileRule2); @@ -559,27 +559,27 @@ public class RuleIndexTest { } @SafeVarargs - private final RuleDefinitionDto createRule(Consumer... consumers) { + private final RuleDto createRule(Consumer... consumers) { return db.rules().insert(consumers); } - private RuleDefinitionDto createJavaRule() { + private RuleDto createJavaRule() { return createRule(r -> r.setLanguage("java")); } - private RuleDefinitionDto createJavaRule(Consumer consumer) { + private RuleDto createJavaRule(Consumer consumer) { return createRule(r -> r.setLanguage("java"), consumer); } @SafeVarargs - private final RuleMetadataDto createRuleMetadata(RuleDefinitionDto rule, Consumer... populaters) { + private final RuleMetadataDto createRuleMetadata(RuleDto rule, Consumer... populaters) { return db.rules().insertOrUpdateMetadata(rule, populaters); } @Test public void search_by_any_of_severities() { createRule(setSeverity(BLOCKER)); - RuleDefinitionDto info = createRule(setSeverity(INFO)); + RuleDto info = createRule(setSeverity(INFO)); index(); RuleQuery query = new RuleQuery().setSeverities(asList(INFO, MINOR)); @@ -601,8 +601,8 @@ public class RuleIndexTest { @Test public void search_by_any_of_statuses() { - RuleDefinitionDto beta = createRule(setStatus(RuleStatus.BETA)); - RuleDefinitionDto ready = createRule(setStatus(RuleStatus.READY)); + RuleDto beta = createRule(setStatus(RuleStatus.BETA)); + RuleDto ready = createRule(setStatus(RuleStatus.READY)); index(); RuleQuery query = new RuleQuery().setStatuses(asList(RuleStatus.DEPRECATED, RuleStatus.READY)); @@ -624,8 +624,8 @@ public class RuleIndexTest { @Test public void activation_parameter_is_ignored_if_profile_is_not_set() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); QProfileDto profile1 = createJavaProfile(); db.qualityProfiles().activateRule(profile1, rule1); index(); @@ -636,9 +636,9 @@ public class RuleIndexTest { @Test public void search_by_activation() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); - RuleDefinitionDto rule3 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); + RuleDto rule3 = createJavaRule(); QProfileDto profile1 = createJavaProfile(); QProfileDto profile2 = createJavaProfile(); db.qualityProfiles().activateRule(profile1, rule1); @@ -659,11 +659,11 @@ public class RuleIndexTest { verifySearch(query); } - private void verifySearch(RuleQuery query, RuleDefinitionDto... expectedRules) { + private void verifySearch(RuleQuery query, RuleDto... expectedRules) { SearchIdResult result = underTest.search(query, new SearchOptions()); assertThat(result.getTotal()).isEqualTo(expectedRules.length); assertThat(result.getUuids()).hasSize(expectedRules.length); - for (RuleDefinitionDto expectedRule : expectedRules) { + for (RuleDto expectedRule : expectedRules) { assertThat(result.getUuids()).contains(expectedRule.getUuid()); } } @@ -683,10 +683,10 @@ public class RuleIndexTest { @Test public void search_by_activation_and_inheritance() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); - RuleDefinitionDto rule3 = createJavaRule(); - RuleDefinitionDto rule4 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); + RuleDto rule3 = createJavaRule(); + RuleDto rule4 = createJavaRule(); QProfileDto parent = createJavaProfile(); QProfileDto child = createJavaProfile(); db.qualityProfiles().activateRule(parent, rule1); @@ -717,9 +717,9 @@ public class RuleIndexTest { @Test public void search_by_activation_and_severity() { - RuleDefinitionDto major = createRule(setSeverity(MAJOR)); - RuleDefinitionDto minor = createRule(setSeverity(MINOR)); - RuleDefinitionDto info = createRule(setSeverity(INFO)); + RuleDto major = createRule(setSeverity(MAJOR)); + RuleDto minor = createRule(setSeverity(MINOR)); + RuleDto info = createRule(setSeverity(INFO)); QProfileDto profile1 = createJavaProfile(); QProfileDto profile2 = createJavaProfile(); db.qualityProfiles().activateRule(profile1, major, ar -> ar.setSeverity(BLOCKER)); @@ -740,7 +740,7 @@ public class RuleIndexTest { @Test public void facet_by_activation_severity_is_ignored_when_profile_is_not_specified() { - RuleDefinitionDto rule = createJavaRule(); + RuleDto rule = createJavaRule(); QProfileDto profile = createJavaProfile(); db.qualityProfiles().activateRule(profile, rule); index(); @@ -762,10 +762,10 @@ public class RuleIndexTest { @Test public void listTags_should_return_tags() { - RuleDefinitionDto rule1 = createRule(setSystemTags("sys1", "sys2")); + RuleDto rule1 = createRule(setSystemTags("sys1", "sys2")); createRuleMetadata(rule1, setTags("tag1")); - RuleDefinitionDto rule2 = createRule(setSystemTags()); + RuleDto rule2 = createRule(setSystemTags()); createRuleMetadata(rule2, setTags("tag2")); index(); @@ -782,28 +782,28 @@ public class RuleIndexTest { @Test public void available_since() { - RuleDefinitionDto ruleOld = createRule(setCreatedAt(1_000L)); - RuleDefinitionDto ruleOlder = createRule(setCreatedAt(2_000L)); + RuleDto ruleOld = createRule(setCreatedAt(-2_000L)); + RuleDto ruleOlder = createRule(setCreatedAt(-1_000L)); index(); // 0. find all rules; verifySearch(new RuleQuery(), ruleOld, ruleOlder); // 1. find all rules available since a date; - RuleQuery availableSinceQuery = new RuleQuery().setAvailableSince(2000L); + RuleQuery availableSinceQuery = new RuleQuery().setAvailableSince(-1000L); verifySearch(availableSinceQuery, ruleOlder); // 2. find no new rules since tomorrow. - RuleQuery availableSinceNowQuery = new RuleQuery().setAvailableSince(3000L); + RuleQuery availableSinceNowQuery = new RuleQuery().setAvailableSince(1000L); verifyEmptySearch(availableSinceNowQuery); } @Test public void global_facet_on_repositories_and_tags() { createRule(setRepositoryKey("php"), setSystemTags("sysTag")); - RuleDefinitionDto rule1 = createRule(setRepositoryKey("php"), setSystemTags()); + RuleDto rule1 = createRule(setRepositoryKey("php"), setSystemTags()); createRuleMetadata(rule1, setTags("tag1")); - RuleDefinitionDto rule2 = createRule(setRepositoryKey("javascript"), setSystemTags()); + RuleDto rule2 = createRule(setRepositoryKey("javascript"), setSystemTags()); createRuleMetadata(rule2, setTags("tag1", "tag2")); index(); @@ -913,7 +913,7 @@ public class RuleIndexTest { @Test public void tags_facet_should_find_tags() { - RuleDefinitionDto rule = createRule(setSystemTags()); + RuleDto rule = createRule(setSystemTags()); createRuleMetadata(rule, setTags("bla")); index(); @@ -1020,9 +1020,9 @@ public class RuleIndexTest { @Test public void sort_by_name() { - RuleDefinitionDto abcd = createRule(setName("abcd")); - RuleDefinitionDto abc = createRule(setName("ABC")); - RuleDefinitionDto fgh = createRule(setName("FGH")); + RuleDto abcd = createRule(setName("abcd")); + RuleDto abc = createRule(setName("ABC")); + RuleDto fgh = createRule(setName("FGH")); index(); // ascending @@ -1038,9 +1038,11 @@ public class RuleIndexTest { @Test public void default_sort_is_by_updated_at_desc() { - RuleDefinitionDto old = createRule(setCreatedAt(1000L), setUpdatedAt(1000L)); - RuleDefinitionDto oldest = createRule(setCreatedAt(1000L), setUpdatedAt(3000L)); - RuleDefinitionDto older = createRule(setCreatedAt(1000L), setUpdatedAt(2000L)); + long currentTimeMillis = System.currentTimeMillis(); + + RuleDto old = createRule(setCreatedAt(1000L), setUpdatedAt(currentTimeMillis + 1000L)); + RuleDto oldest = createRule(setCreatedAt(1000L), setUpdatedAt(currentTimeMillis + 3000L)); + RuleDto older = createRule(setCreatedAt(1000L), setUpdatedAt(currentTimeMillis + 2000L)); index(); SearchIdResult results = underTest.search(new RuleQuery(), new SearchOptions()); @@ -1104,9 +1106,9 @@ public class RuleIndexTest { @Test public void searchAll_keys_by_profile() { - RuleDefinitionDto rule1 = createRule(); - RuleDefinitionDto rule2 = createRule(); - RuleDefinitionDto rule3 = createRule(); + RuleDto rule1 = createRule(); + RuleDto rule2 = createRule(); + RuleDto rule3 = createRule(); QProfileDto profile1 = createJavaProfile(); QProfileDto profile2 = createJavaProfile(); db.qualityProfiles().activateRule(profile1, rule1); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java index ff77b29101d..87dc8cb2332 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java @@ -40,7 +40,6 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -57,7 +56,6 @@ import static java.util.stream.Collectors.toSet; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; -import static org.sonar.db.rule.RuleTesting.newRuleWithoutDescriptionSection; import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_RULE; import static org.sonar.server.security.SecurityStandards.CWES_BY_SQ_CATEGORY; import static org.sonar.server.security.SecurityStandards.SQ_CATEGORY_KEYS_ORDERING; @@ -84,7 +82,7 @@ public class RuleIndexerTest { private DbClient dbClient = dbTester.getDbClient(); private final RuleIndexer underTest = new RuleIndexer(es.client(), dbClient); private DbSession dbSession = dbTester.getSession(); - private RuleDefinitionDto rule = new RuleDefinitionDto() + private RuleDto rule = new RuleDto() .setUuid("rule-uuid") .setRuleKey("S001") .setRepositoryKey("xoo") @@ -135,7 +133,7 @@ public class RuleIndexerTest { public void index_long_rule_description() { String description = IntStream.range(0, 100000).map(i -> i % 100).mapToObj(Integer::toString).collect(joining(" ")); RuleDescriptionSectionDto ruleDescriptionSectionDto = createDefaultRuleDescriptionSection(uuidFactory.create(), description); - RuleDefinitionDto rule = dbTester.rules().insert(r -> r.addOrReplaceRuleDescriptionSectionDto(ruleDescriptionSectionDto)); + RuleDto rule = dbTester.rules().insert(r -> r.addOrReplaceRuleDescriptionSectionDto(ruleDescriptionSectionDto)); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); assertThat(es.countDocuments(TYPE_RULE)).isOne(); @@ -148,7 +146,7 @@ public class RuleIndexerTest { .flatMap(t -> CWES_BY_SQ_CATEGORY.get(t).stream().map(e -> "cwe:" + e)) .collect(toSet()); SecurityStandards securityStandards = SecurityStandards.fromSecurityStandards(standards); - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT) .setSecurityStandards(standards) .addRuleDescriptionSectionDto(RULE_DESCRIPTION_SECTION_DTO)); @@ -183,7 +181,7 @@ public class RuleIndexerTest { @Test public void log_debug_when_hotspot_rule_no_description () { - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT)); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); @@ -196,7 +194,7 @@ public class RuleIndexerTest { @Test public void log_debug_when_hotspot_rule_description_has_none_of_the_key_titles() { - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT) .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), randomAlphabetic(30)))); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); @@ -210,7 +208,7 @@ public class RuleIndexerTest { @Test public void log_debug_when_hotspot_rule_description_is_missing_fixIt_tab_content() { - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT) .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "bar\n" + "

Ask Yourself Whether

\n" + @@ -226,7 +224,7 @@ public class RuleIndexerTest { @Test public void log_debug_when_hotspot_rule_description_is_missing_risk_tab_content() { - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT) .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "

Ask Yourself Whether

\n" + "bar\n" + @@ -243,7 +241,7 @@ public class RuleIndexerTest { @Test public void log_debug_when_hotspot_rule_description_is_missing_vulnerable_tab_content() { - RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() + RuleDto rule = dbTester.rules().insert(RuleTesting.newRuleWithoutDescriptionSection() .setType(RuleType.SECURITY_HOTSPOT) .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "bar\n" + "

Recommended Secure Coding Practices

\n" + diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTesting.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTesting.java index 1bf5894075c..c1b13079b4f 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTesting.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTesting.java @@ -25,7 +25,6 @@ import org.sonar.api.rules.RuleType; import org.sonar.db.DbTester; import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange; @@ -53,10 +52,6 @@ public class IssuesChangesNotificationBuilderTesting { return new Rule(rule.getKey(), RuleType.valueOfNullable(rule.getType()), rule.getName()); } - public static Rule ruleOf(RuleDefinitionDto rule) { - return new Rule(rule.getKey(), RuleType.valueOfNullable(rule.getType()), rule.getName()); - } - public static User userOf(UserDto changeAuthor) { return new User(changeAuthor.getUuid(), changeAuthor.getLogin(), changeAuthor.getName()); } diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java index 1c97688ad39..a0f79856ef1 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/qualityprofile/QProfileRules.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import org.sonar.api.server.ServerSide; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.rule.index.RuleQuery; /** @@ -60,5 +60,5 @@ public interface QProfileRules { * Delete a rule from all Quality profiles. Db session is not committed. As a * consequence Elasticsearch indices are NOT updated. */ - List deleteRule(DbSession dbSession, RuleDefinitionDto rule); + List deleteRule(DbSession dbSession, RuleDto rule); } diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java index 43f6fdb03c6..313914a6f96 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java @@ -40,7 +40,7 @@ import org.sonar.api.rules.RuleQuery; import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import static java.util.Collections.emptyList; @@ -53,28 +53,28 @@ import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; */ public class CachingRuleFinder implements ServerRuleFinder { - private static final Ordering> FIND_BY_QUERY_ORDER = Ordering.natural().reverse().onResultOf(entry -> entry.getKey().getUpdatedAt()); + private static final Ordering> FIND_BY_QUERY_ORDER = Ordering.natural().reverse().onResultOf(entry -> entry.getKey().getUpdatedAt()); - private final Map ruleDtosByKey; - private final Map ruleDtosByUuid; - private final Map rulesByRuleDefinition; + private final Map ruleDtosByKey; + private final Map ruleDtosByUuid; + private final Map ruleByRuleDto; private final Map rulesByKey; public CachingRuleFinder(DbClient dbClient) { try (DbSession dbSession = dbClient.openSession(false)) { - List dtos = dbClient.ruleDao().selectAllDefinitions(dbSession); - this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDefinitionDto::getKey, d -> d)); - this.ruleDtosByUuid = dtos.stream().collect(Collectors.toMap(RuleDefinitionDto::getUuid, d -> d)); - this.rulesByRuleDefinition = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos); - this.rulesByKey = this.rulesByRuleDefinition.entrySet().stream() + List dtos = dbClient.ruleDao().selectAll(dbSession); + this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDto::getKey, d -> d)); + this.ruleDtosByUuid = dtos.stream().collect(Collectors.toMap(RuleDto::getUuid, d -> d)); + this.ruleByRuleDto = buildRulesByRuleDefinitionDto(dbClient, dbSession, dtos); + this.rulesByKey = this.ruleByRuleDto.entrySet().stream() .collect(uniqueIndex(entry -> entry.getKey().getKey(), Map.Entry::getValue)); } } - private static Map buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List dtos) { + private static Map buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List dtos) { Map> ruleParamsByRuleUuid = retrieveRuleParameters(dbClient, dbSession); - Map rulesByDefinition = new HashMap<>(dtos.size()); - for (RuleDefinitionDto definition : dtos) { + Map rulesByDefinition = new HashMap<>(dtos.size()); + for (RuleDto definition : dtos) { rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleUuid.getOrDefault(definition.getUuid(), emptyList()))); } return unmodifiableMap(rulesByDefinition); @@ -107,7 +107,7 @@ public class CachingRuleFinder implements ServerRuleFinder { return null; } - return rulesByRuleDefinition.entrySet().stream() + return ruleByRuleDto.entrySet().stream() .filter(entry -> matchQuery(entry.getKey(), query)) .sorted(FIND_BY_QUERY_ORDER) .map(Map.Entry::getValue) @@ -120,48 +120,47 @@ public class CachingRuleFinder implements ServerRuleFinder { if (query == null) { return Collections.emptyList(); } - return rulesByRuleDefinition.entrySet().stream() + return ruleByRuleDto.entrySet().stream() .filter(entry -> matchQuery(entry.getKey(), query)) .sorted(FIND_BY_QUERY_ORDER) .map(Map.Entry::getValue) .collect(MoreCollectors.toList()); } - private static boolean matchQuery(RuleDefinitionDto ruleDefinition, RuleQuery ruleQuery) { - if (RuleStatus.REMOVED.equals(ruleDefinition.getStatus())) { + private static boolean matchQuery(RuleDto ruleDto, RuleQuery ruleQuery) { + if (RuleStatus.REMOVED.equals(ruleDto.getStatus())) { return false; } String repositoryKey = ruleQuery.getRepositoryKey(); - if (ruleQuery.getRepositoryKey() != null && !repositoryKey.equals(ruleDefinition.getRepositoryKey())) { + if (ruleQuery.getRepositoryKey() != null && !repositoryKey.equals(ruleDto.getRepositoryKey())) { return false; } String key = ruleQuery.getKey(); - if (key != null && !key.equals(ruleDefinition.getRuleKey())) { + if (key != null && !key.equals(ruleDto.getRuleKey())) { return false; } String configKey = ruleQuery.getConfigKey(); - return configKey == null || configKey.equals(ruleDefinition.getConfigKey()); + return configKey == null || configKey.equals(ruleDto.getConfigKey()); } - private static Rule toRule(RuleDefinitionDto ruleDefinition, List params) { - String severity = ruleDefinition.getSeverityString(); - - Rule apiRule = new Rule(); - apiRule - .setName(ruleDefinition.getName()) - .setLanguage(ruleDefinition.getLanguage()) - .setKey(ruleDefinition.getRuleKey()) - .setConfigKey(ruleDefinition.getConfigKey()) - .setIsTemplate(ruleDefinition.isTemplate()) - .setCreatedAt(new Date(ruleDefinition.getCreatedAt())) - .setUpdatedAt(new Date(ruleDefinition.getUpdatedAt())) - .setRepositoryKey(ruleDefinition.getRepositoryKey()) + private static Rule toRule(RuleDto ruleDto, List params) { + String severity = ruleDto.getSeverityString(); + + Rule apiRule = Rule.create() + .setName(ruleDto.getName()) + .setKey(ruleDto.getRuleKey()) + .setConfigKey(ruleDto.getConfigKey()) + .setIsTemplate(ruleDto.isTemplate()) + .setCreatedAt(new Date(ruleDto.getCreatedAt())) + .setUpdatedAt(new Date(ruleDto.getUpdatedAt())) + .setRepositoryKey(ruleDto.getRepositoryKey()) .setSeverity(severity != null ? RulePriority.valueOf(severity) : null) - .setStatus(ruleDefinition.getStatus().name()) - .setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()])) + .setStatus(ruleDto.getStatus().name()) + .setSystemTags(ruleDto.getSystemTags().toArray(new String[ruleDto.getSystemTags().size()])) .setTags(new String[0]) - .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDefinition)); + .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDto)); + Optional.ofNullable(ruleDto.getLanguage()).map(apiRule::setLanguage); List apiParams = new ArrayList<>(); for (RuleParamDto param : params) { @@ -174,17 +173,17 @@ public class CachingRuleFinder implements ServerRuleFinder { } @Override - public Optional findDtoByKey(RuleKey key) { + public Optional findDtoByKey(RuleKey key) { return Optional.ofNullable(this.ruleDtosByKey.get(key)); } @Override - public Optional findDtoByUuid(String uuid) { + public Optional findDtoByUuid(String uuid) { return Optional.ofNullable(this.ruleDtosByUuid.get(uuid)); } @Override - public Collection findAll() { + public Collection findAll() { return ruleDtosByUuid.values(); } diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java index cc2a98c77a8..1a79d6528a3 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java @@ -27,7 +27,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleQuery; import org.sonar.db.DbClient; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; public class WebServerRuleFinderImpl implements WebServerRuleFinder { private final DbClient dbClient; @@ -75,17 +75,17 @@ public class WebServerRuleFinderImpl implements WebServerRuleFinder { } @Override - public Optional findDtoByKey(RuleKey key) { + public Optional findDtoByKey(RuleKey key) { return delegate.findDtoByKey(key); } @Override - public Optional findDtoByUuid(String uuid) { + public Optional findDtoByUuid(String uuid) { return delegate.findDtoByUuid(uuid); } @Override - public Collection findAll() { + public Collection findAll() { return delegate.findAll(); } diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java index da0ca92e525..b7b555a8b94 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java @@ -34,7 +34,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; @@ -53,14 +53,14 @@ public class CachingRuleFinderTest { private final DbClient dbClient = dbTester.getDbClient(); private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(); - private RuleDefinitionDto[] ruleDefinitions; + private RuleDto[] ruleDtos; private RuleParamDto[] ruleParams; private CachingRuleFinder underTest; @Before() public void setUp() { - Consumer setUpdatedAt = rule -> rule.setUpdatedAt(system2.now()); - this.ruleDefinitions = new RuleDefinitionDto[] { + Consumer setUpdatedAt = rule -> rule.setUpdatedAt(system2.now()); + this.ruleDtos = new RuleDto[] { dbTester.rules().insert(setUpdatedAt), dbTester.rules().insert(setUpdatedAt), dbTester.rules().insert(setUpdatedAt), @@ -68,7 +68,7 @@ public class CachingRuleFinderTest { dbTester.rules().insert(setUpdatedAt), dbTester.rules().insert(setUpdatedAt) }; - this.ruleParams = Arrays.stream(ruleDefinitions) + this.ruleParams = Arrays.stream(ruleDtos) .map(rule -> dbTester.rules().insertRuleParam(rule)) .toArray(RuleParamDto[]::new); @@ -92,7 +92,7 @@ public class CachingRuleFinderTest { new CachingRuleFinder(dbClient); verify(dbClient).openSession(anyBoolean()); - verify(ruleDao).selectAllDefinitions(dbSession); + verify(ruleDao).selectAll(dbSession); verify(ruleDao).selectAllRuleParams(dbSession); verifyNoMoreInteractions(ruleDao); } @@ -105,7 +105,7 @@ public class CachingRuleFinderTest { when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); when(dbClient.ruleDao()).thenReturn(ruleDao); List ruleKeys = Arrays.asList(RuleKey.of("A", "B"), RuleKey.of("C", "D"), RuleKey.of("E", "F")); - when(ruleDao.selectAllDefinitions(dbSession)).thenReturn(ruleKeys.stream().map(RuleTesting::newRule).collect(toList())); + when(ruleDao.selectAll(dbSession)).thenReturn(ruleKeys.stream().map(RuleTesting::newRule).collect(toList())); new CachingRuleFinder(dbClient); @@ -114,13 +114,13 @@ public class CachingRuleFinderTest { @Test public void findByKey_returns_all_loaded_rules() { - for (int i = 0; i < ruleDefinitions.length; i++) { - RuleDefinitionDto ruleDefinition = ruleDefinitions[i]; + for (int i = 0; i < ruleDtos.length; i++) { + RuleDto ruleDto = ruleDtos[i]; RuleParamDto ruleParam = ruleParams[i]; - org.sonar.api.rules.Rule rule = underTest.findByKey(ruleDefinition.getKey()); - verifyRule(rule, ruleDefinition, ruleParam); - assertThat(underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey())) + org.sonar.api.rules.Rule rule = underTest.findByKey(ruleDto.getKey()); + verifyRule(rule, ruleDto, ruleParam); + assertThat(underTest.findByKey(ruleDto.getRepositoryKey(), ruleDto.getRuleKey())) .isSameAs(rule); } } @@ -154,17 +154,17 @@ public class CachingRuleFinderTest { public void find_returns_most_recent_rule_when_RuleQuery_has_no_non_null_field() { Rule rule = underTest.find(RuleQuery.create()); - assertThat(toRuleKey(rule)).isEqualTo(ruleDefinitions[5].getKey()); + assertThat(toRuleKey(rule)).isEqualTo(ruleDtos[5].getKey()); } @Test public void find_searches_by_exact_match_of_repository_key_and_returns_most_recent_rule() { String repoKey = "ABCD"; - RuleDefinitionDto[] sameRepoKey = { + RuleDto[] sameRepoKey = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -181,11 +181,11 @@ public class CachingRuleFinderTest { @Test public void find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule() { String ruleKey = "ABCD"; - RuleDefinitionDto[] sameRuleKey = { + RuleDto[] sameRuleKey = { dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -202,11 +202,11 @@ public class CachingRuleFinderTest { @Test public void find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule() { String configKey = "ABCD"; - RuleDefinitionDto[] sameConfigKey = { + RuleDto[] sameConfigKey = { dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -225,7 +225,7 @@ public class CachingRuleFinderTest { String repoKey = "ABCD"; String ruleKey = "EFGH"; String configKey = "IJKL"; - RuleDefinitionDto[] rules = { + RuleDto[] rules = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())), @@ -259,17 +259,18 @@ public class CachingRuleFinderTest { public void findAll_returns_all_rules_when_RuleQuery_has_no_non_null_field() { assertThat(underTest.findAll(RuleQuery.create())) .extracting(CachingRuleFinderTest::toRuleKey) - .containsOnly(Arrays.stream(ruleDefinitions).map(RuleDefinitionDto::getKey).toArray(RuleKey[]::new)); + .containsOnly(Arrays.stream(ruleDtos).map(RuleDto::getKey).toArray(RuleKey[]::new)); } @Test public void findAll_returns_all_rules_with_exact_same_repository_key_and_order_them_most_recent_first() { String repoKey = "ABCD"; - RuleDefinitionDto[] sameRepoKey = { - dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())), - dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())) + long currentTimeMillis = System.currentTimeMillis(); + RuleDto[] sameRepoKey = { + dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(currentTimeMillis + system2.now())), + dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(currentTimeMillis + system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(currentTimeMillis + system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -288,11 +289,11 @@ public class CachingRuleFinderTest { @Test public void findAll_returns_all_rules_with_exact_same_rulekey_and_order_them_most_recent_first() { String ruleKey = "ABCD"; - RuleDefinitionDto[] sameRuleKey = { + RuleDto[] sameRuleKey = { dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -311,11 +312,11 @@ public class CachingRuleFinderTest { @Test public void findAll_returns_all_rules_with_exact_same_configkey_and_order_them_most_recent_first() { String configKey = "ABCD"; - RuleDefinitionDto[] sameConfigKey = { + RuleDto[] sameConfigKey = { dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())) }; - RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); + RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())); CachingRuleFinder underTest = new CachingRuleFinder(dbClient); @@ -336,7 +337,7 @@ public class CachingRuleFinderTest { String repoKey = "ABCD"; String ruleKey = "EFGH"; String configKey = "IJKL"; - RuleDefinitionDto[] rules = { + RuleDto[] rules = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())), @@ -377,14 +378,14 @@ public class CachingRuleFinderTest { @Test public void findDtoByKey_finds_rules() { - for(RuleDefinitionDto dto : ruleDefinitions) { + for(RuleDto dto : ruleDtos) { assertThat(underTest.findDtoByKey(dto.getKey())).contains(dto); } } @Test public void findDtoByUuid_finds_rules() { - for(RuleDefinitionDto dto : ruleDefinitions) { + for(RuleDto dto : ruleDtos) { assertThat(underTest.findDtoByUuid(dto.getUuid())).contains(dto); } } @@ -401,28 +402,28 @@ public class CachingRuleFinderTest { @Test public void findAll_returns_all_rules() { - assertThat(underTest.findAll()).containsOnly(ruleDefinitions); + assertThat(underTest.findAll()).containsOnly(ruleDtos); } private static RuleKey toRuleKey(Rule rule) { return RuleKey.of(rule.getRepositoryKey(), rule.getKey()); } - private void verifyRule(@Nullable Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) { + private void verifyRule(@Nullable Rule rule, RuleDto ruleDto, RuleParamDto ruleParam) { assertThat(rule).isNotNull(); - assertThat(rule.getName()).isEqualTo(ruleDefinition.getName()); - assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage()); - assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey()); - assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey()); - assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate()); - assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt()); - assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt()); - assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey()); - assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString()); - assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0])); + assertThat(rule.getName()).isEqualTo(ruleDto.getName()); + assertThat(rule.getLanguage()).isEqualTo(ruleDto.getLanguage()); + assertThat(rule.getKey()).isEqualTo(ruleDto.getRuleKey()); + assertThat(rule.getConfigKey()).isEqualTo(ruleDto.getConfigKey()); + assertThat(rule.isTemplate()).isEqualTo(ruleDto.isTemplate()); + assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDto.getCreatedAt()); + assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDto.getUpdatedAt()); + assertThat(rule.getRepositoryKey()).isEqualTo(ruleDto.getRepositoryKey()); + assertThat(rule.getSeverity().name()).isEqualTo(ruleDto.getSeverityString()); + assertThat(rule.getSystemTags()).isEqualTo(ruleDto.getSystemTags().toArray(new String[0])); assertThat(rule.getTags()).isEmpty(); - assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDefaultRuleDescriptionSectionDto().getContent()); + assertThat(rule.getDescription()).isEqualTo(ruleDto.getDefaultRuleDescriptionSection().getContent()); assertThat(rule.getParams()).hasSize(1); org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next(); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java index 42a9db4f2eb..2e676765dfa 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -35,6 +35,7 @@ import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.Startable; @@ -56,8 +57,8 @@ import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; import org.sonar.db.rule.RuleDto.Scope; import org.sonar.db.rule.RuleParamDto; @@ -138,7 +139,7 @@ public class RegisterRules implements Startable { persistRepositories(dbSession, ruleDefinitionContext.repositories()); // FIXME lack of resiliency, active rules index is corrupted if rule index fails // to be updated. Only a single DB commit should be executed. - ruleIndexer.commitAndIndex(dbSession, registerRulesContext.getAllModified().map(RuleDefinitionDto::getUuid).collect(toSet())); + ruleIndexer.commitAndIndex(dbSession, registerRulesContext.getAllModified().map(RuleDto::getUuid).collect(toSet())); activeRuleIndexer.commitAndIndex(dbSession, changes); registerRulesContext.getRenamed().forEach(e -> LOG.info("Rule {} re-keyed to {}", e.getValue(), e.getKey().getKey())); profiler.stopDebug(); @@ -153,8 +154,8 @@ public class RegisterRules implements Startable { } private RegisterRulesContext createRegisterRulesContext(DbSession dbSession) { - Map allRules = dbClient.ruleDao().selectAllDefinitions(dbSession).stream() - .collect(uniqueIndex(RuleDefinitionDto::getKey)); + Map allRules = dbClient.ruleDao().selectAll(dbSession).stream() + .collect(uniqueIndex(RuleDto::getKey)); Map> existingDeprecatedKeysById = loadDeprecatedRuleKeys(dbSession); Map> ruleParamsByRuleUuid = loadAllRuleParameters(dbSession); return new RegisterRulesContext(allRules, existingDeprecatedKeysById, ruleParamsByRuleUuid); @@ -173,19 +174,19 @@ public class RegisterRules implements Startable { private static class RegisterRulesContext { // initial immutable data - private final Map dbRules; - private final Set known; + private final Map dbRules; + private final Set known; private final Map> dbDeprecatedKeysByUuid; private final Map> ruleParamsByRuleUuid; - private final Map dbRulesByDbDeprecatedKey; + private final Map dbRulesByDbDeprecatedKey; // mutable data - private final Set created = new HashSet<>(); - private final Map renamed = new HashMap<>(); - private final Set updated = new HashSet<>(); - private final Set unchanged = new HashSet<>(); - private final Set removed = new HashSet<>(); + private final Set created = new HashSet<>(); + private final Map renamed = new HashMap<>(); + private final Set updated = new HashSet<>(); + private final Set unchanged = new HashSet<>(); + private final Set removed = new HashSet<>(); - private RegisterRulesContext(Map dbRules, Map> dbDeprecatedKeysByUuid, + private RegisterRulesContext(Map dbRules, Map> dbDeprecatedKeysByUuid, Map> ruleParamsByRuleUuid) { this.dbRules = ImmutableMap.copyOf(dbRules); this.known = ImmutableSet.copyOf(dbRules.values()); @@ -194,15 +195,15 @@ public class RegisterRules implements Startable { this.dbRulesByDbDeprecatedKey = buildDbRulesByDbDeprecatedKey(dbDeprecatedKeysByUuid, dbRules); } - private static Map buildDbRulesByDbDeprecatedKey(Map> dbDeprecatedKeysByUuid, - Map dbRules) { - Map dbRulesByRuleUuid = dbRules.values().stream() - .collect(uniqueIndex(RuleDefinitionDto::getUuid)); + private static Map buildDbRulesByDbDeprecatedKey(Map> dbDeprecatedKeysByUuid, + Map dbRules) { + Map dbRulesByRuleUuid = dbRules.values().stream() + .collect(uniqueIndex(RuleDto::getUuid)); - Map rulesByKey = new LinkedHashMap<>(); + Map rulesByKey = new LinkedHashMap<>(); for (Map.Entry> entry : dbDeprecatedKeysByUuid.entrySet()) { String ruleUuid = entry.getKey(); - RuleDefinitionDto rule = dbRulesByRuleUuid.get(ruleUuid); + RuleDto rule = dbRulesByRuleUuid.get(ruleUuid); if (rule == null) { LOG.warn("Could not retrieve rule with uuid %s referenced by a deprecated rule key. " + "The following deprecated rule keys seem to be referencing a non-existing rule", @@ -218,9 +219,9 @@ public class RegisterRules implements Startable { return !dbRules.isEmpty(); } - private Optional getDbRuleFor(RulesDefinition.Rule ruleDef) { + private Optional getDbRuleFor(RulesDefinition.Rule ruleDef) { RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key()); - Optional res = Stream.concat(Stream.of(ruleKey), ruleDef.deprecatedRuleKeys().stream()) + Optional res = Stream.concat(Stream.of(ruleKey), ruleDef.deprecatedRuleKeys().stream()) .map(dbRules::get) .filter(Objects::nonNull) .findFirst(); @@ -237,7 +238,7 @@ public class RegisterRules implements Startable { .collect(uniqueIndex(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey)); } - private Set getDBDeprecatedKeysFor(RuleDefinitionDto rule) { + private Set getDBDeprecatedKeysFor(RuleDto rule) { return dbDeprecatedKeysByUuid.getOrDefault(rule.getUuid(), emptySet()); } @@ -245,8 +246,8 @@ public class RegisterRules implements Startable { return ruleParamsByRuleUuid.getOrDefault(ruleUuid, emptyList()); } - private Stream getRemaining() { - Set res = new HashSet<>(dbRules.values()); + private Stream getRemaining() { + Set res = new HashSet<>(dbRules.values()); res.removeAll(unchanged); res.removeAll(renamed.keySet()); res.removeAll(updated); @@ -254,15 +255,15 @@ public class RegisterRules implements Startable { return res.stream(); } - private Stream getRemoved() { + private Stream getRemoved() { return removed.stream(); } - public Stream> getRenamed() { + public Stream> getRenamed() { return renamed.entrySet().stream(); } - private Stream getAllModified() { + private Stream getAllModified() { return Stream.of( created.stream(), updated.stream(), @@ -271,45 +272,45 @@ public class RegisterRules implements Startable { .flatMap(s -> s); } - private boolean isCreated(RuleDefinitionDto ruleDefinition) { - return created.contains(ruleDefinition); + private boolean isCreated(RuleDto ruleDto) { + return created.contains(ruleDto); } - private boolean isRenamed(RuleDefinitionDto ruleDefinition) { - return renamed.containsKey(ruleDefinition); + private boolean isRenamed(RuleDto ruleDto) { + return renamed.containsKey(ruleDto); } - private boolean isUpdated(RuleDefinitionDto ruleDefinition) { - return updated.contains(ruleDefinition); + private boolean isUpdated(RuleDto ruleDto) { + return updated.contains(ruleDto); } - private void created(RuleDefinitionDto ruleDefinition) { - checkState(!known.contains(ruleDefinition), "known RuleDefinitionDto can't be created"); - created.add(ruleDefinition); + private void created(RuleDto ruleDto) { + checkState(!known.contains(ruleDto), "known RuleDto can't be created"); + created.add(ruleDto); } - private void renamed(RuleDefinitionDto ruleDefinition) { - ensureKnown(ruleDefinition); - renamed.put(ruleDefinition, ruleDefinition.getKey()); + private void renamed(RuleDto ruleDto) { + ensureKnown(ruleDto); + renamed.put(ruleDto, ruleDto.getKey()); } - private void updated(RuleDefinitionDto ruleDefinition) { - ensureKnown(ruleDefinition); - updated.add(ruleDefinition); + private void updated(RuleDto ruleDto) { + ensureKnown(ruleDto); + updated.add(ruleDto); } - private void removed(RuleDefinitionDto ruleDefinition) { - ensureKnown(ruleDefinition); - removed.add(ruleDefinition); + private void removed(RuleDto ruleDto) { + ensureKnown(ruleDto); + removed.add(ruleDto); } - private void unchanged(RuleDefinitionDto ruleDefinition) { - ensureKnown(ruleDefinition); - unchanged.add(ruleDefinition); + private void unchanged(RuleDto ruleDto) { + ensureKnown(ruleDto); + unchanged.add(ruleDto); } - private void ensureKnown(RuleDefinitionDto ruleDefinition) { - checkState(known.contains(ruleDefinition), "unknown RuleDefinitionDto"); + private void ensureKnown(RuleDto ruleDto) { + checkState(known.contains(ruleDto), "unknown RuleDto"); } } @@ -333,56 +334,48 @@ public class RegisterRules implements Startable { } private void registerRules(RegisterRulesContext context, List ruleDefs, DbSession session) { - Map dtos = new LinkedHashMap<>(ruleDefs.size()); + Map dtos = new LinkedHashMap<>(ruleDefs.size()); for (RulesDefinition.Rule ruleDef : ruleDefs) { RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key()); - - RuleDefinitionDto ruleDefinitionDto = context.getDbRuleFor(ruleDef) - .orElseGet(() -> { - RuleDefinitionDto newRule = createRuleDto(ruleDef, session); - context.created(newRule); - return newRule; - }); - dtos.put(ruleDef, ruleDefinitionDto); + RuleDto ruleDto = findOrCreateRuleDto(context, session, ruleDef); + dtos.put(ruleDef, ruleDto); // we must detect renaming __before__ we modify the DTO - if (!ruleDefinitionDto.getKey().equals(ruleKey)) { - context.renamed(ruleDefinitionDto); - ruleDefinitionDto.setRuleKey(ruleKey); - } - - if (mergeRule(ruleDef, ruleDefinitionDto)) { - context.updated(ruleDefinitionDto); - } - - if (mergeDebtDefinitions(ruleDef, ruleDefinitionDto)) { - context.updated(ruleDefinitionDto); - } - - if (mergeTags(ruleDef, ruleDefinitionDto)) { - context.updated(ruleDefinitionDto); + if (!ruleDto.getKey().equals(ruleKey)) { + context.renamed(ruleDto); + ruleDto.setRuleKey(ruleKey); } - if (mergeSecurityStandards(ruleDef, ruleDefinitionDto)) { - context.updated(ruleDefinitionDto); + if (anyMerge(ruleDef, ruleDto)) { + context.updated(ruleDto); } - if (context.isUpdated(ruleDefinitionDto) || context.isRenamed(ruleDefinitionDto)) { - update(session, ruleDefinitionDto); - } else if (!context.isCreated(ruleDefinitionDto)) { - context.unchanged(ruleDefinitionDto); + if (context.isUpdated(ruleDto) || context.isRenamed(ruleDto)) { + update(session, ruleDto); + } else if (!context.isCreated(ruleDto)) { + context.unchanged(ruleDto); } } - for (Map.Entry e : dtos.entrySet()) { + for (Map.Entry e : dtos.entrySet()) { mergeParams(context, e.getKey(), e.getValue(), session); updateDeprecatedKeys(context, e.getKey(), e.getValue(), session); } } - private RuleDefinitionDto createRuleDto(RulesDefinition.Rule ruleDef, DbSession session) { - RuleDefinitionDto ruleDto = new RuleDefinitionDto() + @Nonnull + private RuleDto findOrCreateRuleDto(RegisterRulesContext context, DbSession session, RulesDefinition.Rule ruleDef) { + return context.getDbRuleFor(ruleDef) + .orElseGet(() -> { + RuleDto newRule = createRuleDto(ruleDef, session); + context.created(newRule); + return newRule; + }); + } + + private RuleDto createRuleDto(RulesDefinition.Rule ruleDef, DbSession session) { + RuleDto ruleDto = new RuleDto() .setUuid(uuidFactory.create()) .setRuleKey(RuleKey.of(ruleDef.repository().key(), ruleDef.key())) .setPluginKey(ruleDef.pluginKey()) @@ -438,7 +431,15 @@ public class RegisterRules implements Startable { } } - private boolean mergeRule(RulesDefinition.Rule def, RuleDefinitionDto dto) { + private boolean anyMerge(RulesDefinition.Rule ruleDef, RuleDto ruleDto) { + boolean ruleMerged = mergeRule(ruleDef, ruleDto); + boolean debtDefinitionsMerged = mergeDebtDefinitions(ruleDef, ruleDto); + boolean tagsMerged = mergeTags(ruleDef, ruleDto); + boolean securityStandardsMerged = mergeSecurityStandards(ruleDef, ruleDto); + return ruleMerged || debtDefinitionsMerged || tagsMerged || securityStandardsMerged; + } + + private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) { boolean changed = false; if (!Objects.equals(dto.getName(), def.name())) { dto.setName(def.name()); @@ -489,22 +490,22 @@ public class RegisterRules implements Startable { return changed; } - private boolean mergeDescription(RulesDefinition.Rule rule, RuleDefinitionDto ruleDefinitionDto) { + private boolean mergeDescription(RulesDefinition.Rule rule, RuleDto ruleDto) { boolean changed = false; - String currentDescription = Optional.ofNullable(ruleDefinitionDto.getDefaultRuleDescriptionSectionDto()) + String currentDescription = Optional.ofNullable(ruleDto.getDefaultRuleDescriptionSection()) .map(RuleDescriptionSectionDto::getContent) .orElse(null); String htmlDescription = rule.htmlDescription(); String markdownDescription = rule.markdownDescription(); if (isDescriptionUpdated(htmlDescription, currentDescription)) { - ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), htmlDescription)); - ruleDefinitionDto.setDescriptionFormat(Format.HTML); + ruleDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), htmlDescription)); + ruleDto.setDescriptionFormat(Format.HTML); changed = true; } else if (isDescriptionUpdated(markdownDescription, currentDescription)) { - ruleDefinitionDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), markdownDescription)); - ruleDefinitionDto.setDescriptionFormat(Format.MARKDOWN); + ruleDto.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), markdownDescription)); + ruleDto.setDescriptionFormat(Format.MARKDOWN); changed = true; } return changed; @@ -514,7 +515,7 @@ public class RegisterRules implements Startable { return isNotEmpty(description) && !Objects.equals(description, currentDescription); } - private static boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDefinitionDto dto) { + private static boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto) { // Debt definitions are set to null if the sub-characteristic and the remediation function are null DebtRemediationFunction debtRemediationFunction = def.debtRemediationFunction(); boolean hasDebt = debtRemediationFunction != null; @@ -528,7 +529,7 @@ public class RegisterRules implements Startable { return mergeDebtDefinitions(dto, null, null, null, null); } - private static boolean mergeDebtDefinitions(RuleDefinitionDto dto, @Nullable String remediationFunction, + private static boolean mergeDebtDefinitions(RuleDto dto, @Nullable String remediationFunction, @Nullable String remediationCoefficient, @Nullable String remediationOffset, @Nullable String effortToFixDescription) { boolean changed = false; @@ -551,7 +552,7 @@ public class RegisterRules implements Startable { return changed; } - private void mergeParams(RegisterRulesContext context, RulesDefinition.Rule ruleDef, RuleDefinitionDto rule, DbSession session) { + private void mergeParams(RegisterRulesContext context, RulesDefinition.Rule ruleDef, RuleDto rule, DbSession session) { List paramDtos = context.getRuleParametersFor(rule.getUuid()); Map existingParamsByName = new HashMap<>(); @@ -613,7 +614,7 @@ public class RegisterRules implements Startable { return changed; } - private void updateDeprecatedKeys(RegisterRulesContext context, RulesDefinition.Rule ruleDef, RuleDefinitionDto rule, DbSession dbSession) { + private void updateDeprecatedKeys(RegisterRulesContext context, RulesDefinition.Rule ruleDef, RuleDto rule, DbSession dbSession) { Set deprecatedRuleKeysFromDefinition = SingleDeprecatedRuleKey.from(ruleDef); Set deprecatedRuleKeysFromDB = context.getDBDeprecatedKeysFor(rule); @@ -637,7 +638,7 @@ public class RegisterRules implements Startable { .setCreatedAt(system2.now()))); } - private static boolean mergeTags(RulesDefinition.Rule ruleDef, RuleDefinitionDto dto) { + private static boolean mergeTags(RulesDefinition.Rule ruleDef, RuleDto dto) { boolean changed = false; if (RuleStatus.REMOVED == ruleDef.status()) { @@ -651,7 +652,7 @@ public class RegisterRules implements Startable { return changed; } - private static boolean mergeSecurityStandards(RulesDefinition.Rule ruleDef, RuleDefinitionDto dto) { + private static boolean mergeSecurityStandards(RulesDefinition.Rule ruleDef, RuleDto dto) { boolean changed = false; if (RuleStatus.REMOVED == ruleDef.status()) { @@ -667,7 +668,7 @@ public class RegisterRules implements Startable { private void processRemainingDbRules(RegisterRulesContext recorder, DbSession dbSession) { // custom rules check status of template, so they must be processed at the end - List customRules = new ArrayList<>(); + List customRules = new ArrayList<>(); recorder.getRemaining().forEach(rule -> { if (rule.isCustomRule()) { @@ -677,10 +678,10 @@ public class RegisterRules implements Startable { } }); - for (RuleDefinitionDto customRule : customRules) { + for (RuleDto customRule : customRules) { String templateUuid = customRule.getTemplateUuid(); checkNotNull(templateUuid, "Template uuid of the custom rule '%s' is null", customRule); - Optional template = dbClient.ruleDao().selectDefinitionByUuid(templateUuid, dbSession); + Optional template = dbClient.ruleDao().selectByUuid(templateUuid, dbSession); if (template.isPresent() && template.get().getStatus() != RuleStatus.REMOVED) { if (updateCustomRuleFromTemplateRule(customRule, template.get())) { recorder.updated(customRule); @@ -694,7 +695,7 @@ public class RegisterRules implements Startable { dbSession.commit(); } - private void removeRule(DbSession session, RegisterRulesContext recorder, RuleDefinitionDto rule) { + private void removeRule(DbSession session, RegisterRulesContext recorder, RuleDto rule) { LOG.info(format("Disable rule %s", rule.getKey())); rule.setStatus(RuleStatus.REMOVED); rule.setSystemTags(emptySet()); @@ -708,7 +709,7 @@ public class RegisterRules implements Startable { } } - private static boolean updateCustomRuleFromTemplateRule(RuleDefinitionDto customRule, RuleDefinitionDto templateRule) { + private static boolean updateCustomRuleFromTemplateRule(RuleDto customRule, RuleDto templateRule) { boolean changed = false; if (!Objects.equals(customRule.getLanguage(), templateRule.getLanguage())) { customRule.setLanguage(templateRule.getLanguage()); @@ -782,7 +783,7 @@ public class RegisterRules implements Startable { return changes; } - private void update(DbSession session, RuleDefinitionDto rule) { + private void update(DbSession session, RuleDto rule) { rule.setUpdatedAt(system2.now()); dbClient.ruleDao().update(session, rule); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 5f45832020f..895bcc41dab 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -48,7 +48,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -139,33 +138,16 @@ public class RegisterRulesTest { execute(new FakeRepositoryV1()); // verify db - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(3); RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1); - assertThat(rule1.getName()).isEqualTo("One"); - assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One"); - assertThat(rule1.getSeverityString()).isEqualTo(BLOCKER); - assertThat(rule1.getTags()).isEmpty(); - assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag2", "tag3"); - assertThat(rule1.getConfigKey()).isEqualTo("config1"); - assertThat(rule1.getStatus()).isEqualTo(RuleStatus.BETA); - assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime()); - assertThat(rule1.getScope()).isEqualTo(Scope.ALL); - assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1.getTime()); + verifyRule(rule1); + assertThat(rule1.isExternal()).isFalse(); assertThat(rule1.getDefRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name()); assertThat(rule1.getDefRemediationGapMultiplier()).isEqualTo("5d"); assertThat(rule1.getDefRemediationBaseEffort()).isEqualTo("10h"); - assertThat(rule1.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); - assertThat(rule1.getPluginKey()).isEqualTo(FAKE_PLUGIN_KEY); - assertThat(rule1.isExternal()).isFalse(); - assertThat(rule1.isAdHoc()).isFalse(); RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), HOTSPOT_RULE_KEY); - assertThat(hotspotRule.getName()).isEqualTo("Hotspot"); - assertThat(hotspotRule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Minimal hotspot"); - assertThat(hotspotRule.getCreatedAt()).isEqualTo(DATE1.getTime()); - assertThat(hotspotRule.getUpdatedAt()).isEqualTo(DATE1.getTime()); - assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant()); - assertThat(hotspotRule.getSecurityStandards()).containsExactly("cwe:1", "cwe:123", "cwe:863", "owaspTop10-2021:a1", "owaspTop10-2021:a3"); + verifyHotspot(hotspotRule); List params = dbClient.ruleDao().selectRuleParamsByRuleKey(db.getSession(), RULE_KEY1); assertThat(params).hasSize(2); @@ -182,38 +164,47 @@ public class RegisterRulesTest { assertThat(dbClient.ruleRepositoryDao().selectAll(db.getSession())).extracting(RuleRepositoryDto::getKey).containsOnly("fake"); } + private void verifyHotspot(RuleDto hotspotRule) { + assertThat(hotspotRule.getName()).isEqualTo("Hotspot"); + assertThat(hotspotRule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Minimal hotspot"); + assertThat(hotspotRule.getCreatedAt()).isEqualTo(RegisterRulesTest.DATE1.getTime()); + assertThat(hotspotRule.getUpdatedAt()).isEqualTo(RegisterRulesTest.DATE1.getTime()); + assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant()); + assertThat(hotspotRule.getSecurityStandards()).containsExactly("cwe:1", "cwe:123", "cwe:863", "owaspTop10-2021:a1", "owaspTop10-2021:a3"); + } + @Test public void insert_new_external_rule() { execute(new ExternalRuleRepository()); // verify db - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(2); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(2); RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), EXTERNAL_RULE_KEY1); - assertThat(rule1.getName()).isEqualTo("One"); - assertThat(rule1.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One"); - assertThat(rule1.getSeverityString()).isEqualTo(BLOCKER); - assertThat(rule1.getTags()).isEmpty(); - assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag2", "tag3"); - assertThat(rule1.getConfigKey()).isEqualTo("config1"); - assertThat(rule1.getStatus()).isEqualTo(RuleStatus.BETA); - assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime()); - assertThat(rule1.getScope()).isEqualTo(Scope.ALL); - assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1.getTime()); + verifyRule(rule1); + assertThat(rule1.isExternal()).isTrue(); assertThat(rule1.getDefRemediationFunction()).isNull(); assertThat(rule1.getDefRemediationGapMultiplier()).isNull(); assertThat(rule1.getDefRemediationBaseEffort()).isNull(); - assertThat(rule1.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); - assertThat(rule1.getPluginKey()).isEqualTo(FAKE_PLUGIN_KEY); - assertThat(rule1.isExternal()).isTrue(); - assertThat(rule1.isAdHoc()).isFalse(); RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), EXTERNAL_HOTSPOT_RULE_KEY); - assertThat(hotspotRule.getName()).isEqualTo("Hotspot"); - assertThat(hotspotRule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Minimal hotspot"); - assertThat(hotspotRule.getCreatedAt()).isEqualTo(DATE1.getTime()); - assertThat(hotspotRule.getUpdatedAt()).isEqualTo(DATE1.getTime()); - assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant()); - assertThat(hotspotRule.getSecurityStandards()).containsExactly("cwe:1", "cwe:123", "cwe:863", "owaspTop10-2021:a1", "owaspTop10-2021:a3"); + verifyHotspot(hotspotRule); + } + + + private void verifyRule(RuleDto rule) { + assertThat(rule.getName()).isEqualTo("One"); + assertThat(rule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One"); + assertThat(rule.getSeverityString()).isEqualTo(BLOCKER); + assertThat(rule.getTags()).isEmpty(); + assertThat(rule.getSystemTags()).containsOnly("tag1", "tag2", "tag3"); + assertThat(rule.getConfigKey()).isEqualTo("config1"); + assertThat(rule.getStatus()).isEqualTo(RuleStatus.BETA); + assertThat(rule.getCreatedAt()).isEqualTo(DATE1.getTime()); + assertThat(rule.getScope()).isEqualTo(Scope.ALL); + assertThat(rule.getUpdatedAt()).isEqualTo(DATE1.getTime()); + assertThat(rule.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); + assertThat(rule.getPluginKey()).isEqualTo(FAKE_PLUGIN_KEY); + assertThat(rule.isAdHoc()).isFalse(); } @Test @@ -230,12 +221,12 @@ public class RegisterRulesTest { }); // verify db - List rules = dbClient.ruleDao().selectAllDefinitions(db.getSession()); + List rules = dbClient.ruleDao().selectAll(db.getSession()); assertThat(rules) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .extracting(RuleKey::rule) .containsExactly(ruleKey); - RuleDefinitionDto rule = rules.iterator().next(); + RuleDto rule = rules.iterator().next(); // verify index assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()) @@ -246,12 +237,12 @@ public class RegisterRulesTest { execute(context -> context.createRepository("fake", "java").done()); // verify db - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())) - .extracting(RuleDefinitionDto::getKey) + assertThat(dbClient.ruleDao().selectAll(db.getSession())) + .extracting(RuleDto::getKey) .extracting(RuleKey::rule) .containsExactly(ruleKey); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())) - .extracting(RuleDefinitionDto::getStatus) + assertThat(dbClient.ruleDao().selectAll(db.getSession())) + .extracting(RuleDto::getStatus) .containsExactly(REMOVED); // verify index @@ -276,9 +267,9 @@ public class RegisterRulesTest { }); // verify db - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())) + assertThat(dbClient.ruleDao().selectAll(db.getSession())) .hasSize(numberOfRules) - .extracting(RuleDefinitionDto::getStatus) + .extracting(RuleDto::getStatus) .containsOnly(READY); // verify index @@ -290,9 +281,9 @@ public class RegisterRulesTest { execute(context -> context.createRepository("fake", "java").done()); // verify db - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())) + assertThat(dbClient.ruleDao().selectAll(db.getSession())) .hasSize(numberOfRules) - .extracting(RuleDefinitionDto::getStatus) + .extracting(RuleDto::getStatus) .containsOnly(REMOVED); // verify index (documents are still in the index, but all are removed) @@ -316,7 +307,7 @@ public class RegisterRulesTest { @Test public void update_and_remove_rules_on_changes() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(3); RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1); RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY2); RuleDto hotspotRule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), HOTSPOT_RULE_KEY); @@ -327,7 +318,7 @@ public class RegisterRulesTest { rule1.setTags(newHashSet("usertag1", "usertag2")); rule1.setNoteData("user *note*"); rule1.setNoteUserUuid("marius"); - dbClient.ruleDao().insertOrUpdate(db.getSession(), rule1.getMetadata()); + dbClient.ruleDao().update(db.getSession(), rule1); db.getSession().commit(); system.setNow(DATE2.getTime()); @@ -485,7 +476,7 @@ public class RegisterRulesTest { RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("squid", "rule")); // insert custom rule - db.rules().insert(new RuleDefinitionDto() + db.rules().insert(new RuleDto() .setRuleKey(RuleKey.of("squid", "custom")) .setLanguage("java") .setScope(Scope.ALL) @@ -711,13 +702,13 @@ public class RegisterRulesTest { @Test public void rule_previously_created_as_adhoc_becomes_none_adhoc() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake").setIsExternal(true).setIsAdHoc(true)); + RuleDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake").setIsExternal(true).setIsAdHoc(true)); system.setNow(DATE2.getTime()); execute(context -> { NewRepository repo = context.createExternalRepository("fake", rule.getLanguage()); repo.createRule(rule.getRuleKey()) .setName(rule.getName()) - .setHtmlDescription(rule.getDefaultRuleDescriptionSectionDto().getContent()); + .setHtmlDescription(rule.getDefaultRuleDescriptionSection().getContent()); repo.done(); }); @@ -727,7 +718,7 @@ public class RegisterRulesTest { @Test public void remove_no_more_defined_external_rule() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake") + RuleDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake") .setStatus(READY) .setIsExternal(true) .setIsAdHoc(false)); @@ -740,7 +731,7 @@ public class RegisterRulesTest { @Test public void do_not_remove_no_more_defined_ad_hoc_rule() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake") + RuleDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake") .setStatus(READY) .setIsExternal(true) .setIsAdHoc(true)); @@ -777,7 +768,7 @@ public class RegisterRulesTest { @Test public void do_not_update_rules_when_no_changes() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(3); system.setNow(DATE2.getTime()); execute(new FakeRepositoryV1()); @@ -790,7 +781,7 @@ public class RegisterRulesTest { @Test public void do_not_update_already_removed_rules() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(3); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(3); RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1); RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY2); @@ -803,7 +794,7 @@ public class RegisterRulesTest { execute(new FakeRepositoryV2()); // On MySQL, need to update a rule otherwise rule2 will be seen as READY, but why ??? - dbClient.ruleDao().update(db.getSession(), rule1.getDefinition()); + dbClient.ruleDao().update(db.getSession(), rule1); db.getSession().commit(); // rule2 is removed @@ -836,9 +827,9 @@ public class RegisterRulesTest { @Test public void manage_repository_extensions() { execute(new FindbugsRepository(), new FbContribRepository()); - List rules = dbClient.ruleDao().selectAllDefinitions(db.getSession()); + List rules = dbClient.ruleDao().selectAll(db.getSession()); assertThat(rules).hasSize(2); - for (RuleDefinitionDto rule : rules) { + for (RuleDto rule : rules) { assertThat(rule.getRepositoryKey()).isEqualTo("findbugs"); } } @@ -846,7 +837,7 @@ public class RegisterRulesTest { @Test public void remove_system_tags_when_plugin_does_not_provide_any() { // Rule already exists in DB, with some system tags - db.rules().insert(new RuleDefinitionDto() + db.rules().insert(new RuleDto() .setRuleKey("rule1") .setRepositoryKey("findbugs") .setName("Rule One") @@ -859,8 +850,8 @@ public class RegisterRulesTest { // Synchronize rule without tag execute(new FindbugsRepository()); - List rules = dbClient.ruleDao().selectAllDefinitions(db.getSession()); - assertThat(rules).hasSize(1).extracting(RuleDefinitionDto::getKey, RuleDefinitionDto::getSystemTags) + List rules = dbClient.ruleDao().selectAll(db.getSession()); + assertThat(rules).hasSize(1).extracting(RuleDto::getKey, RuleDto::getSystemTags) .containsOnly(tuple(RuleKey.of("findbugs", "rule1"), emptySet())); } @@ -880,7 +871,7 @@ public class RegisterRulesTest { repo.done(); }); - List rules = dbClient.ruleDao().selectAllDefinitions(db.getSession()); + List rules = dbClient.ruleDao().selectAll(db.getSession()); Set deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession()); assertThat(rules).hasSize(1); assertThat(deprecatedRuleKeys).hasSize(2); @@ -902,7 +893,7 @@ public class RegisterRulesTest { repo.done(); }); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(1); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(1); Set deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession()); assertThat(deprecatedRuleKeys).hasSize(2); @@ -912,7 +903,7 @@ public class RegisterRulesTest { repo.done(); }); - assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(1); + assertThat(dbClient.ruleDao().selectAll(db.getSession())).hasSize(1); deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession()); assertThat(deprecatedRuleKeys).isEmpty(); } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java index eef7b1db1b4..140afa3fcd1 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java @@ -28,7 +28,7 @@ import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE; @@ -72,7 +72,7 @@ public class IssueQuery { private final Collection directories; private final Collection files; private final Collection views; - private final Collection rules; + private final Collection rules; private final Collection ruleUuids; private final Collection assignees; private final Collection authors; @@ -187,7 +187,7 @@ public class IssueQuery { return views; } - public Collection rules() { + public Collection rules() { return rules; } @@ -332,7 +332,7 @@ public class IssueQuery { private Collection directories; private Collection files; private Collection views; - private Collection rules; + private Collection rules; private Collection ruleUuids; private Collection assigneeUuids; private Collection authors; @@ -420,7 +420,7 @@ public class IssueQuery { return this; } - public Builder rules(@Nullable Collection rules) { + public Builder rules(@Nullable Collection rules) { this.rules = rules; return this; } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index 72520964fa6..6b08ec07bd9 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -50,7 +50,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.SearchRequest; import org.sonar.server.issue.index.IssueQuery.PeriodStart; import org.sonar.server.user.UserSession; @@ -112,10 +112,10 @@ public class IssueQueryFactory { try (DbSession dbSession = dbClient.openSession(false)) { final ZoneId timeZone = parseTimeZone(request.getTimeZone()).orElse(clock.getZone()); - Collection ruleDefinitionDtos = ruleKeysToRuleId(dbSession, request.getRules()); - Collection ruleUuids = ruleDefinitionDtos.stream().map(RuleDefinitionDto::getUuid).collect(Collectors.toSet()); + Collection ruleDtos = ruleKeysToRuleId(dbSession, request.getRules()); + Collection ruleUuids = ruleDtos.stream().map(RuleDto::getUuid).collect(Collectors.toSet()); - if (request.getRules() != null && request.getRules().stream().collect(toSet()).size() != ruleDefinitionDtos.size()) { + if (request.getRules() != null && request.getRules().stream().collect(toSet()).size() != ruleDtos.size()) { ruleUuids.add("non-existing-uuid"); } @@ -125,7 +125,7 @@ public class IssueQueryFactory { .statuses(request.getStatuses()) .resolutions(request.getResolutions()) .resolved(request.getResolved()) - .rules(ruleDefinitionDtos) + .rules(ruleDtos) .ruleUuids(ruleUuids) .assigneeUuids(request.getAssigneeUuids()) .authors(request.getAuthors()) @@ -431,9 +431,9 @@ public class IssueQueryFactory { return componentDtos; } - private Collection ruleKeysToRuleId(DbSession dbSession, @Nullable Collection rules) { + private Collection ruleKeysToRuleId(DbSession dbSession, @Nullable Collection rules) { if (rules != null) { - return dbClient.ruleDao().selectDefinitionByKeys(dbSession, transform(rules, RuleKey::parse)); + return dbClient.ruleDao().selectByKeys(dbSession, transform(rules, RuleKey::parse)); } return Collections.emptyList(); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java index 16585ecd707..ac1062dde0a 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java @@ -32,7 +32,7 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; import org.sonar.server.es.SearchOptions; @@ -356,7 +356,7 @@ public class IssueIndexFacetsTest { public void facets_on_languages() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); db.rules().insert(ruleDefinitionDto); indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java index 29ceca25501..eb31178750a 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java @@ -36,7 +36,7 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.SearchOptions; import org.sonar.server.permission.index.IndexPermissions; @@ -609,7 +609,7 @@ public class IssueIndexFiltersTest { public void filter_by_rules() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); db.rules().insert(ruleDefinitionDto); indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid())); @@ -622,7 +622,7 @@ public class IssueIndexFiltersTest { public void filter_by_languages() { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); - RuleDefinitionDto ruleDefinitionDto = newRule(); + RuleDto ruleDefinitionDto = newRule(); db.rules().insert(ruleDefinitionDto); indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index bcc3b381627..4a35c325cd8 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -38,7 +38,7 @@ import org.sonar.api.issue.Issue; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; @@ -277,8 +277,8 @@ public class IssueIndexTest { @Test public void list_tags() { - RuleDefinitionDto r1 = db.rules().insert(); - RuleDefinitionDto r2 = db.rules().insert(); + RuleDto r1 = db.rules().insert(); + RuleDto r2 = db.rules().insert(); ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getUuid(), r2.getUuid())); ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java index bb8dc87c153..50493b8252d 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java @@ -35,7 +35,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.rule.RuleDbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.SearchRequest; import org.sonar.server.tester.UserSessionRule; @@ -80,8 +80,8 @@ public class IssueQueryFactoryTest { ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = ruleDbTester.insert(); - RuleDefinitionDto rule2 = ruleDbTester.insert(); + RuleDto rule1 = ruleDbTester.insert(); + RuleDto rule2 = ruleDbTester.insert(); ruleDbTester.insertOrUpdateMetadata(rule1, m -> m.setAdHocName(ruleAdHocName)); ruleDbTester.insertOrUpdateMetadata(rule2, m -> m.setAdHocName(ruleAdHocName)); newRule(RuleKey.of("findbugs", "NullReference")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java index 1c8781ef6ca..567daa7814d 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.sonar.api.issue.Issue; import org.sonar.api.rule.Severity; import org.sonar.core.util.Uuids; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.index.IssueQuery.PeriodStart; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +36,7 @@ public class IssueQueryTest { @Test public void build_query() { - RuleDefinitionDto rule = new RuleDefinitionDto().setUuid(Uuids.createFast()); + RuleDto rule = new RuleDto().setUuid(Uuids.createFast()); PeriodStart filterDate = new IssueQuery.PeriodStart(new Date(10_000_000_000L), false); IssueQuery query = IssueQuery.builder() .issueKeys(List.of("ABCDE")) diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java index f96821ea009..a67e8ded258 100644 --- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java +++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java @@ -34,7 +34,6 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventServiceImpl; @@ -67,9 +66,9 @@ public class QualityProfileChangeEventServiceImplTest { // Template rule RuleDto templateRule = newTemplateRule(RuleKey.of("xoo", "template-key")); - db.rules().insert(templateRule.getDefinition()); + db.rules().insert(templateRule); // Custom rule - RuleDefinitionDto rule1 = newCustomRule(templateRule.getDefinition()) + RuleDto rule1 = newCustomRule(templateRule) .setLanguage("xoo") .setRepositoryKey("repo") .setRuleKey("ruleKey") @@ -119,7 +118,7 @@ public class QualityProfileChangeEventServiceImplTest { QProfileDto activatedQualityProfile = QualityProfileTesting.newQualityProfileDto(); activatedQualityProfile.setLanguage("xoo"); db.qualityProfiles().insert(activatedQualityProfile); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo").setRuleKey("ruleKey")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo").setRuleKey("ruleKey")); RuleParamDto rule1Param = db.rules().insertRuleParam(rule1); ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(activatedQualityProfile, rule1); @@ -129,7 +128,7 @@ public class QualityProfileChangeEventServiceImplTest { QProfileDto deactivatedQualityProfile = QualityProfileTesting.newQualityProfileDto(); db.qualityProfiles().insert(deactivatedQualityProfile); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo2").setRuleKey("ruleKey2")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo2").setRuleKey("ruleKey2")); RuleParamDto rule2Param = db.rules().insertRuleParam(rule2); ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(deactivatedQualityProfile, rule2); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 3bda6ef9f9b..50952f8461a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -54,7 +54,7 @@ import org.sonar.db.component.SnapshotDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.issue.TextRangeResponseFormatter; @@ -516,7 +516,7 @@ public class SearchAction implements HotspotsWsAction { .map(IssueDto::getRuleKey) .collect(Collectors.toSet()); if (!ruleKeys.isEmpty()) { - searchResponseData.addRules(dbClient.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys)); + searchResponseData.addRules(dbClient.ruleDao().selectByKeys(dbSession, ruleKeys)); } } @@ -548,7 +548,7 @@ public class SearchAction implements HotspotsWsAction { SearchWsResponse.Hotspot.Builder builder = SearchWsResponse.Hotspot.newBuilder(); for (IssueDto hotspot : orderedHotspots) { - RuleDefinitionDto rule = searchResponseData.getRule(hotspot.getRuleKey()) + RuleDto rule = searchResponseData.getRule(hotspot.getRuleKey()) // due to join with table Rule when retrieving data from Issues, this can't happen .orElseThrow(() -> new IllegalStateException(format( "Rule with key '%s' not found for Hotspot '%s'", hotspot.getRuleKey(), hotspot.getKey()))); @@ -714,7 +714,7 @@ public class SearchAction implements HotspotsWsAction { private final Paging paging; private final List orderedHotspots; private final Map componentsByUuid = new HashMap<>(); - private final Map rulesByRuleKey = new HashMap<>(); + private final Map rulesByRuleKey = new HashMap<>(); private SearchResponseData(Paging paging, List orderedHotspots) { this.paging = paging; @@ -747,11 +747,11 @@ public class SearchAction implements HotspotsWsAction { return componentsByUuid; } - void addRules(Collection rules) { + void addRules(Collection rules) { rules.forEach(t -> rulesByRuleKey.put(t.getKey(), t)); } - Optional getRule(RuleKey ruleKey) { + Optional getRule(RuleKey ruleKey) { return ofNullable(rulesByRuleKey.get(ruleKey)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java index 4454b05c6d0..759bd3cc839 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java @@ -42,7 +42,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbIssues; import org.sonar.db.protobuf.DbIssues.Locations; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.issue.IssueChangeWSSupport; @@ -113,7 +113,7 @@ public class ShowAction implements HotspotsWsAction { Components components = loadComponents(dbSession, hotspot); Users users = loadUsers(dbSession, hotspot); - RuleDefinitionDto rule = loadRule(dbSession, hotspot); + RuleDto rule = loadRule(dbSession, hotspot); ShowWsResponse.Builder responseBuilder = ShowWsResponse.newBuilder(); formatHotspot(responseBuilder, hotspot, users); @@ -163,7 +163,7 @@ public class ShowAction implements HotspotsWsAction { responseBuilder.setCanChangeStatus(hotspotWsSupport.canChangeStatus(components.getProject())); } - private static void formatRule(ShowWsResponse.Builder responseBuilder, RuleDefinitionDto ruleDefinitionDto) { + private static void formatRule(ShowWsResponse.Builder responseBuilder, RuleDto ruleDefinitionDto) { SecurityStandards securityStandards = SecurityStandards.fromSecurityStandards(ruleDefinitionDto.getSecurityStandards()); SecurityStandards.SQCategory sqCategory = securityStandards.getSqCategory(); @@ -260,9 +260,9 @@ public class ShowAction implements HotspotsWsAction { .forEach(responseBuilder::addUsers); } - private RuleDefinitionDto loadRule(DbSession dbSession, IssueDto hotspot) { + private RuleDto loadRule(DbSession dbSession, IssueDto hotspot) { RuleKey ruleKey = hotspot.getRuleKey(); - return dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey) + return dbClient.ruleDao().selectByKey(dbSession, ruleKey) .orElseThrow(() -> new NotFoundException(format("Rule '%s' does not exist", ruleKey))); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java index 94a6dd20671..efe093e9fa3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/WebIssueStorage.java @@ -38,7 +38,7 @@ import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeMapper; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.rule.ServerRuleFinder; @@ -165,6 +165,6 @@ public class WebIssueStorage extends IssueStorage { } protected Optional getRuleUuid(Issue issue) { - return ruleFinder.findDtoByKey(issue.ruleKey()).map(RuleDefinitionDto::getUuid); + return ruleFinder.findDtoByKey(issue.ruleKey()).map(RuleDto::getUuid); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java index 95a0a51b77f..9a170755d84 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java @@ -54,7 +54,7 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.Action; import org.sonar.server.issue.ActionContext; @@ -292,7 +292,7 @@ public class BulkChangeAction implements IssuesWsAction { return null; } - RuleDefinitionDto ruleDefinitionDto = bulkChangeData.rulesByKey.get(issue.ruleKey()); + RuleDto ruleDefinitionDto = bulkChangeData.rulesByKey.get(issue.ruleKey()); ComponentDto projectDto = bulkChangeData.projectsByUuid.get(issue.projectUuid()); if (ruleDefinitionDto == null || projectDto == null) { return null; @@ -343,7 +343,7 @@ public class BulkChangeAction implements IssuesWsAction { private final Map projectsByUuid; private final Map branchesByProjectUuid; private final Map componentsByUuid; - private final Map rulesByKey; + private final Map rulesByKey; private final List availableActions; BulkChangeData(DbSession dbSession, Request request) { @@ -365,9 +365,9 @@ public class BulkChangeAction implements IssuesWsAction { this.componentsByUuid = getComponents(dbSession, issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream() .collect(uniqueIndex(ComponentDto::uuid, identity())); - this.rulesByKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, + this.rulesByKey = dbClient.ruleDao().selectByKeys(dbSession, issues.stream().map(DefaultIssue::ruleKey).collect(MoreCollectors.toSet())).stream() - .collect(uniqueIndex(RuleDefinitionDto::getKey, identity())); + .collect(uniqueIndex(RuleDto::getKey, identity())); this.availableActions = actions.stream() .filter(action -> propertiesByActions.containsKey(action.key())) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java index 622aaa16a6a..dee115bf149 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java @@ -33,7 +33,7 @@ import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.IssueChangePostProcessor; import org.sonar.server.issue.WebIssueStorage; @@ -71,11 +71,11 @@ public class IssueUpdater { public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSession, DefaultIssue issue, IssueChangeContext context, boolean refreshMeasures) { - Optional rule = getRuleByKey(dbSession, issue.getRuleKey()); + Optional rule = getRuleByKey(dbSession, issue.getRuleKey()); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid()); BranchDto branch = getBranch(dbSession, issue, issue.projectUuid()); ComponentDto component = getComponent(dbSession, issue, issue.componentUuid()); - IssueDto issueDto = doSaveIssue(dbSession, issue, context, rule, project, branch); + IssueDto issueDto = doSaveIssue(dbSession, issue, context, rule.orElse(null), project, branch); SearchResponseData result = new SearchResponseData(issueDto); rule.ifPresent(r -> result.addRules(singletonList(r))); @@ -91,13 +91,13 @@ public class IssueUpdater { } private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, - Optional rule, ComponentDto project, BranchDto branchDto) { + @Nullable RuleDto ruleDto, ComponentDto project, BranchDto branchDto) { IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next(); if ( // since this method is called after an update of the issue, date should never be null issue.updateDate() == null // name of rule is displayed in notification, rule must therefor be present - || !rule.isPresent() + || ruleDto == null // notification are not supported on PRs || !hasNotificationSupport(branchDto)) { return issueDto; @@ -113,7 +113,7 @@ public class IssueUpdater { .setNewResolution(issue.resolution()) .setNewStatus(issue.status()) .setAssignee(assignee.map(assigneeDto -> new User(assigneeDto.getUuid(), assigneeDto.getLogin(), assigneeDto.getName())).orElse(null)) - .setRule(rule.map(r -> new Rule(r.getKey(), RuleType.valueOfNullable(r.getType()), r.getName())).get()) + .setRule(new Rule(ruleDto.getKey(), RuleType.valueOfNullable(ruleDto.getType()), ruleDto.getName())) .setProject(new Project.Builder(project.uuid()) .setKey(project.getKey()) .setProjectName(project.name()) @@ -145,8 +145,8 @@ public class IssueUpdater { return component; } - private Optional getRuleByKey(DbSession session, RuleKey ruleKey) { - Optional rule = dbClient.ruleDao().selectDefinitionByKey(session, ruleKey); + private Optional getRuleByKey(DbSession session, RuleKey ruleKey) { + Optional rule = dbClient.ruleDao().selectByKey(session, ruleKey); return (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) ? rule : Optional.empty(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java index 88b39fcde07..3b4ab79c2db 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.workflow.Transition; @@ -47,7 +47,7 @@ public class SearchResponseData { private Long effortTotal = null; private final Map usersByUuid = new HashMap<>(); - private final List rules = new ArrayList<>(); + private final List rules = new ArrayList<>(); private final Map componentsByUuid = new HashMap<>(); private final ListMultimap commentsByIssueKey = ArrayListMultimap.create(); private final ListMultimap actionsByIssueKey = ArrayListMultimap.create(); @@ -85,7 +85,7 @@ public class SearchResponseData { return new ArrayList<>(usersByUuid.values()); } - public List getRules() { + public List getRules() { return rules; } @@ -119,7 +119,7 @@ public class SearchResponseData { } } - public void addRules(@Nullable List rules) { + public void addRules(@Nullable List rules) { if (rules != null) { this.rules.addAll(rules); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java index b0b155b91a6..8c03a0a0140 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java @@ -39,7 +39,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.markdown.Markdown; import org.sonar.server.es.Facets; @@ -275,14 +275,14 @@ public class SearchResponseFormat { private Common.Rules.Builder formatRules(SearchResponseData data) { Common.Rules.Builder wsRules = Common.Rules.newBuilder(); - List rules = firstNonNull(data.getRules(), emptyList()); - for (RuleDefinitionDto rule : rules) { + List rules = firstNonNull(data.getRules(), emptyList()); + for (RuleDto rule : rules) { wsRules.addRules(formatRule(rule)); } return wsRules; } - private Common.Rule.Builder formatRule(RuleDefinitionDto rule) { + private Common.Rule.Builder formatRule(RuleDto rule) { Common.Rule.Builder builder = Common.Rule.newBuilder() .setKey(rule.getKey().toString()) .setName(nullToEmpty(rule.getName())) @@ -410,7 +410,7 @@ public class SearchResponseFormat { return; } - Map ruleUuidsByRuleKeys = data.getRules().stream().collect(uniqueIndex(RuleDefinitionDto::getUuid, RuleDefinitionDto::getKey)); + Map ruleUuidsByRuleKeys = data.getRules().stream().collect(uniqueIndex(RuleDto::getUuid, RuleDto::getKey)); Common.Facet.Builder wsFacet = wsFacets.addFacetsBuilder(); wsFacet.setProperty(PARAM_RULES); facet.forEach((ruleUuid, count) -> wsFacet.addValuesBuilder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java index 27f29fe0978..53648c30a0f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java @@ -32,7 +32,6 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.util.stream.MoreCollectors; @@ -42,8 +41,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; -import org.sonar.db.rule.RuleMetadataDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.Facets; import org.sonar.server.issue.TransitionService; @@ -166,19 +164,24 @@ public class SearchResponseLoader { } private void loadRules(SearchResponseData preloadedResponseData, Collector collector, DbSession dbSession, SearchResponseData result) { - List preloadedRules = firstNonNull(preloadedResponseData.getRules(), emptyList()); + List preloadedRules = firstNonNull(preloadedResponseData.getRules(), emptyList()); result.addRules(preloadedRules); Set ruleUuidsToLoad = collector.getRuleUuids(); - preloadedRules.stream().map(RuleDefinitionDto::getUuid).collect(toList(preloadedRules.size())) + preloadedRules.stream().map(RuleDto::getUuid).collect(toList(preloadedRules.size())) .forEach(ruleUuidsToLoad::remove); - List rules = dbClient.ruleDao().selectDefinitionByUuids(dbSession, ruleUuidsToLoad); - - getRulesMetadata(dbSession, rules); - + List rules = dbClient.ruleDao().selectByUuids(dbSession, ruleUuidsToLoad); + updateNamesOfAdHocRules(rules); result.addRules(rules); } + private static void updateNamesOfAdHocRules(List rules) { + rules.stream() + .filter(RuleDto::isAdHoc) + .forEach(r -> r.setName(r.getAdHocName())); + } + + private void loadComments(Collector collector, DbSession dbSession, Set fields, SearchResponseData result) { if (fields.contains(COMMENTS)) { List comments = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, collector.getIssueKeys(), IssueChangeDto.TYPE_COMMENT); @@ -345,21 +348,4 @@ public class SearchResponseLoader { } } - private void getRulesMetadata(DbSession dbSession, List rules) { - List adHocRuleKeys = rules.stream().filter(RuleDefinitionDto::isAdHoc) - .map(r -> RuleKey.of(r.getRepositoryKey(), r.getRuleKey())) - .collect(toList()); - - List adHocRulesMetadata = dbClient.ruleDao().selectMetadataByKeys(dbSession, adHocRuleKeys); - - rules.forEach(r -> { - if (r.isAdHoc()) { - String adHocName = adHocRulesMetadata.stream() - .filter(m -> m.getRuleUuid().equals(r.getUuid())).findFirst().map(RuleMetadataDto::getAdHocName) - .orElse(null); - r.setName(adHocName); - } - }); - } - } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java index bf324780112..742e09c4d22 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java @@ -42,7 +42,7 @@ import org.sonar.db.qualityprofile.ExportRuleDto; import org.sonar.db.qualityprofile.ExportRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.builtin.QProfileName; import org.sonar.server.rule.NewCustomRule; import org.sonar.server.rule.NewRuleDescriptionSection; @@ -142,10 +142,10 @@ public class QProfileBackuperImpl implements QProfileBackuper { List importedRules = qProfile.getRules(); - Map ruleDefinitionsByKey = getImportedRulesDefinitions(dbSession, importedRules); + Map ruleDefinitionsByKey = getImportedRulesDefinitions(dbSession, importedRules); checkIfRulesFromExternalEngines(ruleDefinitionsByKey.values()); - Map customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleDefinitionsByKey); + Map customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleDefinitionsByKey); ruleDefinitionsByKey.putAll(customRulesDefinitions); List ruleActivations = toRuleActivations(importedRules, ruleDefinitionsByKey); @@ -156,14 +156,14 @@ public class QProfileBackuperImpl implements QProfileBackuper { /** * Returns map of rule definition for an imported rule key. - * The imported rule key may refer to a deprecated rule key, in which case the the RuleDefinitionDto will correspond to a different key (the new key). + * The imported rule key may refer to a deprecated rule key, in which case the the RuleDto will correspond to a different key (the new key). */ - private Map getImportedRulesDefinitions(DbSession dbSession, List rules) { + private Map getImportedRulesDefinitions(DbSession dbSession, List rules) { Set ruleKeys = rules.stream() .map(ImportedRule::getRuleKey) .collect(toSet()); - Map rulesDefinitions = db.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys).stream() - .collect(Collectors.toMap(RuleDefinitionDto::getKey, identity())); + Map rulesDefinitions = db.ruleDao().selectByKeys(dbSession, ruleKeys).stream() + .collect(Collectors.toMap(RuleDto::getKey, identity())); Set unrecognizedRuleKeys = ruleKeys.stream() .filter(r -> !rulesDefinitions.containsKey(r)) @@ -177,8 +177,8 @@ public class QProfileBackuperImpl implements QProfileBackuper { .filter(r -> !ruleKeys.contains(RuleKey.of(r.getNewRepositoryKey(), r.getNewRuleKey()))) .collect(Collectors.toMap(DeprecatedRuleKeyDto::getRuleUuid, identity())); - List rulesBasedOnDeprecatedKeys = db.ruleDao().selectDefinitionByUuids(dbSession, deprecatedRuleKeysByUuid.keySet()); - for (RuleDefinitionDto rule : rulesBasedOnDeprecatedKeys) { + List rulesBasedOnDeprecatedKeys = db.ruleDao().selectByUuids(dbSession, deprecatedRuleKeysByUuid.keySet()); + for (RuleDto rule : rulesBasedOnDeprecatedKeys) { DeprecatedRuleKeyDto deprecatedRuleKey = deprecatedRuleKeysByUuid.get(rule.getUuid()); RuleKey oldRuleKey = RuleKey.of(deprecatedRuleKey.getOldRepositoryKey(), deprecatedRuleKey.getOldRuleKey()); rulesDefinitions.put(oldRuleKey, rule); @@ -188,9 +188,9 @@ public class QProfileBackuperImpl implements QProfileBackuper { return rulesDefinitions; } - private static void checkIfRulesFromExternalEngines(Collection ruleDefinitions) { - List externalRules = ruleDefinitions.stream() - .filter(RuleDefinitionDto::isExternal) + private static void checkIfRulesFromExternalEngines(Collection ruleDefinitions) { + List externalRules = ruleDefinitions.stream() + .filter(RuleDto::isExternal) .collect(Collectors.toList()); if (!externalRules.isEmpty()) { @@ -199,16 +199,16 @@ public class QProfileBackuperImpl implements QProfileBackuper { } } - private Map createCustomRulesIfNotExist(DbSession dbSession, List rules, Map ruleDefinitionsByKey) { + private Map createCustomRulesIfNotExist(DbSession dbSession, List rules, Map ruleDefinitionsByKey) { List customRulesToCreate = rules.stream() .filter(r -> ruleDefinitionsByKey.get(r.getRuleKey()) == null && r.isCustomRule()) .map(QProfileBackuperImpl::importedRuleToNewCustomRule) .collect(Collectors.toList()); if (!customRulesToCreate.isEmpty()) { - return db.ruleDao().selectDefinitionByKeys(dbSession, ruleCreator.create(dbSession, customRulesToCreate)) + return db.ruleDao().selectByKeys(dbSession, ruleCreator.create(dbSession, customRulesToCreate)) .stream() - .collect(Collectors.toMap(RuleDefinitionDto::getKey, identity())); + .collect(Collectors.toMap(RuleDto::getKey, identity())); } return Collections.emptyMap(); } @@ -225,15 +225,15 @@ public class QProfileBackuperImpl implements QProfileBackuper { .setParameters(r.getParameters()); } - private static List toRuleActivations(List rules, Map ruleDefinitionsByKey) { + private static List toRuleActivations(List rules, Map ruleDefinitionsByKey) { List activatedRule = new ArrayList<>(); for (ImportedRule r : rules) { - RuleDefinitionDto ruleDefinition = ruleDefinitionsByKey.get(r.getRuleKey()); - if (ruleDefinition == null) { + RuleDto ruleDto = ruleDefinitionsByKey.get(r.getRuleKey()); + if (ruleDto == null) { continue; } - activatedRule.add(RuleActivation.create(ruleDefinition.getUuid(), r.getSeverity(), r.getParameters())); + activatedRule.add(RuleActivation.create(ruleDto.getUuid(), r.getSeverity(), r.getParameters())); } return activatedRule; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java index f39c742db22..ef7b0f6ab63 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java @@ -52,7 +52,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; import org.springframework.beans.factory.annotation.Autowired; @@ -164,9 +164,9 @@ public class QProfileExporters { } private List importProfile(QProfileDto profile, RulesProfile definition, DbSession dbSession) { - Map rulesByRuleKey = dbClient.ruleDao().selectAllDefinitions(dbSession) + Map rulesByRuleKey = dbClient.ruleDao().selectAll(dbSession) .stream() - .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey)); + .collect(MoreCollectors.uniqueIndex(RuleDto::getKey)); List activeRules = definition.getActiveRules(); List activations = activeRules.stream() .map(activeRule -> toRuleActivation(activeRule, rulesByRuleKey)) @@ -191,16 +191,16 @@ public class QProfileExporters { } @CheckForNull - private static RuleActivation toRuleActivation(ActiveRule activeRule, Map rulesByRuleKey) { + private static RuleActivation toRuleActivation(ActiveRule activeRule, Map rulesByRuleKey) { RuleKey ruleKey = activeRule.getRule().ruleKey(); - RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); - if (ruleDefinition == null) { + RuleDto ruleDto = rulesByRuleKey.get(ruleKey); + if (ruleDto == null) { return null; } String severity = activeRule.getSeverity().name(); Map params = activeRule.getActiveRuleParams().stream() .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue)); - return RuleActivation.create(ruleDefinition.getUuid(), severity, params); + return RuleActivation.create(ruleDto.getUuid(), severity, params); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java index 449d621a8ad..42b988e685c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java @@ -30,7 +30,7 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; import org.sonar.server.qualityprofile.builtin.RuleActivationContext; @@ -77,8 +77,8 @@ public class QProfileRulesImpl implements QProfileRules { @Override public BulkChangeResult bulkActivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, @Nullable String severity) { verifyNotBuiltIn(profile); - BulkChangeResult bulkChangeResult = doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> { - RuleActivation activation = RuleActivation.create(ruleDefinition.getUuid(), severity, null); + BulkChangeResult bulkChangeResult = doBulk(dbSession, profile, ruleQuery, (context, ruleDto) -> { + RuleActivation activation = RuleActivation.create(ruleDto.getUuid(), severity, null); return ruleActivator.activate(dbSession, activation, context); }); qualityProfileChangeEventService.distributeRuleChangeEvent(List.of(profile), bulkChangeResult.getChanges(), profile.getLanguage()); @@ -104,8 +104,8 @@ public class QProfileRulesImpl implements QProfileRules { @Override public BulkChangeResult bulkDeactivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery) { verifyNotBuiltIn(profile); - BulkChangeResult bulkChangeResult = doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> - ruleActivator.deactivate(dbSession, context, ruleDefinition.getUuid(), false)); + BulkChangeResult bulkChangeResult = doBulk(dbSession, profile, ruleQuery, (context, ruleDto) -> + ruleActivator.deactivate(dbSession, context, ruleDto.getUuid(), false)); qualityProfileChangeEventService.distributeRuleChangeEvent(List.of(profile), bulkChangeResult.getChanges(), profile.getLanguage()); @@ -113,7 +113,7 @@ public class QProfileRulesImpl implements QProfileRules { } @Override - public List deleteRule(DbSession dbSession, RuleDefinitionDto rule) { + public List deleteRule(DbSession dbSession, RuleDto rule) { List changes = new ArrayList<>(); List activeRuleUuids = new ArrayList<>(); db.activeRuleDao().selectByRuleUuid(dbSession, rule.getUuid()).forEach(ar -> { @@ -131,7 +131,7 @@ public class QProfileRulesImpl implements QProfileRules { checkArgument(!profile.isBuiltIn(), "The built-in profile %s is read-only and can't be updated", profile.getName()); } - private BulkChangeResult doBulk(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, BiFunction> fn) { + private BulkChangeResult doBulk(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, BiFunction> fn) { BulkChangeResult result = new BulkChangeResult(); Collection ruleUuids = Sets.newHashSet(ruleIndex.searchAll(ruleQuery)); RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids); @@ -139,8 +139,8 @@ public class QProfileRulesImpl implements QProfileRules { for (String ruleUuid : ruleUuids) { try { context.reset(ruleUuid); - RuleDefinitionDto ruleDefinition = context.getRule().get(); - List changes = fn.apply(context, ruleDefinition); + RuleDto ruleDto = context.getRule().get(); + List changes = fn.apply(context, ruleDto); result.addChanges(changes); if (!changes.isEmpty()) { result.incrementSucceeded(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java index bc6cc6536d8..06ffa487578 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImpl.java @@ -45,7 +45,7 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.DefaultQProfileDto; import org.sonar.db.qualityprofile.OrgQProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; @@ -131,7 +131,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert { private ActiveRuleChange insertActiveRule(DbSession batchDbSession, RulesProfileDto rulesProfileDto, BuiltInQProfile.ActiveRule activeRule, long now) { RuleKey ruleKey = activeRule.getRuleKey(); - RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey) + RuleDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey) .orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey)); ActiveRuleDto dto = new ActiveRuleDto(); @@ -202,7 +202,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert { } } - private Optional getDefinition(RuleKey ruleKey) { + private Optional getDefinition(RuleKey ruleKey) { return ruleFinder.findDtoByKey(requireNonNull(ruleKey, "RuleKey can't be null")); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java index 6573c0eec58..aa119908886 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImpl.java @@ -45,7 +45,7 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.rule.ServerRuleFinder; import org.springframework.beans.factory.annotation.Autowired; @@ -129,7 +129,7 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository if (rulesProfilesByLanguage.isEmpty()) { return Collections.emptyList(); } - Map rulesByRuleKey = loadRuleDefinitionsByRuleKey(); + Map rulesByRuleKey = loadRuleDefinitionsByRuleKey(); Map> buildersByLanguage = rulesProfilesByLanguage .entrySet() .stream() @@ -145,15 +145,15 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository .collect(MoreCollectors.toList()); } - private Map loadRuleDefinitionsByRuleKey() { + private Map loadRuleDefinitionsByRuleKey() { try (DbSession dbSession = dbClient.openSession(false)) { - Collection ruleDefinitions = ruleFinder.findAll(); + Collection ruleDefinitions = ruleFinder.findAll(); Multimap deprecatedRuleKeysByRuleId = dbClient.ruleDao().selectAllDeprecatedRuleKeys(dbSession).stream() .collect(MoreCollectors.index(DeprecatedRuleKeyDto::getRuleUuid)); - Map rulesByRuleKey = new HashMap<>(); - for (RuleDefinitionDto ruleDefinition : ruleDefinitions) { - rulesByRuleKey.put(ruleDefinition.getKey(), ruleDefinition); - deprecatedRuleKeysByRuleId.get(ruleDefinition.getUuid()).forEach(t -> rulesByRuleKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), ruleDefinition)); + Map rulesByRuleKey = new HashMap<>(); + for (RuleDto ruleDto : ruleDefinitions) { + rulesByRuleKey.put(ruleDto.getKey(), ruleDto); + deprecatedRuleKeysByRuleId.get(ruleDto.getUuid()).forEach(t -> rulesByRuleKey.put(RuleKey.of(t.getOldRepositoryKey(), t.getOldRuleKey()), ruleDto)); } return rulesByRuleKey; } @@ -172,7 +172,7 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository * */ private static List toQualityProfileBuilders(Map.Entry> rulesProfilesByLanguageAndName, - Map rulesByRuleKey) { + Map rulesByRuleKey) { String language = rulesProfilesByLanguageAndName.getKey(); // use a LinkedHashMap to keep order of insertion of RulesProfiles Map qualityProfileBuildersByName = new LinkedHashMap<>(); @@ -197,14 +197,14 @@ public class BuiltInQProfileRepositoryImpl implements BuiltInQProfileRepository } private static BuiltInQProfile.Builder updateOrCreateBuilder(String language, @Nullable BuiltInQProfile.Builder existingBuilder, BuiltInQualityProfile builtInProfile, - Map rulesByRuleKey) { + Map rulesByRuleKey) { BuiltInQProfile.Builder builder = createOrReuseBuilder(existingBuilder, language, builtInProfile); builder.setDeclaredDefault(builtInProfile.isDefault()); builtInProfile.rules().forEach(builtInActiveRule -> { RuleKey ruleKey = RuleKey.of(builtInActiveRule.repoKey(), builtInActiveRule.ruleKey()); - RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); - checkState(ruleDefinition != null, "Rule with key '%s' not found", ruleKey); - builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getUuid(), ruleDefinition.getKey(), + RuleDto ruleDto = rulesByRuleKey.get(ruleKey); + checkState(ruleDto != null, "Rule with key '%s' not found", ruleKey); + builder.addRule(new BuiltInQProfile.ActiveRule(ruleDto.getUuid(), ruleDto.getKey(), builtInActiveRule.overriddenSeverity(), builtInActiveRule.overriddenParams())); }); return builder; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java index c1aacdd5f23..ddd1f4be9c2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivationContext.java @@ -33,7 +33,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.qualityprofile.RuleActivation; @@ -83,7 +83,7 @@ public class RuleActivationContext { this.descendantProfilesSupplier = builder.descendantProfilesSupplier; ListMultimap paramsByRuleId = builder.ruleParams.stream().collect(index(RuleParamDto::getRuleUuid)); - for (RuleDefinitionDto rule : builder.rules) { + for (RuleDto rule : builder.rules) { RuleWrapper wrapper = new RuleWrapper(rule, paramsByRuleId.get(rule.getUuid())); rulesByUuid.put(rule.getUuid(), wrapper); } @@ -243,7 +243,7 @@ public class RuleActivationContext { static final class Builder { private long date = System.currentTimeMillis(); private RulesProfileDto baseRulesProfile; - private Collection rules; + private Collection rules; private Collection ruleParams; private Collection profiles; private Collection activeRules; @@ -260,7 +260,7 @@ public class RuleActivationContext { return this; } - Builder setRules(Collection rules) { + Builder setRules(Collection rules) { this.rules = rules; return this; } @@ -308,15 +308,15 @@ public class RuleActivationContext { } public static final class RuleWrapper { - private final RuleDefinitionDto rule; + private final RuleDto rule; private final Map paramsByKey; - private RuleWrapper(RuleDefinitionDto rule, Collection params) { + private RuleWrapper(RuleDto rule, Collection params) { this.rule = rule; this.paramsByKey = params.stream().collect(uniqueIndex(RuleParamDto::getName)); } - public RuleDefinitionDto get() { + public RuleDto get() { return rule; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java index b6da63d6b9b..1d4c5c5bb40 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/builtin/RuleActivator.java @@ -44,7 +44,7 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgQProfileDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.ActiveRuleInheritance; @@ -89,7 +89,7 @@ public class RuleActivator { } private List doActivate(DbSession dbSession, RuleActivation activation, RuleActivationContext context) { - RuleDefinitionDto rule = context.getRule().get(); + RuleDto rule = context.getRule().get(); checkRequest(RuleStatus.REMOVED != rule.getStatus(), "Rule was removed: %s", rule.getKey()); checkRequest(!rule.isTemplate(), "Rule template can't be activated on a Quality profile: %s", rule.getKey()); checkRequest(context.getRulesProfile().getLanguage().equals(rule.getLanguage()), @@ -157,7 +157,7 @@ public class RuleActivator { return stopCascading; } - private ActiveRuleChange handleNewRuleActivation(RuleActivation activation, RuleActivationContext context, RuleDefinitionDto rule, ActiveRuleKey activeRuleKey) { + private ActiveRuleChange handleNewRuleActivation(RuleActivation activation, RuleActivationContext context, RuleDto rule, ActiveRuleKey activeRuleKey) { ActiveRuleChange change = new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, activeRuleKey, rule); applySeverityAndParamToChange(activation, context, change); if (context.isCascading() || isSameAsParent(change, context)) { @@ -484,7 +484,7 @@ public class RuleActivator { } private void completeWithRules(DbSession dbSession, RuleActivationContext.Builder builder, Collection ruleUuids) { - List rules = db.ruleDao().selectDefinitionByUuids(dbSession, ruleUuids); + List rules = db.ruleDao().selectByUuids(dbSession, ruleUuids); builder.setRules(rules); builder.setRuleParams(db.ruleDao().selectRuleParamsByRuleUuids(dbSession, ruleUuids)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java index 7ed7e76f737..2853201598c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java @@ -29,7 +29,7 @@ import org.sonar.api.utils.KeyValueFormat; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.QProfileRules; import org.sonar.server.qualityprofile.RuleActivation; import org.sonar.server.user.UserSession; @@ -110,10 +110,10 @@ public class ActivateRuleAction implements QProfileWsAction { private RuleActivation readActivation(DbSession dbSession, Request request) { RuleKey ruleKey = RuleKey.parse(request.mandatoryParam(PARAM_RULE)); - RuleDefinitionDto ruleDefinition = wsSupport.getRule(dbSession, ruleKey); + RuleDto ruleDto = wsSupport.getRule(dbSession, ruleKey); boolean reset = Boolean.TRUE.equals(request.paramAsBoolean(PARAM_RESET)); if (reset) { - return RuleActivation.createReset(ruleDefinition.getUuid()); + return RuleActivation.createReset(ruleDto.getUuid()); } String severity = request.param(PARAM_SEVERITY); Map params = null; @@ -121,7 +121,7 @@ public class ActivateRuleAction implements QProfileWsAction { if (paramsAsString != null) { params = KeyValueFormat.parse(paramsAsString); } - return RuleActivation.create(ruleDefinition.getUuid(), severity, params); + return RuleActivation.create(ruleDto.getUuid(), severity, params); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java index 5e57db34197..a47320dd6e4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java @@ -41,7 +41,7 @@ import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileChangeQuery; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; @@ -111,7 +111,7 @@ public class ChangelogAction implements QProfileWsAction { List changelogs = load(dbSession, query); Map usersByUuid = getUsersByUserUuid(dbSession, changelogs); - Map rulesByRuleIds = getRulesByRuleUuids(dbSession, changelogs); + Map rulesByRuleIds = getRulesByRuleUuids(dbSession, changelogs); writeResponse(response.newJsonWriter(), total, page, pageSize, changelogs, usersByUuid, rulesByRuleIds); } } @@ -127,19 +127,19 @@ public class ChangelogAction implements QProfileWsAction { .collect(uniqueIndex(UserDto::getUuid)); } - private Map getRulesByRuleUuids(DbSession dbSession, List changes) { + private Map getRulesByRuleUuids(DbSession dbSession, List changes) { Set ruleUuids = changes.stream() .map(c -> c.ruleUuid) .filter(Objects::nonNull) .collect(toSet()); return dbClient.ruleDao() - .selectDefinitionByUuids(dbSession, Lists.newArrayList(ruleUuids)) + .selectByUuids(dbSession, Lists.newArrayList(ruleUuids)) .stream() - .collect(uniqueIndex(RuleDefinitionDto::getUuid)); + .collect(uniqueIndex(RuleDto::getUuid)); } private static void writeResponse(JsonWriter json, int total, int page, int pageSize, List changelogs, - Map usersByUuid, Map rulesByRuleUuids) { + Map usersByUuid, Map rulesByRuleUuids) { json.beginObject(); json.prop("total", total); json.prop(Param.PAGE, page); @@ -156,7 +156,7 @@ public class ChangelogAction implements QProfileWsAction { .prop("authorLogin", user.getLogin()) .prop("authorName", user.getName()); } - RuleDefinitionDto rule = rulesByRuleUuids.get(change.getRuleUuid()); + RuleDto rule = rulesByRuleUuids.get(change.getRuleUuid()); if (rule != null) { changeWriter .prop("ruleKey", rule.getKey().toString()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java index e8d91c6b0f6..f379f4013e8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java @@ -38,7 +38,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleRepositoryDto; import org.sonar.server.qualityprofile.QProfileComparison; import org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff; @@ -111,14 +111,14 @@ public class CompareAction implements QProfileWsAction { QProfileComparisonResult result = comparator.compare(dbSession, left, right); - List referencedRules = dbClient.ruleDao().selectDefinitionByKeys(dbSession, new ArrayList<>(result.collectRuleKeys())); - Map rulesByKey = Maps.uniqueIndex(referencedRules, RuleDefinitionDto::getKey); + List referencedRules = dbClient.ruleDao().selectByKeys(dbSession, new ArrayList<>(result.collectRuleKeys())); + Map rulesByKey = Maps.uniqueIndex(referencedRules, RuleDto::getKey); Map repositoriesByKey = Maps.uniqueIndex(dbClient.ruleRepositoryDao().selectAll(dbSession), RuleRepositoryDto::getKey); writeResult(response.newJsonWriter(), result, rulesByKey, repositoriesByKey); } } - private void writeResult(JsonWriter json, QProfileComparisonResult result, Map rulesByKey, Map repositoriesByKey) { + private void writeResult(JsonWriter json, QProfileComparisonResult result, Map rulesByKey, Map repositoriesByKey) { json.beginObject(); json.name(ATTRIBUTE_LEFT).beginObject(); @@ -149,7 +149,7 @@ public class CompareAction implements QProfileWsAction { .prop(ATTRIBUTE_NAME, profile.getName()); } - private void writeRules(JsonWriter json, Map activeRules, Map rulesByKey, + private void writeRules(JsonWriter json, Map activeRules, Map rulesByKey, Map repositoriesByKey) { json.beginArray(); for (Entry activeRule : activeRules.entrySet()) { @@ -157,7 +157,7 @@ public class CompareAction implements QProfileWsAction { ActiveRuleDto value = activeRule.getValue(); json.beginObject(); - RuleDefinitionDto rule = rulesByKey.get(key); + RuleDto rule = rulesByKey.get(key); writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey())); json.prop(ATTRIBUTE_SEVERITY, value.getSeverityString()); json.endObject(); @@ -165,7 +165,7 @@ public class CompareAction implements QProfileWsAction { json.endArray(); } - private void writeRule(JsonWriter json, RuleDefinitionDto rule, @Nullable RuleRepositoryDto repository) { + private void writeRule(JsonWriter json, RuleDto rule, @Nullable RuleRepositoryDto repository) { String repositoryKey = rule.getRepositoryKey(); json.prop(ATTRIBUTE_KEY, rule.getKey().toString()) .prop(ATTRIBUTE_NAME, rule.getName()) @@ -181,14 +181,14 @@ public class CompareAction implements QProfileWsAction { } } - private void writeDifferences(JsonWriter json, Map modified, Map rulesByKey, + private void writeDifferences(JsonWriter json, Map modified, Map rulesByKey, Map repositoriesByKey) { json.beginArray(); for (Entry diffEntry : modified.entrySet()) { RuleKey key = diffEntry.getKey(); ActiveRuleDiff value = diffEntry.getValue(); json.beginObject(); - RuleDefinitionDto rule = rulesByKey.get(key); + RuleDto rule = rulesByKey.get(key); writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey())); json.name(ATTRIBUTE_LEFT).beginObject(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java index 2b4b3925062..3610f94840d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java @@ -26,7 +26,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.QProfileRules; import org.sonar.server.user.UserSession; @@ -80,7 +80,7 @@ public class DeactivateRuleAction implements QProfileWsAction { String qualityProfileKey = request.mandatoryParam(PARAM_KEY); userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { - RuleDefinitionDto rule = wsSupport.getRule(dbSession, ruleKey); + RuleDto rule = wsSupport.getRule(dbSession, ruleKey); QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey)); wsSupport.checkCanEdit(dbSession, profile); ruleActivator.deactivateAndCommit(dbSession, profile, singletonList(rule.getUuid())); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java index 04b1c88c57c..bb4bd5129e4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java @@ -26,7 +26,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.user.UserSession; @@ -48,9 +48,9 @@ public class QProfileWsSupport { this.userSession = userSession; } - public RuleDefinitionDto getRule(DbSession dbSession, RuleKey ruleKey) { - Optional ruleDefinitionDto = dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey); - RuleDefinitionDto rule = checkFoundWithOptional(ruleDefinitionDto, "Rule with key '%s' not found", ruleKey); + public RuleDto getRule(DbSession dbSession, RuleKey ruleKey) { + Optional ruleDefinitionDto = dbClient.ruleDao().selectByKey(dbSession, ruleKey); + RuleDto rule = checkFoundWithOptional(ruleDefinitionDto, "Rule with key '%s' not found", ruleKey); checkRequest(!rule.isExternal(), "Operation forbidden for rule '%s' imported from an external rule engine.", ruleKey); return rule; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java index 1834a4a76cb..c3d82ccdd91 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleCreator.java @@ -38,11 +38,9 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; -import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.rule.index.RuleIndexer; @@ -82,7 +80,7 @@ public class RuleCreator { validateCustomRule(newRule, dbSession, templateKey); RuleKey customRuleKey = RuleKey.of(templateRule.getRepositoryKey(), newRule.ruleKey()); - Optional definition = loadRule(dbSession, customRuleKey); + Optional definition = loadRule(dbSession, customRuleKey); String customRuleUuid = definition.map(d -> updateExistingRule(d, newRule, dbSession)) .orElseGet(() -> createCustomRule(customRuleKey, newRule, templateRule, dbSession)); @@ -186,12 +184,12 @@ public class RuleCreator { } } - private Optional loadRule(DbSession dbSession, RuleKey ruleKey) { - return dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey); + private Optional loadRule(DbSession dbSession, RuleKey ruleKey) { + return dbClient.ruleDao().selectByKey(dbSession, ruleKey); } private String createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) { - RuleDefinitionDto ruleDefinition = new RuleDefinitionDto() + RuleDto ruleDto = new RuleDto() .setUuid(uuidFactory.create()) .setRuleKey(ruleKey) .setPluginKey(templateRuleDto.getPluginKey()) @@ -214,11 +212,11 @@ public class RuleCreator { .setCreatedAt(system2.now()) .setUpdatedAt(system2.now()); - ruleDefinition.setDescriptionFormat(Format.MARKDOWN); + ruleDto.setDescriptionFormat(Format.MARKDOWN); if (newRule.getRuleDescriptionSections().isEmpty() && newRule.markdownDescription() != null) { RuleDescriptionSectionDto ruleDescriptionSectionDto = createDefaultRuleDescriptionSection(uuidFactory.create(), newRule.markdownDescription()); - ruleDefinition.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); + ruleDto.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); } else { for (NewRuleDescriptionSection ruleDescriptionSection : newRule.getRuleDescriptionSections()) { RuleDescriptionSectionDto ruleDescriptionSectionDto = RuleDescriptionSectionDto.builder() @@ -226,30 +224,24 @@ public class RuleCreator { .key(ruleDescriptionSection.getKey()) .content(ruleDescriptionSection.getContent()) .build(); - ruleDefinition.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); + ruleDto.addRuleDescriptionSectionDto(ruleDescriptionSectionDto); } } - dbClient.ruleDao().insert(dbSession, ruleDefinition); - Set tags = templateRuleDto.getTags(); if (!tags.isEmpty()) { - RuleMetadataDto ruleMetadata = new RuleMetadataDto() - .setRuleUuid(ruleDefinition.getUuid()) - .setTags(tags) - .setCreatedAt(system2.now()) - .setUpdatedAt(system2.now()); - dbClient.ruleDao().insertOrUpdate(dbSession, ruleMetadata); + ruleDto.setTags(tags); } + dbClient.ruleDao().insert(dbSession, ruleDto); for (RuleParamDto templateRuleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateRuleDto.getKey())) { String customRuleParamValue = Strings.emptyToNull(newRule.parameter(templateRuleParamDto.getName())); - createCustomRuleParams(customRuleParamValue, ruleDefinition, templateRuleParamDto, dbSession); + createCustomRuleParams(customRuleParamValue, ruleDto, templateRuleParamDto, dbSession); } - return ruleDefinition.getUuid(); + return ruleDto.getUuid(); } - private void createCustomRuleParams(@Nullable String paramValue, RuleDefinitionDto ruleDto, RuleParamDto templateRuleParam, DbSession dbSession) { + private void createCustomRuleParams(@Nullable String paramValue, RuleDto ruleDto, RuleParamDto templateRuleParam, DbSession dbSession) { RuleParamDto ruleParamDto = RuleParamDto.createFor(ruleDto) .setName(templateRuleParam.getName()) .setType(templateRuleParam.getType()) @@ -258,7 +250,7 @@ public class RuleCreator { dbClient.ruleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto); } - private String updateExistingRule(RuleDefinitionDto ruleDto, NewCustomRule newRule, DbSession dbSession) { + private String updateExistingRule(RuleDto ruleDto, NewCustomRule newRule, DbSession dbSession) { if (ruleDto.getStatus().equals(RuleStatus.REMOVED)) { if (newRule.isPreventReactivation()) { throw new ReactivationException(format("A removed rule with the key '%s' already exists", ruleDto.getKey().rule()), ruleDto.getKey()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java index c6fa6e3342d..37e75095506 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java @@ -43,7 +43,6 @@ import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; @@ -219,7 +218,7 @@ public class RuleUpdater { RuleDto customRule = rule; String templateUuid = customRule.getTemplateUuid(); checkNotNull(templateUuid, "Rule '%s' has no persisted template!", customRule); - Optional templateRule = dbClient.ruleDao().selectDefinitionByUuid(templateUuid, dbSession); + Optional templateRule = dbClient.ruleDao().selectByUuid(templateUuid, dbSession); if (!templateRule.isPresent()) { throw new IllegalStateException(String.format("Template %s of rule %s does not exist", customRule.getTemplateUuid(), customRule.getKey())); @@ -250,7 +249,7 @@ public class RuleUpdater { // Update rule param ruleParamDto.setDefaultValue(value); - dbClient.ruleDao().updateRuleParam(dbSession, customRule.getDefinition(), ruleParamDto); + dbClient.ruleDao().updateRuleParam(dbSession, customRule, ruleParamDto); if (value != null) { // Update linked active rule params or create new one @@ -333,8 +332,7 @@ public class RuleUpdater { private void update(DbSession session, RuleDto rule) { rule.setUpdatedAt(system.now()); - dbClient.ruleDao().update(session, rule.getDefinition()); - dbClient.ruleDao().insertOrUpdate(session, rule.getMetadata()); + dbClient.ruleDao().update(session, rule); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java index c287ee8897a..bfabb7acd2a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java @@ -46,7 +46,6 @@ import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.ActiveRuleInheritance; import org.sonar.server.rule.index.RuleQuery; @@ -139,7 +138,7 @@ public class ActiveRuleCompleter { return activeRuleParamsByActiveRuleKey; } - List completeShow(DbSession dbSession, RuleDefinitionDto rule) { + List completeShow(DbSession dbSession, RuleDto rule) { List activeRules = dbClient.activeRuleDao().selectByOrgRuleUuid(dbSession, rule.getUuid()); Map activeRuleUuidsByKey = new HashMap<>(); for (OrgActiveRuleDto activeRuleDto : activeRules) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java index a94dcaae973..04ddcd300c3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -35,7 +35,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.KeyValueFormat; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.rule.NewCustomRule; import org.sonar.server.rule.ReactivationException; @@ -169,11 +169,11 @@ public class CreateAction implements RulesWsAction { } private Rules.CreateResponse createResponse(DbSession dbSession, RuleKey ruleKey) { - RuleDefinitionDto rule = dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey) + RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, ruleKey) .orElseThrow(() -> new IllegalStateException(String.format("Cannot load rule, that has just been created '%s'", ruleKey))); - List templateRules = new ArrayList<>(); + List templateRules = new ArrayList<>(); if (rule.isCustomRule()) { - Optional templateRule = dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession); + Optional templateRule = dbClient.ruleDao().selectByUuid(rule.getTemplateUuid(), dbSession); templateRule.ifPresent(templateRules::add); } List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid())); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java index 780d52971c6..fca29643a75 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/DeleteAction.java @@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.QProfileRules; import org.sonar.server.rule.index.RuleIndexer; @@ -77,7 +77,7 @@ public class DeleteAction implements RulesWsAction { public void delete(RuleKey ruleKey) { try (DbSession dbSession = dbClient.openSession(false)) { - RuleDefinitionDto rule = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, ruleKey); + RuleDto rule = dbClient.ruleDao().selectOrFailByKey(dbSession, ruleKey); checkArgument(rule.isCustomRule(), "Rule '%s' cannot be deleted because it is not a custom rule", rule.getKey().toString()); qProfileRules.deleteRule(dbSession, rule); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java index 9eaa2f03fc9..b1f3571e5a9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ListAction.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.Rules.ListResponse; @@ -66,7 +66,7 @@ public class ListAction implements RulesWsAction { listResponseBuilder.build().writeTo(wsResponse.stream().output()); } - private static ListResponse.Rule toRule(ListResponse.Rule.Builder ruleBuilder, RuleDefinitionDto dto) { + private static ListResponse.Rule toRule(ListResponse.Rule.Builder ruleBuilder, RuleDto dto) { return ruleBuilder .clear() .setRepository(dto.getRepositoryKey()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java index 9095b67cceb..7346ffdb6a8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java @@ -33,7 +33,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -92,22 +91,22 @@ public class RuleMapper { this.macroInterpreter = macroInterpreter; } - public Rules.Rule toWsRule(RuleDefinitionDto ruleDefinitionDto, SearchResult result, Set fieldsToReturn) { + public Rules.Rule toWsRule(RuleDto ruleDefinitionDto, SearchResult result, Set fieldsToReturn) { Rules.Rule.Builder ruleResponse = Rules.Rule.newBuilder(); applyRuleDefinition(ruleResponse, ruleDefinitionDto, result, fieldsToReturn, Collections.emptyMap()); return ruleResponse.build(); } - public Rules.Rule toWsRule(RuleDefinitionDto ruleDefinition, SearchResult result, Set fieldsToReturn, RuleMetadataDto metadata, + public Rules.Rule toWsRule(RuleDto ruleDto, SearchResult result, Set fieldsToReturn, RuleMetadataDto metadata, Map usersByUuid, Map> deprecatedRuleKeysByRuleUuid) { Rules.Rule.Builder ruleResponse = Rules.Rule.newBuilder(); - applyRuleDefinition(ruleResponse, ruleDefinition, result, fieldsToReturn, deprecatedRuleKeysByRuleUuid); - applyRuleMetadata(ruleResponse, ruleDefinition, metadata, usersByUuid, fieldsToReturn); - setDebtRemediationFunctionFields(ruleResponse, ruleDefinition, metadata, fieldsToReturn); + applyRuleDefinition(ruleResponse, ruleDto, result, fieldsToReturn, deprecatedRuleKeysByRuleUuid); + applyRuleMetadata(ruleResponse, ruleDto, metadata, usersByUuid, fieldsToReturn); + setDebtRemediationFunctionFields(ruleResponse, ruleDto, metadata, fieldsToReturn); return ruleResponse.build(); } - private Rules.Rule.Builder applyRuleDefinition(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDefinitionDto, SearchResult result, + private Rules.Rule.Builder applyRuleDefinition(Rules.Rule.Builder ruleResponse, RuleDto ruleDefinitionDto, SearchResult result, Set fieldsToReturn, Map> deprecatedRuleKeysByRuleUuid) { // Mandatory fields @@ -136,12 +135,12 @@ public class RuleMapper { return ruleResponse; } - private void applyRuleMetadata(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDefinition, RuleMetadataDto metadata, Map usersByUuid, + private void applyRuleMetadata(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, RuleMetadataDto metadata, Map usersByUuid, Set fieldsToReturn) { setTags(ruleResponse, metadata, fieldsToReturn); setNotesFields(ruleResponse, metadata, usersByUuid, fieldsToReturn); setIsRemediationFunctionOverloaded(ruleResponse, metadata, fieldsToReturn); - if (ruleDefinition.isAdHoc()) { + if (ruleDto.isAdHoc()) { setAdHocName(ruleResponse, metadata, fieldsToReturn); setAdHocDescription(ruleResponse, metadata, fieldsToReturn); setAdHocSeverity(ruleResponse, metadata, fieldsToReturn); @@ -177,19 +176,19 @@ public class RuleMapper { } } - private static void setRepository(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setRepository(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_REPO)) { ruleResponse.setRepo(ruleDto.getKey().repository()); } } - private static void setScope(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setScope(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_SCOPE)) { ruleResponse.setScope(toWsRuleScope(ruleDto.getScope())); } } - private static void setDeprecatedKeys(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn, + private static void setDeprecatedKeys(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn, Map> deprecatedRuleKeysByRuleUuid) { if (shouldReturnField(fieldsToReturn, FIELD_DEPRECATED_KEYS)) { List deprecatedRuleKeyDtos = deprecatedRuleKeysByRuleUuid.get(ruleDto.getUuid()); @@ -219,7 +218,7 @@ public class RuleMapper { } } - private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setEffortToFixDescription(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { String gapDescription = ruleDto.getGapDescription(); if ((shouldReturnField(fieldsToReturn, FIELD_EFFORT_TO_FIX_DESCRIPTION) || shouldReturnField(fieldsToReturn, FIELD_GAP_DESCRIPTION)) && gapDescription != null) { @@ -235,7 +234,7 @@ public class RuleMapper { } } - private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_DEFAULT_REM_FUNCTION)) { DebtRemediationFunction defaultDebtRemediationFunction = defaultDebtRemediationFunction(ruleDto); if (defaultDebtRemediationFunction != null) { @@ -260,7 +259,7 @@ public class RuleMapper { } } - private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDefinitionDto, RuleMetadataDto ruleMetadataDto, + private static void setDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDefinitionDto, RuleMetadataDto ruleMetadataDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_REM_FUNCTION)) { DebtRemediationFunction debtRemediationFunction = debtRemediationFunction(ruleDefinitionDto, ruleMetadataDto); @@ -286,13 +285,13 @@ public class RuleMapper { } } - private static void setName(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setName(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_NAME) && ruleDto.getName() != null) { ruleResponse.setName(ruleDto.getName()); } } - private static void setStatus(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setStatus(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_STATUS) && ruleDto.getStatus() != null) { ruleResponse.setStatus(Common.RuleStatus.valueOf(ruleDto.getStatus().toString())); } @@ -304,26 +303,26 @@ public class RuleMapper { } } - private static void setSysTags(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setSysTags(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_SYSTEM_TAGS)) { ruleResponse.getSysTagsBuilder().addAllSysTags(ruleDto.getSystemTags()); } } - private static void setParams(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, SearchResult searchResult, Set fieldsToReturn) { + private static void setParams(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, SearchResult searchResult, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_PARAMS)) { List ruleParameters = searchResult.getRuleParamsByRuleUuid().get(ruleDto.getUuid()); ruleResponse.getParamsBuilder().addAllParams(ruleParameters.stream().map(RuleParamDtoToWsRuleParam.INSTANCE).collect(toList())); } } - private static void setCreatedAt(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setCreatedAt(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_CREATED_AT)) { ruleResponse.setCreatedAt(formatDateTime(ruleDto.getCreatedAt())); } } - private void setDescriptionFields(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private void setDescriptionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_HTML_DESCRIPTION)) { String htmlDescription = RuleDescriptionFormatter.getDescriptionAsHtml(ruleDto); if (htmlDescription != null) { @@ -338,7 +337,7 @@ public class RuleMapper { } } - private static String concatenateSectionTemporaryForSonar16302(RuleDefinitionDto ruleDto) { + private static String concatenateSectionTemporaryForSonar16302(RuleDto ruleDto) { return ruleDto.getRuleDescriptionSectionDtos().stream() .map(RuleDescriptionSectionDto::getContent) .collect(joining()); @@ -358,27 +357,27 @@ public class RuleMapper { } } - private static void setSeverity(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setSeverity(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { String severity = ruleDto.getSeverityString(); if (shouldReturnField(fieldsToReturn, FIELD_SEVERITY) && severity != null) { ruleResponse.setSeverity(severity); } } - private static void setInternalKey(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setInternalKey(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_INTERNAL_KEY) && ruleDto.getConfigKey() != null) { ruleResponse.setInternalKey(ruleDto.getConfigKey()); } } - private static void setLanguage(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setLanguage(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { String language = ruleDto.getLanguage(); if (shouldReturnField(fieldsToReturn, FIELD_LANGUAGE) && language != null) { ruleResponse.setLang(language); } } - private void setLanguageName(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private void setLanguageName(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { String languageKey = ruleDto.getLanguage(); if (shouldReturnField(fieldsToReturn, FIELD_LANGUAGE_NAME) && languageKey != null) { Language language = languages.get(languageKey); @@ -386,21 +385,21 @@ public class RuleMapper { } } - private static void setIsTemplate(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setIsTemplate(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_IS_TEMPLATE)) { ruleResponse.setIsTemplate(ruleDto.isTemplate()); } } - private static void setIsExternal(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, Set fieldsToReturn) { + private static void setIsExternal(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_IS_EXTERNAL)) { ruleResponse.setIsExternal(ruleDto.isExternal()); } } - private static void setTemplateKey(Rules.Rule.Builder ruleResponse, RuleDefinitionDto ruleDto, SearchResult result, Set fieldsToReturn) { + private static void setTemplateKey(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, SearchResult result, Set fieldsToReturn) { if (shouldReturnField(fieldsToReturn, FIELD_TEMPLATE_KEY) && ruleDto.isCustomRule()) { - RuleDefinitionDto templateRule = result.getTemplateRulesByRuleUuid().get(ruleDto.getTemplateUuid()); + RuleDto templateRule = result.getTemplateRulesByRuleUuid().get(ruleDto.getTemplateUuid()); if (templateRule != null) { ruleResponse.setTemplateKey(templateRule.getKey().toString()); } @@ -416,7 +415,7 @@ public class RuleMapper { } @CheckForNull - private static DebtRemediationFunction defaultDebtRemediationFunction(final RuleDefinitionDto ruleDto) { + private static DebtRemediationFunction defaultDebtRemediationFunction(final RuleDto ruleDto) { final String function = ruleDto.getDefRemediationFunction(); if (function == null || function.isEmpty()) { return null; @@ -429,7 +428,7 @@ public class RuleMapper { } @CheckForNull - private static DebtRemediationFunction debtRemediationFunction(RuleDefinitionDto ruleDefinitionDto, RuleMetadataDto ruleMetadataDto) { + private static DebtRemediationFunction debtRemediationFunction(RuleDto ruleDefinitionDto, RuleMetadataDto ruleMetadataDto) { final String function = ruleMetadataDto.getRemediationFunction(); if (function == null || function.isEmpty()) { return defaultDebtRemediationFunction(ruleDefinitionDto); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java index ef135bda375..151c4147f26 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java @@ -48,7 +48,6 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.DeprecatedRuleKeyDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.user.UserDto; @@ -212,7 +211,7 @@ public class SearchAction implements RulesWsAction { private void writeRules(DbSession dbSession, SearchResponse.Builder response, SearchResult result, SearchOptions context) { Map usersByUuid = ruleWsSupport.getUsersByUuid(dbSession, result.rules); Map> deprecatedRuleKeysByRuleUuid = getDeprecatedRuleKeysByRuleUuid(dbSession, result.rules, context); - result.rules.forEach(rule -> response.addRules(mapper.toWsRule(rule.getDefinition(), result, context.getFields(), rule.getMetadata(), usersByUuid, + result.rules.forEach(rule -> response.addRules(mapper.toWsRule(rule, result, context.getFields(), rule.getMetadata(), usersByUuid, deprecatedRuleKeysByRuleUuid))); } @@ -276,7 +275,7 @@ public class SearchAction implements RulesWsAction { .map(RuleDto::getTemplateUuid) .filter(Objects::nonNull) .collect(MoreCollectors.toList()); - List templateRules = dbClient.ruleDao().selectDefinitionByUuids(dbSession, templateRuleUuids); + List templateRules = dbClient.ruleDao().selectByUuids(dbSession, templateRuleUuids); List ruleParamDtos = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, ruleUuids); return new SearchResult() .setRules(rules) @@ -391,7 +390,7 @@ public class SearchAction implements RulesWsAction { static class SearchResult { private List rules; private final ListMultimap ruleParamsByRuleUuid; - private final Map templateRulesByRuleUuid; + private final Map templateRulesByRuleUuid; private Long total; private Facets facets; @@ -422,13 +421,13 @@ public class SearchAction implements RulesWsAction { return this; } - public Map getTemplateRulesByRuleUuid() { + public Map getTemplateRulesByRuleUuid() { return templateRulesByRuleUuid; } - public SearchResult setTemplateRules(List templateRules) { + public SearchResult setTemplateRules(List templateRules) { templateRulesByRuleUuid.clear(); - for (RuleDefinitionDto templateRule : templateRules) { + for (RuleDto templateRule : templateRules) { templateRulesByRuleUuid.put(templateRule.getUuid(), templateRule); } return this; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java index 48c0398d2e1..ab6db925ab9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java @@ -28,7 +28,6 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.exceptions.NotFoundException; @@ -99,8 +98,8 @@ public class ShowAction implements RulesWsAction { RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, key) .orElseThrow(() -> new NotFoundException(format("Rule not found: %s", key))); - List templateRules = ofNullable(rule.getTemplateUuid()) - .flatMap(templateUuid -> dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession)) + List templateRules = ofNullable(rule.getTemplateUuid()) + .flatMap(templateUuid -> dbClient.ruleDao().selectByUuid(rule.getTemplateUuid(), dbSession)) .map(Collections::singletonList).orElseGet(Collections::emptyList); List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid())); @@ -117,10 +116,10 @@ public class ShowAction implements RulesWsAction { private ShowResponse buildResponse(DbSession dbSession, Request request, SearchAction.SearchResult searchResult) { ShowResponse.Builder responseBuilder = ShowResponse.newBuilder(); RuleDto rule = searchResult.getRules().get(0); - responseBuilder.setRule(mapper.toWsRule(rule.getDefinition(), searchResult, Collections.emptySet(), rule.getMetadata(), + responseBuilder.setRule(mapper.toWsRule(rule, searchResult, Collections.emptySet(), rule.getMetadata(), ruleWsSupport.getUsersByUuid(dbSession, searchResult.getRules()), emptyMap())); if (request.mandatoryParamAsBoolean(PARAM_ACTIVES)) { - activeRuleCompleter.completeShow(dbSession, rule.getDefinition()).forEach(responseBuilder::addActives); + activeRuleCompleter.completeShow(dbSession, rule).forEach(responseBuilder::addActives); } return responseBuilder.build(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java index 07d49a9e4cf..c6f791f7056 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java @@ -36,7 +36,6 @@ import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.KeyValueFormat; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.exceptions.NotFoundException; @@ -238,9 +237,9 @@ public class UpdateAction implements RulesWsAction { private UpdateResponse buildResponse(DbSession dbSession, RuleKey key) { RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, key) .orElseThrow(() -> new NotFoundException(format("Rule not found: %s", key))); - List templateRules = new ArrayList<>(1); - if (rule.getDefinition().isCustomRule()) { - dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession).ifPresent(templateRules::add); + List templateRules = new ArrayList<>(1); + if (rule.isCustomRule()) { + dbClient.ruleDao().selectByUuid(rule.getTemplateUuid(), dbSession).ifPresent(templateRules::add); } List ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid())); UpdateResponse.Builder responseBuilder = UpdateResponse.newBuilder(); @@ -250,7 +249,7 @@ public class UpdateAction implements RulesWsAction { .setRuleParameters(ruleParameters) .setTotal(1L); responseBuilder - .setRule(mapper.toWsRule(rule.getDefinition(), searchResult, Collections.emptySet(), rule.getMetadata(), + .setRule(mapper.toWsRule(rule, searchResult, Collections.emptySet(), rule.getMetadata(), ruleWsSupport.getUsersByUuid(dbSession, singletonList(rule)), emptyMap())); return responseBuilder.build(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java index 55a89120d15..33510ef5ebf 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -33,7 +33,7 @@ import org.sonar.core.util.Protobuf; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; @@ -72,7 +72,7 @@ public class IssuesActionTest { @Test public void test_nullable_fields() throws Exception { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null).setPath(null)); @@ -112,7 +112,7 @@ public class IssuesActionTest { @Test public void test_fields_with_non_null_values() throws Exception { UserDto user = db.users().insertUser(u -> u.setLogin("simon").setName("Simon").setEmail("simon@email.com")); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null)); @@ -147,7 +147,7 @@ public class IssuesActionTest { @Test public void return_issues_of_project() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null)); @@ -169,7 +169,7 @@ public class IssuesActionTest { @Test public void does_not_return_issues_from_external_rules() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null)); @@ -177,10 +177,10 @@ public class IssuesActionTest { IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE").setType(randomRuleTypeExceptHotspot())); IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE").setType(randomRuleTypeExceptHotspot())); - RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); + RuleDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true)); IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL").setType(randomRuleTypeExceptHotspot())); - RuleDefinitionDto migrated = db.rules().insert(); + RuleDto migrated = db.rules().insert(); db.executeUpdateSql("update rules set is_external=? where rules.uuid = ?", false, migrated.getUuid()); IssueDto issueFromMigratedRule = db.issues().insert(migrated, project, file, i -> i.setKee("MIGRATED").setType(randomRuleTypeExceptHotspot())); @@ -199,7 +199,7 @@ public class IssuesActionTest { @Test public void return_issues_of_module() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null)); @@ -220,7 +220,7 @@ public class IssuesActionTest { @Test public void return_issues_of_file() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null)); @@ -240,7 +240,7 @@ public class IssuesActionTest { @Test public void return_issues_by_project_and_branch() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); addPermissionTo(project); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); @@ -255,7 +255,7 @@ public class IssuesActionTest { @Test public void return_issues_by_module_and_branch() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); addPermissionTo(project); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); @@ -286,7 +286,7 @@ public class IssuesActionTest { @Test public void issues_on_disabled_modules_are_returned() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project).setEnabled(false)); ComponentDto file = db.components().insertComponent(newFileDto(module, null).setEnabled(false)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java index 7dcdd418184..a362a6527ff 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java @@ -36,7 +36,7 @@ import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.metric.MetricDto; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.protobuf.DbProjectBranches; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -251,7 +251,7 @@ public class ListActionTest { .setMergeBranchUuid(nonMainBranch.uuid()) .setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build())); db.measures().insertLiveMeasure(pullRequest, qualityGateStatus, m -> m.setData("ERROR")); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(BUG).setResolution(null)); db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(BUG).setResolution(RESOLUTION_FIXED)); db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(VULNERABILITY).setResolution(null)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index dfd0a15bb4c..fbc38e45601 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.metric.MetricDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; @@ -107,7 +107,7 @@ public class ListActionTest { newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK")); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null)); indexIssues(); @@ -136,7 +136,7 @@ public class ListActionTest { newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK")); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null)); indexIssues(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java index 21612c44734..a294136d4c7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java @@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.project.ProjectDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.webhook.WebhookDto; import org.sonar.server.es.TestProjectIndexers; @@ -196,7 +196,7 @@ public class ComponentCleanerServiceTest { ProjectDto project = dbClient.projectDao().selectByUuid(dbSession, componentDto.uuid()).get(); BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.getUuid()).get(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, componentDto); SnapshotDto analysis = db.components().insertSnapshot(componentDto); mockResourceTypeAsValidProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java index 80c7985abe9..59ad707b5d7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/developers/ws/SearchEventsActionNewIssuesTest.java @@ -34,7 +34,7 @@ import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.index.IssueIndexSyncProgressChecker; @@ -258,7 +258,7 @@ public class SearchEventsActionNewIssuesTest { } private void insertIssue(ComponentDto component, SnapshotDto analysis) { - RuleDefinitionDto rule = db.rules().insert(r -> r.setType(randomRuleTypeExceptHotspot())); + RuleDto rule = db.rules().insert(r -> r.setType(randomRuleTypeExceptHotspot())); db.issues().insert(rule, component, component, i -> i.setIssueCreationDate(new Date(analysis.getCreatedAt())) .setAssigneeUuid(userSession.getUuid()) @@ -266,7 +266,7 @@ public class SearchEventsActionNewIssuesTest { } private void insertSecurityHotspot(ComponentDto component, SnapshotDto analysis) { - RuleDefinitionDto rule = db.rules().insert(r -> r.setType(RuleType.SECURITY_HOTSPOT)); + RuleDto rule = db.rules().insert(r -> r.setType(RuleType.SECURITY_HOTSPOT)); db.issues().insert(rule, component, component, i -> i.setIssueCreationDate(new Date(analysis.getCreatedAt())) .setAssigneeUuid(userSession.getUuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java index eea631a1179..277fdf506f3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AddCommentActionTest.java @@ -41,7 +41,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -141,7 +141,7 @@ public class AddCommentActionTest { public void fails_with_NotFoundException_if_issue_is_not_a_hotspot(RuleType ruleType) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(ruleType)); + RuleDto rule = dbTester.rules().insert(t -> t.setType(ruleType)); IssueDto notAHotspot = dbTester.issues().insertIssue(rule, project, file, i -> i.setType(ruleType)); userSessionRule.logIn(); TestRequest request = newRequest(notAHotspot, randomAlphabetic(12)); @@ -163,7 +163,7 @@ public class AddCommentActionTest { public void fails_with_NotFoundException_if_hotspot_is_closed() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insertHotspotRule(); + RuleDto rule = dbTester.rules().insertHotspotRule(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED)); userSessionRule.logIn(); TestRequest request = newRequest(hotspot, randomAlphabetic(12)); @@ -178,7 +178,7 @@ public class AddCommentActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insertHotspotRule(); + RuleDto rule = dbTester.rules().insertHotspotRule(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); TestRequest request = newRequest(hotspot, comment); @@ -193,7 +193,7 @@ public class AddCommentActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insertHotspotRule(); + RuleDto rule = dbTester.rules().insertHotspotRule(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); @@ -205,7 +205,7 @@ public class AddCommentActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); userSessionRule.logIn().registerComponents(project).addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insertHotspotRule(); + RuleDto rule = dbTester.rules().insertHotspotRule(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); String comment = randomAlphabetic(12); @@ -220,7 +220,7 @@ public class AddCommentActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.logIn().registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = dbTester.rules().insertHotspotRule(); + RuleDto rule = dbTester.rules().insertHotspotRule(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution)); String comment = randomAlphabetic(12); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java index 7d80092e4fe..bf74da81cc2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/AssignActionTest.java @@ -46,7 +46,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.ForbiddenException; @@ -445,7 +445,7 @@ public class AssignActionTest { public void fail_if_trying_to_assign_issue(RuleType ruleType, String status) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(ruleType); + RuleDto rule = newRule(ruleType); IssueDto issue = dbTester.issues().insertIssue(rule, project, file, i -> i .setStatus(status) .setType(ruleType)); @@ -479,7 +479,7 @@ public class AssignActionTest { public void fail_with_NotFoundException_if_hotspot_is_closed() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto issue = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED)); UserDto me = insertUser(randomAlphanumeric(10)); userSessionRule.logIn().registerComponents(project); @@ -537,11 +537,11 @@ public class AssignActionTest { request.execute().assertNoContent(); } - private RuleDefinitionDto newRule(RuleType ruleType) { - RuleDefinitionDto ruleDefinition = RuleTesting.newRule() + private RuleDto newRule(RuleType ruleType) { + RuleDto ruleDto = RuleTesting.newRule() .setType(ruleType); - dbTester.rules().insert(ruleDefinition); - return ruleDefinition; + dbTester.rules().insert(ruleDto); + return ruleDto; } private UserDto insertUser(String login) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java index b3daf475aa8..d95e8a2289f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java @@ -46,7 +46,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -242,7 +242,7 @@ public class ChangeStatusActionTest { public void fails_with_NotFoundException_if_hotspot_is_closed(String status, @Nullable String resolution) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto closedHotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED)); userSessionRule.logIn(); TestRequest request = actionTester.newRequest() @@ -272,7 +272,7 @@ public class ChangeStatusActionTest { public void fails_with_NotFoundException_if_issue_is_not_a_hotspot(String status, @Nullable String resolution, RuleType ruleType) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(ruleType); + RuleDto rule = newRule(ruleType); IssueDto notAHotspot = dbTester.issues().insert(IssueTesting.newIssue(rule, project, file).setType(ruleType)); userSessionRule.logIn(); TestRequest request = newRequest(notAHotspot, status, resolution, NO_COMMENT); @@ -576,17 +576,17 @@ public class ChangeStatusActionTest { return res; } - private RuleDefinitionDto newRule(RuleType ruleType) { + private RuleDto newRule(RuleType ruleType) { return newRule(ruleType, t -> { }); } - private RuleDefinitionDto newRule(RuleType ruleType, Consumer populate) { - RuleDefinitionDto ruleDefinition = RuleTesting.newRule() + private RuleDto newRule(RuleType ruleType, Consumer populate) { + RuleDto ruleDto = RuleTesting.newRule() .setType(ruleType); - populate.accept(ruleDefinition); - dbTester.rules().insert(ruleDefinition); - return ruleDefinition; + populate.accept(ruleDto); + dbTester.rules().insert(ruleDto); + return ruleDto; } private static void verifyAllSame3Objects(List allValues) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index f7900b0933f..cf43d53108e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -54,7 +54,7 @@ import org.sonar.db.issue.IssueDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbCommons; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -400,7 +400,7 @@ public class SearchActionTest { indexPermissions(); IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(project, file, rule); }) .toArray(IssueDto[]::new); @@ -428,7 +428,7 @@ public class SearchActionTest { Arrays.stream(RuleType.values()) .filter(t -> t != SECURITY_HOTSPOT) .forEach(ruleType -> { - RuleDefinitionDto rule = newRule(ruleType); + RuleDto rule = newRule(ruleType); dbTester.issues().insert(rule, project, file, t -> t.setType(ruleType)); }); indexIssues(); @@ -449,12 +449,12 @@ public class SearchActionTest { Arrays.stream(RuleType.values()) .filter(t -> t != SECURITY_HOTSPOT) .forEach(ruleType -> { - RuleDefinitionDto rule = newRule(ruleType); + RuleDto rule = newRule(ruleType); dbTester.issues().insert(rule, project, file, t -> t.setType(ruleType)); }); IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(project, fileWithHotspot, rule); }) .toArray(IssueDto[]::new); @@ -478,7 +478,7 @@ public class SearchActionTest { indexPermissions(); IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(project, project, rule); }) .toArray(IssueDto[]::new); @@ -505,7 +505,7 @@ public class SearchActionTest { ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2)); IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); insertHotspot(project1, file1, rule); return insertHotspot(project2, file2, rule); }) @@ -541,7 +541,7 @@ public class SearchActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); IssueDto[] hotspots = STATUSES.stream() .map(status -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(rule, project, file, t -> t.setStatus(status)); }) .toArray(IssueDto[]::new); @@ -575,7 +575,7 @@ public class SearchActionTest { ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2)); IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); insertHotspot(project1, file1, rule); return insertHotspot(project2, file2, rule); }) @@ -618,7 +618,7 @@ public class SearchActionTest { ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2)); IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); insertHotspot(project1, file1, rule); return insertHotspot(project2, file2, rule); }) @@ -659,19 +659,19 @@ public class SearchActionTest { ComponentDto filePR = dbTester.components().insertComponent(newFileDto(pullRequest)); IssueDto[] hotspotProject = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(project, fileProject, rule); }) .toArray(IssueDto[]::new); IssueDto[] hotspotBranch = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(branch, fileBranch, rule); }) .toArray(IssueDto[]::new); IssueDto[] hotspotPR = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); return insertHotspot(pullRequest, filePR, rule); }) .toArray(IssueDto[]::new); @@ -707,7 +707,7 @@ public class SearchActionTest { ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1)); IssueDto[] assigneeHotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); insertHotspot(rule, project1, file1, randomAlphabetic(5)); return insertHotspot(rule, project1, file1, assigneeUuid); }) @@ -857,7 +857,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto unresolvedHotspot = insertHotspot(rule, project, file, t -> t.setResolution(null)); // unrealistic case since a resolution must be set, but shows a limit of current implementation (resolution is enough) IssueDto badlyResolved = insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW).setResolution(randomAlphabetic(5))); @@ -874,7 +874,7 @@ public class SearchActionTest { } private Stream insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(ComponentDto project, ComponentDto file) { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); List hotspots = Arrays.stream(validStatusesAndResolutions()) .flatMap(objects -> { String status = (String) objects[0]; @@ -899,7 +899,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = insertHotspot(rule, project, file, t -> t .setStatus(randomAlphabetic(11)) @@ -948,7 +948,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(securityStandards)); + RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(securityStandards)); IssueDto hotspot = insertHotspot(project, file, rule); indexIssues(); @@ -981,7 +981,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); insertHotspot(rule, project, file, t -> t.setResolution(null) .setLine(null) @@ -1012,7 +1012,7 @@ public class SearchActionTest { ComponentDto directory2 = dbTester.components().insertComponent(newDirectory(project, "foo/bar")); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto fileHotspot = insertHotspot(project, file, rule); IssueDto dirHotspot = insertHotspot(project, directory, rule); IssueDto projectHotspot = insertHotspot(project, project, rule); @@ -1060,7 +1060,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto directory = dbTester.components().insertComponent(newDirectory(branch, "donut/acme")); ComponentDto file = dbTester.components().insertComponent(newFileDto(branch)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto fileHotspot = insertHotspot(branch, file, rule); IssueDto dirHotspot = insertHotspot(branch, directory, rule); IssueDto projectHotspot = insertHotspot(branch, branch, rule); @@ -1095,7 +1095,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto directory = dbTester.components().insertComponent(newDirectory(pullRequest, "donut/acme")); ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto fileHotspot = insertHotspot(pullRequest, file, rule); IssueDto dirHotspot = insertHotspot(pullRequest, directory, rule); IssueDto projectHotspot = insertHotspot(pullRequest, pullRequest, rule); @@ -1134,10 +1134,10 @@ public class SearchActionTest { .flatMap(sqCategory -> { Set cwes = SecurityStandards.CWES_BY_SQ_CATEGORY.get(sqCategory); Set securityStandards = singleton("cwe:" + (cwes == null ? "unknown" : cwes.iterator().next())); - RuleDefinitionDto rule1 = newRule( + RuleDto rule1 = newRule( SECURITY_HOTSPOT, t -> t.setUuid(sqCategory.name() + "_a").setName("rule_" + sqCategory.name() + "_a").setSecurityStandards(securityStandards)); - RuleDefinitionDto rule2 = newRule( + RuleDto rule2 = newRule( SECURITY_HOTSPOT, t -> t.setUuid(sqCategory.name() + "_b").setName("rule_" + sqCategory.name() + "_b").setSecurityStandards(securityStandards)); return Stream.of( @@ -1167,7 +1167,7 @@ public class SearchActionTest { ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/a")); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/b")); ComponentDto file3 = dbTester.components().insertComponent(newFileDto(project).setPath("a/a/d")); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); List hotspots = Stream.of( newHotspot(rule, project, file3).setLine(8), newHotspot(rule, project, file3).setLine(10), @@ -1210,7 +1210,7 @@ public class SearchActionTest { DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder().addFlow(DbIssues.Flow.newBuilder().addAllLocation(hotspotLocations)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); dbTester.issues().insertHotspot(rule, project, file, h -> h.setLocations(locations.build())); indexIssues(); @@ -1243,7 +1243,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); int total = 436; List hotspots = IntStream.range(0, total) .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) @@ -1268,7 +1268,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); verifyPaging(project, file, rule, 336, 100); } @@ -1279,14 +1279,14 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); int total = 336; int pageSize = 1 + new Random().nextInt(100); verifyPaging(project, file, rule, total, pageSize); } - private void verifyPaging(ComponentDto project, ComponentDto file, RuleDefinitionDto rule, int total, int pageSize) { + private void verifyPaging(ComponentDto project, ComponentDto file, RuleDto rule, int total, int pageSize) { List hotspots = IntStream.range(0, total) .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setKee("issue_" + i))) .collect(toList()); @@ -1336,7 +1336,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); List hotspots = IntStream.range(0, 1 + RANDOM.nextInt(15)) .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) .collect(toList()); @@ -1355,7 +1355,7 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); int total = 1 + RANDOM.nextInt(20); List hotspots = IntStream.range(0, total) .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) @@ -1378,9 +1378,9 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT); - RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); - RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); insertHotspot(project, file, rule1); IssueDto hotspot2 = insertHotspot(project, file, rule2); insertHotspot(project, file, rule3); @@ -1400,9 +1400,9 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT); - RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); - RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); insertHotspot(project, file, rule1); IssueDto hotspot2 = insertHotspot(project, file, rule2); insertHotspot(project, file, rule3); @@ -1422,9 +1422,9 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT); - RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); - RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); insertHotspot(project, file, rule1); insertHotspot(project, file, rule2); IssueDto hotspot3 = insertHotspot(project, file, rule3); @@ -1444,9 +1444,9 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT); - RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); - RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10-2021:a5", "cwe:489"))); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10-2021:a5", "cwe:489"))); insertHotspot(project, file, rule1); insertHotspot(project, file, rule2); IssueDto hotspot3 = insertHotspot(project, file, rule3); @@ -1466,9 +1466,9 @@ public class SearchActionTest { userSessionRule.registerComponents(project); indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT); - RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); - RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601"))); insertHotspot(project, file, rule1); insertHotspot(project, file, rule2); IssueDto hotspot3 = insertHotspot(project, file, rule3); @@ -1489,7 +1489,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project)); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); final IssueDto hotspot = insertHotspot(project, file1, rule); insertHotspot(project, file2, rule); @@ -1513,7 +1513,7 @@ public class SearchActionTest { long periodDate = 800_996_999_332L; dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(periodDate).setLast(false)); dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(periodDate - 1_500).setLast(true)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); List hotspotsInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)) .mapToObj(i -> { long issueCreationDate = periodDate + ONE_MINUTE + (RANDOM.nextInt(300) * ONE_MINUTE); @@ -1566,7 +1566,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); dbTester.components().insertSnapshot(project, t -> t.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master")); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); List hotspotsInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)) .mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))) .collect(toList()); @@ -1611,7 +1611,7 @@ public class SearchActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(false)); dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(null).setLast(true)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto afterRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setIssueCreationTime(referenceDate + 1000)); IssueDto atRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate)); IssueDto beforeRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setIssueCreationTime(referenceDate - 1000)); @@ -1643,7 +1643,7 @@ public class SearchActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(pr)); dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(true)); dbTester.components().insertSnapshot(pr, t -> t.setPeriodDate(null).setLast(true)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto afterRef = dbTester.issues().insertHotspot(rule, pr, file, t -> t.setIssueCreationTime(referenceDate + 1000)); IssueDto atRef = dbTester.issues().insertHotspot(rule, pr, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate)); IssueDto beforeRef = dbTester.issues().insertHotspot(rule, pr, file, t -> t.setIssueCreationTime(referenceDate - 1000)); @@ -1684,7 +1684,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(true)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto afterRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setIssueCreationTime(referenceDate + 1000)); IssueDto atRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate)); IssueDto beforeRef = dbTester.issues().insertHotspot(rule, project, file, t -> t.setIssueCreationTime(referenceDate - 1000)); @@ -1741,7 +1741,7 @@ public class SearchActionTest { ComponentDto file = dbTester.components().insertComponent(newFileDto(projectBranchComponentDto)); dbTester.components().insertSnapshot(projectBranch, t -> t.setPeriodDate(referenceDate).setLast(true)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto afterRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate + 1000)); IssueDto atRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate)); IssueDto beforeRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate - 1000)); @@ -1785,7 +1785,7 @@ public class SearchActionTest { IssueDto[] hotspots = IntStream.range(0, 3) .mapToObj(i -> { - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT) + RuleDto rule = newRule(SECURITY_HOTSPOT) .setSecurityStandards(Sets.newHashSet(SQCategory.WEAK_CRYPTOGRAPHY.getKey())); return insertHotspot(rule, project, fileWithHotspot, issueDto -> issueDto.setKee("hotspot-" + i) .setAssigneeUuid("assignee-uuid") @@ -1804,25 +1804,25 @@ public class SearchActionTest { .assertJson(actionTester.getDef().responseExampleAsString()); } - private IssueDto insertHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule) { + private IssueDto insertHotspot(ComponentDto project, ComponentDto file, RuleDto rule) { return insertHotspot(rule, project, file, t -> { }); } - private IssueDto insertHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, @Nullable String assigneeUuid) { + private IssueDto insertHotspot(RuleDto rule, ComponentDto project, ComponentDto file, @Nullable String assigneeUuid) { return insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assigneeUuid)); } - private IssueDto insertHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer consumer) { + private IssueDto insertHotspot(RuleDto rule, ComponentDto project, ComponentDto file, Consumer consumer) { return dbTester.issues().insertHotspot(rule, project, file, consumer); } - private static IssueDto newHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto component) { + private static IssueDto newHotspot(RuleDto rule, ComponentDto project, ComponentDto component) { return newHotspot(rule, project, component, t -> { }); } - private static IssueDto newHotspot(RuleDefinitionDto rule, ComponentDto project, ComponentDto component, Consumer consumer) { + private static IssueDto newHotspot(RuleDto rule, ComponentDto project, ComponentDto component, Consumer consumer) { IssueDto res = newIssue(rule, project, component) .setStatus(STATUS_TO_REVIEW); consumer.accept(res); @@ -1899,16 +1899,16 @@ public class SearchActionTest { viewIndexer.indexAll(); } - private RuleDefinitionDto newRule(RuleType ruleType) { + private RuleDto newRule(RuleType ruleType) { return newRule(ruleType, t -> { }); } - private RuleDefinitionDto newRule(RuleType ruleType, Consumer populate) { - RuleDefinitionDto ruleDefinition = RuleTesting.newRule() + private RuleDto newRule(RuleType ruleType, Consumer populate) { + RuleDto ruleDto = RuleTesting.newRule() .setType(ruleType); - populate.accept(ruleDefinition); - dbTester.rules().insert(ruleDefinition); - return ruleDefinition; + populate.accept(ruleDto); + dbTester.rules().insert(ruleDto); + return ruleDto; } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java index ec3a28866ac..ae7b290965a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java @@ -55,7 +55,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbCommons; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTesting; @@ -147,7 +147,7 @@ public class ShowActionTest { public void fails_with_NotFoundException_if_issue_is_not_a_hotspot(RuleType ruleType) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(ruleType); + RuleDto rule = newRule(ruleType); IssueDto notAHotspot = dbTester.issues().insertIssue(rule, project, file, i -> i.setType(ruleType)); TestRequest request = newRequest(notAHotspot); @@ -168,7 +168,7 @@ public class ShowActionTest { public void fails_with_NotFoundException_if_issue_is_hotspot_is_closed() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(Issue.STATUS_CLOSED)); TestRequest request = newRequest(hotspot); @@ -182,7 +182,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPrivateProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); TestRequest request = newRequest(hotspot); @@ -226,7 +226,7 @@ public class ShowActionTest { .setEndOffset(12) .build()) .build()))); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); var hotspot = dbTester.issues().insertHotspot(rule, project, file, i -> i.setLocations(locations.build())); mockChangelogAndCommentsFormattingContext(); @@ -250,7 +250,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -266,7 +266,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -281,7 +281,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -300,7 +300,7 @@ public class ShowActionTest { userSessionRule.addProjectPermission(permission, project); } ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -320,7 +320,7 @@ public class ShowActionTest { userSessionRule.addProjectPermission(permission, project); } ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -352,7 +352,7 @@ public class ShowActionTest { userSessionRule.addProjectPermission(permission, project); } ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -375,7 +375,7 @@ public class ShowActionTest { userSessionRule.addProjectPermission(permission, project); } ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -403,7 +403,7 @@ public class ShowActionTest { userSessionRule.registerComponents(project); userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(status).setResolution(resolution)); mockChangelogAndCommentsFormattingContext(); @@ -436,7 +436,7 @@ public class ShowActionTest { String description = "== Title\n
line1\nline2
"; - RuleDefinitionDto rule = newRuleWithoutSection(SECURITY_HOTSPOT, + RuleDto rule = newRuleWithoutSection(SECURITY_HOTSPOT, r -> r.setTemplateUuid("123") .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), description)) .setDescriptionFormat(MARKDOWN)); @@ -457,7 +457,7 @@ public class ShowActionTest { userSessionRule.logIn().addProjectPermission(UserRole.USER, project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRuleWithoutSection(SECURITY_HOTSPOT, r -> r.setTemplateUuid("123")); + RuleDto rule = newRuleWithoutSection(SECURITY_HOTSPOT, r -> r.setTemplateUuid("123")); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -473,7 +473,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); mockChangelogAndCommentsFormattingContext(); @@ -492,7 +492,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setLocations(DbIssues.Locations.newBuilder().build())); mockChangelogAndCommentsFormattingContext(); @@ -509,7 +509,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder() @@ -537,7 +537,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(randomAlphabetic(10))); mockChangelogAndCommentsFormattingContext(); @@ -552,7 +552,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); @@ -574,7 +574,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(t -> t.setEmail(null)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); @@ -591,7 +591,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto assignee = dbTester.users().insertUser(t -> t.setActive(false)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(assignee.getUuid())); mockChangelogAndCommentsFormattingContext(); @@ -608,7 +608,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); String authorLogin = randomAlphabetic(10); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(authorLogin)); mockChangelogAndCommentsFormattingContext(); @@ -625,7 +625,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); @@ -646,7 +646,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(t -> t.setEmail(null)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); @@ -663,7 +663,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); UserDto author = dbTester.users().insertUser(t -> t.setActive(false)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAuthorLogin(author.getLogin())); mockChangelogAndCommentsFormattingContext(); @@ -691,7 +691,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) @@ -716,7 +716,7 @@ public class ShowActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(standards)); + RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(standards)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) @@ -751,7 +751,7 @@ public class ShowActionTest { public void returns_project_twice_when_hotspot_on_project() { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, project, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) @@ -771,7 +771,7 @@ public class ShowActionTest { ComponentDto branch = dbTester.components().insertProjectBranch(project); ComponentDto file = dbTester.components().insertComponent(newFileDto(branch)); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, branch, file, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) @@ -792,7 +792,7 @@ public class ShowActionTest { t -> t.setBranchType(BranchType.PULL_REQUEST)); ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest)); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); IssueDto hotspot = dbTester.issues().insertHotspot(rule, pullRequest, file, t -> t.setLocations(DbIssues.Locations.newBuilder() .setTextRange(DbCommons.TextRange.newBuilder().build()) @@ -810,7 +810,7 @@ public class ShowActionTest { public void returns_hotspot_changelog_and_comments() { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setLocations(DbIssues.Locations.newBuilder() @@ -847,7 +847,7 @@ public class ShowActionTest { public void returns_user_details_of_users_from_ChangelogAndComments() { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file); FormattingContext formattingContext = mockChangelogAndCommentsFormattingContext(); @@ -871,7 +871,7 @@ public class ShowActionTest { public void returns_user_of_users_from_ChangelogAndComments_and_assignee_and_author() { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); UserDto author = dbTester.users().insertUser(); UserDto assignee = dbTester.users().insertUser(); @@ -901,7 +901,7 @@ public class ShowActionTest { public void do_not_duplicate_user_if_author_assignee_ChangeLogComment_user() { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.registerComponents(project); - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT); + RuleDto rule = newRule(SECURITY_HOTSPOT); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); UserDto author = dbTester.users().insertUser(); IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, @@ -937,7 +937,7 @@ public class ShowActionTest { .setName("Joe")); long time = 1577976190000L; - RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT, r -> r.setRuleKey("S4787") + RuleDto rule = newRule(SECURITY_HOTSPOT, r -> r.setRuleKey("S4787") .setRepositoryKey("java") .setName("rule-name") .setSecurityStandards(Sets.newHashSet(SQCategory.WEAK_CRYPTOGRAPHY.getKey()))); @@ -989,7 +989,7 @@ public class ShowActionTest { return formattingContext; } - private void verifyRule(Hotspots.Rule wsRule, RuleDefinitionDto dto) { + private void verifyRule(Hotspots.Rule wsRule, RuleDto dto) { assertThat(wsRule.getKey()).isEqualTo(dto.getKey().toString()); assertThat(wsRule.getName()).isEqualTo(dto.getName()); assertThat(wsRule.getSecurityCategory()).isEqualTo(SQCategory.OTHERS.getKey()); @@ -1023,21 +1023,21 @@ public class ShowActionTest { .setParam("hotspot", hotspot.getKey()); } - private RuleDefinitionDto newRule(RuleType ruleType) { + private RuleDto newRule(RuleType ruleType) { return newRule(ruleType, t -> { }); } - private RuleDefinitionDto newRule(RuleType ruleType, Consumer populate) { + private RuleDto newRule(RuleType ruleType, Consumer populate) { return newRule(ruleType, RuleTesting::newRule, populate); } - private RuleDefinitionDto newRuleWithoutSection(RuleType ruleType, Consumer populate) { + private RuleDto newRuleWithoutSection(RuleType ruleType, Consumer populate) { return newRule(ruleType, RuleTesting::newRuleWithoutDescriptionSection, populate); } - private RuleDefinitionDto newRule(RuleType ruleType, Supplier ruleDefinitionDtoSupplier, Consumer populate) { - RuleDefinitionDto ruleDefinitionDto = ruleDefinitionDtoSupplier.get().setType(ruleType); + private RuleDto newRule(RuleType ruleType, Supplier ruleDefinitionDtoSupplier, Consumer populate) { + RuleDto ruleDefinitionDto = ruleDefinitionDtoSupplier.get().setType(ruleType); populate.accept(ruleDefinitionDto); dbTester.rules().insert(ruleDefinitionDto); return ruleDefinitionDto; diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregation.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregation.java index 8e2d4a3f237..255561532f4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregation.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregation.java @@ -23,7 +23,7 @@ import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; import java.util.Collection; import org.sonar.api.rule.RuleKey; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; public class RulesAggregation { @@ -33,7 +33,7 @@ public class RulesAggregation { this.rules = HashMultiset.create(); } - public RulesAggregation add(RuleDefinitionDto ruleDto) { + public RulesAggregation add(RuleDto ruleDto) { rules.add(new Rule(ruleDto.getKey(), ruleDto.getName())); return this; } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java index 652f1369e5f..5b6bf08de7e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java @@ -21,7 +21,7 @@ package org.sonar.server.issue; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +38,7 @@ public class RulesAggregationTest { public void count_rules() { RulesAggregation rulesAggregation = new RulesAggregation(); RuleKey ruleKey = RuleKey.of("xoo", "S001"); - RuleDefinitionDto ruleDto = RuleTesting.newRule(ruleKey).setName("Rule name"); + RuleDto ruleDto = RuleTesting.newRule(ruleKey).setName("Rule name"); rulesAggregation.add(ruleDto); rulesAggregation.add(ruleDto); @@ -53,7 +53,7 @@ public class RulesAggregationTest { public void count_rules_with_different_rules() { RulesAggregation rulesAggregation = new RulesAggregation(); - RuleDefinitionDto ruleDto = RuleTesting.newRule(RuleKey.of("xoo", "S001")).setName("Rule name 1"); + RuleDto ruleDto = RuleTesting.newRule(RuleKey.of("xoo", "S001")).setName("Rule name 1"); rulesAggregation.add(ruleDto); rulesAggregation.add(ruleDto); rulesAggregation.add(RuleTesting.newRule(RuleKey.of("xoo", "S002")).setName("Rule name 2")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java index c6deac39db6..2d671139ae4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.workflow.FunctionExecutor; import org.sonar.server.issue.workflow.IssueWorkflow; import org.sonar.server.tester.UserSessionRule; @@ -115,7 +115,7 @@ public class TransitionActionTest { } private IssueDto newIssue() { - RuleDefinitionDto rule = newRule().setUuid(Uuids.createFast()); + RuleDto rule = newRule().setUuid(Uuids.createFast()); ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = (newFileDto(project)); return IssueTesting.newIssue(rule, project, file); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionServiceTest.java index 3a0f9c6c50b..0870a8d7224 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/TransitionServiceTest.java @@ -29,7 +29,7 @@ import org.sonar.core.issue.IssueChangeContext; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.workflow.FunctionExecutor; import org.sonar.server.issue.workflow.IssueWorkflow; import org.sonar.server.issue.workflow.Transition; @@ -64,7 +64,7 @@ public class TransitionServiceTest { public void list_transitions() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(ISSUE_ADMIN, project); @@ -77,7 +77,7 @@ public class TransitionServiceTest { public void list_transitions_returns_empty_list_on_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(ISSUE_ADMIN, project); @@ -90,7 +90,7 @@ public class TransitionServiceTest { public void list_transitions_returns_only_transitions_that_do_not_requires_issue_admin_permission() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn(); @@ -103,7 +103,7 @@ public class TransitionServiceTest { public void list_transitions_returns_nothing_when_not_logged() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); List result = underTest.listTransitions(issue.toDefaultIssue()); @@ -115,7 +115,7 @@ public class TransitionServiceTest { public void do_transition() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); DefaultIssue defaultIssue = issue.toDefaultIssue(); @@ -129,7 +129,7 @@ public class TransitionServiceTest { public void do_transition_fail_on_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); DefaultIssue defaultIssue = externalIssue.toDefaultIssue(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java index 6e1fac26ae2..b72c2687c8a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java @@ -37,7 +37,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.rule.DefaultRuleFinder; @@ -83,7 +83,7 @@ public class WebIssueStorageTest { @Test public void insert_new_issues() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); @@ -132,7 +132,7 @@ public class WebIssueStorageTest { @Test public void update_issues() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); @@ -215,7 +215,7 @@ public class WebIssueStorageTest { @Test public void rule_uuid_is_set_on_updated_issue() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); @@ -229,7 +229,7 @@ public class WebIssueStorageTest { @Test public void rule_uuid_is_not_set_on_updated_issue_when_rule_is_removed() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(REMOVED)); + RuleDto rule = db.rules().insert(r -> r.setStatus(REMOVED)); ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java index 42c2147d6c6..86143f0b918 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDbTester; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -205,7 +205,7 @@ public class AddCommentActionTest { .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java index 919beedfa1e..b3e51da4eb4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java @@ -27,7 +27,7 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceTypesRule; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; @@ -84,7 +84,7 @@ public class AuthorsActionTest { String luke = "luke.skywalker"; ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(luke)); indexIssues(); @@ -102,7 +102,7 @@ public class AuthorsActionTest { String luke = "luke.skywalker"; ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(luke)); indexIssues(); @@ -124,7 +124,7 @@ public class AuthorsActionTest { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project1, project2); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project1, project1, issue -> issue.setAuthorLogin(leia)); db.issues().insertIssue(rule, project2, project2, issue -> issue.setAuthorLogin(luke)); indexIssues(); @@ -155,7 +155,7 @@ public class AuthorsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, portfolio)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); indexIssues(); viewIndexer.indexAll(); @@ -174,7 +174,7 @@ public class AuthorsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, application)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); indexIssues(); viewIndexer.indexAll(); @@ -193,7 +193,7 @@ public class AuthorsActionTest { String luke = "luke.skywalker"; ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(han)); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia)); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(luke)); @@ -269,7 +269,7 @@ public class AuthorsActionTest { public void json_example() { ComponentDto project = db.components().insertPrivateProject(); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin("luke.skywalker")); db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin("leia.organa")); indexIssues(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java index a9df4e32d09..07d0d2af52f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java @@ -40,7 +40,7 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.UnauthorizedException; @@ -139,7 +139,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); @@ -163,7 +163,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setSeverity(MAJOR).setType(CODE_SMELL) .setStatus(STATUS_OPEN).setResolution(null)); @@ -187,7 +187,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setTags(asList("tag1", "tag2")) .setStatus(STATUS_OPEN).setResolution(null)); @@ -212,7 +212,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); UserDto assignee = db.users().insertUser(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(assignee.getUuid()) .setStatus(STATUS_OPEN).setResolution(null)); @@ -238,7 +238,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); @@ -263,7 +263,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); UserDto oldAssignee = db.users().insertUser(); UserDto userToAssign = db.users().insertUser(); IssueDto issue1 = db.issues().insertIssue(rule, project, file, @@ -298,7 +298,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); @@ -355,7 +355,7 @@ public class BulkChangeActionTest { ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(BranchType.BRANCH)); ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); @@ -392,7 +392,7 @@ public class BulkChangeActionTest { ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(branchType)); ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); @@ -414,7 +414,7 @@ public class BulkChangeActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG) @@ -451,7 +451,7 @@ public class BulkChangeActionTest { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); // These 2 issues will be ignored as they are resolved, changing type is not possible @@ -485,7 +485,7 @@ public class BulkChangeActionTest { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG).setSeverity(MINOR) .setStatus(STATUS_OPEN).setResolution(null)); // These 2 issues will be ignored as there's nothing to do @@ -519,7 +519,7 @@ public class BulkChangeActionTest { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG).setSeverity(MINOR) .setStatus(STATUS_OPEN).setResolution(null)); // These 2 issues will be ignored as there's nothing to do @@ -548,9 +548,9 @@ public class BulkChangeActionTest { userSession.logIn(user); ComponentDto project = db.components().insertPrivateProject(); addUserProjectPermissions(user, project, USER, ISSUE_ADMIN); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); - RuleDefinitionDto externalRule = db.rules().insertIssueRule(r -> r.setIsExternal(true)); + RuleDto externalRule = db.rules().insertIssueRule(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insertIssue(externalRule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); BulkChangeWsResponse response = call(builder() @@ -568,7 +568,7 @@ public class BulkChangeActionTest { ComponentDto project1 = db.components().insertPrivateProject(); addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN); ComponentDto project2 = db.components().insertPrivateProject(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto authorizedIssue = db.issues().insertIssue(rule, project1, project1, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); // User has not browse permission on these 2 issues @@ -601,7 +601,7 @@ public class BulkChangeActionTest { addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN); ComponentDto project2 = db.components().insertPrivateProject(); addUserProjectPermissions(user, project2, USER); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto authorizedIssue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); // User has not issue admin permission on these 2 issues @@ -633,7 +633,7 @@ public class BulkChangeActionTest { addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN); ComponentDto project2 = db.components().insertPrivateProject(); addUserProjectPermissions(user, project2, USER); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto authorizedIssue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setSeverity(MAJOR) .setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); // User has not issue admin permission on these 2 issues @@ -663,7 +663,7 @@ public class BulkChangeActionTest { userSession.logIn(user); ComponentDto project = db.components().insertPrivateProject(); addUserProjectPermissions(user, project, USER); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, project, i -> i.setType(BUG) .setStatus(STATUS_OPEN).setResolution(null)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java index 944b11c59ff..209be35bf0d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java @@ -31,7 +31,6 @@ import org.sonar.core.issue.FieldDiffs; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTesting; @@ -336,7 +335,7 @@ public class ChangelogActionTest { } private IssueDto insertNewIssue() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); return db.issues().insertIssue(rule, project, file); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java index 7a0540a8bf2..c9d8180ca8b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -112,7 +112,7 @@ public class DoTransitionActionTest { public void do_transition() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn(db.users().insertUser()).addProjectPermission(USER, project, file); @@ -129,7 +129,7 @@ public class DoTransitionActionTest { public void fail_if_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto externalRule = db.rules().insertIssueRule(r -> r.setIsExternal(true)); + RuleDto externalRule = db.rules().insertIssueRule(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insertIssue(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(USER, project, file); @@ -142,7 +142,7 @@ public class DoTransitionActionTest { public void fail_if_hotspot() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertHotspotRule(); + RuleDto rule = db.rules().insertHotspotRule(); IssueDto hotspot = db.issues().insertHotspot(rule, project, file, i -> i.setType(RuleType.SECURITY_HOTSPOT)); userSession.logIn().addProjectPermission(USER, project, file); @@ -172,7 +172,7 @@ public class DoTransitionActionTest { public void fail_if_no_transition_param() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(USER, project, file); @@ -184,7 +184,7 @@ public class DoTransitionActionTest { public void fail_if_not_enough_permission_to_access_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(CODEVIEWER, project, file); @@ -196,7 +196,7 @@ public class DoTransitionActionTest { public void fail_if_not_enough_permission_to_apply_transition() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL)); userSession.logIn().addProjectPermission(USER, project, file); @@ -228,7 +228,7 @@ public class DoTransitionActionTest { .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java index d8a70c3c710..a819ec58b3c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java @@ -33,7 +33,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.issue.IssueFieldsSetter; @@ -103,7 +103,7 @@ public class IssueUpdaterTest { @Test public void verify_notification_without_resolution() { UserDto assignee = db.users().insertUser(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); DefaultIssue issue = db.issues().insertIssue(rule, project, file, @@ -132,7 +132,7 @@ public class IssueUpdaterTest { @Test public void verify_notification_with_resolution() { UserDto assignee = db.users().insertUser(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); DefaultIssue issue = db.issues().insertIssue(rule, project, file, @@ -160,7 +160,7 @@ public class IssueUpdaterTest { @Test public void verify_notification_on_branch() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BRANCH)); ComponentDto file = db.components().insertComponent(newFileDto(branch)); @@ -188,7 +188,7 @@ public class IssueUpdaterTest { @Test public void verify_no_notification_on_pr() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST)); ComponentDto file = db.components().insertComponent(newFileDto(branch)); @@ -203,7 +203,7 @@ public class IssueUpdaterTest { @Test public void verify_notification_when_issue_is_linked_on_removed_rule() { - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED)); + RuleDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED)); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR)).toDefaultIssue(); @@ -218,7 +218,7 @@ public class IssueUpdaterTest { @Test public void verify_notification_when_assignee_has_changed() { UserDto oldAssignee = db.users().insertUser(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setAssigneeUuid(oldAssignee.getUuid())) @@ -246,7 +246,7 @@ public class IssueUpdaterTest { @Test public void saveIssue_populates_specified_SearchResponseData_with_rule_project_and_component_retrieved_from_DB() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issueDto = db.issues().insertIssue(rule, project, file); @@ -262,7 +262,7 @@ public class IssueUpdaterTest { assertThat(preloadedSearchResponseData.getIssues().iterator().next()) .isNotSameAs(issueDto); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(rule.getKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) @@ -272,7 +272,7 @@ public class IssueUpdaterTest { @Test public void saveIssue_populates_specified_SearchResponseData_with_no_rule_but_with_project_and_component_if_rule_is_removed() { - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED)); + RuleDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED)); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issueDto = db.issues().insertIssue(rule, project, file); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java index ad121f485fd..08a41344085 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java @@ -34,7 +34,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.issue.AvatarResolverImpl; import org.sonar.server.issue.IssueFieldsSetter; @@ -109,7 +109,7 @@ public class SearchActionComponentsTest { @Test public void search_all_issues_when_no_parameter() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto issue = db.issues().insertIssue(rule, project, projectFile); @@ -124,7 +124,7 @@ public class SearchActionComponentsTest { @Test public void issues_on_different_projects() { - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue1 = db.issues().insertIssue(rule, project, file); @@ -153,7 +153,7 @@ public class SearchActionComponentsTest { ComponentDto file1 = db.components().insertComponent(newFileDto(module1)); ComponentDto module2 = db.components().insertComponent(newModuleDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(module2)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file1); IssueDto issue2 = db.issues().insertIssue(rule, project, file2); allowAnyoneOnProjects(project); @@ -170,7 +170,7 @@ public class SearchActionComponentsTest { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto module = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1")); ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("ISSUE_IN_MODULE")); db.issues().insertIssue(rule, project, project, i -> i.setKee("ISSUE_IN_ROOT_MODULE")); allowAnyoneOnProjects(project); @@ -194,7 +194,7 @@ public class SearchActionComponentsTest { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueAfterLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) .setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); @@ -217,7 +217,7 @@ public class SearchActionComponentsTest { ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1")); db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime())); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueAfterLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01) .setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100"))); @@ -239,7 +239,7 @@ public class SearchActionComponentsTest { public void search_by_file_uuid() { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project); indexIssues(); @@ -260,7 +260,7 @@ public class SearchActionComponentsTest { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setDbKey("FK2")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); IssueDto issueOnFile = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); IssueDto issueOnTest = db.issues().insertIssue(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4")); allowAnyoneOnProjects(project); @@ -282,7 +282,7 @@ public class SearchActionComponentsTest { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project); indexIssues(); @@ -317,7 +317,7 @@ public class SearchActionComponentsTest { ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "D2", "src/main/java/dir")); ComponentDto file1 = db.components().insertComponent(newFileDto(module1, directory1, "F1").setDbKey("FK1").setPath(directory1.path() + "/MyComponent.java")); db.components().insertComponent(newFileDto(module2, directory2, "F2").setDbKey("FK2").setPath(directory2.path() + "/MyComponent.java")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project); indexIssues(); @@ -349,7 +349,7 @@ public class SearchActionComponentsTest { ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); db.components().insertComponent(newProjectCopy(project, view)); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project, view); indexIssuesAndViews(); @@ -364,7 +364,7 @@ public class SearchActionComponentsTest { public void search_by_sub_view_uuid() { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView")); @@ -382,7 +382,7 @@ public class SearchActionComponentsTest { public void search_by_sub_view_uuid_return_only_authorized_view() { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); - RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); + RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setDbKey("MyView")); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView")); @@ -404,7 +404,7 @@ public class SearchActionComponentsTest { ComponentDto project2 = db.components().insertPrivateProject(); db.components().insertComponents(newProjectCopy(project1, application)); db.components().insertComponents(newProjectCopy(project2, application)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project1, project1); IssueDto issue2 = db.issues().insertIssue(rule, project2, project2); allowAnyoneOnApplication(application, project1, project2); @@ -433,8 +433,8 @@ public class SearchActionComponentsTest { db.components().insertComponents(newProjectCopy(project2, applicationBranch1)); db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2)); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); IssueDto issueOnProject1 = db.issues().insertIssue(issueRule, project1, project1); IssueDto issueOnProject1Branch1 = db.issues().insertIssue(issueRule, project1Branch1, project1Branch1); db.issues().insertHotspot(hotspotRule, project1Branch1, project1Branch1); @@ -474,7 +474,7 @@ public class SearchActionComponentsTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto application = db.components().insertPublicApplication(); db.components().insertComponents(newProjectCopy("PC1", project, application)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project); allowAnyoneOnProjects(project); indexIssuesAndViews(); @@ -490,7 +490,7 @@ public class SearchActionComponentsTest { public void search_application_without_projects() { ComponentDto project = db.components().insertPublicProject(); ComponentDto application = db.components().insertPublicApplication(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project); allowAnyoneOnProjects(project, application); indexIssuesAndViews(); @@ -505,7 +505,7 @@ public class SearchActionComponentsTest { @Test public void search_by_application_and_by_leak() { Date now = new Date(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto application = db.components().insertPublicApplication(); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); @@ -540,7 +540,7 @@ public class SearchActionComponentsTest { ComponentDto application = db.components().insertPublicApplication(); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project1, project1); IssueDto issue2 = db.issues().insertIssue(rule, project2, project2); allowAnyoneOnApplication(application, project1, project2); @@ -559,7 +559,7 @@ public class SearchActionComponentsTest { @Test public void search_by_application_and_project_and_leak() { Date now = new Date(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto application = db.components().insertPublicApplication(); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); @@ -591,7 +591,7 @@ public class SearchActionComponentsTest { @Test public void search_by_application_and_by_leak_when_one_project_has_no_leak() { Date now = new Date(); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto application = db.components().insertPublicApplication(); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); @@ -621,7 +621,7 @@ public class SearchActionComponentsTest { @Test public void search_by_branch() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = db.issues().insertIssue(rule, project, file); @@ -658,7 +658,7 @@ public class SearchActionComponentsTest { @Test public void return_branch_in_component_list() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); @@ -682,7 +682,7 @@ public class SearchActionComponentsTest { @Test public void search_by_pull_request() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); @@ -709,7 +709,7 @@ public class SearchActionComponentsTest { @Test public void search_using_main_branch_name() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); @@ -733,7 +733,7 @@ public class SearchActionComponentsTest { @Test public void does_not_return_branch_issues_on_not_contextualized_search() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); @@ -752,7 +752,7 @@ public class SearchActionComponentsTest { @Test public void does_not_return_branch_issues_when_using_db_key() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java index 0e8de7098b7..8eadb1276ab 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java @@ -34,7 +34,7 @@ import org.sonar.api.utils.Durations; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.issue.AvatarResolverImpl; @@ -96,7 +96,7 @@ public class SearchActionFacetsTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); UserDto user = db.users().insertUser(); db.issues().insertIssue(rule, project, file, i -> i .setSeverity("MAJOR") @@ -134,7 +134,7 @@ public class SearchActionFacetsTest { public void display_projects_facet() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file); indexPermissions(); indexIssues(); @@ -157,7 +157,7 @@ public class SearchActionFacetsTest { ComponentDto file1 = db.components().insertComponent(newFileDto(project1)); ComponentDto file2 = db.components().insertComponent(newFileDto(project2)); ComponentDto file3 = db.components().insertComponent(newFileDto(project3)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project1, file1); db.issues().insertIssue(rule, project2, file2); db.issues().insertIssue(rule, project3, file3); @@ -179,7 +179,7 @@ public class SearchActionFacetsTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java/dir")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file); indexPermissions(); indexIssues(); @@ -200,7 +200,7 @@ public class SearchActionFacetsTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file); indexPermissions(); indexIssues(); @@ -220,7 +220,7 @@ public class SearchActionFacetsTest { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); ComponentDto file3 = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file1); db.issues().insertIssue(rule, project, file2); indexPermissions(); @@ -241,7 +241,7 @@ public class SearchActionFacetsTest { public void fail_to_display_fileUuids_facet_when_no_project_is_set() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file); indexPermissions(); indexIssues(); @@ -267,7 +267,7 @@ public class SearchActionFacetsTest { ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir" + index)); ComponentDto file = db.components().insertComponent(newFileDto(directory)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(user.getUuid()) .setStatus(ISSUE_STATUSES[random.nextInt(ISSUE_STATUSES.length)]) .setType(rule.getType())); @@ -312,7 +312,7 @@ public class SearchActionFacetsTest { @Test public void check_projects_facet_max_size() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IntStream.rangeClosed(1, 110) .forEach(i -> { ComponentDto project = db.components().insertPublicProject(); @@ -337,8 +337,8 @@ public class SearchActionFacetsTest { ComponentDto project2 = db.components().insertPublicProject(); ComponentDto file1 = db.components().insertComponent(newFileDto(module1)); ComponentDto file2 = db.components().insertComponent(newFileDto(module1)); - RuleDefinitionDto rule1 = db.rules().insertIssueRule(); - RuleDefinitionDto rule2 = db.rules().insertIssueRule(); + RuleDto rule1 = db.rules().insertIssueRule(); + RuleDto rule2 = db.rules().insertIssueRule(); UserDto user1 = db.users().insertUser(); UserDto user2 = db.users().insertUser(); db.issues().insertIssue(rule1, project1, file1, i -> i @@ -401,7 +401,7 @@ public class SearchActionFacetsTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); UserDto john = db.users().insertUser(); UserDto alice = db.users().insertUser(); db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(john.getUuid())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 2954b7b8c8c..b18c7ab60b7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -54,7 +54,6 @@ import org.sonar.db.issue.IssueDto; import org.sonar.db.permission.GroupPermissionDto; import org.sonar.db.protobuf.DbCommons; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.rule.RuleTesting; @@ -155,7 +154,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); UserDto simon = db.users().insertUser(); - RuleDefinitionDto rule = newIssueRule().getDefinition(); + RuleDto rule = newIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i .setEffort(10L) .setLine(42) @@ -190,7 +189,7 @@ public class SearchActionTest { public void issue_on_external_rule() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo")); + RuleDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo")); IssueDto issue = db.issues().insertIssue(rule, project, file); indexPermissionsAndIssues(); @@ -207,7 +206,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo").setIsAdHoc(true)); + RuleDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo").setIsAdHoc(true)); IssueDto issue = db.issues().insertIssue(rule, project, file); indexIssues(); @@ -224,7 +223,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo").setIsAdHoc(true)); + RuleDto rule = db.rules().insertIssueRule(RuleTesting.EXTERNAL_XOO, r -> r.setIsExternal(true).setLanguage("xoo").setIsAdHoc(true)); RuleMetadataDto ruleMetadata = db.rules().insertOrUpdateMetadata(rule, m -> m.setAdHocName("different_rule_name")); IssueDto issue = db.issues().insertIssue(rule, project, file); indexIssues(); @@ -279,7 +278,7 @@ public class SearchActionTest { .setEndOffset(12) .build()) .build()))); - RuleDefinitionDto rule = newIssueRule().getDefinition(); + RuleDto rule = newIssueRule(); db.issues().insertIssue(rule, project, file, i -> i.setLocations(locations.build())); indexIssues(); @@ -300,7 +299,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newIssueRule().getDefinition(); + RuleDto rule = newIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); dbClient.issueChangeDao().insert(session, new IssueChangeDto() @@ -339,7 +338,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newIssueRule().getDefinition(); + RuleDto rule = newIssueRule(); IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); dbClient.issueChangeDao().insert(session, new IssueChangeDto() @@ -380,7 +379,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = newIssueRule().getDefinition(); + RuleDto rule = newIssueRule(); db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(simon.getUuid()).setType(CODE_SMELL)); indexIssues(); userSession.logIn("john"); @@ -422,7 +421,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("java")); - db.issues().insertIssue(rule.getDefinition(), project, file); + db.issues().insertIssue(rule, project, file); session.commit(); indexIssues(); @@ -443,7 +442,7 @@ public class SearchActionTest { ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto("PROJECT_ID").setDbKey("PROJECT_KEY").setLanguage("java")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY").setLanguage("java")); - db.issues().insertIssue(rule.getDefinition(), project, file); + db.issues().insertIssue(rule, project, file); session.commit(); indexIssues(); @@ -822,7 +821,7 @@ public class SearchActionTest { public void search_by_author() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project, null)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("leia")); IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("luke")); IssueDto issue3 = db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("han, solo")); @@ -1003,13 +1002,13 @@ public class SearchActionTest { public void only_vulnerabilities_are_returned_by_cwe() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")) .setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); @@ -1028,13 +1027,13 @@ public class SearchActionTest { public void only_vulnerabilities_are_returned_by_owasp() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1", "owaspTop10-2021:a2")) .setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); @@ -1053,13 +1052,13 @@ public class SearchActionTest { public void only_vulnerabilities_are_returned_by_owasp_2021() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1", "owaspTop10-2021:a2")) .setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); @@ -1078,13 +1077,13 @@ public class SearchActionTest { public void only_vulnerabilities_are_returned_by_sansTop25() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:266", "cwe:732", "owaspTop10:a5")) .setSystemTags(Sets.newHashSet("cert", "cwe", "owasp-a5", "sans-top25-porous")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("cert", "cwe", "owasp-a5", "sans-top25-porous")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); @@ -1103,13 +1102,13 @@ public class SearchActionTest { public void only_vulnerabilities_are_returned_by_sonarsource_security() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")) .setSystemTags(Sets.newHashSet("cwe", "owasp-a1", "sans-top25-insecure", "sql")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("cwe", "owasp-a1", "sans-top25-insecure", "sql")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); @@ -1128,7 +1127,7 @@ public class SearchActionTest { public void security_hotspots_are_not_returned_by_default() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, file, i -> i.setType(RuleType.BUG)); db.issues().insertIssue(rule, project, file, i -> i.setType(RuleType.VULNERABILITY)); db.issues().insertIssue(rule, project, file, i -> i.setType(CODE_SMELL)); @@ -1146,11 +1145,11 @@ public class SearchActionTest { public void security_hotspots_are_not_returned_by_issues_param() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); + RuleDto issueRule = db.rules().insertIssueRule(); IssueDto bugIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(RuleType.BUG)); IssueDto vulnerabilityIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(RuleType.VULNERABILITY)); IssueDto codeSmellIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(CODE_SMELL)); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); IssueDto hotspot = db.issues().insertHotspot(hotspotRule, project, file); indexPermissionsAndIssues(); @@ -1167,13 +1166,13 @@ public class SearchActionTest { public void security_hotspots_are_not_returned_by_cwe() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + Consumer ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")) .setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); Consumer issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql")); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); indexPermissions(); @@ -1193,9 +1192,9 @@ public class SearchActionTest { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); db.issues().insertHotspot(hotspotRule, project, file, issueDto -> issueDto.setAssigneeUuid(user.getUuid())); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); + RuleDto issueRule = db.rules().insertIssueRule(); IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueDto -> issueDto.setAssigneeUuid(user.getUuid())); IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueDto -> issueDto.setAssigneeUuid(user.getUuid())); IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueDto -> issueDto.setAssigneeUuid(user.getUuid())); @@ -1216,7 +1215,7 @@ public class SearchActionTest { public void security_hotspots_are_not_returned_by_rule() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); db.issues().insertHotspot(hotspotRule, project, file); indexPermissionsAndIssues(); @@ -1231,7 +1230,7 @@ public class SearchActionTest { public void security_hotspots_are_not_returned_by_issues_param_only() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto rule = db.rules().insertHotspotRule(); + RuleDto rule = db.rules().insertHotspotRule(); List hotspots = IntStream.range(1, 2 + new Random().nextInt(10)) .mapToObj(value -> db.issues().insertHotspot(rule, project, file)) .collect(Collectors.toList()); @@ -1250,7 +1249,7 @@ public class SearchActionTest { public void fail_if_trying_to_filter_issues_by_hotspots() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto hotspotRule = newHotspotRule().getDefinition(); + RuleDto hotspotRule = newHotspotRule(); db.issues().insertHotspot(hotspotRule, project, file); insertIssues(i -> i.setType(RuleType.BUG), i -> i.setType(RuleType.VULNERABILITY), i -> i.setType(RuleType.CODE_SMELL)); @@ -1267,11 +1266,11 @@ public class SearchActionTest { public void security_hotspot_are_ignored_when_filtering_by_severities() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); + RuleDto issueRule = db.rules().insertIssueRule(); IssueDto bugIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(RuleType.BUG).setSeverity(Severity.MAJOR.name())); IssueDto vulnerabilityIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(RuleType.VULNERABILITY).setSeverity(Severity.MAJOR.name())); IssueDto codeSmellIssue = db.issues().insertIssue(issueRule, project, file, i -> i.setType(CODE_SMELL).setSeverity(Severity.MAJOR.name())); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); db.issues().insertHotspot(hotspotRule, project, file, i -> i.setSeverity(Severity.MAJOR.name())); indexPermissions(); indexIssues(); @@ -1446,7 +1445,7 @@ public class SearchActionTest { .setName("Rule name") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Rule desc")) .setStatus(RuleStatus.READY); - db.rules().insert(rule.getDefinition()); + db.rules().insert(rule); return rule; } @@ -1456,7 +1455,7 @@ public class SearchActionTest { .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Rule desc")) .setStatus(RuleStatus.READY) .setType(SECURITY_HOTSPOT_VALUE); - db.rules().insert(rule.getDefinition()); + db.rules().insert(rule); return rule; } @@ -1484,7 +1483,7 @@ public class SearchActionTest { private void insertIssues(Consumer... populators) { UserDto john = db.users().insertUser(); userSession.logIn(john); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); for (Consumer populator : populators) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java index eb1ed655373..7ba6e06b156 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDbTester; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -206,7 +206,7 @@ public class SetSeverityActionTest { .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java index a850f26913c..63d70c9305e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java @@ -38,7 +38,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -194,7 +194,7 @@ public class SetTagsActionTest { @Test public void fail_when_security_hotspot() { - RuleDefinitionDto rule = db.rules().insertHotspotRule(); + RuleDto rule = db.rules().insertHotspotRule(); ComponentDto project = db.components().insertPublicProject(newPublicProjectDto()); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issueDto = db.issues().insertHotspot(rule, project, file); @@ -226,7 +226,7 @@ public class SetTagsActionTest { @SafeVarargs private final IssueDto insertIssueForPublicProject(Consumer... consumers) { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPublicProject(newPublicProjectDto()); ComponentDto file = db.components().insertComponent(newFileDto(project)); return db.issues().insertIssue(rule, project, file, consumers); @@ -261,7 +261,7 @@ public class SetTagsActionTest { .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java index e0051da80d2..04418f2a760 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java @@ -44,7 +44,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDbTester; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -226,7 +226,7 @@ public class SetTypeActionTest { } private IssueDto newIssueWithProject(RuleType type) { - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); return issueDbTester.insert(rule, project, file, i -> i.setType(type)); @@ -249,7 +249,7 @@ public class SetTypeActionTest { .extracting(IssueDto::getKey) .containsOnly(issue.getKey()); assertThat(preloadedSearchResponseData.getRules()) - .extracting(RuleDefinitionDto::getKey) + .extracting(RuleDto::getKey) .containsOnly(issue.getRuleKey()); assertThat(preloadedSearchResponseData.getComponents()) .extracting(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java index cddcebc270b..a8033f0c840 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.issue.IssueDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.issue.index.IssueIndex; @@ -80,7 +80,7 @@ public class TagsActionTest { @Test public void search_tags() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag3", "tag4", "tag5"))); @@ -96,8 +96,8 @@ public class TagsActionTest { @Test public void search_tags_ignores_hotspots() { ComponentDto project = db.components().insertPrivateProject(); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); Consumer setTags = issue -> issue.setTags(asList("tag1", "tag2")); db.issues().insertIssue(issueRule, project, project, setTags); db.issues().insertHotspot(hotspotRule, project, project, setTags); @@ -110,7 +110,7 @@ public class TagsActionTest { @Test public void search_tags_by_query() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag12", "tag4", "tag5"))); @@ -122,8 +122,8 @@ public class TagsActionTest { @Test public void search_tags_by_query_ignores_hotspots() { - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); ComponentDto project = db.components().insertPrivateProject(); db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(asList("tag1", "tag12", "tag4", "tag5"))); @@ -141,7 +141,7 @@ public class TagsActionTest { @Test public void search_tags_by_project() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(singletonList("tag1"))); @@ -156,7 +156,7 @@ public class TagsActionTest { @Test public void search_tags_by_branch_equals_main_branch() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); @@ -171,7 +171,7 @@ public class TagsActionTest { @Test public void search_tags_by_branch() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); @@ -186,7 +186,7 @@ public class TagsActionTest { @Test public void search_tags_by_branch_not_exist_fall_back_to_main_branch() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); @@ -201,7 +201,7 @@ public class TagsActionTest { @Test public void search_all_tags_by_query() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); @@ -216,8 +216,8 @@ public class TagsActionTest { @Test public void search_tags_by_project_ignores_hotspots() { - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.issues().insertHotspot(hotspotRule, project1, project1, issue -> issue.setTags(singletonList("tag1"))); @@ -237,7 +237,7 @@ public class TagsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, portfolio)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe"))); indexIssues(); viewIndexer.indexAll(); @@ -251,8 +251,8 @@ public class TagsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, portfolio)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("cwe"))); db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("foo"))); indexIssues(); @@ -267,7 +267,7 @@ public class TagsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, application)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe"))); indexIssues(); viewIndexer.indexAll(); @@ -281,8 +281,8 @@ public class TagsActionTest { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy(project, application)); permissionIndexer.allowOnlyAnyone(project); - RuleDefinitionDto issueRule = db.rules().insertIssueRule(); - RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(); + RuleDto issueRule = db.rules().insertIssueRule(); + RuleDto hotspotRule = db.rules().insertHotspotRule(); db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("cwe"))); db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("foo"))); indexIssues(); @@ -293,7 +293,7 @@ public class TagsActionTest { @Test public void return_limited_size() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2"))); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag3", "tag4", "tag5"))); @@ -309,7 +309,7 @@ public class TagsActionTest { @Test public void do_not_return_issues_without_permission() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(asList("tag1", "tag2"))); @@ -352,7 +352,7 @@ public class TagsActionTest { @Test public void json_example() { - RuleDefinitionDto rule = db.rules().insertIssueRule(); + RuleDto rule = db.rules().insertIssueRule(); ComponentDto project = db.components().insertPrivateProject(); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("convention", "security"))); db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe"))); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java index a1b2120ef7c..522938b2261 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java @@ -42,7 +42,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.qualityprofile.builtin.QProfileName; import org.sonar.server.rule.RuleCreator; @@ -79,7 +79,7 @@ public class QProfileBackuperImplTest { @Test public void backup_generates_xml_file() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule.getLanguage()); ActiveRuleDto activeRule = activate(profile, rule); @@ -103,7 +103,7 @@ public class QProfileBackuperImplTest { @Test public void backup_rules_having_parameters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto profile = createProfile(rule.getLanguage()); ActiveRuleDto activeRule = activate(profile, rule, param); @@ -126,7 +126,7 @@ public class QProfileBackuperImplTest { @Test public void backup_empty_profile() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule.getLanguage()); StringWriter writer = new StringWriter(); @@ -141,9 +141,9 @@ public class QProfileBackuperImplTest { @Test public void backup_custom_rules_with_params() { - RuleDefinitionDto templateRule = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto + RuleDto templateRule = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto .setIsTemplate(true)); - RuleDefinitionDto rule = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto + RuleDto rule = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(UuidFactoryFast.getInstance().create(), "custom rule description")) .setName("custom rule name") .setStatus(RuleStatus.READY) @@ -166,8 +166,8 @@ public class QProfileBackuperImplTest { "" + activeRule.getSeverityString() + "" + "" + rule.getName() + "" + "" + templateRule.getKey().rule() + "" + - "" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "" + - "default" + rule.getDefaultRuleDescriptionSectionDto().getContent() + "" + + "" + rule.getDefaultRuleDescriptionSection().getContent() + "" + + "default" + rule.getDefaultRuleDescriptionSection().getContent() + "" + "" + "" + param.getName() + "" + "20" + @@ -386,7 +386,7 @@ public class QProfileBackuperImplTest { @Test public void copy_profile() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto from = createProfile(rule.getLanguage()); ActiveRuleDto activeRule = activate(from, rule, param); @@ -462,7 +462,7 @@ public class QProfileBackuperImplTest { .hasMessage("The quality profile cannot be restored as it contains rules from external rule engines: sonarjs:s001"); } - private RuleDefinitionDto createRule() { + private RuleDto createRule() { return db.rules().insert(); } @@ -470,11 +470,11 @@ public class QProfileBackuperImplTest { return db.qualityProfiles().insert(p -> p.setLanguage(language)); } - private ActiveRuleDto activate(QProfileDto profile, RuleDefinitionDto rule) { + private ActiveRuleDto activate(QProfileDto profile, RuleDto rule) { return db.qualityProfiles().activateRule(profile, rule); } - private ActiveRuleDto activate(QProfileDto profile, RuleDefinitionDto rule, RuleParamDto param) { + private ActiveRuleDto activate(QProfileDto profile, RuleDto rule, RuleParamDto param) { ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile, rule); ActiveRuleParamDto dto = ActiveRuleParamDto.createFor(param) .setValue("20") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java index 4282ef2abba..88ef5dd0feb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java @@ -34,7 +34,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsTester; @@ -66,8 +66,8 @@ public class QProfileComparisonTest { private QProfileRules qProfileRules; private QProfileComparison comparison; - private RuleDefinitionDto xooRule1; - private RuleDefinitionDto xooRule2; + private RuleDto xooRule1; + private RuleDto xooRule2; private QProfileDto left; private QProfileDto right; @@ -82,8 +82,8 @@ public class QProfileComparisonTest { qProfileRules = new QProfileRulesImpl(db, ruleActivator, ruleIndex, activeRuleIndexer, qualityProfileChangeEventService); comparison = new QProfileComparison(db); - xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR").getDefinition(); - xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR").getDefinition(); + xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR"); + xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR"); db.ruleDao().insert(dbSession, xooRule1); db.ruleDao().insert(dbSession, xooRule2); db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java index 812a193354b..0a188fbfe2e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java @@ -40,7 +40,7 @@ import org.sonar.api.utils.ValidationMessages; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.rule.DefaultRuleFinder; @@ -70,7 +70,7 @@ public class QProfileExportersTest { new StandardExporter(), new XooExporter()}; private final ProfileImporter[] importers = new ProfileImporter[] { new XooProfileImporter(), new XooProfileImporterWithMessages(), new XooProfileImporterWithError()}; - private RuleDefinitionDto rule; + private RuleDto rule; private final QProfileRules qProfileRules = mock(QProfileRules.class); private final QProfileExporters underTest = new QProfileExporters(db.getDbClient(), ruleFinder, qProfileRules, exporters, importers); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java index c185e40e7f9..5c61b335891 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java @@ -41,7 +41,7 @@ import org.sonar.db.qualityprofile.OrgQProfileDto; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; @@ -69,7 +69,7 @@ public class QProfileFactoryImplTest { private DbSession dbSession = db.getSession(); private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class); private QProfileFactory underTest = new QProfileFactoryImpl(db.getDbClient(), new SequenceUuidFactory(), system2, activeRuleIndexer); - private RuleDefinitionDto rule; + private RuleDto rule; private RuleParamDto ruleParam; @Before diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java index 031316d8b07..1d59efb389d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java @@ -28,7 +28,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; import org.sonar.server.qualityprofile.builtin.RuleActivator; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; @@ -72,9 +72,9 @@ public class QProfileResetImplTest { @Test public void reset() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE)); - RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getUuid()))); - RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getUuid()))); @@ -93,10 +93,10 @@ public class QProfileResetImplTest { QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE)); QProfileDto childProfile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE)); qProfileTree.setParentAndCommit(db.getSession(), childProfile, parentProfile); - RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); qProfileRules.activateAndCommit(db.getSession(), parentProfile, singleton(RuleActivation.create(existingRule.getUuid()))); qProfileRules.activateAndCommit(db.getSession(), childProfile, singleton(RuleActivation.create(existingRule.getUuid()))); - RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); underTest.reset(db.getSession(), childProfile, singletonList(RuleActivation.create(newRule.getUuid()))); @@ -109,7 +109,7 @@ public class QProfileResetImplTest { @Test public void fail_when_profile_is_built_in() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE).setIsBuiltIn(true)); - RuleDefinitionDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); assertThatThrownBy(() -> { underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid()))); @@ -122,7 +122,7 @@ public class QProfileResetImplTest { @Test public void fail_when_profile_is_not_persisted() { QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setRulesProfileUuid(null).setLanguage(LANGUAGE); - RuleDefinitionDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); + RuleDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE)); assertThatThrownBy(() -> { underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid()))); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java index 1b84a819800..dc700a257d2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java @@ -20,6 +20,7 @@ package org.sonar.server.qualityprofile; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -37,7 +38,6 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.es.EsTester; @@ -95,7 +95,7 @@ public class QProfileRuleImplTest { @Test public void system_activates_rule_without_parameters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null); List changes = activate(profile, activation); @@ -108,7 +108,7 @@ public class QProfileRuleImplTest { @Test public void user_activates_rule_without_parameters() { userSession.logIn(); - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null); List changes = activate(profile, activation); @@ -120,7 +120,7 @@ public class QProfileRuleImplTest { @Test public void activate_rule_with_default_severity_and_parameters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -134,7 +134,7 @@ public class QProfileRuleImplTest { @Test public void activate_rule_with_parameters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -148,7 +148,7 @@ public class QProfileRuleImplTest { @Test public void activate_rule_with_default_severity() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); @@ -164,7 +164,7 @@ public class QProfileRuleImplTest { */ @Test public void activate_rule_with_empty_parameter_having_no_default_value() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -182,7 +182,7 @@ public class QProfileRuleImplTest { */ @Test public void activate_rule_with_negative_integer_value_on_parameter_having_no_default_value() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto paramWithoutDefault = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue(null)); RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -198,7 +198,7 @@ public class QProfileRuleImplTest { @Test public void activation_ignores_unsupported_parameters() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -212,7 +212,7 @@ public class QProfileRuleImplTest { @Test public void update_an_already_activated_rule() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -232,7 +232,7 @@ public class QProfileRuleImplTest { @Test public void update_activation_with_parameter_without_default_value() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto paramWithoutDefault = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue(null)); RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -253,7 +253,7 @@ public class QProfileRuleImplTest { @Test public void reset_parameter_to_default_value() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -273,7 +273,7 @@ public class QProfileRuleImplTest { @Test public void update_activation_removes_parameter_without_default_value() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto paramWithoutDefault = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue(null)); RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -294,7 +294,7 @@ public class QProfileRuleImplTest { @Test public void update_activation_with_new_parameter() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -316,7 +316,7 @@ public class QProfileRuleImplTest { @Test public void ignore_activation_without_changes() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); // initial activation @@ -334,7 +334,7 @@ public class QProfileRuleImplTest { @Test public void do_not_change_severity_and_params_if_unset_and_already_activated() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10")); QProfileDto profile = createProfile(rule); @@ -354,7 +354,7 @@ public class QProfileRuleImplTest { @Test public void fail_to_activate_rule_if_profile_is_on_different_languages() { - RuleDefinitionDto rule = createJavaRule(); + RuleDto rule = createJavaRule(); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("js")); RuleActivation activation = RuleActivation.create(rule.getUuid()); @@ -364,7 +364,7 @@ public class QProfileRuleImplTest { @Test public void fail_to_activate_rule_if_rule_has_REMOVED_status() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED)); + RuleDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED)); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); @@ -374,7 +374,7 @@ public class QProfileRuleImplTest { @Test public void fail_to_activate_if_template() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setIsTemplate(true)); + RuleDto rule = db.rules().insert(r -> r.setIsTemplate(true)); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); @@ -384,7 +384,7 @@ public class QProfileRuleImplTest { @Test public void fail_to_activate_if_invalid_parameter() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10").setType(PropertyType.INTEGER.name())); QProfileDto profile = createProfile(rule); @@ -395,9 +395,9 @@ public class QProfileRuleImplTest { @Test public void ignore_parameters_when_activating_custom_rule() { - RuleDefinitionDto templateRule = db.rules().insert(r -> r.setIsTemplate(true)); + RuleDto templateRule = db.rules().insert(r -> r.setIsTemplate(true)); RuleParamDto templateParam = db.rules().insertRuleParam(templateRule, p -> p.setName("format")); - RuleDefinitionDto customRule = db.rules().insert(newCustomRule(templateRule)); + RuleDto customRule = db.rules().insert(newCustomRule(templateRule)); RuleParamDto customParam = db.rules().insertRuleParam(customRule, p -> p.setName("format").setDefaultValue("txt")); QProfileDto profile = createProfile(customRule); @@ -417,7 +417,7 @@ public class QProfileRuleImplTest { @Test public void user_deactivates_a_rule() { userSession.logIn(); - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); List changes = activate(profile, activation); @@ -433,7 +433,7 @@ public class QProfileRuleImplTest { @Test public void system_deactivates_a_rule() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); List changes = activate(profile, activation); @@ -446,7 +446,7 @@ public class QProfileRuleImplTest { verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage())); } - private void assertThatChangeIsDeactivation(List changes, RuleDefinitionDto rule) { + private void assertThatChangeIsDeactivation(List changes, RuleDto rule) { assertThat(changes).hasSize(1); ActiveRuleChange change = changes.get(0); assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.DEACTIVATED); @@ -455,7 +455,7 @@ public class QProfileRuleImplTest { @Test public void ignore_deactivation_if_rule_is_not_activated() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); List changes = deactivate(profile, rule); @@ -466,7 +466,7 @@ public class QProfileRuleImplTest { @Test public void deactivate_rule_that_has_REMOVED_status() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); RuleActivation activation = RuleActivation.create(rule.getUuid()); List changes = activate(profile, activation); @@ -483,7 +483,7 @@ public class QProfileRuleImplTest { @Test public void activation_on_child_profile_is_propagated_to_descendants() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); QProfileDto grandChildProfile = createChildProfile(childProfile); @@ -497,7 +497,7 @@ public class QProfileRuleImplTest { @Test public void update_on_child_profile_is_propagated_to_descendants() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -523,7 +523,7 @@ public class QProfileRuleImplTest { @Test public void override_activation_of_inherited_profile() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -545,7 +545,7 @@ public class QProfileRuleImplTest { @Test public void updated_activation_on_parent_is_not_propagated_to_overridden_profiles() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -572,7 +572,7 @@ public class QProfileRuleImplTest { @Test public void reset_on_parent_is_not_propagated_to_overridden_profiles() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -590,7 +590,9 @@ public class QProfileRuleImplTest { RuleActivation updateActivation = RuleActivation.createReset(rule.getUuid()); changes = activate(parentProfile, updateActivation); - assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue())); + Map test = new HashMap<>(); + test.put(param.getName(), param.getDefaultValue()); + assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, test); assertThatRuleIsUpdated(childProfile, rule, rule.getSeverityString(), INHERITED, of(param.getName(), param.getDefaultValue())); assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar")); assertThat(changes).hasSize(2); @@ -599,7 +601,7 @@ public class QProfileRuleImplTest { @Test public void active_on_parent_a_rule_already_activated_on_child() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -619,7 +621,7 @@ public class QProfileRuleImplTest { @Test public void do_not_mark_as_overridden_if_same_values_than_parent() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); RuleParamDto param = db.rules().insertRuleParam(rule); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -638,7 +640,7 @@ public class QProfileRuleImplTest { @Test public void propagate_deactivation_on_children() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -657,7 +659,7 @@ public class QProfileRuleImplTest { @Test public void propagate_deactivation_on_children_even_when_overridden() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -680,7 +682,7 @@ public class QProfileRuleImplTest { @Test public void cannot_deactivate_rule_inherited() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -697,7 +699,7 @@ public class QProfileRuleImplTest { @Test public void reset_child_profile_do_not_change_parent() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -722,7 +724,7 @@ public class QProfileRuleImplTest { @Test public void reset_parent_is_not_propagated_when_child_overrides() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto baseProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(baseProfile); QProfileDto grandChildProfile = createChildProfile(childProfile); @@ -759,7 +761,7 @@ public class QProfileRuleImplTest { @Test public void ignore_reset_if_not_activated() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); createChildProfile(parentProfile); @@ -792,8 +794,7 @@ public class QProfileRuleImplTest { assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize); assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize); assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).hasSize(bulkSize); - rules.stream().forEach( - r -> assertThatRuleIsActivated(profile, r.getDefinition(), null, MINOR, null, emptyMap())); + rules.forEach(r -> assertThatRuleIsActivated(profile, r, null, MINOR, null, emptyMap())); } @Test @@ -827,13 +828,12 @@ public class QProfileRuleImplTest { assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize); assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize); assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).isEmpty(); - rules.stream().forEach( - r -> assertThatRuleIsNotPresent(profile, r.getDefinition())); + rules.forEach(r -> assertThatRuleIsNotPresent(profile, r)); } @Test public void bulk_deactivation_ignores_errors() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -856,8 +856,8 @@ public class QProfileRuleImplTest { @Test public void bulk_change_severity() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); QProfileDto parentProfile = createProfile(rule1); QProfileDto childProfile = createChildProfile(parentProfile); QProfileDto grandchildProfile = createChildProfile(childProfile); @@ -889,7 +889,7 @@ public class QProfileRuleImplTest { @Test public void delete_rule_from_all_profiles() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); QProfileDto grandChildProfile = createChildProfile(childProfile); @@ -914,7 +914,7 @@ public class QProfileRuleImplTest { @Test public void activation_fails_when_profile_is_built_in() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); assertThatThrownBy(() -> { @@ -929,7 +929,7 @@ public class QProfileRuleImplTest { assertThat(activeRules).isEmpty(); } - private List deactivate(QProfileDto profile, RuleDefinitionDto rule) { + private List deactivate(QProfileDto profile, RuleDto rule) { return underTest.deactivateAndCommit(db.getSession(), profile, singleton(rule.getUuid())); } @@ -937,7 +937,7 @@ public class QProfileRuleImplTest { return underTest.activateAndCommit(db.getSession(), profile, singleton(activation)); } - private QProfileDto createProfile(RuleDefinitionDto rule) { + private QProfileDto createProfile(RuleDto rule) { return db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage())); } @@ -960,7 +960,7 @@ public class QProfileRuleImplTest { assertThat(loaded.getRulesUpdatedAt()).isNotEmpty(); } - private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List changes, + private void assertThatRuleIsActivated(QProfileDto profile, RuleDto rule, @Nullable List changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() @@ -984,7 +984,7 @@ public class QProfileRuleImplTest { } } - private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDefinitionDto rule) { + private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDto rule) { Optional activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) @@ -993,7 +993,7 @@ public class QProfileRuleImplTest { assertThat(activeRule).isEmpty(); } - private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, + private void assertThatRuleIsUpdated(QProfileDto profile, RuleDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() @@ -1022,11 +1022,11 @@ public class QProfileRuleImplTest { assertThat(db.countRowsOfTable(db.getSession(), "active_rules")).isZero(); } - private RuleDefinitionDto createRule() { + private RuleDto createRule() { return db.rules().insert(r -> r.setSeverity(Severity.MAJOR)); } - private RuleDefinitionDto createJavaRule() { + private RuleDto createJavaRule() { return db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("java")); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java index 3d07cbd70a6..c718b4e8909 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRulesImplTest.java @@ -30,7 +30,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileChangeQuery; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; @@ -70,7 +70,7 @@ public class QProfileRulesImplTest { @Test public void activate_one_rule() { QProfileDto qProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage())); + RuleDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage())); RuleActivation ruleActivation = RuleActivation.create(rule.getUuid(), Severity.CRITICAL, Collections.emptyMap()); qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation)); @@ -86,7 +86,7 @@ public class QProfileRulesImplTest { UserDto user = db.users().insertUser(); userSession.logIn(user); QProfileDto qProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage())); + RuleDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage())); RuleActivation ruleActivation = RuleActivation.create(rule.getUuid(), Severity.CRITICAL, Collections.emptyMap()); qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java index 80311899071..7cf8aec8d4b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java @@ -33,7 +33,7 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; @@ -76,7 +76,7 @@ public class QProfileTreeImplTest { @Test public void set_itself_as_parent_fails() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto profile = createProfile(rule); assertThatThrownBy(() -> underTest.setParentAndCommit(db.getSession(), profile, profile)) @@ -86,7 +86,7 @@ public class QProfileTreeImplTest { @Test public void set_child_as_parent_fails() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); @@ -97,7 +97,7 @@ public class QProfileTreeImplTest { @Test public void set_grandchild_as_parent_fails() { - RuleDefinitionDto rule = createRule(); + RuleDto rule = createRule(); QProfileDto parentProfile = createProfile(rule); QProfileDto childProfile = createChildProfile(parentProfile); QProfileDto grandchildProfile = createChildProfile(childProfile); @@ -109,8 +109,8 @@ public class QProfileTreeImplTest { @Test public void cannot_set_parent_if_language_is_different() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("foo")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("bar")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("foo")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("bar")); QProfileDto parentProfile = createProfile(rule1); List changes = activate(parentProfile, RuleActivation.create(rule1.getUuid())); @@ -127,8 +127,8 @@ public class QProfileTreeImplTest { @Test public void set_then_unset_parent() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); QProfileDto profile1 = createProfile(rule1); List changes = activate(profile1, RuleActivation.create(rule1.getUuid())); @@ -153,8 +153,8 @@ public class QProfileTreeImplTest { @Test public void set_then_unset_parent_keep_overridden_rules() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); QProfileDto profile1 = createProfile(rule1); List changes = activate(profile1, RuleActivation.create(rule1.getUuid())); assertThat(changes).hasSize(1); @@ -185,8 +185,8 @@ public class QProfileTreeImplTest { @Test public void activation_errors_are_ignored_when_setting_a_parent() { - RuleDefinitionDto rule1 = createJavaRule(); - RuleDefinitionDto rule2 = createJavaRule(); + RuleDto rule1 = createJavaRule(); + RuleDto rule2 = createJavaRule(); QProfileDto parentProfile = createProfile(rule1); activate(parentProfile, RuleActivation.create(rule1.getUuid())); activate(parentProfile, RuleActivation.create(rule2.getUuid())); @@ -206,7 +206,7 @@ public class QProfileTreeImplTest { return qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation)); } - private QProfileDto createProfile(RuleDefinitionDto rule) { + private QProfileDto createProfile(RuleDto rule) { return db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage())); } @@ -217,7 +217,7 @@ public class QProfileTreeImplTest { .setName("Child of " + parent.getName())); } - private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List changes, + private void assertThatRuleIsActivated(QProfileDto profile, RuleDto rule, @Nullable List changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() @@ -241,7 +241,7 @@ public class QProfileTreeImplTest { } } - private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDefinitionDto rule) { + private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDto rule) { Optional activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) @@ -250,7 +250,7 @@ public class QProfileTreeImplTest { assertThat(activeRule).isEmpty(); } - private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, + private void assertThatRuleIsUpdated(QProfileDto profile, RuleDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() @@ -265,11 +265,11 @@ public class QProfileTreeImplTest { assertThat(params).hasSize(expectedParams.size()); } - private RuleDefinitionDto createRule() { + private RuleDto createRule() { return db.rules().insert(r -> r.setSeverity(Severity.MAJOR)); } - private RuleDefinitionDto createJavaRule() { + private RuleDto createJavaRule() { return db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("java")); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java index f5153a0d973..729ded73f01 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java @@ -44,7 +44,7 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; import org.sonar.server.qualityprofile.builtin.BuiltInQProfile; import org.sonar.server.qualityprofile.builtin.BuiltInQProfileInsert; @@ -124,7 +124,7 @@ public class RegisterQualityProfilesNotificationTest { @Test public void do_not_send_notification_when_profile_is_not_updated() { String language = newLanguageKey(); - RuleDefinitionDto dbRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto dbRule = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile = insertBuiltInProfile(language); activateRuleInDb(dbProfile, dbRule, MAJOR); addPluginProfile(dbProfile, dbRule); @@ -138,10 +138,10 @@ public class RegisterQualityProfilesNotificationTest { @Test public void send_notification_when_a_new_rule_is_activated() { String language = newLanguageKey(); - RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto existingRule = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile = insertBuiltInProfile(language); activateRuleInDb(dbProfile, existingRule, MAJOR); - RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto newRule = db.rules().insert(r -> r.setLanguage(language)); addPluginProfile(dbProfile, existingRule, newRule); builtInQProfileRepositoryRule.initialize(); @@ -161,7 +161,7 @@ public class RegisterQualityProfilesNotificationTest { @Test public void send_notification_when_a_rule_is_deactivated() { String language = newLanguageKey(); - RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto existingRule = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile = insertBuiltInProfile(language); activateRuleInDb(dbProfile, existingRule, MAJOR); addPluginProfile(dbProfile); @@ -184,14 +184,14 @@ public class RegisterQualityProfilesNotificationTest { public void send_a_single_notification_when_multiple_rules_are_activated() { String language = newLanguageKey(); - RuleDefinitionDto existingRule1 = db.rules().insert(r -> r.setLanguage(language)); - RuleDefinitionDto newRule1 = db.rules().insert(r -> r.setLanguage(language)); + RuleDto existingRule1 = db.rules().insert(r -> r.setLanguage(language)); + RuleDto newRule1 = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile1 = insertBuiltInProfile(language); activateRuleInDb(dbProfile1, existingRule1, MAJOR); addPluginProfile(dbProfile1, existingRule1, newRule1); - RuleDefinitionDto existingRule2 = db.rules().insert(r -> r.setLanguage(language)); - RuleDefinitionDto newRule2 = db.rules().insert(r -> r.setLanguage(language)); + RuleDto existingRule2 = db.rules().insert(r -> r.setLanguage(language)); + RuleDto newRule2 = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile2 = insertBuiltInProfile(language); activateRuleInDb(dbProfile2, existingRule2, MAJOR); addPluginProfile(dbProfile2, existingRule2, newRule2); @@ -217,7 +217,7 @@ public class RegisterQualityProfilesNotificationTest { @Test public void notification_does_not_include_inherited_profiles_when_rule_is_added() { String language = newLanguageKey(); - RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto newRule = db.rules().insert(r -> r.setLanguage(language)); QProfileDto builtInQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language)); QProfileDto childQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee())); @@ -240,7 +240,7 @@ public class RegisterQualityProfilesNotificationTest { @Test public void notification_does_not_include_inherited_profiled_when_rule_is_changed() { String language = newLanguageKey(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR)); + RuleDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR)); QProfileDto builtInProfile = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language)); db.qualityProfiles().activateRule(builtInProfile, rule, ar -> ar.setSeverity(Severity.MINOR)); @@ -266,7 +266,7 @@ public class RegisterQualityProfilesNotificationTest { @Test public void notification_does_not_include_inherited_profiles_when_rule_is_deactivated() { String language = newLanguageKey(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR)); + RuleDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR)); QProfileDto builtInQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language)); db.qualityProfiles().activateRule(builtInQProfileDto, rule); @@ -293,10 +293,10 @@ public class RegisterQualityProfilesNotificationTest { @Test public void notification_contains_send_start_and_end_date() { String language = newLanguageKey(); - RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto existingRule = db.rules().insert(r -> r.setLanguage(language)); RulesProfileDto dbProfile = insertBuiltInProfile(language); activateRuleInDb(dbProfile, existingRule, MAJOR); - RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language)); + RuleDto newRule = db.rules().insert(r -> r.setLanguage(language)); addPluginProfile(dbProfile, existingRule, newRule); builtInQProfileRepositoryRule.initialize(); long startDate = RANDOM.nextInt(5000); @@ -308,7 +308,7 @@ public class RegisterQualityProfilesNotificationTest { verify(builtInQualityProfilesNotification).onChange(any(), eq(startDate), eq(endDate)); } - private void addPluginProfile(RulesProfileDto dbProfile, RuleDefinitionDto... dbRules) { + private void addPluginProfile(RulesProfileDto dbProfile, RuleDto... dbRules) { BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(dbProfile.getName(), dbProfile.getLanguage()); @@ -319,19 +319,19 @@ public class RegisterQualityProfilesNotificationTest { builtInQProfileRepositoryRule.add(newLanguage(dbProfile.getLanguage()), dbProfile.getName(), false, activeRules); } - private static BuiltInQProfile.ActiveRule[] toActiveRules(List rules, RuleDefinitionDto[] dbRules) { - Map dbRulesByRuleKey = Arrays.stream(dbRules) - .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey)); + private static BuiltInQProfile.ActiveRule[] toActiveRules(List rules, RuleDto[] dbRules) { + Map dbRulesByRuleKey = Arrays.stream(dbRules) + .collect(MoreCollectors.uniqueIndex(RuleDto::getKey)); return rules.stream() .map(r -> { RuleKey ruleKey = RuleKey.of(r.repoKey(), r.ruleKey()); - RuleDefinitionDto ruleDefinitionDto = dbRulesByRuleKey.get(ruleKey); + RuleDto ruleDefinitionDto = dbRulesByRuleKey.get(ruleKey); checkState(ruleDefinitionDto != null, "Rule '%s' not found", ruleKey); return new BuiltInQProfile.ActiveRule(ruleDefinitionDto.getUuid(), r); }).toArray(BuiltInQProfile.ActiveRule[]::new); } - private void addPluginProfile(QProfileDto profile, RuleDefinitionDto... dbRules) { + private void addPluginProfile(QProfileDto profile, RuleDto... dbRules) { BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage()); @@ -348,7 +348,7 @@ public class RegisterQualityProfilesNotificationTest { return ruleProfileDto; } - private void activateRuleInDb(RulesProfileDto profile, RuleDefinitionDto rule, RulePriority severity) { + private void activateRuleInDb(RulesProfileDto profile, RuleDto rule, RulePriority severity) { ActiveRuleDto dto = new ActiveRuleDto() .setProfileUuid(profile.getUuid()) .setSeverity(severity.name()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java index 277c675070e..639eac40407 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java @@ -35,7 +35,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.language.LanguageTesting; import org.sonar.server.qualityprofile.builtin.BuiltInQProfile; import org.sonar.server.qualityprofile.builtin.BuiltInQProfileInsert; @@ -151,8 +151,8 @@ public class RegisterQualityProfilesTest { db.qualityProfiles().insert(qProfileWithoutRule, qProfileWithOneRule); db.qualityProfiles().setAsDefault(qProfileWithoutRule); - RuleDefinitionDto ruleDefinition = db.rules().insert(); - db.qualityProfiles().activateRule(qProfileWithOneRule, ruleDefinition); + RuleDto ruleDto = db.rules().insert(); + db.qualityProfiles().activateRule(qProfileWithOneRule, ruleDto); db.commit(); builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfileWithoutRule.getName(), true); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImplTest.java index 2b012c6c2e9..300cdd7ba69 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImplTest.java @@ -40,7 +40,7 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileChangeQuery; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; @@ -76,8 +76,8 @@ public class BuiltInQProfileInsertImplTest { @Test public void insert_active_rules_and_changelog() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo"); @@ -123,7 +123,7 @@ public class BuiltInQProfileInsertImplTest { @Test public void insert_active_rules_with_params() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); RuleParamDto param1 = db.rules().insertRuleParam(rule1, p -> p.setType(PropertyType.STRING.name())); RuleParamDto param2 = db.rules().insertRuleParam(rule1, p -> p.setType(PropertyType.STRING.name())); @@ -193,7 +193,7 @@ public class BuiltInQProfileInsertImplTest { // TODO test lot of active_rules, params, orgas - private void verifyActiveRuleInDb(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity, RuleParamDto... paramDtos) { + private void verifyActiveRuleInDb(QProfileDto profile, RuleDto rule, String expectedSeverity, RuleParamDto... paramDtos) { ActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByKey(dbSession, ActiveRuleKey.of(profile, rule.getKey())).get(); assertThat(activeRule.getUuid()).isNotNull(); assertThat(activeRule.getInheritance()).isNull(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImplTest.java index 1587b951d95..4eb4ab9bc5e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImplTest.java @@ -28,7 +28,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.db.DbClient; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.language.LanguageTesting; import org.sonar.server.qualityprofile.builtin.BuiltInQProfile.ActiveRule; import org.sonar.server.rule.DefaultRuleFinder; @@ -56,8 +56,8 @@ public class BuiltInQProfileRepositoryImplTest { @Test public void create_qprofile_with_rule() { - RuleDefinitionDto rule1 = db.rules().insert(); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); db.rules().insert(); DummyProfileDefinition definition = new DummyProfileDefinition("foo", "foo", false, asList(rule1.getKey(), rule2.getKey())); BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(dbClient, ruleFinder, new Languages(FOO_LANGUAGE), definition); @@ -171,9 +171,9 @@ public class BuiltInQProfileRepositoryImplTest { @Test public void create_qprofile_with_deprecated_rule() { - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insertDeprecatedKey(d -> d.setRuleUuid(rule1.getUuid()).setOldRepositoryKey("oldRepo").setOldRuleKey("oldKey")); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); DummyProfileDefinition definition = new DummyProfileDefinition("foo", "foo", false, asList(RuleKey.of("oldRepo", "oldKey"), rule2.getKey())); BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(dbClient, ruleFinder, new Languages(FOO_LANGUAGE), definition); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java index 2797a0b21db..457e833c55b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryRule.java @@ -30,7 +30,7 @@ import org.sonar.api.resources.Language; import org.sonar.api.rule.RuleKey; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.core.util.stream.MoreCollectors; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import static com.google.common.base.Preconditions.checkState; @@ -84,18 +84,18 @@ public class BuiltInQProfileRepositoryRule extends ExternalResource implements B return builder.build(); } - public BuiltInQProfile create(BuiltInQualityProfilesDefinition.BuiltInQualityProfile api, RuleDefinitionDto... rules) { + public BuiltInQProfile create(BuiltInQualityProfilesDefinition.BuiltInQualityProfile api, RuleDto... rules) { BuiltInQProfile.Builder builder = new BuiltInQProfile.Builder() .setLanguage(api.language()) .setName(api.name()) .setDeclaredDefault(api.isDefault()); - Map rulesByRuleKey = Arrays.stream(rules) - .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey)); + Map rulesByRuleKey = Arrays.stream(rules) + .collect(MoreCollectors.uniqueIndex(RuleDto::getKey)); api.rules().forEach(rule -> { RuleKey ruleKey = RuleKey.of(rule.repoKey(), rule.ruleKey()); - RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); - Preconditions.checkState(ruleDefinition != null, "Rule '%s' not found", ruleKey); - builder.addRule(new BuiltInQProfile.ActiveRule(ruleDefinition.getUuid(), rule)); + RuleDto ruleDto = rulesByRuleKey.get(ruleKey); + Preconditions.checkState(ruleDto != null, "Rule '%s' not found", ruleKey); + builder.addRule(new BuiltInQProfile.ActiveRule(ruleDto.getUuid(), rule)); }); return builder .build(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImplTest.java index 4dfc4c57b0b..26f80f3e578 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileUpdateImplTest.java @@ -43,7 +43,7 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; import org.sonar.server.qualityprofile.ActiveRuleChange; @@ -106,8 +106,8 @@ public class BuiltInQProfileUpdateImplTest { @Test public void activate_new_rules() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); newQp.activateRule(rule1.getRepositoryKey(), rule1.getRuleKey()).overrideSeverity(Severity.CRITICAL); @@ -127,7 +127,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void already_activated_rule_is_updated_in_case_of_differences() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey()).overrideSeverity(Severity.CRITICAL); @@ -147,7 +147,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void already_activated_rule_is_not_touched_if_no_differences() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey()).overrideSeverity(Severity.CRITICAL); @@ -167,8 +167,8 @@ public class BuiltInQProfileUpdateImplTest { @Test public void deactivate_rule_that_is_not_in_built_in_definition_anymore() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); newQp.activateRule(rule2.getRepositoryKey(), rule2.getRuleKey()).overrideSeverity(Severity.MAJOR); @@ -190,9 +190,9 @@ public class BuiltInQProfileUpdateImplTest { @Test public void activate_deactivate_and_update_three_rules_at_the_same_time() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); - RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule3 = db.rules().insert(r -> r.setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); @@ -221,7 +221,7 @@ public class BuiltInQProfileUpdateImplTest { // SONAR-10473 @Test public void activate_rule_on_built_in_profile_resets_severity_to_default_if_not_overridden() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("xoo")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo"); @@ -245,7 +245,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void activate_rule_on_built_in_profile_resets_params_to_default_if_not_overridden() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); @@ -273,7 +273,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void propagate_activation_to_descendant_profiles() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); QProfileDto childProfile = createChildProfile(profile); @@ -296,7 +296,7 @@ public class BuiltInQProfileUpdateImplTest { // SONAR-14559 @Test public void propagate_rule_update_to_descendant_active_rule() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); activateRuleInDb(RulesProfileDto.from(parentProfile), rule, RulePriority.valueOf(Severity.MINOR), null); @@ -323,7 +323,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void propagate_rule_param_update_to_descendant_active_rule_params() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); @@ -352,7 +352,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void do_not_load_descendants_if_no_changes() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); QProfileDto childProfile = createChildProfile(profile); @@ -385,7 +385,7 @@ public class BuiltInQProfileUpdateImplTest { @Test public void propagate_deactivation_to_descendant_profiles() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo")); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); QProfileDto childProfile = createChildProfile(profile); @@ -424,7 +424,7 @@ public class BuiltInQProfileUpdateImplTest { .setIsBuiltIn(false); } - private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List changes, + private void assertThatRuleIsActivated(QProfileDto profile, RuleDto rule, @Nullable List changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() @@ -454,7 +454,7 @@ public class BuiltInQProfileUpdateImplTest { .containsExactlyInAnyOrder(expectedParams); } - private static void assertThatRuleIsNewlyActivated(List activeRules, RuleDefinitionDto rule, RulePriority severity) { + private static void assertThatRuleIsNewlyActivated(List activeRules, RuleDto rule, RulePriority severity) { ActiveRuleDto activeRule = findRule(activeRules, rule).get(); assertThat(activeRule.getInheritance()).isNull(); @@ -463,7 +463,7 @@ public class BuiltInQProfileUpdateImplTest { assertThat(activeRule.getUpdatedAt()).isEqualTo(NOW); } - private static void assertThatRuleIsUpdated(List activeRules, RuleDefinitionDto rule, RulePriority severity, @Nullable ActiveRuleInheritance expectedInheritance) { + private static void assertThatRuleIsUpdated(List activeRules, RuleDto rule, RulePriority severity, @Nullable ActiveRuleInheritance expectedInheritance) { ActiveRuleDto activeRule = findRule(activeRules, rule).get(); if (expectedInheritance != null) { @@ -476,15 +476,15 @@ public class BuiltInQProfileUpdateImplTest { assertThat(activeRule.getUpdatedAt()).isEqualTo(NOW); } - private static void assertThatRuleIsUpdated(List activeRules, RuleDefinitionDto rule, RulePriority severity) { + private static void assertThatRuleIsUpdated(List activeRules, RuleDto rule, RulePriority severity) { assertThatRuleIsUpdated(activeRules, rule, severity, null); } - private static void assertThatRuleIsUpdated(ActiveRuleDto activeRules, RuleDefinitionDto rule, RulePriority severity, @Nullable ActiveRuleInheritance expectedInheritance) { + private static void assertThatRuleIsUpdated(ActiveRuleDto activeRules, RuleDto rule, RulePriority severity, @Nullable ActiveRuleInheritance expectedInheritance) { assertThatRuleIsUpdated(singletonList(activeRules), rule, severity, expectedInheritance); } - private static void assertThatRuleIsUntouched(List activeRules, RuleDefinitionDto rule, RulePriority severity) { + private static void assertThatRuleIsUntouched(List activeRules, RuleDto rule, RulePriority severity) { ActiveRuleDto activeRule = findRule(activeRules, rule).get(); assertThat(activeRule.getInheritance()).isNull(); @@ -493,13 +493,13 @@ public class BuiltInQProfileUpdateImplTest { assertThat(activeRule.getUpdatedAt()).isEqualTo(PAST); } - private void assertThatRuleIsDeactivated(QProfileDto profile, RuleDefinitionDto rule) { + private void assertThatRuleIsDeactivated(QProfileDto profile, RuleDto rule) { Collection activeRules = db.getDbClient().activeRuleDao().selectByRulesAndRuleProfileUuids( db.getSession(), singletonList(rule.getUuid()), singletonList(profile.getRulesProfileUuid())); assertThat(activeRules).isEmpty(); } - private static void assertThatRuleIsDeactivated(List activeRules, RuleDefinitionDto rule) { + private static void assertThatRuleIsDeactivated(List activeRules, RuleDto rule) { assertThat(findRule(activeRules, rule)).isEmpty(); } @@ -521,17 +521,17 @@ public class BuiltInQProfileUpdateImplTest { assertThat(reloaded.getRulesUpdatedAt()).isNull(); } - private static Optional findRule(List activeRules, RuleDefinitionDto rule) { + private static Optional findRule(List activeRules, RuleDto rule) { return activeRules.stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst(); } - private ActiveRuleDto activateRuleInDb(RulesProfileDto profile, RuleDefinitionDto rule, RulePriority severity) { + private ActiveRuleDto activateRuleInDb(RulesProfileDto profile, RuleDto rule, RulePriority severity) { return activateRuleInDb(profile, rule, severity, null); } - private ActiveRuleDto activateRuleInDb(RulesProfileDto ruleProfile, RuleDefinitionDto rule, RulePriority severity, @Nullable ActiveRuleInheritance inheritance) { + private ActiveRuleDto activateRuleInDb(RulesProfileDto ruleProfile, RuleDto rule, RulePriority severity, @Nullable ActiveRuleInheritance inheritance) { ActiveRuleDto dto = new ActiveRuleDto() .setKey(ActiveRuleKey.of(ruleProfile, RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()))) .setProfileUuid(ruleProfile.getUuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQualityProfilesUpdateListenerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQualityProfilesUpdateListenerTest.java index aac2248e266..9ef320a5b69 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQualityProfilesUpdateListenerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQualityProfilesUpdateListenerTest.java @@ -30,7 +30,7 @@ import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.core.util.Uuids; import org.sonar.db.qualityprofile.ActiveRuleKey; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.notification.NotificationManager; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.builtin.BuiltInQPChangeNotificationBuilder.Profile; @@ -169,8 +169,8 @@ public class BuiltInQualityProfilesUpdateListenerTest { profiles.putAll(new QProfileName(language.getKey(), profileName), asList(new ActiveRuleChange( type, - ActiveRuleKey.parse("qp:repo:rule1"), new RuleDefinitionDto().setUuid(ruleUuid1)), - new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule2"), new RuleDefinitionDto().setUuid(ruleUuid2)))); + ActiveRuleKey.parse("qp:repo:rule1"), new RuleDto().setUuid(ruleUuid1)), + new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule2"), new RuleDto().setUuid(ruleUuid2)))); return tuple(profileName, language.getKey(), language.getName(), 2); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/RuleActivatorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/RuleActivatorTest.java index a4feaed3b9e..4be34c2e932 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/RuleActivatorTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/RuleActivatorTest.java @@ -36,7 +36,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService; @@ -79,7 +79,7 @@ public class RuleActivatorTest { @Test public void reset_overridden_active_rule() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); @@ -115,7 +115,7 @@ public class RuleActivatorTest { @Test public void request_new_severity_and_param_for_child_rule() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); @@ -151,7 +151,7 @@ public class RuleActivatorTest { @Test public void set_severity_and_param_for_child_rule_when_activating() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER)); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10")); QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true)); @@ -181,7 +181,7 @@ public class RuleActivatorTest { @Test public void fail_if_rule_language_doesnt_match_qp() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo") + RuleDto rule = db.rules().insert(r -> r.setLanguage("xoo") .setRepositoryKey("repo") .setRuleKey("rule") .setSeverity(Severity.BLOCKER)); @@ -206,7 +206,7 @@ public class RuleActivatorTest { } - private ActiveRuleDto activateRuleInDb(RulesProfileDto ruleProfile, RuleDefinitionDto rule, RulePriority severity, @Nullable ActiveRuleInheritance inheritance) { + private ActiveRuleDto activateRuleInDb(RulesProfileDto ruleProfile, RuleDto rule, RulePriority severity, @Nullable ActiveRuleInheritance inheritance) { ActiveRuleDto dto = new ActiveRuleDto() .setKey(ActiveRuleKey.of(ruleProfile, RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()))) .setProfileUuid(ruleProfile.getUuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java index a7c573e2643..0ca344862d2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.BadRequestException; @@ -128,7 +128,7 @@ public class ActivateRuleActionTest { public void fail_activate_external_rule() { userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto rule = db.rules().insert(r -> r.setIsExternal(true)); TestRequest request = ws.newRequest() .setMethod("POST") @@ -144,7 +144,7 @@ public class ActivateRuleActionTest { public void activate_rule() { userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(RuleTesting.randomRuleKey()); + RuleDto rule = db.rules().insert(RuleTesting.randomRuleKey()); TestRequest request = ws.newRequest() .setMethod("POST") .setParam(PARAM_RULE, rule.getKey().toString()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java index e09e88d9179..6bd8db5b59a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java @@ -39,7 +39,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.OrgActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsClient; @@ -127,7 +127,7 @@ public class ChangeParentActionTest { QProfileDto parent1 = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); + RuleDto rule1 = createRule(); createActiveRule(rule1, parent1); ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); activeRuleIndexer.indexAll(); @@ -156,8 +156,8 @@ public class ChangeParentActionTest { QProfileDto parent2 = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); - RuleDefinitionDto rule2 = createRule(); + RuleDto rule1 = createRule(); + RuleDto rule2 = createRule(); createActiveRule(rule1, parent1); createActiveRule(rule2, parent2); ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid())); @@ -187,7 +187,7 @@ public class ChangeParentActionTest { QProfileDto parent = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); + RuleDto rule1 = createRule(); createActiveRule(rule1, parent); ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); activeRuleIndexer.indexAll(); @@ -214,8 +214,8 @@ public class ChangeParentActionTest { QProfileDto parent2 = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); - RuleDefinitionDto rule2 = createRule(); + RuleDto rule1 = createRule(); + RuleDto rule2 = createRule(); createActiveRule(rule1, parent1); createActiveRule(rule2, parent2); ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); @@ -269,7 +269,7 @@ public class ChangeParentActionTest { QProfileDto parent = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); + RuleDto rule1 = createRule(); createActiveRule(rule1, parent); ruleIndexer.commitAndIndex(dbSession, rule1.getUuid()); activeRuleIndexer.indexAll(); @@ -298,8 +298,8 @@ public class ChangeParentActionTest { QProfileDto parent2 = createProfile(); QProfileDto child = createProfile(); - RuleDefinitionDto rule1 = createRule(); - RuleDefinitionDto rule2 = createRule(); + RuleDto rule1 = createRule(); + RuleDto rule2 = createRule(); createActiveRule(rule1, parent1); createActiveRule(rule2, parent2); ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid())); @@ -367,8 +367,8 @@ public class ChangeParentActionTest { return profile; } - private RuleDefinitionDto createRule() { - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of(ruleRepository, randomAlphanumeric(5))) + private RuleDto createRule() { + RuleDto rule = RuleTesting.newRule(RuleKey.of(ruleRepository, randomAlphanumeric(5))) .setLanguage(language.getKey()) .setSeverity(Severity.BLOCKER) .setStatus(RuleStatus.READY); @@ -377,7 +377,7 @@ public class ChangeParentActionTest { return rule; } - private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) { + private ActiveRuleDto createActiveRule(RuleDto rule, QProfileDto profile) { ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) .setSeverity(rule.getSeverityString()); dbClient.activeRuleDao().insert(dbSession, activeRule); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java index 59ea0ad6759..bd1270ece65 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java @@ -34,7 +34,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileChangeDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.ActiveRuleInheritance; @@ -65,7 +65,7 @@ public class ChangelogActionTest { public void return_change_with_all_fields() { QProfileDto profile = db.qualityProfiles().insert(); UserDto user = db.users().insertUser(); - RuleDefinitionDto rule = db.rules().insert(RuleKey.of("java", "S001")); + RuleDto rule = db.rules().insert(RuleKey.of("java", "S001")); insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( "ruleUuid", rule.getUuid(), "severity", "MINOR", @@ -104,7 +104,7 @@ public class ChangelogActionTest { @Test public void find_changelog_by_profile_key() { QProfileDto profile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( @@ -136,7 +136,7 @@ public class ChangelogActionTest { @Test public void find_changelog_by_language_and_name() { QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( @@ -182,7 +182,7 @@ public class ChangelogActionTest { public void changelog_filter_by_since() { QProfileDto qualityProfile = db.qualityProfiles().insert(); system2.setNow(DateUtils.parseDateTime("2011-04-25T01:15:42+0100").getTime()); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( @@ -220,14 +220,14 @@ public class ChangelogActionTest { public void sort_changelog_events_in_reverse_chronological_order() { QProfileDto profile = db.qualityProfiles().insert(); system2.setNow(DateUtils.parseDateTime("2011-04-25T01:15:42+0100").getTime()); - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); insertChange(profile, ActiveRuleChange.Type.ACTIVATED, null, ImmutableMap.of( "ruleUuid", rule1.getUuid(), "severity", "MINOR")); system2.setNow(DateUtils.parseDateTime("2011-04-25T01:15:43+0100").getTime()); UserDto user = db.users().insertUser(); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); insertChange(profile, ActiveRuleChange.Type.DEACTIVATED, user, ImmutableMap.of("ruleUuid", rule2.getUuid())); @@ -288,7 +288,7 @@ public class ChangelogActionTest { @Test public void changelog_on_no_more_existing_user() { QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); insertChange(c -> c.setRulesProfileUuid(qualityProfile.getRulesProfileUuid()) .setUserUuid("UNKNOWN") .setChangeType(ActiveRuleChange.Type.ACTIVATED.name()) @@ -320,7 +320,7 @@ public class ChangelogActionTest { String profileUuid = profile.getRulesProfileUuid(); system2.setNow(DateUtils.parseDateTime("2015-02-23T17:58:39+0100").getTime()); - RuleDefinitionDto rule1 = db.rules().insert(RuleKey.of("squid", "S2438"), r -> r.setName("\"Threads\" should not be used where \"Runnables\" are expected")); + RuleDto rule1 = db.rules().insert(RuleKey.of("squid", "S2438"), r -> r.setName("\"Threads\" should not be used where \"Runnables\" are expected")); UserDto user1 = db.users().insertUser(u -> u.setLogin("anakin.skywalker").setName("Anakin Skywalker")); insertChange(c -> c.setRulesProfileUuid(profileUuid) .setUserUuid(user1.getUuid()) @@ -328,7 +328,7 @@ public class ChangelogActionTest { .setData(ImmutableMap.of("severity", "CRITICAL", "ruleUuid", rule1.getUuid()))); system2.setNow(DateUtils.parseDateTime("2015-02-23T17:58:18+0100").getTime()); - RuleDefinitionDto rule2 = db.rules().insert(RuleKey.of("squid", "S2162"), r -> r.setName("\"equals\" methods should be symmetric and work for subclasses")); + RuleDto rule2 = db.rules().insert(RuleKey.of("squid", "S2162"), r -> r.setName("\"equals\" methods should be symmetric and work for subclasses")); UserDto user2 = db.users().insertUser(u -> u.setLogin("padme.amidala").setName("Padme Amidala")); insertChange(c -> c.setRulesProfileUuid(profileUuid) .setUserUuid(user2.getUuid()) @@ -336,7 +336,7 @@ public class ChangelogActionTest { .setData(ImmutableMap.of("ruleUuid", rule2.getUuid()))); system2.setNow(DateUtils.parseDateTime("2014-09-12T15:20:46+0200").getTime()); - RuleDefinitionDto rule3 = db.rules().insert(RuleKey.of("squid", "S00101"), r -> r.setName("Class names should comply with a naming convention")); + RuleDto rule3 = db.rules().insert(RuleKey.of("squid", "S00101"), r -> r.setName("Class names should comply with a naming convention")); UserDto user3 = db.users().insertUser(u -> u.setLogin("obiwan.kenobi").setName("Obiwan Kenobi")); insertChange(c -> c.setRulesProfileUuid(profileUuid) .setUserUuid(user3.getUuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java index 2f364997b33..842d309ddd2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java @@ -35,7 +35,6 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; import org.sonar.db.rule.RuleParamDto; @@ -68,11 +67,11 @@ public class CompareActionTest { public void compare_nominal() { createRepository("blah", "xoo", "Blah"); - RuleDefinitionDto rule1 = createRule("xoo", "rule1"); - RuleDefinitionDto rule2 = createRule("xoo", "rule2"); - RuleDefinitionDto rule3 = createRule("xoo", "rule3"); - RuleDefinitionDto rule4 = createRuleWithParam("xoo", "rule4"); - RuleDefinitionDto rule5 = createRule("xoo", "rule5"); + RuleDto rule1 = createRule("xoo", "rule1"); + RuleDto rule2 = createRule("xoo", "rule2"); + RuleDto rule3 = createRule("xoo", "rule3"); + RuleDto rule4 = createRuleWithParam("xoo", "rule4"); + RuleDto rule5 = createRule("xoo", "rule5"); /* * Profile 1: @@ -109,7 +108,7 @@ public class CompareActionTest { @Test public void compare_param_on_left() { - RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1"); + RuleDto rule1 = createRuleWithParam("xoo", "rule1"); createRepository("blah", "xoo", "Blah"); QProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234"); createActiveRuleWithParam(rule1, profile1, "polop"); @@ -125,7 +124,7 @@ public class CompareActionTest { @Test public void compare_param_on_right() { - RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1"); + RuleDto rule1 = createRuleWithParam("xoo", "rule1"); createRepository("blah", "xoo", "Blah"); QProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234"); createActiveRule(rule1, profile1); @@ -200,21 +199,27 @@ public class CompareActionTest { return db.qualityProfiles().insert(p -> p.setKee(key).setName(name).setLanguage(lang)); } - private RuleDefinitionDto createRule(String lang, String id) { - RuleDto rule = RuleDto.createFor(RuleKey.of("blah", id)) + private RuleDto createRule(String lang, String id) { + RuleDto rule = createFor(RuleKey.of("blah", id)) .setUuid(Uuids.createFast()) .setName(StringUtils.capitalize(id)) .setLanguage(lang) .setSeverity(Severity.BLOCKER) .setScope(Scope.MAIN) .setStatus(RuleStatus.READY); - RuleDefinitionDto ruleDefinition = rule.getDefinition(); - dbClient.ruleDao().insert(session, ruleDefinition); - return ruleDefinition; + RuleDto ruleDto = rule; + dbClient.ruleDao().insert(session, ruleDto); + return ruleDto; } - private RuleDefinitionDto createRuleWithParam(String lang, String id) { - RuleDefinitionDto rule = createRule(lang, id); + private static RuleDto createFor(RuleKey key) { + return new RuleDto() + .setRepositoryKey(key.repository()) + .setRuleKey(key.rule()); + } + + private RuleDto createRuleWithParam(String lang, String id) { + RuleDto rule = createRule(lang, id); RuleParamDto param = RuleParamDto.createFor(rule) .setName("param_" + id) .setType(RuleParamType.STRING.toString()); @@ -222,14 +227,14 @@ public class CompareActionTest { return rule; } - private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) { + private ActiveRuleDto createActiveRule(RuleDto rule, QProfileDto profile) { ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) .setSeverity(rule.getSeverityString()); dbClient.activeRuleDao().insert(session, activeRule); return activeRule; } - private ActiveRuleDto createActiveRuleWithParam(RuleDefinitionDto rule, QProfileDto profile, String value) { + private ActiveRuleDto createActiveRuleWithParam(RuleDto rule, QProfileDto profile, String value) { ActiveRuleDto activeRule = createActiveRule(rule, profile); RuleParamDto paramDto = dbClient.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0); ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value); @@ -237,7 +242,7 @@ public class CompareActionTest { return activeRule; } - private ActiveRuleDto createActiveRuleWithSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) { + private ActiveRuleDto createActiveRuleWithSeverity(RuleDto rule, QProfileDto profile, String severity) { ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) .setSeverity(severity); dbClient.activeRuleDao().insert(session, activeRule); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java index 3cd0742ec30..647c410c614 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java @@ -37,7 +37,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; @@ -71,10 +71,9 @@ import static org.sonar.server.language.LanguageTesting.newLanguages; public class CreateActionTest { private static final String XOO_LANGUAGE = "xoo"; - private static final RuleDefinitionDto RULE = RuleTesting.newXooX1() + private static final RuleDto RULE = RuleTesting.newXooX1() .setSeverity("MINOR") - .setLanguage(XOO_LANGUAGE) - .getDefinition(); + .setLanguage(XOO_LANGUAGE); @Rule public DbTester db = DbTester.create(); @@ -194,7 +193,7 @@ public class CreateActionTest { assertThat(response.getMediaType()).isEqualTo(MediaTypes.JSON); } - private void insertRule(RuleDefinitionDto ruleDto) { + private void insertRule(RuleDto ruleDto) { dbClient.ruleDao().insert(dbSession, ruleDto); dbSession.commit(); ruleIndexer.commitAndIndex(dbSession, ruleDto.getUuid()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java index 85b0dc3c784..45a86e09a83 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java @@ -33,7 +33,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.BadRequestException; @@ -85,7 +85,7 @@ public class DeactivateRuleActionTest { public void deactivate_rule() { userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(RuleTesting.randomRuleKey()); + RuleDto rule = db.rules().insert(RuleTesting.randomRuleKey()); TestRequest request = ws.newRequest() .setMethod("POST") .setParam(PARAM_RULE, rule.getKey().toString()) @@ -133,7 +133,7 @@ public class DeactivateRuleActionTest { public void fail_activate_external_rule() { userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); QProfileDto qualityProfile = db.qualityProfiles().insert(); - RuleDefinitionDto rule = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto rule = db.rules().insert(r -> r.setIsExternal(true)); TestRequest request = ws.newRequest() .setMethod("POST") @@ -147,7 +147,7 @@ public class DeactivateRuleActionTest { @Test public void fail_deactivate_if_built_in_profile() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES); QProfileDto qualityProfile = db.qualityProfiles().insert(profile -> profile.setIsBuiltIn(true)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java index f8579c35740..c391c252b2f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java @@ -36,7 +36,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; @@ -94,9 +94,9 @@ public class InheritanceActionTest { @Test public void inheritance_nominal() { - RuleDefinitionDto rule1 = createRule("xoo", "rule1"); - RuleDefinitionDto rule2 = createRule("xoo", "rule2"); - RuleDefinitionDto rule3 = createRule("xoo", "rule3"); + RuleDto rule1 = createRule("xoo", "rule1"); + RuleDto rule2 = createRule("xoo", "rule2"); + RuleDto rule3 = createRule("xoo", "rule3"); /* * sonar way (2) <- companyWide (2) <- buWide (2, 1 overriding) <- (forProject1 (2), forProject2 (2)) @@ -136,9 +136,9 @@ public class InheritanceActionTest { @Test public void inheritance_parent_child() throws Exception { - RuleDefinitionDto rule1 = db.rules().insert(); - RuleDefinitionDto rule2 = db.rules().insert(); - RuleDefinitionDto rule3 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); + RuleDto rule3 = db.rules().insert(); ruleIndexer.commitAndIndex(db.getSession(), asList(rule1.getUuid(), rule2.getUuid(), rule3.getUuid())); QProfileDto parent = db.qualityProfiles().insert(); @@ -170,7 +170,7 @@ public class InheritanceActionTest { @Test public void inheritance_ignores_removed_rules() throws Exception { - RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED)); + RuleDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED)); ruleIndexer.commitAndIndex(db.getSession(), rule.getUuid()); QProfileDto profile = db.qualityProfiles().insert(); @@ -232,9 +232,9 @@ public class InheritanceActionTest { qProfileTree.setParentAndCommit(dbSession, parent, profile); } - private RuleDefinitionDto createRule(String lang, String id) { + private RuleDto createRule(String lang, String id) { long now = new Date().getTime(); - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("blah", id)) + RuleDto rule = RuleTesting.newRule(RuleKey.of("blah", id)) .setLanguage(lang) .setSeverity(Severity.BLOCKER) .setStatus(RuleStatus.READY) @@ -245,7 +245,7 @@ public class InheritanceActionTest { return rule; } - private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) { + private ActiveRuleDto createActiveRule(RuleDto rule, QProfileDto profile) { long now = new Date().getTime(); ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) .setSeverity(rule.getSeverityString()) @@ -255,7 +255,7 @@ public class InheritanceActionTest { return activeRule; } - private void overrideActiveRuleSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) { + private void overrideActiveRuleSeverity(RuleDto rule, QProfileDto profile, String severity) { qProfileRules.activateAndCommit(dbSession, profile, singleton(RuleActivation.create(rule.getUuid(), severity, null))); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java index 4be4925981a..f737bbefe4f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileWsSupportTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -84,7 +84,7 @@ public class QProfileWsSupportTest { @Test public void getRule_throws_BadRequest_if_rule_is_external() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setIsExternal(true)); + RuleDto rule = db.rules().insert(r -> r.setIsExternal(true)); assertThatThrownBy(() -> underTest.getRule(db.getSession(), rule.getKey())) .isInstanceOf(BadRequestException.class) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java index 7159997ddc1..8895000e638 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java @@ -36,7 +36,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsTester; import org.sonar.server.es.SearchOptions; @@ -97,7 +97,7 @@ public class QProfilesWsMediumTest { @Test public void deactivate_rule() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto"); + RuleDto rule = createRule(profile.getLanguage(), "toto"); createActiveRule(rule, profile); ruleIndexer.commitAndIndex(dbSession, rule.getUuid()); activeRuleIndexer.indexAll(); @@ -119,10 +119,10 @@ public class QProfilesWsMediumTest { @Test public void bulk_deactivate_rule() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1"); - RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2"); - RuleDefinitionDto rule2 = createRule(profile.getLanguage(), "toto3"); - RuleDefinitionDto rule3 = createRule(profile.getLanguage(), "toto4"); + RuleDto rule0 = createRule(profile.getLanguage(), "toto1"); + RuleDto rule1 = createRule(profile.getLanguage(), "toto2"); + RuleDto rule2 = createRule(profile.getLanguage(), "toto3"); + RuleDto rule3 = createRule(profile.getLanguage(), "toto4"); createActiveRule(rule0, profile); createActiveRule(rule2, profile); createActiveRule(rule3, profile); @@ -147,8 +147,8 @@ public class QProfilesWsMediumTest { public void bulk_deactivate_rule_not_all() { QProfileDto profile = createProfile("java"); QProfileDto php = createProfile("php"); - RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1"); - RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2"); + RuleDto rule0 = createRule(profile.getLanguage(), "toto1"); + RuleDto rule1 = createRule(profile.getLanguage(), "toto2"); createActiveRule(rule0, profile); createActiveRule(rule1, profile); createActiveRule(rule0, php); @@ -173,8 +173,8 @@ public class QProfilesWsMediumTest { @Test public void bulk_deactivate_rule_by_profile() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "hello"); - RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "world"); + RuleDto rule0 = createRule(profile.getLanguage(), "hello"); + RuleDto rule1 = createRule(profile.getLanguage(), "world"); createActiveRule(rule0, profile); createActiveRule(rule1, profile); dbSession.commit(); @@ -197,7 +197,7 @@ public class QProfilesWsMediumTest { @Test public void activate_rule() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto"); + RuleDto rule = createRule(profile.getLanguage(), "toto"); ruleIndexer.commitAndIndex(dbSession, rule.getUuid()); // 0. Assert No Active Rule for profile @@ -217,7 +217,7 @@ public class QProfilesWsMediumTest { @Test public void activate_rule_diff_languages() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule = createRule("php", "toto"); + RuleDto rule = createRule("php", "toto"); ruleIndexer.commitAndIndex(dbSession, rule.getUuid()); // 0. Assert No Active Rule for profile @@ -239,7 +239,7 @@ public class QProfilesWsMediumTest { @Test public void activate_rule_override_severity() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto"); + RuleDto rule = createRule(profile.getLanguage(), "toto"); ruleIndexer.commitAndIndex(dbSession, rule.getUuid()); // 0. Assert No Active Rule for profile @@ -346,8 +346,8 @@ public class QProfilesWsMediumTest { @Test public void bulk_activate_rule_by_query_with_severity() { QProfileDto profile = createProfile("java"); - RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto"); - RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "tata"); + RuleDto rule0 = createRule(profile.getLanguage(), "toto"); + RuleDto rule1 = createRule(profile.getLanguage(), "tata"); dbSession.commit(); // 0. Assert No Active Rule for profile @@ -403,7 +403,7 @@ public class QProfilesWsMediumTest { QProfileDto childProfile = QualityProfileTesting.newQualityProfileDto().setParentKee(profile.getKee()).setLanguage("java"); dbClient.qualityProfileDao().insert(dbSession, profile, childProfile); - RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule"); + RuleDto rule = createRule(profile.getLanguage(), "rule"); ActiveRuleDto active1 = ActiveRuleDto.createFor(profile, rule) .setSeverity(rule.getSeverityString()); ActiveRuleDto active2 = ActiveRuleDto.createFor(childProfile, rule) @@ -439,8 +439,8 @@ public class QProfilesWsMediumTest { return profile; } - private RuleDefinitionDto createRule(String lang, String id) { - RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("blah", id)) + private RuleDto createRule(String lang, String id) { + RuleDto rule = RuleTesting.newRule(RuleKey.of("blah", id)) .setLanguage(lang) .setSeverity(Severity.BLOCKER) .setStatus(RuleStatus.READY); @@ -449,7 +449,7 @@ public class QProfilesWsMediumTest { return rule; } - private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) { + private ActiveRuleDto createActiveRule(RuleDto rule, QProfileDto profile) { ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) .setSeverity(rule.getSeverityString()); dbClient.activeRuleDao().insert(dbSession, activeRule); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index abf09be52ae..1af11399c92 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.permission.GlobalPermission; import org.sonar.db.project.ProjectDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileDbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; @@ -311,10 +311,10 @@ public class SearchActionTest { @Test public void statistics_on_active_rules() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey())); - RuleDefinitionDto rule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto deprecatedRule1 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition(); - RuleDefinitionDto deprecatedRule2 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition(); - RuleDefinitionDto inactiveRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); + RuleDto rule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto deprecatedRule1 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)); + RuleDto deprecatedRule2 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)); + RuleDto inactiveRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); db.qualityProfiles().activateRule(profile, rule); db.qualityProfiles().activateRule(profile, deprecatedRule1); db.qualityProfiles().activateRule(profile, deprecatedRule2); @@ -385,20 +385,20 @@ public class SearchActionTest { p -> p.setName("Sonar way").setKee("AU-TpxcB-iU5OvuD2FL7").setIsBuiltIn(true).setLanguage(python.getKey())); db.qualityProfiles().setAsDefault(sonarWayCs, myCompanyProfile, sonarWayPython); // rules - List javaRules = range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey())).getDefinition()) + List javaRules = range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey()))) .collect(MoreCollectors.toList()); - List deprecatedJavaRules = range(0, 5) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey()).setStatus(DEPRECATED)).getDefinition()) + List deprecatedJavaRules = range(0, 5) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey()).setStatus(DEPRECATED))) .collect(MoreCollectors.toList()); range(0, 7).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, javaRules.get(i))); range(0, 2).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, deprecatedJavaRules.get(i))); range(0, 10).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, javaRules.get(i))); range(0, 5).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, deprecatedJavaRules.get(i))); range(0, 2) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(python.getKey())).getDefinition()) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(python.getKey()))) .forEach(rule -> db.qualityProfiles().activateRule(sonarWayPython, rule)); range(0, 3) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey()))) .forEach(rule -> db.qualityProfiles().activateRule(sonarWayCs, rule)); // project range(0, 7) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java index 54c2c5ea951..39972bb3f9d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java @@ -28,7 +28,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; @@ -127,11 +127,11 @@ public class ShowActionTest { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey())); // Active rules range(0, 10) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition()) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()))) .forEach(r -> db.qualityProfiles().activateRule(profile, r)); // Deprecated rules range(0, 3) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()).setStatus(DEPRECATED)).getDefinition()) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()).setStatus(DEPRECATED))) .forEach(r -> db.qualityProfiles().activateRule(profile, r)); // Projects range(0, 7) @@ -149,12 +149,12 @@ public class ShowActionTest { public void compare_to_sonar_way_profile() { QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey())); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey())); - RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto sonarWayRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto sonarWayRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); - RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); + RuleDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto sonarWayRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto sonarWayRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); + RuleDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); db.qualityProfiles().activateRule(profile, commonRule); db.qualityProfiles().activateRule(profile, profileRule1); db.qualityProfiles().activateRule(profile, profileRule2); @@ -179,7 +179,7 @@ public class ShowActionTest { public void compare_to_sonar_way_profile_when_same_active_rules() { QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey())); QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey())); - RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition(); + RuleDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())); db.qualityProfiles().activateRule(profile, commonRule); db.qualityProfiles().activateRule(sonarWayProfile, commonRule); ruleIndexer.indexAll(); @@ -323,7 +323,7 @@ public class ShowActionTest { .setParentKee(parentProfile.getKee())); // Active rules range(0, 10) - .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()) + .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey()))) .forEach(r -> db.qualityProfiles().activateRule(profile, r)); // Projects range(0, 7) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java index 4e850f33292..7516b80edd5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java @@ -41,7 +41,6 @@ import org.sonar.core.util.SequenceUuidFactory; import org.sonar.core.util.UuidFactory; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; import org.sonar.db.rule.RuleParamDto; @@ -186,7 +185,7 @@ public class RuleCreatorTest { @Test public void create_custom_rule_with_no_parameter_value() { // insert template rule - RuleDefinitionDto templateRule = createTemplateRuleWithIntArrayParam(); + RuleDto templateRule = createTemplateRuleWithIntArrayParam(); NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setRuleDescriptionSections(Set.of(new NewRuleDescriptionSection("default", "some description"))) @@ -207,7 +206,7 @@ public class RuleCreatorTest { @Test public void create_custom_rule_with_multiple_parameter_values() { // insert template rule - RuleDefinitionDto templateRule = createTemplateRuleWithIntArrayParam(); + RuleDto templateRule = createTemplateRuleWithIntArrayParam(); NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setRuleDescriptionSections(Set.of(new NewRuleDescriptionSection("default", "some description"))) @@ -229,7 +228,7 @@ public class RuleCreatorTest { @Test public void batch_create_custom_rules() { // insert template rule - RuleDefinitionDto templateRule = createTemplateRuleWithIntArrayParam(); + RuleDto templateRule = createTemplateRuleWithIntArrayParam(); NewCustomRule firstRule = NewCustomRule.createForCustomRule("CUSTOM_RULE_1", templateRule.getKey()) .setName("My custom") @@ -256,7 +255,7 @@ public class RuleCreatorTest { @Test public void fail_to_create_custom_rules_when_wrong_rule_template() { // insert rule - RuleDefinitionDto rule = newRule(RuleKey.of("java", "S001")).setIsTemplate(false); + RuleDto rule = newRule(RuleKey.of("java", "S001")).setIsTemplate(false); dbTester.rules().insert(rule); dbSession.commit(); @@ -275,7 +274,7 @@ public class RuleCreatorTest { @Test public void fail_to_create_custom_rule_with_invalid_parameter() { // insert template rule - RuleDefinitionDto templateRule = createTemplateRuleWithIntArrayParam(); + RuleDto templateRule = createTemplateRuleWithIntArrayParam(); assertThatThrownBy(() -> { // Create custom rule @@ -294,7 +293,7 @@ public class RuleCreatorTest { @Test public void fail_to_create_custom_rule_with_invalid_parameters() { // insert template rule - RuleDefinitionDto templateRule = createTemplateRuleWithTwoIntParams(); + RuleDto templateRule = createTemplateRuleWithTwoIntParams(); // Create custom rule NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) @@ -326,8 +325,8 @@ public class RuleCreatorTest { .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Old description")) .setDescriptionFormat(Format.MARKDOWN) .setSeverity(Severity.INFO); - dbTester.rules().insert(rule.getDefinition()); - dbTester.rules().insertRuleParam(rule.getDefinition(), param -> param.setDefaultValue("a.*")); + dbTester.rules().insert(rule); + dbTester.rules().insertRuleParam(rule, param -> param.setDefaultValue("a.*")); dbSession.commit(); // Create custom rule with same key, but with different values @@ -339,13 +338,13 @@ public class RuleCreatorTest { .setParameters(ImmutableMap.of("regex", "c.*")); RuleKey customRuleKey = underTest.create(dbSession, newRule); - RuleDefinitionDto result = dbTester.getDbClient().ruleDao().selectOrFailDefinitionByKey(dbSession, customRuleKey); + RuleDto result = dbTester.getDbClient().ruleDao().selectOrFailByKey(dbSession, customRuleKey); assertThat(result.getKey()).isEqualTo(RuleKey.of("java", key)); assertThat(result.getStatus()).isEqualTo(RuleStatus.READY); // These values should be the same than before assertThat(result.getName()).isEqualTo("Old name"); - assertThat(result.getDefaultRuleDescriptionSectionDto().getContent()).isEqualTo("Old description"); + assertThat(result.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Old description"); assertThat(result.getSeverityString()).isEqualTo(Severity.INFO); List params = dbTester.getDbClient().ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey); @@ -365,8 +364,8 @@ public class RuleCreatorTest { .setName("Old name") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Old description")) .setSeverity(Severity.INFO); - dbTester.rules().insert(rule.getDefinition()); - dbTester.rules().insertRuleParam(rule.getDefinition(), param -> param.setDefaultValue("a.*")); + dbTester.rules().insert(rule); + dbTester.rules().insertRuleParam(rule, param -> param.setDefaultValue("a.*")); dbSession.commit(); // Create custom rule with same key, but with different values @@ -516,7 +515,7 @@ public class RuleCreatorTest { @Test public void fail_to_create_custom_rule_when_wrong_rule_template() { // insert rule - RuleDefinitionDto rule = newRule(RuleKey.of("java", "S001")).setIsTemplate(false); + RuleDto rule = newRule(RuleKey.of("java", "S001")).setIsTemplate(false); dbTester.rules().insert(rule); dbSession.commit(); @@ -563,15 +562,15 @@ public class RuleCreatorTest { .setSecurityStandards(Sets.newHashSet("owaspTop10:a1", "cwe:123")) .setCreatedAt(new Date().getTime()) .setUpdatedAt(new Date().getTime()); - dbTester.rules().insert(templateRule.getDefinition()); + dbTester.rules().insert(templateRule); dbTester.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleUuid(templateRule.getUuid())); - dbTester.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); - ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getDefinition().getUuid()); + dbTester.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); + ruleIndexer.commitAndIndex(dbTester.getSession(), templateRule.getUuid()); return templateRule; } - private RuleDefinitionDto createTemplateRuleWithIntArrayParam() { - RuleDefinitionDto templateRule = newRule(RuleKey.of("java", "S002")) + private RuleDto createTemplateRuleWithIntArrayParam() { + RuleDto templateRule = newRule(RuleKey.of("java", "S002")) .setIsTemplate(true) .setLanguage("java") .setConfigKey("S002") @@ -588,8 +587,8 @@ public class RuleCreatorTest { return templateRule; } - private RuleDefinitionDto createTemplateRuleWithTwoIntParams() { - RuleDefinitionDto templateRule = newRule(RuleKey.of("java", "S003")) + private RuleDto createTemplateRuleWithTwoIntParams() { + RuleDto templateRule = newRule(RuleKey.of("java", "S003")) .setIsTemplate(true) .setLanguage("java") .setConfigKey("S003") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java index bc9480a8981..0dfcd2f2dbf 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java @@ -43,7 +43,6 @@ import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QualityProfileTesting; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; @@ -111,7 +110,7 @@ public class RuleUpdaterTest { .setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()) .setRemediationGapMultiplier("1d") .setRemediationBaseEffort("5min"); - db.rules().insert(ruleDto.getDefinition()); + db.rules().insert(ruleDto); db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid())); dbSession.commit(); @@ -143,7 +142,7 @@ public class RuleUpdaterTest { .setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()) .setRemediationGapMultiplier("1d") .setRemediationBaseEffort("5min"); - db.rules().insert(ruleDto.getDefinition()); + db.rules().insert(ruleDto); db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid())); dbSession.commit(); @@ -169,7 +168,7 @@ public class RuleUpdaterTest { RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) .setNoteData("my *note*") .setNoteUserUuid("me"); - db.rules().insert(ruleDto.getDefinition()); + db.rules().insert(ruleDto); db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid())); dbSession.commit(); @@ -190,7 +189,7 @@ public class RuleUpdaterTest { // insert db db.rules().insert(RuleTesting.newDto(RULE_KEY) .setTags(Sets.newHashSet("security")) - .setSystemTags(Sets.newHashSet("java8", "javadoc")).getDefinition()); + .setSystemTags(Sets.newHashSet("java8", "javadoc"))); dbSession.commit(); // java8 is a system tag -> ignore @@ -213,7 +212,7 @@ public class RuleUpdaterTest { .setUuid("57a3af91-32f8-48b0-9e11-0eac14ffa915") .setTags(Sets.newHashSet("security")) .setSystemTags(Sets.newHashSet("java8", "javadoc")); - db.rules().insert(ruleDto.getDefinition()); + db.rules().insert(ruleDto); db.rules().insertOrUpdateMetadata(ruleDto.getMetadata()); dbSession.commit(); @@ -313,7 +312,7 @@ public class RuleUpdaterTest { .setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()) .setRemediationGapMultiplier(null) .setRemediationBaseEffort("1min"); - db.rules().insert(ruleDto.getDefinition()); + db.rules().insert(ruleDto); db.rules().insertOrUpdateMetadata(ruleDto.getMetadata().setRuleUuid(ruleDto.getUuid())); dbSession.commit(); @@ -337,17 +336,17 @@ public class RuleUpdaterTest { public void update_custom_rule() { // Create template rule RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); - db.rules().insert(templateRule.getDefinition()); - db.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); - db.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("format").setType("STRING").setDescription("Format")); + db.rules().insert(templateRule); + db.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); + db.rules().insertRuleParam(templateRule, param -> param.setName("format").setType("STRING").setDescription("Format")); // Create custom rule - RuleDefinitionDto customRule = newCustomRule(templateRule) + RuleDto customRule = newCustomRule(templateRule) .setName("Old name") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Old description")) .setSeverity(Severity.MINOR) .setStatus(RuleStatus.BETA) - .getDefinition(); + ; db.rules().insert(customRule); db.rules().insertRuleParam(customRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue("a.*")); db.rules().insertRuleParam(customRule, param -> param.setName("format").setType("STRING").setDescription("Format").setDefaultValue(null)); @@ -386,11 +385,11 @@ public class RuleUpdaterTest { public void update_custom_rule_with_empty_parameter() { // Create template rule RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); - db.rules().insert(templateRule.getDefinition()); - db.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(null)); + db.rules().insert(templateRule); + db.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(null)); // Create custom rule - RuleDefinitionDto customRule = newCustomRule(templateRule.getDefinition()) + RuleDto customRule = newCustomRule(templateRule) .setName("Old name") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Old description")) .setSeverity(Severity.MINOR) @@ -419,17 +418,17 @@ public class RuleUpdaterTest { public void update_active_rule_parameters_when_updating_custom_rule() { // Create template rule with 3 parameters RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")).setLanguage("xoo"); - RuleDefinitionDto templateRuleDefinition = templateRule.getDefinition(); + RuleDto templateRuleDefinition = templateRule; db.rules().insert(templateRuleDefinition); db.rules().insertRuleParam(templateRuleDefinition, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); db.rules().insertRuleParam(templateRuleDefinition, param -> param.setName("format").setType("STRING").setDescription("format").setDefaultValue("csv")); db.rules().insertRuleParam(templateRuleDefinition, param -> param.setName("message").setType("STRING").setDescription("message")); // Create custom rule - RuleDefinitionDto customRule = newCustomRule(templateRule) + RuleDto customRule = newCustomRule(templateRule) .setSeverity(Severity.MAJOR) .setLanguage("xoo") - .getDefinition(); + ; db.rules().insert(customRule); RuleParamDto ruleParam1 = db.rules().insertRuleParam(customRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue("a.*")); db.rules().insertRuleParam(customRule, param -> param.setName("format").setType("STRING").setDescription("format").setDefaultValue("txt")); @@ -487,11 +486,11 @@ public class RuleUpdaterTest { @Test public void fail_to_update_custom_rule_when_empty_name() { // Create template rule - RuleDefinitionDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")).getDefinition(); + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); db.rules().insert(templateRule); // Create custom rule - RuleDefinitionDto customRule = newCustomRule(templateRule); + RuleDto customRule = newCustomRule(templateRule); db.rules().insert(customRule); dbSession.commit(); @@ -512,11 +511,11 @@ public class RuleUpdaterTest { public void fail_to_update_custom_rule_when_empty_description() { // Create template rule RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); - db.rules().insert(templateRule.getDefinition()); + db.rules().insert(templateRule); // Create custom rule RuleDto customRule = newCustomRule(templateRule); - db.rules().insert(customRule.getDefinition()); + db.rules().insert(customRule); dbSession.commit(); @@ -531,11 +530,11 @@ public class RuleUpdaterTest { @Test public void fail_to_update_plugin_rule_if_name_is_set() { - RuleDefinitionDto ruleDefinition = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); + RuleDto ruleDto = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); dbSession.commit(); assertThatThrownBy(() -> { - createForPluginRule(ruleDefinition.getKey()).setName("New name"); + createForPluginRule(ruleDto.getKey()).setName("New name"); }) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Not a custom rule"); @@ -543,11 +542,11 @@ public class RuleUpdaterTest { @Test public void fail_to_update_plugin_rule_if_description_is_set() { - RuleDefinitionDto ruleDefinition = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); + RuleDto ruleDto = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); dbSession.commit(); assertThatThrownBy(() -> { - createForPluginRule(ruleDefinition.getKey()).setMarkdownDescription("New description"); + createForPluginRule(ruleDto.getKey()).setMarkdownDescription("New description"); }) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Not a custom rule"); @@ -555,11 +554,11 @@ public class RuleUpdaterTest { @Test public void fail_to_update_plugin_rule_if_severity_is_set() { - RuleDefinitionDto ruleDefinition = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); + RuleDto ruleDto = db.rules().insert(newRule(RuleKey.of("squid", "S01"))); dbSession.commit(); assertThatThrownBy(() -> { - createForPluginRule(ruleDefinition.getKey()).setSeverity(CRITICAL); + createForPluginRule(ruleDto.getKey()).setSeverity(CRITICAL); }) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Not a custom rule"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java index 794fac371d0..04f86fe59ef 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ActiveRuleCompleterTest.java @@ -26,7 +26,7 @@ import org.sonar.api.resources.Languages; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonarqube.ws.Rules; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +39,7 @@ public class ActiveRuleCompleterTest { @Test public void test_completeShow() { ActiveRuleCompleter underTest = new ActiveRuleCompleter(dbTester.getDbClient(), new Languages()); - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); QProfileDto qualityProfile = dbTester.qualityProfiles().insert(); ActiveRuleDto activeRule = dbTester.qualityProfiles().activateRule(qualityProfile, rule); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java index 9c2f4bcbd70..9f9d9d7bbb9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java @@ -29,7 +29,6 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.SequenceUuidFactory; import org.sonar.core.util.UuidFactory; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -91,9 +90,9 @@ public class CreateActionTest { logInAsQProfileAdministrator(); // Template rule RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")).setType(CODE_SMELL); - db.rules().insert(templateRule.getDefinition()); + db.rules().insert(templateRule); db.rules().insertOrUpdateMetadata(templateRule.getMetadata().setRuleUuid(templateRule.getUuid())); - db.rules().insertRuleParam(templateRule.getDefinition(), param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); + db.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); String result = ws.newRequest() .setParam("custom_key", "MY_CUSTOM") @@ -135,10 +134,10 @@ public class CreateActionTest { @Test public void create_custom_rule_with_prevent_reactivation_param_to_true() { logInAsQProfileAdministrator(); - RuleDefinitionDto templateRule = newTemplateRule(RuleKey.of("java", "S001")).getDefinition(); + RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")); db.rules().insert(templateRule); // insert a removed rule - RuleDefinitionDto customRule = newCustomRule(templateRule) + RuleDto customRule = newCustomRule(templateRule) .setRuleKey("MY_CUSTOM") .setStatus(RuleStatus.REMOVED) .setName("My custom rule") @@ -191,7 +190,7 @@ public class CreateActionTest { public void create_custom_rule_of_removed_template_should_fail() { logInAsQProfileAdministrator(); - RuleDefinitionDto templateRule = db.rules().insert(r -> r.setIsTemplate(true).setStatus(RuleStatus.REMOVED)); + RuleDto templateRule = db.rules().insert(r -> r.setIsTemplate(true).setStatus(RuleStatus.REMOVED)); TestRequest request = ws.newRequest() .setParam("custom_key", "MY_CUSTOM") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java index 0aed0f986a3..d1d6bfd8787 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/DeleteActionTest.java @@ -26,7 +26,7 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; @@ -65,11 +65,11 @@ public class DeleteActionTest { public void delete_custom_rule() { logInAsQProfileAdministrator(); - RuleDefinitionDto templateRule = dbTester.rules().insert( + RuleDto templateRule = dbTester.rules().insert( r -> r.setIsTemplate(true), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); - RuleDefinitionDto customRule = dbTester.rules().insert( + RuleDto customRule = dbTester.rules().insert( r -> r.setTemplateUuid(templateRule.getUuid()), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); @@ -82,7 +82,7 @@ public class DeleteActionTest { verify(ruleIndexer).commitAndIndex(any(), eq(customRule.getUuid())); // Verify custom rule has status REMOVED - RuleDefinitionDto customRuleReloaded = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, customRule.getKey()); + RuleDto customRuleReloaded = dbClient.ruleDao().selectOrFailByKey(dbSession, customRule.getKey()); assertThat(customRuleReloaded).isNotNull(); assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.REMOVED); assertThat(customRuleReloaded.getUpdatedAt()).isNotEqualTo(PAST); @@ -115,7 +115,7 @@ public class DeleteActionTest { @Test public void fail_to_delete_if_not_custom() { logInAsQProfileAdministrator(); - RuleDefinitionDto rule = dbTester.rules().insert(); + RuleDto rule = dbTester.rules().insert(); assertThatThrownBy(() -> { tester.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java index 3482799dea2..161e06d44a3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java @@ -40,7 +40,7 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.user.UserDto; @@ -155,8 +155,8 @@ public class SearchActionTest { @Test public void return_all_rules() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setLanguage("java")); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setLanguage("java")); + RuleDto rule1 = db.rules().insert(r1 -> r1.setLanguage("java")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setLanguage("java")); indexRules(); verify(r -> { @@ -166,10 +166,10 @@ public class SearchActionTest { @Test public void return_note_login() { UserDto user1 = db.users().insertUser(); - RuleDefinitionDto rule1 = db.rules().insert(); + RuleDto rule1 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule1, user1); UserDto disableUser = db.users().insertDisabledUser(); - RuleDefinitionDto rule2 = db.rules().insert(); + RuleDto rule2 = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule2, disableUser); indexRules(); @@ -186,8 +186,8 @@ public class SearchActionTest { @Test public void filter_by_rule_key() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setLanguage("java")); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setLanguage("java")); + RuleDto rule1 = db.rules().insert(r1 -> r1.setLanguage("java")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setLanguage("java")); indexRules(); verify(r -> r.setParam(PARAM_RULE_KEY, rule1.getKey().toString()), rule1); @@ -196,8 +196,8 @@ public class SearchActionTest { @Test public void filter_by_rule_name() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever")); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); + RuleDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); indexRules(); verify(r -> r.setParam("q", "Be"), rule1); @@ -215,8 +215,8 @@ public class SearchActionTest { @Test public void filter_by_rule_name_requires_all_words_to_match() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever")); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); + RuleDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); indexRules(); verify(r -> r.setParam("q", "Best other")); @@ -226,8 +226,8 @@ public class SearchActionTest { @Test public void filter_by_rule_name_does_not_interpret_query() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule for-ever")); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); + RuleDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule for-ever")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); indexRules(); // do not interpret "-" as a "not" @@ -236,9 +236,9 @@ public class SearchActionTest { @Test public void filter_by_rule_description() { - RuleDefinitionDto rule1 = db.rules() + RuleDto rule1 = db.rules() .insert(r1 -> r1.addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "This is the best rule now&forever"))); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); + RuleDto rule2 = db.rules().insert(r1 -> r1.setName("Some other stuff")); indexRules(); verify(r -> r.setParam("q", "Best "), rule1); @@ -248,9 +248,9 @@ public class SearchActionTest { @Test public void filter_by_rule_name_or_descriptions_requires_all_words_to_match_anywhere() { - RuleDefinitionDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever") + RuleDto rule1 = db.rules().insert(r1 -> r1.setName("Best rule ever") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "This is a good rule"))); - RuleDefinitionDto rule2 = db.rules().insert(r1 -> r1.setName("Another thing") + RuleDto rule2 = db.rules().insert(r1 -> r1.setName("Another thing") .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Another thing"))); indexRules(); @@ -260,7 +260,7 @@ public class SearchActionTest { @Test public void return_all_rule_fields_by_default() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); indexRules(); Rules.SearchResponse response = ws.newRequest().executeProtobuf(Rules.SearchResponse.class); @@ -279,7 +279,7 @@ public class SearchActionTest { @Test public void return_subset_of_fields() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); indexRules(); Rules.SearchResponse response = ws.newRequest() @@ -307,10 +307,10 @@ public class SearchActionTest { @Test public void return_deprecatedKeys_in_response_on_demand() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("java")); db.rules().insertDeprecatedKey(r -> r.setRuleUuid(rule1.getUuid()).setOldRuleKey("oldrulekey").setOldRepositoryKey("oldrepositorykey")); db.rules().insertDeprecatedKey(r -> r.setRuleUuid(rule1.getUuid()).setOldRuleKey("oldrulekey2").setOldRepositoryKey("oldrepositorykey2")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("javascript")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("javascript")); indexRules(); @@ -340,9 +340,9 @@ public class SearchActionTest { @Test public void should_filter_on_specific_tags() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("java")); RuleMetadataDto metadata1 = insertMetadata(rule1, setTags("tag1", "tag2")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("java")); RuleMetadataDto metadata2 = insertMetadata(rule2); indexRules(); @@ -354,13 +354,13 @@ public class SearchActionTest { @Test public void when_searching_for_several_tags_combine_them_with_OR() { - RuleDefinitionDto bothTagsRule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto bothTagsRule = db.rules().insert(r -> r.setLanguage("java")); insertMetadata(bothTagsRule, setTags("tag1", "tag2")); - RuleDefinitionDto oneTagRule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto oneTagRule = db.rules().insert(r -> r.setLanguage("java")); insertMetadata(oneTagRule, setTags("tag1")); - RuleDefinitionDto otherTagRule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto otherTagRule = db.rules().insert(r -> r.setLanguage("java")); insertMetadata(otherTagRule, setTags("tag2")); - RuleDefinitionDto noTagRule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto noTagRule = db.rules().insert(r -> r.setLanguage("java")); insertMetadata(noTagRule, setTags()); indexRules(); @@ -373,7 +373,7 @@ public class SearchActionTest { @Test public void should_list_tags_in_tags_facet() { String[] tags = get101Tags(); - RuleDefinitionDto rule = db.rules().insert(setSystemTags("x")); + RuleDto rule = db.rules().insert(setSystemTags("x")); insertMetadata(rule, setTags(tags)); indexRules(); @@ -388,7 +388,7 @@ public class SearchActionTest { @Test public void should_list_tags_ordered_by_count_then_by_name_in_tags_facet() { - RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag7", "tag5", "tag3", "tag1", "tag9")); + RuleDto rule = db.rules().insert(setSystemTags("tag7", "tag5", "tag3", "tag1", "tag9")); insertMetadata(rule, setTags("tag2", "tag4", "tag6", "tag8", "tagA")); db.rules().insert(setSystemTags("tag2")); indexRules(); @@ -404,7 +404,7 @@ public class SearchActionTest { @Test public void should_include_selected_matching_tag_in_facet() { - RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA", "x")); + RuleDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA", "x")); indexRules(); SearchResponse result = ws.newRequest() @@ -416,7 +416,7 @@ public class SearchActionTest { @Test public void should_included_selected_non_matching_tag_in_facet() { - RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA")); + RuleDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA")); indexRules(); SearchResponse result = ws.newRequest() @@ -428,7 +428,7 @@ public class SearchActionTest { @Test public void should_return_specific_tags() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); RuleMetadataDto metadata = insertMetadata(rule, setTags("tag1", "tag2")); indexRules(); @@ -443,7 +443,7 @@ public class SearchActionTest { @Test public void should_return_specified_fields() { - RuleDefinitionDto rule = db.rules().insert(r1 -> r1.setLanguage("java")); + RuleDto rule = db.rules().insert(r1 -> r1.setLanguage("java")); indexRules(); checkField(rule, "repo", Rule::getRepo, rule.getRepositoryKey()); @@ -464,7 +464,7 @@ public class SearchActionTest { @Test public void return_lang_key_field_when_language_name_is_not_available() { String unknownLanguage = "unknown_" + randomAlphanumeric(5); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(unknownLanguage)); + RuleDto rule = db.rules().insert(r -> r.setLanguage(unknownLanguage)); indexRules(); @@ -481,7 +481,7 @@ public class SearchActionTest { @Test public void search_debt_rules_with_default_and_overridden_debt_values() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") + RuleDto rule = db.rules().insert(r -> r.setLanguage("java") .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()) .setDefRemediationGapMultiplier("1h") .setDefRemediationBaseEffort("15min")); @@ -515,7 +515,7 @@ public class SearchActionTest { @Test public void search_debt_rules_with_default_linear_offset_and_overridden_constant_debt() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") + RuleDto rule = db.rules().insert(r -> r.setLanguage("java") .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()) .setDefRemediationGapMultiplier("1h") .setDefRemediationBaseEffort("15min")); @@ -549,7 +549,7 @@ public class SearchActionTest { @Test public void search_debt_rules_with_default_linear_offset_and_overridden_linear_debt() { - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") + RuleDto rule = db.rules().insert(r -> r.setLanguage("java") .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()) .setDefRemediationGapMultiplier("1h") .setDefRemediationBaseEffort("15min")); @@ -583,9 +583,9 @@ public class SearchActionTest { @Test public void search_template_rules() { - RuleDefinitionDto templateRule = db.rules().insert(r -> r.setLanguage("java") + RuleDto templateRule = db.rules().insert(r -> r.setLanguage("java") .setIsTemplate(true)); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") + RuleDto rule = db.rules().insert(r -> r.setLanguage("java") .setTemplateUuid(templateRule.getUuid())); indexRules(); @@ -605,9 +605,9 @@ public class SearchActionTest { @Test public void search_custom_rules_from_template_key() { - RuleDefinitionDto templateRule = db.rules().insert(r -> r.setLanguage("java") + RuleDto templateRule = db.rules().insert(r -> r.setLanguage("java") .setIsTemplate(true)); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java") + RuleDto rule = db.rules().insert(r -> r.setLanguage("java") .setTemplateUuid(templateRule.getUuid())); indexRules(); @@ -639,7 +639,7 @@ public class SearchActionTest { @Test public void search_all_active_rules() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java")); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null); qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation)); @@ -662,7 +662,7 @@ public class SearchActionTest { public void search_profile_active_rules() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java")); QProfileDto waterproofProfile = db.qualityProfiles().insert(p -> p.setLanguage("java")); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); RuleParamDto ruleParam1 = db.rules().insertRuleParam(rule, p -> p.setDefaultValue("some value") .setType("STRING") .setDescription("My small description") @@ -721,7 +721,7 @@ public class SearchActionTest { public void search_for_active_rules_when_parameter_value_is_null() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java")); - RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule = db.rules().insert(r -> r.setLanguage("java")); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setDefaultValue("some value") .setType("STRING") @@ -769,7 +769,7 @@ public class SearchActionTest { QProfileDto profile = db.qualityProfiles().insert(q -> q.setLanguage("language1")); // on same language, not activated => match - RuleDefinitionDto rule1 = db.rules().insert(r -> r + RuleDto rule1 = db.rules().insert(r -> r .setLanguage(profile.getLanguage()) .setRepositoryKey("repositoryKey1") .setSystemTags(new HashSet<>(singletonList("tag1"))) @@ -778,7 +778,7 @@ public class SearchActionTest { .setType(RuleType.CODE_SMELL)); // on same language, activated => no match - RuleDefinitionDto rule2 = db.rules().insert(r -> r + RuleDto rule2 = db.rules().insert(r -> r .setLanguage(profile.getLanguage()) .setRepositoryKey("repositoryKey2") .setSystemTags(new HashSet<>(singletonList("tag2"))) @@ -789,7 +789,7 @@ public class SearchActionTest { qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation)); // on other language, not activated => no match - RuleDefinitionDto rule3 = db.rules().insert(r -> r + RuleDto rule3 = db.rules().insert(r -> r .setLanguage("language3") .setRepositoryKey("repositoryKey3") .setSystemTags(new HashSet<>(singletonList("tag3"))) @@ -862,9 +862,9 @@ public class SearchActionTest { @Test public void statuses_facet_should_be_sticky() { - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("java")); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("java").setStatus(RuleStatus.BETA)); - RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("java").setStatus(RuleStatus.DEPRECATED)); + RuleDto rule1 = db.rules().insert(r -> r.setLanguage("java")); + RuleDto rule2 = db.rules().insert(r -> r.setLanguage("java").setStatus(RuleStatus.BETA)); + RuleDto rule3 = db.rules().insert(r -> r.setLanguage("java").setStatus(RuleStatus.DEPRECATED)); indexRules(); @@ -884,12 +884,12 @@ public class SearchActionTest { public void compare_to_another_profile() { QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA)); QProfileDto anotherProfile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA)); - RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); - RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); - RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); - RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); - RuleDefinitionDto anotherProfileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); - RuleDefinitionDto anotherProfileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition(); + RuleDto commonRule = db.rules().insertRule(r -> r.setLanguage(JAVA)); + RuleDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)); + RuleDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)); + RuleDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(JAVA)); + RuleDto anotherProfileRule1 = db.rules().insertRule(r -> r.setLanguage(JAVA)); + RuleDto anotherProfileRule2 = db.rules().insertRule(r -> r.setLanguage(JAVA)); db.qualityProfiles().activateRule(profile, commonRule); db.qualityProfiles().activateRule(profile, profileRule1); db.qualityProfiles().activateRule(profile, profileRule2); @@ -912,7 +912,7 @@ public class SearchActionTest { } @SafeVarargs - private final void checkField(RuleDefinitionDto rule, String fieldName, Extractor responseExtractor, T... expected) { + private final void checkField(RuleDto rule, String fieldName, Extractor responseExtractor, T... expected) { SearchResponse result = ws.newRequest() .setParam("f", fieldName) .executeProtobuf(SearchResponse.class); @@ -921,7 +921,7 @@ public class SearchActionTest { } @SafeVarargs - private final RuleMetadataDto insertMetadata(RuleDefinitionDto rule, Consumer... populaters) { + private final RuleMetadataDto insertMetadata(RuleDto rule, Consumer... populaters) { RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(rule, populaters); ruleIndexer.commitAndIndex(db.getSession(), rule.getUuid()); return metadata; @@ -931,13 +931,13 @@ public class SearchActionTest { verify(requestPopulator); } - private void verify(Consumer requestPopulator, RuleDefinitionDto... expectedRules) { + private void verify(Consumer requestPopulator, RuleDto... expectedRules) { TestRequest request = ws.newRequest(); requestPopulator.accept(request); Rules.SearchResponse response = request.executeProtobuf(Rules.SearchResponse.class); assertThat(response.getP()).isOne(); - RuleKey[] expectedRuleKeys = stream(expectedRules).map(RuleDefinitionDto::getKey).collect(MoreCollectors.toList()).toArray(new RuleKey[0]); + RuleKey[] expectedRuleKeys = stream(expectedRules).map(RuleDto::getKey).collect(MoreCollectors.toList()).toArray(new RuleKey[0]); assertThat(response.getRulesList()) .extracting(r -> RuleKey.parse(r.getKey())) .containsExactlyInAnyOrder(expectedRuleKeys); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java index 77e97e592b5..3e06e45ce86 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java @@ -33,7 +33,6 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.rule.RuleParamDto; @@ -87,7 +86,7 @@ public class ShowActionTest { @Test public void show_rule_key() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); ShowResponse result = ws.newRequest() .setParam(PARAM_KEY, rule.getKey().toString()) @@ -98,7 +97,7 @@ public class ShowActionTest { @Test public void show_rule_with_basic_info() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule); ShowResponse result = ws.newRequest() @@ -121,7 +120,7 @@ public class ShowActionTest { @Test public void show_rule_tags() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(rule, setTags("tag1", "tag2"), m -> m.setNoteData(null).setNoteUserUuid(null)); ShowResponse result = ws.newRequest() @@ -134,7 +133,7 @@ public class ShowActionTest { @Test public void show_rule_with_note_login() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); db.rules().insertOrUpdateMetadata(rule, user); @@ -147,7 +146,7 @@ public class ShowActionTest { @Test public void show_rule_with_default_debt_infos() { - RuleDefinitionDto rule = db.rules().insert(r -> r + RuleDto rule = db.rules().insert(r -> r .setDefRemediationFunction("LINEAR_OFFSET") .setDefRemediationGapMultiplier("5d") .setDefRemediationBaseEffort("10h") @@ -171,7 +170,7 @@ public class ShowActionTest { @Test public void show_rule_with_only_overridden_debt() { - RuleDefinitionDto rule = db.rules().insert(r -> r + RuleDto rule = db.rules().insert(r -> r .setDefRemediationFunction(null) .setDefRemediationGapMultiplier(null) .setDefRemediationBaseEffort(null)); @@ -199,7 +198,7 @@ public class ShowActionTest { @Test public void show_rule_with_default_and_overridden_debt_infos() { - RuleDefinitionDto rule = db.rules().insert(r -> r + RuleDto rule = db.rules().insert(r -> r .setDefRemediationFunction("LINEAR_OFFSET") .setDefRemediationGapMultiplier("5d") .setDefRemediationBaseEffort("10h")); @@ -227,7 +226,7 @@ public class ShowActionTest { @Test public void show_rule_with_no_default_and_no_overridden_debt() { - RuleDefinitionDto rule = db.rules().insert(r -> r + RuleDto rule = db.rules().insert(r -> r .setDefRemediationFunction(null) .setDefRemediationGapMultiplier(null) .setDefRemediationBaseEffort(null)); @@ -254,7 +253,7 @@ public class ShowActionTest { @Test public void show_deprecated_rule_debt_fields() { - RuleDefinitionDto rule = db.rules().insert(r -> r + RuleDto rule = db.rules().insert(r -> r .setDefRemediationFunction("LINEAR_OFFSET") .setDefRemediationGapMultiplier("5d") .setDefRemediationBaseEffort("10h") @@ -285,9 +284,9 @@ public class ShowActionTest { public void encode_html_description_of_custom_rule() { // Template rule RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")); - db.rules().insert(templateRule.getDefinition()); + db.rules().insert(templateRule); // Custom rule - RuleDefinitionDto customRule = newCustomRule(templateRule.getDefinition()) + RuleDto customRule = newCustomRule(templateRule) .addOrReplaceRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "
line1\nline2
")) .setDescriptionFormat(MARKDOWN); db.rules().insert(customRule); @@ -304,7 +303,7 @@ public class ShowActionTest { @Test public void show_external_rule() { - RuleDefinitionDto externalRule = db.rules().insert(r -> r + RuleDto externalRule = db.rules().insert(r -> r .setIsExternal(true) .setName("ext rule name")); @@ -318,7 +317,7 @@ public class ShowActionTest { @Test public void show_adhoc_rule() { - RuleDefinitionDto externalRule = db.rules().insert(r -> r + RuleDto externalRule = db.rules().insert(r -> r .setIsExternal(true) .setIsAdHoc(true)); RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(externalRule, m -> m @@ -342,7 +341,7 @@ public class ShowActionTest { @Test public void ignore_predefined_info_on_adhoc_rule() { - RuleDefinitionDto externalRule = db.rules().insert(r -> r + RuleDto externalRule = db.rules().insert(r -> r .setIsExternal(true) .setIsAdHoc(true) .setName("predefined name") @@ -370,7 +369,7 @@ public class ShowActionTest { @Test public void adhoc_info_are_empty_when_no_metadata() { - RuleDefinitionDto externalRule = db.rules().insert(r -> r + RuleDto externalRule = db.rules().insert(r -> r .setIsExternal(true) .setIsAdHoc(true) .setName(null) @@ -390,7 +389,7 @@ public class ShowActionTest { @Test public void show_rule_with_activation() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*")); db.rules().insertOrUpdateMetadata(rule, m -> m.setNoteData(null).setNoteUserUuid(null)); QProfileDto qProfile = db.qualityProfiles().insert(); @@ -417,7 +416,7 @@ public class ShowActionTest { @Test public void show_rule_without_activation() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); db.rules().insertOrUpdateMetadata(rule, m -> m.setNoteData(null).setNoteUserUuid(null)); QProfileDto qProfile = db.qualityProfiles().insert(); db.qualityProfiles().activateRule(qProfile, rule); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java index e61c6b5da86..7864d6d1cf1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java @@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.rule.index.RuleIndex; @@ -79,7 +79,7 @@ public class TagsActionTest { @Test public void system_tag() { - RuleDefinitionDto r = db.rules().insert(setSystemTags("tag")); + RuleDto r = db.rules().insert(setSystemTags("tag")); ruleIndexer.commitAndIndex(db.getSession(), r.getUuid()); String result = ws.newRequest().execute().getInput(); @@ -88,7 +88,7 @@ public class TagsActionTest { @Test public void tag() { - RuleDefinitionDto r = db.rules().insert(setSystemTags()); + RuleDto r = db.rules().insert(setSystemTags()); ruleIndexer.commitAndIndex(db.getSession(), r.getUuid()); db.rules().insertOrUpdateMetadata(r, setTags("tag")); ruleIndexer.commitAndIndex(db.getSession(), r.getUuid()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java index 671f4e7a5d2..4e1818d62f6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java @@ -29,7 +29,7 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleMetadataDto; import org.sonar.db.user.UserDto; @@ -102,13 +102,13 @@ public class UpdateActionTest { @Test public void update_custom_rule() { logInAsQProfileAdministrator(); - RuleDefinitionDto templateRule = db.rules().insert( + RuleDto templateRule = db.rules().insert( r -> r.setRuleKey(RuleKey.of("java", "S001")), r -> r.setIsTemplate(true), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); db.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); - RuleDefinitionDto customRule = db.rules().insert( + RuleDto customRule = db.rules().insert( r -> r.setRuleKey(RuleKey.of("java", "MY_CUSTOM")), r -> r.setName("Old custom"), r -> r.addOrReplaceRuleDescriptionSectionDto(createRuleDescriptionSectionDto()), @@ -154,7 +154,7 @@ public class UpdateActionTest { public void update_tags() { logInAsQProfileAdministrator(); - RuleDefinitionDto rule = db.rules().insert(setSystemTags("stag1", "stag2")); + RuleDto rule = db.rules().insert(setSystemTags("stag1", "stag2")); db.rules().insertOrUpdateMetadata(rule, setTags("tag1", "tag2"), m -> m.setNoteData(null).setNoteUserUuid(null)); Rules.UpdateResponse result = ws.newRequest().setMethod("POST") @@ -174,7 +174,7 @@ public class UpdateActionTest { public void update_rule_remediation_function() { logInAsQProfileAdministrator(); - RuleDefinitionDto rule = db.rules().insert( + RuleDto rule = db.rules().insert( r -> r.setDefRemediationFunction(LINEAR.toString()), r -> r.setDefRemediationGapMultiplier("10d"), r -> r.setDefRemediationBaseEffort(null)); @@ -213,7 +213,7 @@ public class UpdateActionTest { @Test public void update_note() { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); UserDto userHavingUpdatingNote = db.users().insertUser(); db.rules().insertOrUpdateMetadata(rule, userHavingUpdatingNote, m -> m.setNoteData("old data")); UserDto userAuthenticated = db.users().insertUser(); @@ -239,12 +239,12 @@ public class UpdateActionTest { @Test public void fail_to_update_custom_when_description_is_empty() { logInAsQProfileAdministrator(); - RuleDefinitionDto templateRule = db.rules().insert( + RuleDto templateRule = db.rules().insert( r -> r.setRuleKey(RuleKey.of("java", "S001")), r -> r.setIsTemplate(true), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); - RuleDefinitionDto customRule = db.rules().insert( + RuleDto customRule = db.rules().insert( r -> r.setRuleKey(RuleKey.of("java", "MY_CUSTOM")), r -> r.setName("Old custom"), r -> r.addOrReplaceRuleDescriptionSectionDto(createRuleDescriptionSectionDto()), @@ -266,7 +266,7 @@ public class UpdateActionTest { @Test public void throw_IllegalArgumentException_if_trying_to_update_builtin_rule_description() { logInAsQProfileAdministrator(); - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); assertThatThrownBy(() -> { ws.newRequest().setMethod("POST") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java index bb1133faed1..5dda021a112 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.metric.MetricDto; import org.sonar.db.protobuf.DbCommons; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.protobuf.DbIssues; -import org.sonar.db.rule.RuleDefinitionDto; +import org.sonar.db.rule.RuleDto; import org.sonar.db.source.FileSourceTester; import org.sonar.server.component.ws.ComponentViewerJsonWriter; import org.sonar.server.exceptions.ForbiddenException; @@ -249,7 +249,7 @@ public class IssueSnippetsActionTest { } private String insertIssue(ComponentDto file, DbIssues.Location... locations) { - RuleDefinitionDto rule = db.rules().insert(); + RuleDto rule = db.rules().insert(); DbIssues.Flow flow = DbIssues.Flow.newBuilder().addAllLocation(Arrays.asList(locations)).build(); IssueDto issue = db.issues().insert(rule, project, file, i -> { -- 2.39.5