use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class ProjectTrackerBaseLazyInputTest method migrate_and_return_module_and_folder_issues_on_module.
@Test
public void migrate_and_return_module_and_folder_issues_on_module() {
ComponentDto module = dbTester.components().insertComponent(newModuleDto(rootProjectDto).setPath("moduleAInDb"));
when(reportModulesPath.get()).thenReturn(ImmutableMap.of(module.getDbKey(), "moduleAInReport"));
ComponentDto folder = dbTester.components().insertComponent(newDirectory(module, "src"));
ComponentDto file = dbTester.components().insertComponent(newFileDto(module));
IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null));
IssueDto openIssueOnModule = dbTester.issues().insert(rule, rootProjectDto, module, i -> i.setStatus("OPEN").setMessage("Issue on module").setResolution(null));
IssueDto openIssueOnDir = dbTester.issues().insert(rule, rootProjectDto, folder, i -> i.setStatus("OPEN").setMessage("Issue on dir").setResolution(null));
IssueDto openIssue1OnFile = dbTester.issues().insert(rule, rootProjectDto, file, i -> i.setStatus("OPEN").setResolution(null));
assertThat(underTest.loadIssues()).extracting(DefaultIssue::key, DefaultIssue::getMessage).containsExactlyInAnyOrder(tuple(openIssueOnProject.getKey(), openIssueOnProject.getMessage()), tuple(openIssueOnModule.getKey(), "[moduleAInReport] Issue on module"), tuple(openIssueOnDir.getKey(), "[moduleAInReport/src] Issue on dir"));
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method add_change.
@Test
public void add_change() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = db.rules().insert();
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));
DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
issueCacheAppender.append(issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true).setCurrentChange(new FieldDiffs().setIssueKey("ISSUE").setUserUuid("john_uuid").setDiff("technicalDebt", null, 1L).setCreationDate(new Date(NOW)))).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
assertThat(issueChangeDto).extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey, IssueChangeDto::getIssueChangeCreationDate).containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john_uuid", "technicalDebt=1", issue.getKey(), NOW);
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "0"));
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method insert_merged_issue.
@Test
public void insert_merged_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));
when(system2.now()).thenReturn(NOW);
String issueKey = "ISSUE-3";
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(true).setIsOnReferencedBranch(true).setIsOnChangedLine(true).setCopied(true).setType(RuleType.BUG).setCreationDate(new Date(NOW)).setSelectedAt(NOW).addComment(new DefaultIssueComment().setKey("COMMENT").setIssueKey(issueKey).setUserUuid("john_uuid").setMarkdownText("Some text").setUpdatedAt(new Date(NOW)).setCreatedAt(new Date(NOW)).setNew(true)).setCurrentChange(new FieldDiffs().setIssueKey(issueKey).setUserUuid("john_uuid").setDiff("technicalDebt", null, 1L).setCreationDate(new Date(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.isNewCodeReferenceIssue()).isTrue();
List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey));
assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE);
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 ExportIssuesStepTest method verify_field_by_field_mapping.
@Test
public void verify_field_by_field_mapping() {
String componentUuid = "component uuid";
long componentRef = 5454;
componentRepository.register(componentRef, componentUuid, false);
IssueDto issueDto = new IssueDto().setKee("issue uuid").setComponentUuid(componentUuid).setType(988).setMessage("msg").setLine(10).setChecksum("checksum").setResolution("resolution").setSeverity("severity").setManualSeverity(true).setGap(13.13d).setEffort(99L).setAssigneeUuid("assignee-uuid").setAuthorLogin("author").setTagsString("tags").setIssueCreationTime(963L).setIssueUpdateTime(852L).setIssueCloseTime(741L);
// fields tested separately and/or required to match SQL request
issueDto.setType(RuleType.CODE_SMELL).setLocations(Locations.newBuilder().addFlow(DbIssues.Flow.newBuilder()).build()).setRuleUuid(readyRuleDto.getUuid()).setStatus(STATUS_OPEN).setProjectUuid(SOME_PROJECT_UUID);
insertIssue(issueDto);
underTest.execute(new TestComputationStepContext());
ProjectDump.Issue issue = getWrittenIssue();
assertThat(issue.getUuid()).isEqualTo(issueDto.getKey());
assertThat(issue.getComponentRef()).isEqualTo(componentRef);
assertThat(issue.getType()).isEqualTo(issueDto.getType());
assertThat(issue.getMessage()).isEqualTo(issueDto.getMessage());
assertThat(issue.getLine()).isEqualTo(issueDto.getLine());
assertThat(issue.getChecksum()).isEqualTo(issueDto.getChecksum());
assertThat(issue.getStatus()).isEqualTo(issueDto.getStatus());
assertThat(issue.getResolution()).isEqualTo(issueDto.getResolution());
assertThat(issue.getSeverity()).isEqualTo(issueDto.getSeverity());
assertThat(issue.getManualSeverity()).isEqualTo(issueDto.isManualSeverity());
assertThat(issue.getGap()).isEqualTo(issueDto.getGap());
assertThat(issue.getEffort()).isEqualTo(issueDto.getEffort());
assertThat(issue.getAssignee()).isEqualTo(issueDto.getAssigneeUuid());
assertThat(issue.getAuthor()).isEqualTo(issueDto.getAuthorLogin());
assertThat(issue.getTags()).isEqualTo(issueDto.getTagsString());
assertThat(issue.getIssueCreatedAt()).isEqualTo(issueDto.getIssueCreationTime());
assertThat(issue.getIssueUpdatedAt()).isEqualTo(issueDto.getIssueUpdateTime());
assertThat(issue.getIssueClosedAt()).isEqualTo(issueDto.getIssueCloseTime());
assertThat(issue.getLocations()).isNotEmpty();
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class ExportAdHocRulesStepTest method insertIssue.
private void insertIssue(RuleDto ruleDto, String projectUuid, String componentUuid) {
IssueDto dto = createBaseIssueDto(ruleDto, projectUuid, componentUuid);
insertIssue(dto);
}
Aggregations