.setComponentKey("org.sonar.sample:Sample") .setComponentUuid("CDEF") .setProjectUuid("GHIJ") .setModuleUuid("BCDE") .setModuleUuidPath("ABCD.BCDE.")
@SafeVarargs private final IssueDto insertNewClosedIssue(ComponentDto component, RuleDefinitionDto rule, long issueCloseTime, Consumer<IssueDto>... consumers) { IssueDto res = new IssueDto() .setKee(UuidFactoryFast.getInstance().create()) .setRuleId(rule.getId()) .setType(rule.getType()) .setComponentUuid(component.uuid()) .setProjectUuid(component.projectUuid()) .setStatus(Issue.STATUS_CLOSED) .setIssueCloseTime(issueCloseTime); Arrays.asList(consumers).forEach(c -> c.accept(res)); underTest.insert(res); dbSession.commit(); return res; }
@Test public void should_reload_issue_and_resolve_conflict() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setType(CODE_SMELL) .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setProjectUuid("U1") .setComponentUuid("U2") .setNew(false) .setStatus(STATUS_OPEN); // Issue as seen and changed by end-user IssueMapper mapper = mock(IssueMapper.class); IssueDto issueDto = new IssueDto() .setKee("ABCDE") .setType(CODE_SMELL) .setRuleId(10) .setRuleKey("squid", "AvoidCycles") .setProjectUuid("U1") .setComponentUuid("U2") .setLine(10) .setStatus(STATUS_OPEN) // field changed by user .setAssigneeUuid("arthur-uuid"); new UpdateConflictResolver().resolve(issue, issueDto, mapper); ArgumentCaptor<IssueDto> argument = ArgumentCaptor.forClass(IssueDto.class); verify(mapper).update(argument.capture()); IssueDto updatedIssue = argument.getValue(); assertThat(updatedIssue.getKee()).isEqualTo("ABCDE"); assertThat(updatedIssue.getAssigneeUuid()).isEqualTo("arthur-uuid"); }
@Test public void commitAndIndexIssues_removes_issue_from_index_if_it_does_not_exist_in_db() { IssueDto issue1 = new IssueDto().setKee("I1").setProjectUuid("P1"); addIssueToIndex(issue1.getProjectUuid(), issue1.getKey()); IssueDto issue2 = db.issues().insertIssue(organization); underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2)); // issue1 is removed from index, issue2 is persisted and indexed assertThatIndexHasOnly(issue2); assertThatDbHasOnly(issue2); assertThatEsQueueTableHasSize(0); }
@Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_orphan_component(RuleType ruleType) { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto component = randomComponent(organization); IssueDto issue = insertNewClosedIssue(component, ruleType); IssueChangeDto issueChange = insertToClosedDiff(issue); IssueDto issueMissingComponent = insertNewClosedIssue(component, ruleType, t -> t.setComponentUuid("does_not_exist")); insertToClosedDiff(issueMissingComponent); IssueDto issueMissingProject = insertNewClosedIssue(component, ruleType, t -> t.setProjectUuid("does_not_exist")); insertToClosedDiff(issueMissingProject); RecorderResultHandler resultHandler = new RecorderResultHandler(); underTest.scrollClosedByComponentUuid(component.uuid(), NO_FILTERING_ON_CLOSE_DATE, resultHandler); assertThat(resultHandler.issues) .extracting(IssueDto::getKey, t -> t.getClosedChangeData().get()) .containsOnly(tuple(issue.getKey(), issueChange.getChangeData())); }
private void prepareTables() { db.rules().insertRule(RULE.setIsExternal(true)); OrganizationDto organizationDto = db.organizations().insert(); ComponentDto projectDto = db.components().insertPrivateProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY)); db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setDbKey(FILE_KEY)); underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY1) .setMessage("the message") .setRuleId(RULE.getId()) .setComponentUuid(FILE_UUID) .setProjectUuid(PROJECT_UUID)); underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY2) .setRuleId(RULE.getId()) .setComponentUuid(FILE_UUID) .setProjectUuid(PROJECT_UUID)); db.getSession().commit(); }
.setModuleUuid(issue.moduleUuid()) .setModuleUuidPath(issue.moduleUuidPath()) .setProjectUuid(issue.projectUuid()) .setProjectKey(issue.projectKey()) .setIssueCreationDate(issue.creationDate())
.setModuleUuid(issue.moduleUuid()) .setModuleUuidPath(issue.moduleUuidPath()) .setProjectUuid(issue.projectUuid()) .setProjectKey(issue.projectKey()) .setIssueAttributes(KeyValueFormat.format(issue.attributes()))
public static IssueDto createFor(Project project, RuleDto rule) { return new IssueDto() .setProjectUuid(project.getUuid()) .setRuleId(rule.getId()) .setKee(Uuids.create()); }
.setModuleUuid(issue.moduleUuid()) .setModuleUuidPath(issue.moduleUuidPath()) .setProjectUuid(issue.projectUuid()) .setProjectKey(issue.projectKey()) .setIssueCreationDate(issue.creationDate())
.setModuleUuid(issue.moduleUuid()) .setModuleUuidPath(issue.moduleUuidPath()) .setProjectUuid(issue.projectUuid()) .setProjectKey(issue.projectKey()) .setIssueAttributes(KeyValueFormat.format(issue.attributes()))