]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18629 Drop deprecated test utility methods in Issue and Rule testing
authorZipeng WU <zipeng.wu@sonarsource.com>
Fri, 10 Mar 2023 12:45:43 +0000 (13:45 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 13 Mar 2023 20:02:44 +0000 (20:02 +0000)
12 files changed:
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssueFinderTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleCreatorTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/filter_by_leak_period.json

index 1d1caf214c3abe32d0e920d7777196e1db1132d1..1a3efbb6252fbf805b2858ea5dacb92136357527 100644 (file)
@@ -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();
   }
index 1267e778bad2568a7e5ed02618d92fa96fc61639..b4bce20d4cc326e8df5271063f90c3886106ccbd 100644 (file)
@@ -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())
index 8af97e2dd06f7e0d6be52536748846e01455959d..690834f36854aa21c3b332383364a902813c66e8 100644 (file)
@@ -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<RuleDto>... populaters) {
-    RuleDto ruleDto = newRuleDto();
+    RuleDto ruleDto = RuleTesting.newRule();
     asList(populaters).forEach(populater -> populater.accept(ruleDto));
     return insert(ruleDto);
   }
 
   public RuleDto insertRule(Consumer<RuleDto> populateRuleDto) {
-    RuleDto ruleDto = newRuleDto();
+    RuleDto ruleDto = RuleTesting.newRule();
     populateRuleDto.accept(ruleDto);
 
     if (ruleDto.getUuid() == null) {
index fdeec2d7f850ed8457e34693f4bf14a134b62741..6d5cc8f4cfd9909f983cbeb7d9ef2fc80b3ea67b 100644 (file)
@@ -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);
   }
 
index 3f32d7a106d4c1067d34cd17d77229ee2c5499d6..74e475bb805358f26dfe936478542e4a28565f89 100644 (file)
@@ -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) {
index 475e03fef3068bd6e98510fee45ffdbcd333a1e6..b5b020c85970d0f11f02d00c3fdd862dce84528a 100644 (file)
@@ -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);
   }
 
 }
index e57236298574e1b255a0703b4351369e56718454..bcdb79f67e435e675c00d77bab4d3d4bfec10a0f 100644 (file)
@@ -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);
   }
 
 }
index 5e0e0b0aaaf5cc2fe9b864ed6d819a03b6f148bc..be6fa5684b67f0b8b61a00430dc7862dea9d5feb 100644 (file)
@@ -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();
index 57778ced0709e605ec587dcdf3807bb2f071dff1..598a912ea8cf54ba2ce2b50433a9bc1ffd5cd919 100644 (file)
@@ -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")
index ace4e8814a99c6ba3ac246fdb2e1ae5a31cd1833..07fb2efbe5c8e6d1d1000ac737b31bfe3b91e557 100644 (file)
@@ -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")
index 3b3c462452cbe28f4995fa32ad7e19970a2a0fe4..26653fa8c83249e234c60d2bb67f666807283144 100644 (file)
  */
 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" +
index cfc1450e3ae11f482dc57463c3bcf269dbe5f73c..65d8323fe65182effabd961e850353d0ae7b5f56 100644 (file)
@@ -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": [