Search in sources :

Example 1 with IssueMapper

use of org.sonar.db.issue.IssueMapper in project sonarqube by SonarSource.

the class UpdateConflictResolverTest method should_reload_issue_and_resolve_conflict.

@Test
public void should_reload_issue_and_resolve_conflict() {
    DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setType(RuleType.CODE_SMELL).setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false).setStatus(Issue.STATUS_OPEN);
    // Issue as seen and changed by end-user
    IssueMapper mapper = mock(IssueMapper.class);
    when(mapper.selectByKey("ABCDE")).thenReturn(new IssueDto().setKee("ABCDE").setType(RuleType.CODE_SMELL).setRuleId(10).setRuleKey("squid", "AvoidCycles").setComponentKey("struts:org.apache.struts.Action").setLine(10).setStatus(Issue.STATUS_OPEN).setAssignee("arthur"));
    new UpdateConflictResolver().resolve(issue, mapper);
    ArgumentCaptor<IssueDto> argument = ArgumentCaptor.forClass(IssueDto.class);
    verify(mapper).update(argument.capture());
    IssueDto updatedIssue = argument.getValue();
    assertThat(updatedIssue.getKee()).isEqualTo("ABCDE");
    assertThat(updatedIssue.getAssignee()).isEqualTo("arthur");
}
Also used : IssueMapper(org.sonar.db.issue.IssueMapper) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 2 with IssueMapper

use of org.sonar.db.issue.IssueMapper in project sonarqube by SonarSource.

the class PersistIssuesStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(true);
        CloseableIterator<DefaultIssue> issues = issueCache.traverse()) {
        IssueMapper mapper = dbSession.getMapper(IssueMapper.class);
        IssueChangeMapper changeMapper = dbSession.getMapper(IssueChangeMapper.class);
        while (issues.hasNext()) {
            DefaultIssue issue = issues.next();
            boolean saved = persistIssueIfRequired(mapper, issue);
            if (saved) {
                insertChanges(changeMapper, issue);
            }
        }
        dbSession.flushStatements();
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueMapper(org.sonar.db.issue.IssueMapper) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Aggregations

DefaultIssue (org.sonar.core.issue.DefaultIssue)2 IssueMapper (org.sonar.db.issue.IssueMapper)2 Test (org.junit.Test)1 DbSession (org.sonar.db.DbSession)1 IssueChangeMapper (org.sonar.db.issue.IssueChangeMapper)1 IssueDto (org.sonar.db.issue.IssueDto)1