3 * Copyright (C) 2009-2019 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 com.google.common.collect.ImmutableMap;
24 import java.io.IOException;
25 import org.apache.commons.io.FileUtils;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.TemporaryFolder;
29 import org.sonar.scanner.mediumtest.ScannerMediumTester;
30 import org.sonar.scanner.mediumtest.AnalysisResult;
31 import org.sonar.xoo.XooPlugin;
32 import org.sonar.xoo.rule.XooRulesDefinition;
34 import static org.assertj.core.api.Assertions.assertThat;
36 public class IssuesOnModuleMediumTest {
39 public TemporaryFolder temp = new TemporaryFolder();
42 public ScannerMediumTester tester = new ScannerMediumTester()
43 .registerPlugin("xoo", new XooPlugin())
44 .addDefaultQProfile("xoo", "Sonar Way")
45 .addRules(new XooRulesDefinition())
46 .addActiveRule("xoo", "OneIssuePerModule", null, "One issue per module", "MINOR", "xoo", "xoo");
49 public void scanTempProject() throws IOException {
51 File baseDir = temp.getRoot();
52 File srcDir = new File(baseDir, "src");
55 File xooFile1 = new File(srcDir, "sample1.xoo");
56 FileUtils.write(xooFile1, "Sample1 xoo\ncontent");
58 AnalysisResult result = tester.newAnalysis()
59 .properties(ImmutableMap.<String, String>builder()
60 .put("sonar.task", "scan")
61 .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
62 .put("sonar.projectKey", "com.foo.project")
63 .put("sonar.projectName", "Foo Project")
64 .put("sonar.projectVersion", "1.0-SNAPSHOT")
65 .put("sonar.projectDescription", "Description of Foo Project")
66 .put("sonar.sources", "src")
70 assertThat(result.issuesFor(result.getReportComponent("com.foo.project"))).hasSize(1);