From 2760f7f89bb81ffbfc572f7f183aaf6a5c3367cd Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Fri, 10 Mar 2023 13:45:43 +0100 Subject: [PATCH] SONAR-18629 Drop deprecated test utility methods in Issue and Rule testing --- .../issue/IntegrateIssuesVisitorTest.java | 14 +-- .../java/org/sonar/db/issue/IssueTesting.java | 23 +---- .../java/org/sonar/db/rule/RuleDbTester.java | 5 +- .../java/org/sonar/db/rule/RuleTesting.java | 70 ++------------- .../sonar/server/issue/IssueFinderTest.java | 8 +- .../server/issue/SetSeverityActionTest.java | 10 +-- .../sonar/server/issue/SetTypeActionTest.java | 8 +- .../server/issue/ws/SearchActionTest.java | 86 ++++++++++--------- .../sonar/server/rule/RuleCreatorTest.java | 2 +- .../sonar/server/rule/RuleUpdaterTest.java | 12 +-- .../server/rule/ws/CreateActionTest.java | 10 ++- .../filter_by_leak_period.json | 2 +- 12 files changed, 93 insertions(+), 157 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java index 1d1caf214c3..1a3efbb6252 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java @@ -31,6 +31,7 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; +import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.analysis.Branch; @@ -335,13 +336,12 @@ public class IntegrateIssuesVisitorTest { ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); dbTester.components().insertComponents(project, file); - RuleDto ruleDto = RuleTesting.newDto(ruleKey); + RuleDto ruleDto = RuleTesting.newRule(ruleKey); dbTester.rules().insert(ruleDto); ruleRepositoryRule.add(ruleKey); - IssueDto issue = IssueTesting.newDto(ruleDto, file, project) + IssueDto issue = IssueTesting.newIssue(ruleDto, project, file) .setKee("ISSUE") - .setStatus(Issue.STATUS_OPEN) .setSeverity(Severity.MAJOR); dbTester.getDbClient().issueDao().insert(dbTester.getSession(), issue); dbTester.getSession().commit(); @@ -352,14 +352,14 @@ public class IntegrateIssuesVisitorTest { ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID_ON_BRANCH).setKey(FILE_KEY); dbTester.components().insertComponents(project, file); - RuleDto ruleDto = RuleTesting.newDto(ruleKey); + RuleDto ruleDto = RuleTesting.newRule(ruleKey); dbTester.rules().insert(ruleDto); ruleRepositoryRule.add(ruleKey); - IssueDto issue = IssueTesting.newDto(ruleDto, file, project) + IssueDto issue = IssueTesting.newIssue(ruleDto, project, file) .setKee("ISSUE") - .setStatus(Issue.STATUS_OPEN) - .setSeverity(Severity.MAJOR); + .setSeverity(Severity.MAJOR) + .setChecksum(null); dbTester.getDbClient().issueDao().insert(dbTester.getSession(), issue); dbTester.getSession().commit(); } 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 1267e778bad..b4bce20d4cc 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 @@ -60,7 +60,7 @@ public class IssueTesting { return new IssueDto() .setKee("uuid_" + randomAlphabetic(5)) .setRule(rule) - .setType(RuleType.values()[nextInt(RuleType.values().length)]) + .setType(rule.getType()) .setProjectUuid(projectUuid) .setProjectKey(projectKey) .setComponent(file) @@ -96,27 +96,6 @@ public class IssueTesting { .setUpdatedAt(nextLong()); } - /** - * @deprecated use newIssue(...) - */ - @Deprecated - public static IssueDto newDto(RuleDto rule, ComponentDto file, ComponentDto project) { - return new IssueDto() - .setKee(Uuids.createFast()) - .setRule(rule) - .setType(RuleType.CODE_SMELL) - .setComponent(file) - .setProject(project) - .setStatus(Issue.STATUS_OPEN) - .setResolution(null) - .setSeverity(Severity.MAJOR) - .setEffort(10L) - .setIssueCreationDate(DateUtils.parseDate("2014-09-04")) - .setIssueUpdateDate(DateUtils.parseDate("2014-12-04")) - .setCreatedAt(1_400_000_000_000L) - .setUpdatedAt(1_400_000_000_000L); - } - public static NewCodeReferenceIssueDto newCodeReferenceIssue(IssueDto issue) { return new NewCodeReferenceIssueDto() .setUuid(Uuids.createFast()) 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 8af97e2dd06..690834f3685 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 @@ -31,7 +31,6 @@ import static java.util.Arrays.asList; 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; -import static org.sonar.db.rule.RuleTesting.newRuleDto; public class RuleDbTester { private static final RuleType[] RULE_TYPES_EXCEPT_HOTSPOTS = Arrays.stream(RuleType.values()) @@ -143,13 +142,13 @@ public class RuleDbTester { @SafeVarargs public final RuleDto insertRule(Consumer... populaters) { - RuleDto ruleDto = newRuleDto(); + RuleDto ruleDto = RuleTesting.newRule(); asList(populaters).forEach(populater -> populater.accept(ruleDto)); return insert(ruleDto); } public RuleDto insertRule(Consumer populateRuleDto) { - RuleDto ruleDto = newRuleDto(); + RuleDto ruleDto = RuleTesting.newRule(); populateRuleDto.accept(ruleDto); if (ruleDto.getUuid() == null) { 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 fdeec2d7f85..6d5cc8f4cfd 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 @@ -19,8 +19,6 @@ */ package org.sonar.db.rule; -import com.google.common.collect.ImmutableSet; -import java.util.Date; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; @@ -32,7 +30,6 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RuleParamType; import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryFast; -import org.sonar.core.util.Uuids; import org.sonar.db.rule.RuleDto.Scope; import static com.google.common.base.Preconditions.checkNotNull; @@ -64,6 +61,10 @@ public class RuleTesting { // only static helpers } + + public static RuleDto newRule() { + return newRule(RuleKey.of(randomAlphanumeric(30), randomAlphanumeric(30))); + } public static RuleDto newRule(RuleDescriptionSectionDto... ruleDescriptionSectionDtos) { return newRule(randomRuleKey(), ruleDescriptionSectionDtos); } @@ -92,7 +93,7 @@ public class RuleTesting { .setDescriptionFormat(RuleDto.Format.HTML) .setType(CODE_SMELL) .setStatus(RuleStatus.READY) - .setConfigKey("configKey_" + randomAlphanumeric(5)) + .setConfigKey("configKey_" + ruleKey.rule()) .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) .setIsTemplate(false) .setIsExternal(false) @@ -140,72 +141,17 @@ public class RuleTesting { .setCreatedAt(System.currentTimeMillis()); } - /** - * @deprecated use newRule(...) - */ - @Deprecated public static RuleDto newXooX1() { - return newDto(XOO_X1).setLanguage("xoo"); + return newRule(XOO_X1).setLanguage("xoo"); } - /** - * @deprecated use newRule(...) - */ - @Deprecated public static RuleDto newXooX2() { - return newDto(XOO_X2).setLanguage("xoo"); + return newRule(XOO_X2).setLanguage("xoo"); } - /** - * @deprecated use newRule(...) - */ - @Deprecated - public static RuleDto newXooX3() { - return newDto(XOO_X3).setLanguage("xoo"); - } - - /** - * @deprecated use newRule(...) - */ - @Deprecated - public static RuleDto newDto(RuleKey ruleKey) { - - return new RuleDto() - .setUuid("uuid_" + Uuids.createFast()) - .setRuleKey(ruleKey.rule()) - .setRepositoryKey(ruleKey.repository()) - .setName("Rule " + ruleKey.rule()) - .setDescriptionFormat(RuleDto.Format.HTML) - .addRuleDescriptionSectionDto(createDefaultRuleDescriptionSection(uuidFactory.create(), "Description" + ruleKey.rule())) - .setStatus(RuleStatus.READY) - .setConfigKey("InternalKey" + ruleKey.rule()) - .setSeverity(Severity.INFO) - .setIsTemplate(false) - .setSystemTags(ImmutableSet.of("systag1", "systag2")) - .setLanguage("js") - .setDefRemediationFunction("LINEAR_OFFSET") - .setDefRemediationGapMultiplier("5d") - .setDefRemediationBaseEffort("10h") - .setGapDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix") - .setType(CODE_SMELL) - .setCreatedAt(new Date().getTime()) - .setUpdatedAt(new Date().getTime()) - .setScope(Scope.MAIN) - .setTags(ImmutableSet.of("tag1", "tag2")) - .setRemediationFunction("LINEAR") - .setRemediationGapMultiplier("1h"); - } - - /** - * @deprecated use newRule(...) - */ - @Deprecated - public static RuleDto newRuleDto() { - return newDto(RuleKey.of(randomAlphanumeric(30), randomAlphanumeric(30))); - } public static RuleDto newTemplateRule(RuleKey ruleKey) { - return newDto(ruleKey) + return newRule(ruleKey) .setIsTemplate(true); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java index 3f32d7a106d..74e475bb805 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java @@ -38,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.api.web.UserRole.CODEVIEWER; import static org.sonar.api.web.UserRole.USER; import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.issue.IssueTesting.newDto; -import static org.sonar.db.rule.RuleTesting.newRuleDto; +import static org.sonar.db.issue.IssueTesting.newIssue; +import static org.sonar.db.rule.RuleTesting.newRule; public class IssueFinderTest { @@ -87,10 +87,10 @@ public class IssueFinderTest { } private IssueDto insertIssue() { - RuleDto rule = ruleDbTester.insert(newRuleDto()); + RuleDto rule = ruleDbTester.insert(newRule()); ComponentDto project = componentDbTester.insertPrivateProject(); ComponentDto file = componentDbTester.insertComponent(newFileDto(project)); - return issueDbTester.insert(newDto(rule, file, project)); + return issueDbTester.insert(newIssue(rule, project, file)); } private void addProjectPermission(IssueDto issueDto, String permission) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java index 475e03fef30..b5b020c8597 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java @@ -32,6 +32,7 @@ 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.issue.IssueTesting; import org.sonar.db.rule.RuleDto; import org.sonar.server.tester.AnonymousMockUserSession; import org.sonar.server.tester.UserSessionRule; @@ -44,8 +45,7 @@ import static org.sonar.api.web.UserRole.ISSUE_ADMIN; import static org.sonar.api.web.UserRole.USER; import static org.sonar.core.issue.IssueChangeContext.issueChangeContextByUserBuilder; import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.issue.IssueTesting.newDto; -import static org.sonar.db.rule.RuleTesting.newRuleDto; +import static org.sonar.db.rule.RuleTesting.newRule; public class SetSeverityActionTest { @@ -91,7 +91,7 @@ public class SetSeverityActionTest { @Test public void support_only_unresolved_issues() { - IssueDto issueDto = newIssue().setSeverity(MAJOR); + IssueDto issueDto = newIssue().setSeverity(MAJOR).setChecksum(null); DefaultIssue issue = issueDto.toDefaultIssue(); setUserWithBrowseAndAdministerIssuePermission(issueDto); @@ -128,10 +128,10 @@ public class SetSeverityActionTest { } private IssueDto newIssue() { - RuleDto rule = db.rules().insert(newRuleDto()); + RuleDto rule = db.rules().insert(newRule()); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - return newDto(rule, file, project); + return IssueTesting.newIssue(rule, project, file); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetTypeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetTypeActionTest.java index e5723629857..bcdb79f67e4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetTypeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetTypeActionTest.java @@ -31,6 +31,7 @@ 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.issue.IssueTesting; import org.sonar.db.rule.RuleDto; import org.sonar.server.tester.UserSessionRule; @@ -42,8 +43,7 @@ import static org.sonar.api.web.UserRole.ISSUE_ADMIN; import static org.sonar.api.web.UserRole.USER; import static org.sonar.core.issue.IssueChangeContext.issueChangeContextByUserBuilder; import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.issue.IssueTesting.newDto; -import static org.sonar.db.rule.RuleTesting.newRuleDto; +import static org.sonar.db.rule.RuleTesting.newRule; public class SetTypeActionTest { @@ -123,10 +123,10 @@ public class SetTypeActionTest { } private IssueDto newIssue() { - RuleDto rule = db.rules().insert(newRuleDto()); + RuleDto rule = db.rules().insert(newRule()); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); - return newDto(rule, file, project); + return IssueTesting.newIssue(rule, project, file); } } 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 5e0e0b0aaaf..be6fa5684b6 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 @@ -48,7 +48,6 @@ import org.sonar.db.DbSession; 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.component.SnapshotDto; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; @@ -101,7 +100,7 @@ import static org.sonar.api.utils.DateUtils.parseDate; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.api.web.UserRole.ISSUE_ADMIN; import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.issue.IssueTesting.newDto; +import static org.sonar.db.issue.IssueTesting.newIssue; import static org.sonar.db.protobuf.DbIssues.MessageFormattingType.CODE; import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; import static org.sonar.db.rule.RuleTesting.XOO_X1; @@ -175,7 +174,6 @@ public class SearchActionTest { .setStatus(STATUS_RESOLVED) .setResolution(RESOLUTION_FIXED) .setSeverity("MAJOR") - .setType(CODE_SMELL) .setAuthorLogin("John") .setAssigneeUuid(simon.getUuid()) .setTags(asList("bug", "owasp")) @@ -472,11 +470,10 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js")); - IssueDto issue = newDto(newIssueRule(), file, project) + IssueDto issue = newIssue(newIssueRule(), project, file) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setAuthorLogin(fabrice.getLogin()) - .setAssigneeUuid(simon.getUuid()) - .setType(CODE_SMELL); + .setAssigneeUuid(simon.getUuid()); dbClient.issueDao().insert(session, issue); session.commit(); indexIssues(); @@ -562,7 +559,7 @@ public class SearchActionTest { .setKey("REMOVED_FILE_KEY") .setEnabled(false)); - IssueDto issue = newDto(rule, removedFile, project) + IssueDto issue = newIssue(rule, project, removedFile) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setComponent(removedFile) .setStatus("OPEN").setResolution("OPEN") @@ -585,7 +582,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); for (int i = 0; i < SearchOptions.MAX_PAGE_SIZE + 1; i++) { - IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); + IssueDto issue = newIssue(rule, project, file).setAssigneeUuid(null).setChecksum(null); dbClient.issueDao().insert(session, issue); } session.commit(); @@ -603,7 +600,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, project) + IssueDto issue1 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -611,7 +608,7 @@ public class SearchActionTest { .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR") .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, project) + IssueDto issue2 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -619,7 +616,7 @@ public class SearchActionTest { .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR") .setAssigneeUuid(alice.getUuid()); - IssueDto issue3 = newDto(rule, file, project) + IssueDto issue3 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -651,21 +648,27 @@ public class SearchActionTest { ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, project) + IssueDto issue1 = newIssue(rule, project, file) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) .setStatus("OPEN") + .setMessage(null) + .setTags(null) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR") + .setChecksum(null) .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, project) + IssueDto issue2 = newIssue(rule, project, file) .setIssueCreationDate(parseDateTime("2014-09-06T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) .setStatus("OPEN") + .setMessage(null) + .setTags(null) .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR") + .setChecksum(null) .setAssigneeUuid(alice.getUuid()); dbClient.issueDao().insert(session, issue1, issue2); session.commit(); @@ -698,21 +701,23 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, project) + IssueDto issue1 = newIssue(rule, project, file) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) .setStatus("OPEN") .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR") + .setChecksum(null) .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, project) + IssueDto issue2 = newIssue(rule, project, file) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) .setStatus("OPEN") .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR") + .setChecksum(null) .setAssigneeUuid(alice.getUuid()); dbClient.issueDao().insert(session, issue1, issue2); session.commit(); @@ -737,19 +742,25 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, pr) + IssueDto issue1 = newIssue(rule, pr, file) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) + .setTags(null) + .setMessage(null) .setStatus("OPEN") + .setAuthorLogin("john") .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR") .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, pr) + IssueDto issue2 = newIssue(rule, pr, file) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) .setIssueUpdateDate(parseDateTime("2017-12-04T00:00:00+0100")) .setEffort(10L) + .setTags(null) + .setMessage(null) .setStatus("OPEN") + .setAuthorLogin("john") .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR") .setAssigneeUuid(alice.getUuid()); @@ -775,7 +786,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, project) + IssueDto issue1 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -783,7 +794,7 @@ public class SearchActionTest { .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR") .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, project) + IssueDto issue2 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -791,7 +802,7 @@ public class SearchActionTest { .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR") .setAssigneeUuid(alice.getUuid()); - IssueDto issue3 = newDto(rule, file, project) + IssueDto issue3 = newIssue(rule, project, file) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -824,15 +835,15 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, file, project) + IssueDto issue1 = newIssue(rule, project, file) .setStatus("OPEN") .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setAssigneeUuid(john.getUuid()); - IssueDto issue2 = newDto(rule, file, project) + IssueDto issue2 = newIssue(rule, project, file) .setStatus("OPEN") .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setAssigneeUuid(alice.getUuid()); - IssueDto issue3 = newDto(rule, file, project) + IssueDto issue3 = newIssue(rule, project, file) .setStatus("OPEN") .setKee("82fd47d4-4037-b650-80bc-7b112bd4eac2") .setAssigneeUuid(null); @@ -888,21 +899,21 @@ public class SearchActionTest { ComponentDto testCodeFile = db.components().insertComponent( newFileDto(project, null, "ANOTHER_FILE_ID").setKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, mainCodeFile, project) + IssueDto issue1 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) .setStatus("OPEN") .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setSeverity("MAJOR"); - IssueDto issue2 = newDto(rule, mainCodeFile, project) + IssueDto issue2 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) .setStatus("OPEN") .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR"); - IssueDto issue3 = newDto(rule, testCodeFile, project) + IssueDto issue3 = newIssue(rule, project, testCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -929,24 +940,21 @@ public class SearchActionTest { ComponentDto testCodeFile = db.components().insertComponent( newFileDto(project, null, "ANOTHER_FILE_ID").setKey("ANOTHER_FILE_KEY").setQualifier(UNIT_TEST_FILE)); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, mainCodeFile, project) - .setType(CODE_SMELL) + IssueDto issue1 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) .setStatus("OPEN") .setKee("83ec1d05-9397-4137-9978-85368bcc3b90") .setSeverity("MAJOR"); - IssueDto issue2 = newDto(rule, mainCodeFile, project) - .setType(CODE_SMELL) + IssueDto issue2 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) .setStatus("OPEN") .setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2") .setSeverity("MAJOR"); - IssueDto issue3 = newDto(rule, testCodeFile, project) - .setType(CODE_SMELL) + IssueDto issue3 = newIssue(rule, project, testCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -971,16 +979,14 @@ public class SearchActionTest { ComponentDto mainCodeFile = db.components().insertComponent( newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); - IssueDto issue1 = newDto(rule, mainCodeFile, project) - .setType(CODE_SMELL) + IssueDto issue1 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) .setStatus("OPEN") .setKee("83ec1d05-9397-4137-9978-85368bcc3b90") .setSeverity("MAJOR"); - IssueDto issue2 = newDto(rule, mainCodeFile, project) - .setType(CODE_SMELL) + IssueDto issue2 = newIssue(rule, project, mainCodeFile) .setIssueCreationDate(parseDate("2014-09-04")) .setIssueUpdateDate(parseDate("2017-12-04")) .setEffort(10L) @@ -1004,13 +1010,13 @@ public class SearchActionTest { ComponentDto project = db.components().insertPublicProject("PROJECT_ID", c -> c.setKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); - dbClient.issueDao().insert(session, newDto(rule, file, project) + dbClient.issueDao().insert(session, newIssue(rule, project, file) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac1") .setIssueUpdateDate(parseDateTime("2014-11-02T00:00:00+0100"))); - dbClient.issueDao().insert(session, newDto(rule, file, project) + dbClient.issueDao().insert(session, newIssue(rule, project, file) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setIssueUpdateDate(parseDateTime("2014-11-01T00:00:00+0100"))); - dbClient.issueDao().insert(session, newDto(rule, file, project) + dbClient.issueDao().insert(session, newIssue(rule, project, file) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac3") .setIssueUpdateDate(parseDateTime("2014-11-03T00:00:00+0100"))); session.commit(); @@ -1670,7 +1676,7 @@ public class SearchActionTest { indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); for (int i = 0; i < 12; i++) { - IssueDto issue = newDto(rule, file, project); + IssueDto issue = newIssue(rule, project, file).setChecksum(null); dbClient.issueDao().insert(session, issue); } session.commit(); 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 57778ced070..598a912ea8c 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 @@ -562,7 +562,7 @@ public class RuleCreatorTest { } private RuleDto createTemplateRule() { - RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S001")) + RuleDto templateRule = RuleTesting.newRule(RuleKey.of("java", "S001")) .setIsTemplate(true) .setLanguage("java") .setPluginKey("sonarjava") 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 ace4e8814a9..07fb2efbe5c 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 @@ -102,7 +102,7 @@ public class RuleUpdaterTest { @Test public void no_changes() { - RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) + RuleDto ruleDto = RuleTesting.newRule(RULE_KEY) // the following fields are not supposed to be updated .setNoteData("my *note*") .setNoteUserUuid("me") @@ -132,7 +132,7 @@ public class RuleUpdaterTest { UserDto user = db.users().insertUser(); userSessionRule.logIn(user); - RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) + RuleDto ruleDto = RuleTesting.newRule(RULE_KEY) .setNoteData(null) .setNoteUserUuid(null) @@ -163,7 +163,7 @@ public class RuleUpdaterTest { @Test public void remove_markdown_note() { - RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) + RuleDto ruleDto = RuleTesting.newRule(RULE_KEY) .setNoteData("my *note*") .setNoteUserUuid("me"); db.rules().insert(ruleDto); @@ -184,7 +184,7 @@ public class RuleUpdaterTest { @Test public void set_tags() { // insert db - db.rules().insert(RuleTesting.newDto(RULE_KEY) + db.rules().insert(RuleTesting.newRule(RULE_KEY) .setTags(Sets.newHashSet("security")) .setSystemTags(Sets.newHashSet("java8", "javadoc"))); dbSession.commit(); @@ -205,7 +205,7 @@ public class RuleUpdaterTest { @Test public void remove_tags() { - RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) + RuleDto ruleDto = RuleTesting.newRule(RULE_KEY) .setUuid("57a3af91-32f8-48b0-9e11-0eac14ffa915") .setTags(Sets.newHashSet("security")) .setSystemTags(Sets.newHashSet("java8", "javadoc")); @@ -301,7 +301,7 @@ public class RuleUpdaterTest { @Test public void reset_remediation_function() { - RuleDto ruleDto = RuleTesting.newDto(RULE_KEY) + RuleDto ruleDto = RuleTesting.newRule(RULE_KEY) .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR.name()) .setDefRemediationGapMultiplier("1d") .setDefRemediationBaseEffort("5min") 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 3b3c462452c..26653fa8c83 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 @@ -19,12 +19,14 @@ */ package org.sonar.server.rule.ws; +import java.util.Set; import org.junit.Rule; import org.junit.Test; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.core.util.SequenceUuidFactory; import org.sonar.core.util.UuidFactory; @@ -88,7 +90,11 @@ public class CreateActionTest { public void create_custom_rule() { logInAsQProfileAdministrator(); // Template rule - RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")).setType(CODE_SMELL); + RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001")) + .setType(BUG) + .setTags(Set.of()) + .setLanguage("js") + .setSystemTags(Set.of("systag1", "systag2")); db.rules().insert(templateRule); db.rules().insertRuleParam(templateRule, param -> param.setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*")); @@ -112,7 +118,7 @@ public class CreateActionTest { " \"severity\": \"MAJOR\",\n" + " \"status\": \"BETA\",\n" + " \"type\": \"BUG\",\n" + - " \"internalKey\": \"InternalKeyS001\",\n" + + " \"internalKey\": \"configKey_S001\",\n" + " \"isTemplate\": false,\n" + " \"templateKey\": \"java:S001\",\n" + " \"sysTags\": [\"systag1\", \"systag2\"],\n" + diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/filter_by_leak_period.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/filter_by_leak_period.json index cfc1450e3ae..65d8323fe65 100644 --- a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/filter_by_leak_period.json +++ b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/filter_by_leak_period.json @@ -24,7 +24,7 @@ "tags": [], "creationDate": "2014-09-06T00:00:00+0100", "updateDate": "2017-12-04T00:00:00+0100", - "type": "CODE_SMELL", + "type": "CODE_SMELL" } ], "components": [ -- 2.39.5