use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class ScrollForFileMoveComponentDaoTest method insertFileAndSource.
private ComponentAndSource insertFileAndSource(ComponentDto parent, String qualifier) {
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(parent).setQualifier(qualifier));
FileSourceDto fileSource = db.fileSources().insertFileSource(file);
return new ComponentAndSource(file, fileSource);
}
use of org.sonar.db.source.FileSourceDto 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.source.FileSourceDto 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());
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class SourceService method getLines.
private <E> Optional<Iterable<E>> getLines(DbSession dbSession, String fileUuid, int from, int toInclusive, Function<DbFileSources.Line, E> function) {
verifyLine(from);
checkArgument(toInclusive >= from, String.format("Line number must greater than or equal to %d, got %d", from, toInclusive));
FileSourceDto dto = dbClient.fileSourceDao().selectByFileUuid(dbSession, fileUuid);
if (dto == null) {
return Optional.empty();
}
return Optional.of(dto.getSourceData().getLinesList().stream().filter(line -> line.hasLine() && line.getLine() >= from).limit((toInclusive - from) + 1L).map(function).collect(MoreCollectors.toList()));
}
use of org.sonar.db.source.FileSourceDto in project sonarqube by SonarSource.
the class LinesActionTest method insertFileWithData.
private ComponentDto insertFileWithData(DbFileSources.Data fileData, ComponentDto project) {
ComponentDto file = insertFile(project);
db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto().setUuid(Uuids.createFast()).setProjectUuid(project.projectUuid()).setFileUuid(file.uuid()).setSourceData(fileData));
db.commit();
return file;
}
Aggregations