use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class SiblingComponentsWithOpenIssuesTest method should_find_sibling_components_with_open_issues_from_pullrequest.
@Test
public void should_find_sibling_components_with_open_issues_from_pullrequest() {
ComponentDto project = db.components().insertPublicProject();
setRoot(project);
setBranch(BranchType.BRANCH);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST), b -> b.setMergeBranchUuid(project.uuid()));
RuleDefinitionDto rule = db.rules().insert();
ComponentDto fileWithResolvedIssueOnPullrequest = db.components().insertComponent(ComponentTesting.newFileDto(pullRequest, null));
db.issues().insert(rule, pullRequest, fileWithResolvedIssueOnPullrequest, i -> i.setStatus("RESOLVED"));
underTest = new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, db.getDbClient());
assertThat(underTest.getUuids(fileWithResolvedIssueOnPullrequest.getKey())).hasSize(1);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ComponentIssuesLoaderTest method loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago.
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));
Date[] issueDates = new Date[] { addDays(NOW, -10), addDays(NOW, -31), addDays(NOW, -30), DATE_LIMIT_30_DAYS_BACK_MIDNIGHT, addDays(NOW, -29), addDays(NOW, -60) };
IssueDto[] issues = Arrays.stream(issueDates).map(issueDate -> {
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));
return closedIssue;
}).toArray(IssueDto[]::new);
when(system2.now()).thenReturn(NOW.getTime());
List<DefaultIssue> defaultIssues = underTest.loadClosedIssues(file.uuid());
assertThat(defaultIssues).extracting(DefaultIssue::key).containsOnly(issues[0].getKey(), issues[2].getKey(), issues[3].getKey(), issues[4].getKey());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ComponentIssuesLoaderTest method loadClosedIssues_returns_single_DefaultIssue_with_null_line_if_first_row_has_no_line_diff.
@Test
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));
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));
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 2), null));
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30));
when(system2.now()).thenReturn(NOW.getTime());
ComponentIssuesLoader underTest = newComponentIssuesLoader(newEmptySettings());
List<DefaultIssue> defaultIssues = underTest.loadClosedIssues(file.uuid());
assertThat(defaultIssues).hasSize(1);
assertThat(defaultIssues.iterator().next().getLine()).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ComponentIssuesLoaderTest method loadClosedIssues_returns_single_DefaultIssue_by_issue_based_on_first_row.
@Test
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));
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));
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 3), 20));
db.issues().insertFieldDiffs(issue, newToClosedDiffsWithLine(addDays(issueDate, 1), 30));
when(system2.now()).thenReturn(NOW.getTime());
ComponentIssuesLoader underTest = newComponentIssuesLoader(newEmptySettings());
List<DefaultIssue> defaultIssues = underTest.loadClosedIssues(file.uuid());
assertThat(defaultIssues).hasSize(1);
assertThat(defaultIssues.iterator().next().getLine()).isEqualTo(20);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ComponentIssuesLoaderTest method loadLatestDiffChangesForReopeningOfClosedIssues_adds_2_diff_changes_if_most_recent_status_and_resolution_are_not_the_same_diff.
@Test
public void loadLatestDiffChangesForReopeningOfClosedIssues_adds_2_diff_changes_if_most_recent_status_and_resolution_are_not_the_same_diff() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
RuleDefinitionDto rule = db.rules().insert();
IssueDto issue = db.issues().insert(rule, project, file);
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5));
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2", "resolution", "valRes2")).setIssueChangeCreationDate(19));
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3")).setIssueChangeCreationDate(20));
db.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13));
ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null, /* not used in method */
null, /* not used in method */
newConfiguration("0"), null);
DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey());
underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue));
assertThat(defaultIssue.changes()).hasSize(2);
assertThat(defaultIssue.changes()).extracting(t -> t.get("status")).filteredOn(t -> hasValue(t, "valStatus3")).hasSize(1);
assertThat(defaultIssue.changes()).extracting(t -> t.get("resolution")).filteredOn(t -> hasValue(t, "valRes2")).hasSize(1);
}
Aggregations