Search in sources :

Example 76 with DefaultIssue

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

the class UpdateConflictResolverTest method severity_changed_by_user_should_be_kept.

@Test
public void severity_changed_by_user_should_be_kept() {
    DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false).setStatus(Issue.STATUS_OPEN);
    // Changed by scan
    issue.setSeverity(Severity.BLOCKER);
    issue.setManualSeverity(false);
    // Issue as seen and changed by end-user
    IssueDto dbIssue = new IssueDto().setKee("ABCDE").setStatus(Issue.STATUS_OPEN).setSeverity(Severity.INFO).setManualSeverity(true);
    new UpdateConflictResolver().mergeFields(dbIssue, issue);
    assertThat(issue.severity()).isEqualTo(Severity.INFO);
    assertThat(issue.manualSeverity()).isTrue();
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 77 with DefaultIssue

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

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

the class CommentDensityRuleTest method issue_if_not_enough_comments.

@Test
public void issue_if_not_enough_comments() {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, "25"), 1_000L));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(10.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(40));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(360));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // min_comments = (min_percent * ncloc) / (1 - min_percent)
    // -> threshold of 25% for 360 ncloc is 120 comment lines. 40 are already written.
    assertThat(issue.effortToFix()).isEqualTo(120.0 - 40.0);
    assertThat(issue.message()).isEqualTo("80 more comment lines need to be written to reach the minimum threshold of 25.0% comment density.");
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 79 with DefaultIssue

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

the class TestErrorRuleTest method no_issues_if_test_measures_are_absent.

@Test
public void no_issues_if_test_measures_are_absent() throws Exception {
    activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue).isNull();
}
Also used : ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 80 with DefaultIssue

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

the class MovedIssueVisitorTest method onIssue_throws_ISE_if_issue_has_different_component_uuid_from_component_but_it_is_not_the_one_of_original_file.

@Test
public void onIssue_throws_ISE_if_issue_has_different_component_uuid_from_component_but_it_is_not_the_one_of_original_file() {
    DefaultIssue issue = mockIssue("other component uuid");
    when(issue.toString()).thenReturn("[bad issue, bad!]");
    when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key")));
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " + "file of current file ReportComponent{ref=1, key='key_1', type=FILE}");
    underTest.onIssue(FILE, issue);
}
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