Search in sources :

Example 36 with DefaultIssue

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

the class NewEffortAggregatorTest method no_measures_if_no_periods.

@Test
public void no_measures_if_no_periods() {
    periodsHolder.setPeriod(null);
    DefaultIssue unresolved = new DefaultIssue().setEffort(Duration.create(10));
    verifyZeroInteractions(calculator);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, unresolved);
    underTest.afterComponent(FILE);
    assertThat(measureRepository.getRawMeasures(FILE)).isEmpty();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 37 with DefaultIssue

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

the class NewEffortAggregatorTest method new_reliability_effort_is_only_computed_using_bug_issues.

@Test
public void new_reliability_effort_is_only_computed_using_bug_issues() {
    periodsHolder.setPeriod(PERIOD);
    DefaultIssue bugIssue = newBugIssue(15);
    // Issues of type CODE SMELL and VULNERABILITY should be ignored
    DefaultIssue codeSmellIssue = newCodeSmellIssue(10);
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12);
    when(calculator.calculate(same(bugIssue), anyList(), same(PERIOD))).thenReturn(3L);
    when(calculator.calculate(same(codeSmellIssue), anyList(), same(PERIOD))).thenReturn(4L);
    when(calculator.calculate(same(vulnerabilityIssue), anyList(), same(PERIOD))).thenReturn(5L);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, bugIssue);
    underTest.onIssue(FILE, codeSmellIssue);
    underTest.onIssue(FILE, vulnerabilityIssue);
    underTest.afterComponent(FILE);
    // Only effort of BUG issue is used
    assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 3);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 38 with DefaultIssue

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

the class SendIssueNotificationsStepTest method send_global_new_issues_notification.

@Test
public void send_global_new_issues_notification() throws Exception {
    issueCache.newAppender().append(new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION)).close();
    when(notificationService.hasProjectSubscribersForTypes(PROJECT_UUID, SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true);
    underTest.execute();
    verify(notificationService).deliver(any(NewIssuesNotification.class));
    verify(newIssuesNotificationMock).setProject(PROJECT_KEY, PROJECT_UUID, PROJECT_NAME);
    verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
    verify(newIssuesNotificationMock).setStatistics(eq(PROJECT_NAME), any(NewIssuesStatistics.Stats.class));
    verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION);
}
Also used : NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Example 39 with DefaultIssue

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

the class SendIssueNotificationsStepTest method send_issues_change_notification.

@Test
public void send_issues_change_notification() throws Exception {
    DefaultIssue issue = new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION).setChanged(true).setSendNotifications(true);
    issueCache.newAppender().append(issue).close();
    when(notificationService.hasProjectSubscribersForTypes(PROJECT_UUID, SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true);
    underTest.execute();
    verify(notificationService).deliver(any(IssueChangeNotification.class));
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification) Test(org.junit.Test)

Example 40 with DefaultIssue

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

the class PersistIssuesStepTest method insert_new_issue.

@Test
public void insert_new_issue() {
    RuleDto rule = RuleTesting.newDto(RuleKey.of("xoo", "S01"));
    dbClient.ruleDao().insert(session, rule);
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    dbClient.componentDao().insert(session, project);
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    dbClient.componentDao().insert(session, file);
    session.commit();
    issueCache.newAppender().append(new DefaultIssue().setKey("ISSUE").setType(RuleType.CODE_SMELL).setRuleKey(rule.getKey()).setComponentUuid(file.uuid()).setProjectUuid(project.uuid()).setSeverity(Severity.BLOCKER).setStatus(Issue.STATUS_OPEN).setNew(true).setType(RuleType.BUG)).close();
    step.execute();
    IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE");
    assertThat(result.getKey()).isEqualTo("ISSUE");
    assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
    assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
    assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
    assertThat(result.getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(result.getStatus()).isEqualTo(Issue.STATUS_OPEN);
    assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) OrganizationDto(org.sonar.db.organization.OrganizationDto) 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