Search in sources :

Example 51 with DefaultIssue

use of org.sonar.core.issue.DefaultIssue 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 52 with DefaultIssue

use of org.sonar.core.issue.DefaultIssue 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 53 with DefaultIssue

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

the class ServerIssueStorageTest method load_component_id_from_db.

@Test
public void load_component_id_from_db() {
    dbTester.prepareDbUnit(getClass(), "load_component_id_from_db.xml");
    long componentId = storage.component(dbTester.getSession(), new DefaultIssue().setComponentKey("struts:Action")).getId();
    assertThat(componentId).isEqualTo(100);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 54 with DefaultIssue

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

the class ServerIssueStorageTest method load_project_id_from_db.

@Test
public void load_project_id_from_db() {
    dbTester.prepareDbUnit(getClass(), "load_project_id_from_db.xml");
    long projectId = storage.project(dbTester.getSession(), new DefaultIssue().setProjectKey("struts")).getId();
    assertThat(projectId).isEqualTo(1);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 55 with DefaultIssue

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

the class SetSeverityActionTest method support_only_issues_with_issue_admin_permission.

@Test
public void support_only_issues_with_issue_admin_permission() {
    DefaultIssue authorizedIssue = newIssue().setSeverity(MAJOR).toDefaultIssue();
    setUserWithBrowseAndAdministerIssuePermission(authorizedIssue.projectUuid());
    DefaultIssue unauthorizedIssue = newIssue().setSeverity(MAJOR).toDefaultIssue();
    assertThat(action.supports(authorizedIssue.setResolution(null))).isTrue();
    assertThat(action.supports(unauthorizedIssue.setResolution(null))).isFalse();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

DefaultIssue (org.sonar.core.issue.DefaultIssue)140 Test (org.junit.Test)120 Date (java.util.Date)27 ActiveRule (org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule)15 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)14 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)8 IssueDto (org.sonar.db.issue.IssueDto)8 DbSession (org.sonar.db.DbSession)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Issue (org.sonar.api.issue.Issue)4 FieldDiffs (org.sonar.core.issue.FieldDiffs)4 ArrayList (java.util.ArrayList)3 RuleKey (org.sonar.api.rule.RuleKey)3 User (org.sonar.api.user.User)3 IssueChangeMapper (org.sonar.db.issue.IssueChangeMapper)3 IssueMapper (org.sonar.db.issue.IssueMapper)3 RuleDto (org.sonar.db.rule.RuleDto)3 IssueChangeNotification (org.sonar.server.issue.notification.IssueChangeNotification)3 DefaultUser (org.sonar.core.user.DefaultUser)2 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)2