*/
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;
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;
// 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);
}
.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)
.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);
}
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;
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;
.setStatus(STATUS_RESOLVED)
.setResolution(RESOLUTION_FIXED)
.setSeverity("MAJOR")
- .setType(CODE_SMELL)
.setAuthorLogin("John")
.setAssigneeUuid(simon.getUuid())
.setTags(asList("bug", "owasp"))
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();
.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")
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();
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)
.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)
.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)
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();
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();
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());
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)
.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)
.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)
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);
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)
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)
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)
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();
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();