Search in sources :

Example 6 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class IssueCacheTest method should_add_new_issue.

@Test
public void should_add_new_issue() {
    IssueCache cache = new IssueCache(caches);
    TrackedIssue issue1 = createIssue("111", "org.struts.Action", null);
    TrackedIssue issue2 = createIssue("222", "org.struts.Action", null);
    TrackedIssue issue3 = createIssue("333", "org.struts.Filter", null);
    issue3.setAssignee("foo");
    cache.put(issue1).put(issue2).put(issue3);
    assertThat(issueKeys(cache.byComponent("org.struts.Action"))).containsOnly("111", "222");
    assertThat(issueKeys(cache.byComponent("org.struts.Filter"))).containsOnly("333");
    assertThat(cache.byComponent("org.struts.Filter").iterator().next().assignee()).isEqualTo("foo");
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) AbstractCachesTest(org.sonar.scanner.index.AbstractCachesTest) Test(org.junit.Test)

Example 7 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class IssueCacheTest method should_update_existing_issue.

@Test
public void should_update_existing_issue() {
    IssueCache cache = new IssueCache(caches);
    TrackedIssue issue = createIssue("111", "org.struts.Action", Severity.BLOCKER);
    cache.put(issue);
    issue.setSeverity(Severity.MINOR);
    cache.put(issue);
    List<TrackedIssue> issues = ImmutableList.copyOf(cache.byComponent("org.struts.Action"));
    assertThat(issues).hasSize(1);
    TrackedIssue reloaded = issues.iterator().next();
    assertThat(reloaded.key()).isEqualTo("111");
    assertThat(reloaded.severity()).isEqualTo(Severity.MINOR);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) AbstractCachesTest(org.sonar.scanner.index.AbstractCachesTest) Test(org.junit.Test)

Example 8 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class TrackedIssueAdapterTest method improve_coverage.

@Test
public void improve_coverage() {
    Date creationDate = new Date();
    TrackedIssue trackedIssue = new TrackedIssue().setKey("XYZ123").setComponentKey("foo").setRuleKey(RuleKey.of("repo", "rule")).setSeverity("MAJOR").setMessage("msg").setStartLine(1).setGap(2.0).setStatus("RESOLVED").setResolution("FIXED").setAssignee("tata").setNew(true).setCreationDate(creationDate);
    Issue issue = new TrackedIssueAdapter(trackedIssue);
    assertThat(issue.key()).isEqualTo("XYZ123");
    assertThat(issue.componentKey()).isEqualTo("foo");
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
    assertThat(issue.severity()).isEqualTo("MAJOR");
    assertThat(issue.message()).isEqualTo("msg");
    assertThat(issue.line()).isEqualTo(1);
    assertThat(issue.gap()).isEqualTo(2.0);
    assertThat(issue.status()).isEqualTo("RESOLVED");
    assertThat(issue.resolution()).isEqualTo("FIXED");
    assertThat(issue.assignee()).isEqualTo("tata");
    assertThat(issue.isNew()).isTrue();
    assertThat(issue.attribute("foo")).isNull();
    assertThat(issue.creationDate()).isEqualTo(creationDate);
    assertThat(issue.language()).isNull();
    assertThat(issue.updateDate()).isNull();
    assertThat(issue.closeDate()).isNull();
    assertThat(issue.authorLogin()).isNull();
    assertThat(issue.comments()).isEmpty();
    assertThat(issue.effort()).isNull();
    assertThat(issue.projectKey()).isNull();
    assertThat(issue.projectUuid()).isNull();
    assertThat(issue.componentUuid()).isNull();
    assertThat(issue.tags()).isEmpty();
    assertThat(issue).isNotEqualTo(null);
    assertThat(issue).isNotEqualTo("Foo");
    assertThat(issue).isEqualTo(new TrackedIssueAdapter(trackedIssue));
    assertThat(issue.hashCode()).isEqualTo(trackedIssue.key().hashCode());
    assertThat(issue).isNotEqualTo(new TrackedIssueAdapter(new TrackedIssue().setKey("another")));
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) Issue(org.sonar.api.issue.Issue) TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) Date(java.util.Date) TrackedIssueAdapter(org.sonar.scanner.issue.TrackedIssueAdapter) Test(org.junit.Test)

Example 9 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class ScanOnlyChangedTest method assertNumberIssues.

private static void assertNumberIssues(TaskResult result, int expectedNew, int expectedOpen, int expectedResolved) {
    int newIssues = 0;
    int openIssues = 0;
    int resolvedIssue = 0;
    for (TrackedIssue issue : result.trackedIssues()) {
        System.out.println(issue.getMessage() + " " + issue.key() + " " + issue.getRuleKey() + " " + issue.isNew() + " " + issue.resolution() + " " + issue.componentKey() + " " + issue.startLine());
        if (issue.isNew()) {
            newIssues++;
        } else if (issue.resolution() != null) {
            resolvedIssue++;
        } else {
            openIssues++;
        }
    }
    System.out.println("new: " + newIssues + " open: " + openIssues + " resolved " + resolvedIssue);
    assertThat(newIssues).isEqualTo(expectedNew);
    assertThat(openIssues).isEqualTo(expectedOpen);
    assertThat(resolvedIssue).isEqualTo(expectedResolved);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue)

Example 10 with TrackedIssue

use of org.sonar.scanner.issue.tracking.TrackedIssue in project sonarqube by SonarSource.

the class EmptyFileTest method testIssueTrackingWithIssueOnEmptyFile.

@Test
public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
    File projectDir = copyProject("/mediumtest/xoo/sample-with-empty-file");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.xoo.internalKey", "my/internal/key").start();
    for (TrackedIssue i : result.trackedIssues()) {
        System.out.println(i.startLine() + " " + i.getMessage());
    }
    assertThat(result.trackedIssues()).hasSize(11);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Aggregations

TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)25 Test (org.junit.Test)12 Date (java.util.Date)3 RuleKey (org.sonar.api.rule.RuleKey)3 AbstractCachesTest (org.sonar.scanner.index.AbstractCachesTest)3 File (java.io.File)2 StringWriter (java.io.StringWriter)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 Rule (org.sonar.api.batch.rule.Rule)2 Issue (org.sonar.api.issue.Issue)2 TaskResult (org.sonar.scanner.mediumtest.TaskResult)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 InputPath (org.sonar.api.batch.fs.InputPath)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 PostJobIssue (org.sonar.api.batch.postjob.issue.PostJobIssue)1 RulePriority (org.sonar.api.rules.RulePriority)1 IssueListener (org.sonar.batch.bootstrapper.IssueListener)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 IssueCache (org.sonar.scanner.issue.IssueCache)1