public Collection<ShortBranchIssue> loadCandidateIssuesForMergingInTargetBranch(Component component) { String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getDbKey()); Set<String> uuids = shortBranchComponentsWithIssues.getUuids(componentKey); if (uuids.isEmpty()) { return Collections.emptyList(); } try (DbSession session = dbClient.openSession(false)) { return dbClient.issueDao().selectOpenByComponentUuids(session, uuids) .stream() .map(ShortBranchIssuesLoader::toShortBranchIssue) .collect(Collectors.toList()); } }
@Test public void selectOpenByComponentUuid_should_correctly_map_required_fields() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo") .setBranchType(BranchType.SHORT)); ComponentDto file = db.components().insertComponent(newFileDto(projectBranch)); IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus("RESOLVED").setResolution("FALSE-POSITIVE")); ShortBranchIssueDto fp = underTest.selectOpenByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())).get(0); assertThat(fp.getLine()).isEqualTo(fpIssue.getLine()); assertThat(fp.getMessage()).isEqualTo(fpIssue.getMessage()); assertThat(fp.getChecksum()).isEqualTo(fpIssue.getChecksum()); assertThat(fp.getRuleKey()).isEqualTo(fpIssue.getRuleKey()); assertThat(fp.getStatus()).isEqualTo(fpIssue.getStatus()); assertThat(fp.getLine()).isNotNull(); assertThat(fp.getLine()).isNotZero(); assertThat(fp.getMessage()).isNotNull(); assertThat(fp.getChecksum()).isNotNull(); assertThat(fp.getChecksum()).isNotEmpty(); assertThat(fp.getRuleKey()).isNotNull(); assertThat(fp.getStatus()).isNotNull(); assertThat(fp.getBranchName()).isEqualTo("feature/foo"); assertThat(fp.getIssueCreationDate()).isNotNull(); }
@Test public void selectOpenByComponentUuid() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo") .setBranchType(BranchType.SHORT)); ComponentDto file = db.components().insertComponent(newFileDto(projectBranch)); IssueDto openIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_OPEN).setResolution(null)); IssueDto closedIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)); IssueDto reopenedIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_REOPENED).setResolution(null)); IssueDto confirmedIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_CONFIRMED).setResolution(null)); IssueDto wontfixIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_RESOLVED).setResolution(Issue.RESOLUTION_WONT_FIX)); IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus(Issue.STATUS_RESOLVED).setResolution(Issue.RESOLUTION_FALSE_POSITIVE)); assertThat(underTest.selectOpenByComponentUuids(db.getSession(), Collections.singletonList(file.uuid()))) .extracting("kee") .containsOnly(openIssue.getKey(), reopenedIssue.getKey(), confirmedIssue.getKey(), wontfixIssue.getKey(), fpIssue.getKey()); }
public Collection<ShortBranchIssue> loadCandidateIssuesForMergingInTargetBranch(Component component) { String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getKey()); Set<String> uuids = shortBranchComponentsWithIssues.getUuids(componentKey); if (uuids.isEmpty()) { return Collections.emptyList(); } try (DbSession session = dbClient.openSession(false)) { return dbClient.issueDao().selectOpenByComponentUuids(session, uuids) .stream() .map(ShortBranchIssuesLoader::toShortBranchIssue) .collect(Collectors.toList()); } }