Search in sources :

Example 26 with DefaultIssue

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

the class SkippedTestRuleTest method no_issues_if_measure_is_absent.

@Test
public void no_issues_if_measure_is_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 27 with DefaultIssue

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

the class TrackerRawInputFactoryTest method load_issues_of_compute_engine_common_rules.

@Test
public void load_issues_of_compute_engine_common_rules() throws Exception {
    when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(true);
    fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;");
    DefaultIssue ceIssue = new DefaultIssue().setRuleKey(RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), "InsufficientCoverage")).setMessage("not enough coverage").setGap(10.0);
    when(commonRuleEngine.process(FILE)).thenReturn(asList(ceIssue));
    Input<DefaultIssue> input = underTest.create(FILE);
    assertThat(input.getIssues()).containsOnly(ceIssue);
    assertInitializedIssue(input.getIssues().iterator().next());
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 28 with DefaultIssue

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

the class UpdateConflictResolverTest method should_keep_changes_made_by_user.

@Test
public void should_keep_changes_made_by_user() {
    DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false);
    // Before starting scan
    issue.setAssignee(null);
    issue.setCreationDate(DateUtils.parseDate("2012-01-01"));
    issue.setUpdateDate(DateUtils.parseDate("2012-02-02"));
    // Changed by scan
    issue.setLine(200);
    issue.setSeverity(Severity.BLOCKER);
    issue.setManualSeverity(false);
    issue.setAuthorLogin("simon");
    issue.setChecksum("CHECKSUM-ABCDE");
    issue.setResolution(null);
    issue.setStatus(Issue.STATUS_REOPENED);
    // Issue as seen and changed by end-user
    IssueDto dbIssue = new IssueDto().setKee("ABCDE").setRuleId(10).setRuleKey("squid", "AvoidCycles").setComponentUuid("100").setComponentKey("struts:org.apache.struts.Action").setLine(10).setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_RESOLVED).setAssignee("arthur").setSeverity(Severity.MAJOR).setManualSeverity(false);
    new UpdateConflictResolver().mergeFields(dbIssue, issue);
    assertThat(issue.key()).isEqualTo("ABCDE");
    assertThat(issue.componentKey()).isEqualTo("struts:org.apache.struts.Action");
    // Scan wins on :
    assertThat(issue.line()).isEqualTo(200);
    assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issue.manualSeverity()).isFalse();
    // User wins on :
    assertThat(issue.assignee()).isEqualTo("arthur");
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.status()).isEqualTo(Issue.STATUS_RESOLVED);
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 29 with DefaultIssue

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

the class CommentDensityRuleTest method issue_if_not_enough_comments__test_ceil.

@Test
public void issue_if_not_enough_comments__test_ceil() {
    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(0.0, 1));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(0));
    measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(1));
    DefaultIssue issue = underTest.processFile(FILE, "java");
    assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
    assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
    // 1 ncloc requires 1 comment line to reach 25% of comment density
    assertThat(issue.effortToFix()).isEqualTo(1.0);
    assertThat(issue.message()).isEqualTo("1 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 30 with DefaultIssue

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

the class CommentDensityRuleTest method no_issues_if_enough_comments.

@Test
public void no_issues_if_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(90.0, 1));
    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)

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