use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method update_conflicting_issue.
@Test
public void update_conflicting_issue() {
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
db.rules().insert(rule);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project, null));
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setCreatedAt(NOW - 1_000_000_000L).setUpdatedAt(NOW + 1_000_000_000L));
issue = dbClient.issueDao().selectByKey(db.getSession(), issue.getKey()).get();
DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
when(system2.now()).thenReturn(NOW);
DefaultIssue defaultIssue = issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true);
issueCacheAppender.append(defaultIssue).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
ArgumentCaptor<IssueDto> issueDtoCaptor = ArgumentCaptor.forClass(IssueDto.class);
verify(conflictResolver).resolve(eq(defaultIssue), issueDtoCaptor.capture(), any(IssueMapper.class));
assertThat(issueDtoCaptor.getValue().getKey()).isEqualTo(issue.getKey());
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "1"));
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method insert_copied_issue_with_minimal_info.
@Test
public void insert_copied_issue_with_minimal_info() {
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
db.rules().insert(rule);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project, null));
when(system2.now()).thenReturn(NOW);
String issueKey = "ISSUE-2";
protoIssueCache.newAppender().append(new DefaultIssue().setKey(issueKey).setType(RuleType.CODE_SMELL).setRuleKey(rule.getKey()).setComponentUuid(file.uuid()).setComponentKey(file.getKey()).setProjectUuid(project.uuid()).setProjectKey(project.getKey()).setSeverity(BLOCKER).setStatus(STATUS_OPEN).setNew(false).setIsOnReferencedBranch(true).setCopied(true).setType(RuleType.BUG).setCreationDate(new Date(NOW)).setSelectedAt(NOW)).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
IssueDto result = dbClient.issueDao().selectOrFailByKey(session, issueKey);
assertThat(result.getKey()).isEqualTo(issueKey);
assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
assertThat(result.getSeverity()).isEqualTo(BLOCKER);
assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
assertThat(result.getTags()).isEmpty();
assertThat(result.isNewCodeReferenceIssue()).isFalse();
assertThat(dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey))).isEmpty();
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_project_and_associated_data.
@Test
public void delete_project_and_associated_data() {
RuleDefinitionDto 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"));
ComponentDto file = db.components().insertComponent(newFileDto(directory));
SnapshotDto analysis = db.components().insertSnapshot(project);
IssueDto issue1 = db.issues().insert(rule, project, file);
IssueChangeDto issueChange1 = db.issues().insertChange(issue1);
IssueDto issue2 = db.issues().insert(rule, project, file);
FileSourceDto fileSource = db.fileSources().insertFileSource(file);
db.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue1));
ComponentDto otherProject = db.components().insertPrivateProject();
ComponentDto otherModule = db.components().insertComponent(newModuleDto(otherProject));
ComponentDto otherDirectory = db.components().insertComponent(newDirectory(otherModule, "a/b"));
ComponentDto otherFile = db.components().insertComponent(newFileDto(otherDirectory));
SnapshotDto otherAnalysis = db.components().insertSnapshot(otherProject);
IssueDto otherIssue1 = db.issues().insert(rule, otherProject, otherFile);
IssueChangeDto otherIssueChange1 = db.issues().insertChange(otherIssue1);
IssueDto otherIssue2 = db.issues().insert(rule, otherProject, otherFile);
FileSourceDto otherFileSource = db.fileSources().insertFileSource(otherFile);
db.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(otherIssue1));
underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
dbSession.commit();
assertThat(uuidsIn("components")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid());
assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid());
assertThat(uuidsIn("snapshots")).containsOnly(otherAnalysis.getUuid());
assertThat(uuidsIn("issues", "kee")).containsOnly(otherIssue1.getKey(), otherIssue2.getKey());
assertThat(uuidsIn("issue_changes", "kee")).containsOnly(otherIssueChange1.getKey());
assertThat(uuidsIn("new_code_reference_issues", "issue_key")).containsOnly(otherIssue1.getKey());
assertThat(uuidsIn("file_sources", "file_uuid")).containsOnly(otherFileSource.getFileUuid());
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_disabled_components_without_issues.
@Test
public void delete_disabled_components_without_issues() {
ComponentDto project = db.components().insertPublicProject(p -> p.setEnabled(true));
ComponentDto enabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(true));
ComponentDto disabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(false));
ComponentDto enabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(true));
ComponentDto disabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(false));
RuleDefinitionDto rule = db.rules().insert();
IssueDto closed1 = db.issues().insert(rule, project, enabledFileWithIssues, issue -> {
issue.setStatus("CLOSED");
issue.setResolution(Issue.RESOLUTION_FIXED);
issue.setIssueCloseDate(new Date());
});
IssueDto closed2 = db.issues().insert(rule, project, disabledFileWithIssues, issue -> {
issue.setStatus("CLOSED");
issue.setResolution(Issue.RESOLUTION_FIXED);
issue.setIssueCloseDate(new Date());
});
PurgeListener purgeListener = mock(PurgeListener.class);
Set<String> disabledComponentUuids = ImmutableSet.of(disabledFileWithIssues.uuid(), disabledFileWithoutIssues.uuid());
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid(), disabledComponentUuids), purgeListener, new PurgeProfiler());
assertThat(db.getDbClient().componentDao().selectByProjectUuid(project.uuid(), dbSession)).extracting("uuid").containsOnly(project.uuid(), enabledFileWithIssues.uuid(), disabledFileWithIssues.uuid(), enabledFileWithoutIssues.uuid());
verify(purgeListener).onComponentsDisabling(project.uuid(), disabledComponentUuids);
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PurgeDaoTest method close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration.
@Test
public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
db.components().insertSnapshot(project);
db.components().insertSnapshot(project);
db.components().insertSnapshot(project, s -> s.setLast(false));
ComponentDto module = db.components().insertComponent(newModuleDto(project).setEnabled(false));
ComponentDto dir = db.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
ComponentDto srcFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
ComponentDto testFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
ComponentDto enabledFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(true));
IssueDto openOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
IssueDto confirmOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
IssueDto openOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
IssueDto confirmOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("CONFIRM"));
IssueDto openOnEnabledComponent = db.issues().insert(rule, project, enabledFile, issue -> issue.setStatus("OPEN"));
IssueDto confirmOnEnabledComponent = db.issues().insert(rule, project, enabledFile, issue -> issue.setStatus("CONFIRM"));
assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isZero();
assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isZero();
assertThat(db.countSql("select count(*) from issues where resolution = 'REMOVED'")).isZero();
db.fileSources().insertFileSource(srcFile);
FileSourceDto nonSelectedFileSource = db.fileSources().insertFileSource(enabledFile);
assertThat(db.countRowsOfTable("file_sources")).isEqualTo(2);
MetricDto metric1 = db.measures().insertMetric();
MetricDto metric2 = db.measures().insertMetric();
LiveMeasureDto liveMeasureMetric1OnFile = db.measures().insertLiveMeasure(srcFile, metric1);
LiveMeasureDto liveMeasureMetric2OnFile = db.measures().insertLiveMeasure(srcFile, metric2);
LiveMeasureDto liveMeasureMetric1OnDir = db.measures().insertLiveMeasure(dir, metric1);
LiveMeasureDto liveMeasureMetric2OnDir = db.measures().insertLiveMeasure(dir, metric2);
LiveMeasureDto liveMeasureMetric1OnProject = db.measures().insertLiveMeasure(project, metric1);
LiveMeasureDto liveMeasureMetric2OnProject = db.measures().insertLiveMeasure(project, metric2);
LiveMeasureDto liveMeasureMetric1OnNonSelected = db.measures().insertLiveMeasure(enabledFile, metric1);
LiveMeasureDto liveMeasureMetric2OnNonSelected = db.measures().insertLiveMeasure(enabledFile, metric2);
assertThat(db.countRowsOfTable("live_measures")).isEqualTo(8);
PurgeListener purgeListener = mock(PurgeListener.class);
// back to present
Set<String> selectedComponentUuids = ImmutableSet.of(module.uuid(), srcFile.uuid(), testFile.uuid());
underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid(), project.uuid(), selectedComponentUuids), purgeListener, new PurgeProfiler());
dbSession.commit();
verify(purgeListener).onComponentsDisabling(project.uuid(), selectedComponentUuids);
verify(purgeListener).onComponentsDisabling(project.uuid(), ImmutableSet.of(dir.uuid()));
// set purge_status=1 for non-last snapshot
assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isOne();
// close open issues of selected
assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4);
for (IssueDto issue : Arrays.asList(openOnFile, confirmOnFile, openOnDir, confirmOnDir)) {
assertThat(db.getDbClient().issueDao().selectOrFailByKey(dbSession, issue.getKey())).extracting(IssueDto::getStatus, IssueDto::getResolution).containsExactlyInAnyOrder("CLOSED", "REMOVED");
}
for (IssueDto issue : Arrays.asList(openOnEnabledComponent, confirmOnEnabledComponent)) {
assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get()).extracting("status", "resolution").containsExactlyInAnyOrder(issue.getStatus(), null);
}
// delete file sources of selected
assertThat(db.countRowsOfTable("file_sources")).isOne();
assertThat(db.getDbClient().fileSourceDao().selectByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
// deletes live measure of selected
assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4);
List<LiveMeasureDto> liveMeasureDtos = db.getDbClient().liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), enabledFile.uuid()), ImmutableSet.of(metric1.getUuid(), metric2.getUuid()));
assertThat(liveMeasureDtos).extracting(LiveMeasureDto::getComponentUuid).containsOnly(enabledFile.uuid(), project.uuid());
assertThat(liveMeasureDtos).extracting(LiveMeasureDto::getMetricUuid).containsOnly(metric1.getUuid(), metric2.getUuid());
}
Aggregations