3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.scanner.mediumtest.issues;
22 import org.junit.rules.TemporaryFolder;
23 import org.junit.After;
24 import org.junit.Before;
25 import com.google.common.collect.ImmutableMap;
26 import org.sonar.api.CoreProperties;
27 import org.sonar.batch.bootstrapper.IssueListener;
28 import org.sonar.scanner.mediumtest.ScannerMediumTester;
29 import org.sonar.scanner.mediumtest.TaskResult;
30 import org.sonar.xoo.XooPlugin;
31 import org.sonar.xoo.rule.XooRulesDefinition;
32 import org.apache.commons.io.FileUtils;
33 import org.junit.Test;
35 import java.util.Date;
36 import java.util.LinkedList;
37 import java.util.List;
39 import static org.assertj.core.api.Assertions.assertThat;
41 public class IssuesIssuesModeMediumTest {
43 public TemporaryFolder temp = new TemporaryFolder();
45 public ScannerMediumTester testerPreview = ScannerMediumTester.builder()
46 .registerPlugin("xoo", new XooPlugin())
47 .addDefaultQProfile("xoo", "Sonar Way")
48 .addRules(new XooRulesDefinition())
49 .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
50 .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")
51 .setLastBuildDate(new Date())
55 public void prepare() {
56 testerPreview.start();
65 public void testIssueCallback() throws Exception {
66 File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
67 File tmpDir = temp.getRoot();
68 FileUtils.copyDirectory(projectDir, tmpDir);
69 IssueRecorder issueListener = new IssueRecorder();
71 TaskResult result1 = testerPreview
72 .newScanTask(new File(tmpDir, "sonar-project.properties"))
73 .setIssueListener(issueListener)
74 .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)
77 assertThat(result1.trackedIssues()).hasSize(14);
78 assertThat(issueListener.issueList).hasSize(14);
79 issueListener = new IssueRecorder();
81 TaskResult result2 = testerPreview
82 .newScanTask(new File(tmpDir, "sonar-project.properties"))
83 .setIssueListener(issueListener)
84 .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)
87 assertThat(result2.trackedIssues()).hasSize(14);
88 assertThat(issueListener.issueList).hasSize(14);
91 private class IssueRecorder implements IssueListener {
92 List<Issue> issueList = new LinkedList<>();
95 public void handle(Issue issue) {