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.deprecated;
22 import com.google.common.collect.ImmutableMap;
24 import java.io.IOException;
25 import org.apache.commons.io.FileUtils;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.rules.TemporaryFolder;
30 import org.sonar.scanner.mediumtest.ScannerMediumTester;
31 import org.sonar.scanner.mediumtest.TaskResult;
32 import org.sonar.xoo.XooPlugin;
33 import org.sonar.xoo.rule.XooRulesDefinition;
35 import static org.assertj.core.api.Assertions.assertThat;
36 import static org.assertj.core.groups.Tuple.tuple;
38 public class DeprecatedApiMediumTest {
41 public TemporaryFolder temp = new TemporaryFolder();
43 public ScannerMediumTester tester = ScannerMediumTester.builder()
44 .registerPlugin("xoo", new XooPlugin())
45 .addRules(new XooRulesDefinition())
46 .addDefaultQProfile("xoo", "Sonar Way")
47 .addActiveRule("xoo", "DeprecatedResourceApi", null, "One issue per line", "MAJOR", null, "xoo")
51 public void prepare() {
61 public void testIssueDetails() throws IOException {
63 File baseDir = temp.getRoot();
64 File srcDir = new File(baseDir, "src");
67 File xooFileInRootDir = new File(srcDir, "sample.xoo");
68 FileUtils.write(xooFileInRootDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
70 File xooFileInAnotherDir = new File(srcDir, "package/sample.xoo");
71 FileUtils.write(xooFileInAnotherDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
73 TaskResult result = tester.newTask()
74 .properties(ImmutableMap.<String, String>builder()
75 .put("sonar.task", "scan")
76 .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
77 .put("sonar.projectKey", "com.foo.project")
78 .put("sonar.projectName", "Foo Project")
79 .put("sonar.projectVersion", "1.0-SNAPSHOT")
80 .put("sonar.projectDescription", "Description of Foo Project")
81 .put("sonar.sources", "src")
85 assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
86 tuple("Issue created using deprecated API", 0),
87 tuple("Issue created using deprecated API", 1));
88 assertThat(result.issuesFor(result.inputFile("src/package/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
89 tuple("Issue created using deprecated API", 0),
90 tuple("Issue created using deprecated API", 1));
91 assertThat(result.issuesFor(result.inputDir("src"))).extracting("msg", "textRange.startLine").containsOnly(
92 tuple("Issue created using deprecated API", 0));
93 assertThat(result.issuesFor(result.inputDir("src/package"))).extracting("msg", "textRange.startLine").containsOnly(
94 tuple("Issue created using deprecated API", 0));
99 public void createIssueOnRootDir() throws IOException {
101 File baseDir = temp.getRoot();
103 File xooFileInRootDir = new File(baseDir, "sample.xoo");
104 FileUtils.write(xooFileInRootDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
106 File xooFileInAnotherDir = new File(baseDir, "package/sample.xoo");
107 FileUtils.write(xooFileInAnotherDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
109 TaskResult result = tester.newTask()
110 .properties(ImmutableMap.<String, String>builder()
111 .put("sonar.task", "scan")
112 .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
113 .put("sonar.projectKey", "com.foo.project")
114 .put("sonar.projectName", "Foo Project")
115 .put("sonar.projectVersion", "1.0-SNAPSHOT")
116 .put("sonar.projectDescription", "Description of Foo Project")
117 .put("sonar.sources", ".")
121 assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
122 tuple("Issue created using deprecated API", 0),
123 tuple("Issue created using deprecated API", 1));
124 assertThat(result.issuesFor(result.inputFile("package/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
125 tuple("Issue created using deprecated API", 0),
126 tuple("Issue created using deprecated API", 1));
127 assertThat(result.issuesFor(result.inputDir(""))).extracting("msg", "textRange.startLine").containsOnly(
128 tuple("Issue created using deprecated API", 0));
129 assertThat(result.issuesFor(result.inputDir("package"))).extracting("msg", "textRange.startLine").containsOnly(
130 tuple("Issue created using deprecated API", 0));