Search in sources :

Example 66 with DefaultIssue

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

the class TransitionTest method should_verify_conditions.

@Test
public void should_verify_conditions() {
    DefaultIssue issue = new DefaultIssue();
    Transition transition = Transition.builder("close").from("OPEN").to("CLOSED").conditions(condition1, condition2).build();
    when(condition1.matches(issue)).thenReturn(true);
    when(condition2.matches(issue)).thenReturn(false);
    assertThat(transition.supports(issue)).isFalse();
    when(condition1.matches(issue)).thenReturn(true);
    when(condition2.matches(issue)).thenReturn(true);
    assertThat(transition.supports(issue)).isTrue();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 67 with DefaultIssue

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

the class CloseIssuesOnRemovedComponentsVisitorTest method close_issue.

@Test
public void close_issue() throws Exception {
    String fileUuid = "FILE1";
    String issueUuid = "ABCD";
    when(componentsWithUnprocessedIssues.getUuids()).thenReturn(newHashSet(fileUuid));
    DefaultIssue issue = new DefaultIssue().setKey(issueUuid);
    when(baseIssuesLoader.loadForComponentUuid(fileUuid)).thenReturn(Collections.singletonList(issue));
    underTest.visit(ReportComponent.builder(PROJECT, 1).build());
    verify(issueLifecycle).doAutomaticTransition(issue);
    CloseableIterator<DefaultIssue> issues = issueCache.traverse();
    assertThat(issues.hasNext()).isTrue();
    DefaultIssue result = issues.next();
    assertThat(result.key()).isEqualTo(issueUuid);
    assertThat(result.isBeingClosed()).isTrue();
    assertThat(result.isOnDisabledRule()).isFalse();
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 68 with DefaultIssue

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

the class EffortAggregatorTest method reliability_effort_is_only_computed_using_bug_issues.

@Test
public void reliability_effort_is_only_computed_using_bug_issues() {
    DefaultIssue bugIssue = newBugIssue(10);
    // Issues of type CODE SMELL and VULNERABILITY should be ignored
    DefaultIssue codeSmellIssue = newCodeSmellIssue(15);
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12);
    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
    assertMeasure(FILE, RELIABILITY_REMEDIATION_EFFORT_KEY, 10L);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 69 with DefaultIssue

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

the class EffortAggregatorTest method security_effort_is_only_computed_using_code_smell_issues.

@Test
public void security_effort_is_only_computed_using_code_smell_issues() {
    DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(10);
    // Issues of type BUG and CODE SMELL should be ignored
    DefaultIssue bugIssue = newBugIssue(15);
    DefaultIssue codeSmellIssue = newCodeSmellIssue(12);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, vulnerabilityIssue);
    underTest.onIssue(FILE, bugIssue);
    underTest.onIssue(FILE, codeSmellIssue);
    underTest.afterComponent(FILE);
    // Only effort of VULNERABILITY issue is used
    assertMeasure(FILE, SECURITY_REMEDIATION_EFFORT_KEY, 10L);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 70 with DefaultIssue

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

the class EffortAggregatorTest method sum_maintainability_effort_of_unresolved_issues.

@Test
public void sum_maintainability_effort_of_unresolved_issues() {
    DefaultIssue unresolved1 = newCodeSmellIssue(10);
    DefaultIssue unresolved2 = newCodeSmellIssue(30);
    DefaultIssue unresolvedWithoutEffort = newCodeSmellIssueWithoutEffort();
    DefaultIssue resolved = newCodeSmellIssue(50).setResolution(RESOLUTION_FIXED);
    underTest.beforeComponent(FILE);
    underTest.onIssue(FILE, unresolved1);
    underTest.onIssue(FILE, unresolved2);
    underTest.onIssue(FILE, unresolvedWithoutEffort);
    underTest.onIssue(FILE, resolved);
    underTest.afterComponent(FILE);
    // total maintainability effort
    assertMeasure(FILE, TECHNICAL_DEBT_KEY, 10L + 30L);
}
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