Search in sources :

Example 21 with TrackedIssue

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

the class DefaultProjectIssuesTest method toTrackedIssue.

private TrackedIssue toTrackedIssue(DefaultIssue issue) {
    TrackedIssue trackedIssue = new TrackedIssue();
    trackedIssue.setKey(issue.key());
    trackedIssue.setRuleKey(issue.ruleKey());
    trackedIssue.setComponentKey(issue.componentKey());
    trackedIssue.setSeverity(issue.severity());
    trackedIssue.setResolution(issue.resolution());
    return trackedIssue;
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue)

Example 22 with TrackedIssue

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

the class IssueCacheTest method createIssue.

private TrackedIssue createIssue(String key, String componentKey, String severity) {
    TrackedIssue issue = new TrackedIssue();
    issue.setKey(key);
    issue.setComponentKey(componentKey);
    issue.setSeverity(severity);
    return issue;
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue)

Example 23 with TrackedIssue

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

the class IssueCacheTest method should_get_all_issues.

@Test
public void should_get_all_issues() {
    IssueCache cache = new IssueCache(caches);
    TrackedIssue issue1 = createIssue("111", "org.struts.Action", Severity.BLOCKER);
    TrackedIssue issue2 = createIssue("222", "org.struts.Filter", Severity.INFO);
    cache.put(issue1).put(issue2);
    List<TrackedIssue> issues = ImmutableList.copyOf(cache.all());
    assertThat(issues).containsOnly(issue1, issue2);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) AbstractCachesTest(org.sonar.scanner.index.AbstractCachesTest) Test(org.junit.Test)

Example 24 with TrackedIssue

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

the class IssueModeAndReportsMediumTest method testIssueTracking.

@Test
public void testIssueTracking() throws Exception {
    File projectDir = copyProject("/mediumtest/xoo/sample");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).start();
    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(16);
    assertThat(openIssues).isEqualTo(2);
    assertThat(resolvedIssue).isEqualTo(1);
    // progress report
    String logs = StringUtils.join(logTester.logs(LoggerLevel.INFO), "\n");
    assertThat(logs).contains("Performing issue tracking");
    assertThat(logs).contains("6/6 components tracked");
    // assert that original fields of a matched issue are kept
    assertThat(result.trackedIssues()).haveExactly(1, new Condition<TrackedIssue>() {

        @Override
        public boolean matches(TrackedIssue value) {
            return value.isNew() == false && "resolved-on-project".equals(value.key()) && "OPEN".equals(value.status()) && new Date(date("14/03/2004")).equals(value.creationDate());
        }
    });
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 25 with TrackedIssue

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

the class DefaultPostJobContextTest method testIssues.

@Test
public void testIssues() throws IOException {
    when(analysisMode.isIssues()).thenReturn(true);
    assertThat(context.settings()).isSameAs(settings);
    TrackedIssue defaultIssue = new TrackedIssue();
    defaultIssue.setComponentKey("foo:src/Foo.php");
    defaultIssue.setGap(2.0);
    defaultIssue.setNew(true);
    defaultIssue.setKey("xyz");
    defaultIssue.setStartLine(1);
    defaultIssue.setMessage("msg");
    defaultIssue.setSeverity("BLOCKER");
    when(issueCache.all()).thenReturn(Arrays.asList(defaultIssue));
    PostJobIssue issue = context.issues().iterator().next();
    assertThat(issue.componentKey()).isEqualTo("foo:src/Foo.php");
    assertThat(issue.isNew()).isTrue();
    assertThat(issue.key()).isEqualTo("xyz");
    assertThat(issue.line()).isEqualTo(1);
    assertThat(issue.message()).isEqualTo("msg");
    assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(issue.inputComponent()).isNull();
    String moduleKey = "foo";
    componentStore.put(TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder()));
    componentStore.put(new TestInputFileBuilder(moduleKey, "src/Foo.php").build());
    assertThat(issue.inputComponent()).isNotNull();
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) PostJobIssue(org.sonar.api.batch.postjob.issue.PostJobIssue) 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