Search in sources :

Example 1 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class DoTransitionAction method doTransition.

private void doTransition(DbSession session, DefaultIssue defaultIssue, String transitionKey) {
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
    transitionService.checkTransitionPermission(transitionKey, defaultIssue);
    if (transitionService.doTransition(defaultIssue, context, transitionKey)) {
        issueUpdater.saveIssue(session, defaultIssue, context, null);
    }
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) Date(java.util.Date)

Example 2 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class IssueUpdaterTest method update_issue.

@Test
public void update_issue() throws Exception {
    DefaultIssue issue = issueDbTester.insertIssue(newIssue().setSeverity(MAJOR)).toDefaultIssue();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
    issueFieldsSetter.setSeverity(issue, BLOCKER, context);
    underTest.saveIssue(dbTester.getSession(), issue, context, null);
    IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issue.key()).get();
    assertThat(issueReloaded.getSeverity()).isEqualTo(BLOCKER);
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Example 3 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_notification_when_issue_is_linked_on_removed_rule.

@Test
public void verify_notification_when_issue_is_linked_on_removed_rule() throws Exception {
    RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
    ComponentDto project = componentDbTester.insertProject();
    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
    DefaultIssue issue = issueDbTester.insertIssue(newDto(rule, file, project)).setSeverity(MAJOR).toDefaultIssue();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
    issueFieldsSetter.setSeverity(issue, BLOCKER, context);
    underTest.saveIssue(dbTester.getSession(), issue, context, null);
    verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
    assertThat(notificationArgumentCaptor.getValue().getFieldValue("ruleName")).isNull();
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) RuleTesting.newRuleDto(org.sonar.db.rule.RuleTesting.newRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Example 4 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class ServerIssueStorageTest method should_update_issues.

@Test
public void should_update_issues() {
    dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
    // override generated key
    comment.setKey("FGHIJ");
    Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000");
    DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setType(RuleType.BUG).setNew(false).setChanged(true).setLine(5000).setProjectUuid("CDEF").setEffort(Duration.create(10L)).setChecksum("FFFFF").setAuthorLogin("simon").setAssignee("loic").setFieldChange(context, "severity", "INFO", "BLOCKER").setResolution("FIXED").setStatus("RESOLVED").setSeverity("BLOCKER").setAttribute("foo", "bar").addComment(comment).setCreationDate(date).setUpdateDate(date).setCloseDate(date).setRuleKey(RuleKey.of("xxx", "unknown")).setComponentKey("struts:Action").setProjectKey("struts");
    storage.save(issue);
    dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] { "id", "created_at", "updated_at", "issue_change_creation_date" }, "issues", "issue_changes");
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) Test(org.junit.Test)

Example 5 with IssueChangeContext

use of org.sonar.core.issue.IssueChangeContext in project sonarqube by SonarSource.

the class MovedIssueVisitorTest method onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed.

@Test
public void onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed() {
    MovedFilesRepository.OriginalFile originalFile = new MovedFilesRepository.OriginalFile("original uuid", "original key");
    DefaultIssue issue = mockIssue(originalFile.getUuid());
    when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(Optional.of(originalFile));
    underTest.onIssue(FILE, issue);
    verify(issue).setComponentUuid(FILE.getUuid());
    verify(issue).setComponentKey(FILE.getKey());
    verify(issue).setModuleUuid(null);
    verify(issue).setModuleUuidPath(null);
    verify(issue).setChanged(true);
    ArgumentCaptor<IssueChangeContext> issueChangeContextCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
    verify(issue).setFieldChange(issueChangeContextCaptor.capture(), eq("file"), eq(originalFile.getUuid()), eq(FILE.getUuid()));
    assertThat(issueChangeContextCaptor.getValue().date()).isEqualTo(new Date(ANALYSIS_DATE));
    assertThat(issueChangeContextCaptor.getValue().userUuid()).isNull();
    assertThat(issueChangeContextCaptor.getValue().scan()).isFalse();
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) MovedFilesRepository(org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Aggregations

IssueChangeContext (org.sonar.core.issue.IssueChangeContext)34 DefaultIssue (org.sonar.core.issue.DefaultIssue)33 Date (java.util.Date)30 IssueDto (org.sonar.db.issue.IssueDto)23 Test (org.junit.Test)19 ComponentDto (org.sonar.db.component.ComponentDto)17 DbSession (org.sonar.db.DbSession)13 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)12 UserDto (org.sonar.db.user.UserDto)12 DbClient (org.sonar.db.DbClient)9 WebIssueStorage (org.sonar.server.issue.WebIssueStorage)9 IssuesChangesNotificationBuilder (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder)9 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)9 UserChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange)9 IssuesChangesNotificationSerializer (org.sonar.server.issue.notification.IssuesChangesNotificationSerializer)9 NotificationManager (org.sonar.server.notification.NotificationManager)9 RuleStatus (org.sonar.api.rule.RuleStatus)8 BLOCKER (org.sonar.api.rule.Severity.BLOCKER)8 System2 (org.sonar.api.utils.System2)8 BranchType (org.sonar.db.component.BranchType)8