Search in sources :

Example 81 with DefaultIssue

use of org.sonar.core.issue.DefaultIssue 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(6451, "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().login()).isNull();
    assertThat(issueChangeContextCaptor.getValue().scan()).isFalse();
}
Also used : IssueChangeContext(org.sonar.core.issue.IssueChangeContext) MovedFilesRepository(org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Example 82 with DefaultIssue

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

the class MovedIssueVisitorTest method mockIssue.

private DefaultIssue mockIssue(String fileUuid) {
    DefaultIssue issue = mock(DefaultIssue.class);
    when(issue.componentUuid()).thenReturn(fileUuid);
    return issue;
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 83 with DefaultIssue

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

the class NewEffortAggregatorTest method sum_new_reliability_effort_of_issues.

@Test
public void sum_new_reliability_effort_of_issues() {
    periodsHolder.setPeriod(PERIOD);
    DefaultIssue unresolved1 = newBugIssue(10L);
    DefaultIssue unresolved2 = newBugIssue(30L);
    DefaultIssue unresolvedWithoutDebt = newBugIssueWithoutEffort();
    DefaultIssue resolved = newBugIssue(50L).setResolution(RESOLUTION_FIXED);
    when(calculator.calculate(same(unresolved1), anyList(), same(PERIOD))).thenReturn(4L);
    when(calculator.calculate(same(unresolved2), anyList(), same(PERIOD))).thenReturn(3L);
    verifyNoMoreInteractions(calculator);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, unresolved1);
    underTest.onIssue(FILE, unresolved2);
    underTest.onIssue(FILE, unresolvedWithoutDebt);
    underTest.onIssue(FILE, resolved);
    underTest.afterComponent(FILE);
    assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 3 + 4);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 84 with DefaultIssue

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

the class NewEffortAggregatorTest method aggregate_new_characteristic_measures_of_children.

@Test
public void aggregate_new_characteristic_measures_of_children() {
    periodsHolder.setPeriod(PERIOD);
    DefaultIssue codeSmellIssue = newCodeSmellIssue(10);
    when(calculator.calculate(same(codeSmellIssue), anyList(), same(PERIOD))).thenReturn(4L);
    DefaultIssue bugIssue = newBugIssue(8);
    when(calculator.calculate(same(bugIssue), anyList(), same(PERIOD))).thenReturn(3L);
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12);
    when(calculator.calculate(same(vulnerabilityIssue), anyList(), same(PERIOD))).thenReturn(6L);
    DefaultIssue codeSmellProjectIssue = newCodeSmellIssue(30);
    when(calculator.calculate(same(codeSmellProjectIssue), anyList(), same(PERIOD))).thenReturn(1L);
    DefaultIssue bugProjectIssue = newBugIssue(28);
    when(calculator.calculate(same(bugProjectIssue), anyList(), same(PERIOD))).thenReturn(2L);
    DefaultIssue vulnerabilityProjectIssue = newVulnerabilityIssue(32);
    when(calculator.calculate(same(vulnerabilityProjectIssue), anyList(), same(PERIOD))).thenReturn(4L);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, codeSmellIssue);
    underTest.onIssue(FILE, bugIssue);
    underTest.onIssue(FILE, vulnerabilityIssue);
    underTest.afterComponent(FILE);
    underTest.beforeComponent(PROJECT);
    underTest.onIssue(PROJECT, codeSmellProjectIssue);
    underTest.onIssue(PROJECT, bugProjectIssue);
    underTest.onIssue(PROJECT, vulnerabilityProjectIssue);
    underTest.afterComponent(PROJECT);
    assertVariation(PROJECT, NEW_TECHNICAL_DEBT_KEY, 4 + 1);
    assertVariation(PROJECT, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 3 + 2);
    assertVariation(PROJECT, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 6 + 4);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 85 with DefaultIssue

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

the class NewEffortAggregatorTest method new_security_effort_is_only_computed_using_vulnerability_issues.

@Test
public void new_security_effort_is_only_computed_using_vulnerability_issues() {
    periodsHolder.setPeriod(PERIOD);
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12);
    // Issues of type CODE SMELL and BUG should be ignored
    DefaultIssue codeSmellIssue = newCodeSmellIssue(10);
    DefaultIssue bugIssue = newBugIssue(15);
    when(calculator.calculate(same(vulnerabilityIssue), anyList(), same(PERIOD))).thenReturn(5L);
    when(calculator.calculate(same(codeSmellIssue), anyList(), same(PERIOD))).thenReturn(4L);
    when(calculator.calculate(same(bugIssue), anyList(), same(PERIOD))).thenReturn(3L);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, codeSmellIssue);
    underTest.onIssue(FILE, bugIssue);
    underTest.onIssue(FILE, vulnerabilityIssue);
    underTest.afterComponent(FILE);
    // Only effort of VULNERABILITY issue is used
    assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 5);
}
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