diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-09 17:56:32 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-09 17:56:32 +0100 |
commit | bd814b0f9f41fbb27b24e280c95cec341f83a38a (patch) | |
tree | 6a733a9a9e842a6970749dec973ea95961f228b1 /sonar-batch | |
parent | eb1c4e9fd43cdf253b9eefa75755a7bebd0347c2 (diff) | |
parent | a2fa3e4651b30a3cb9284a34656ed8ecfc13d274 (diff) | |
download | sonarqube-bd814b0f9f41fbb27b24e280c95cec341f83a38a.tar.gz sonarqube-bd814b0f9f41fbb27b24e280c95cec341f83a38a.zip |
Merge remote-tracking branch 'origin/branch-5.0'
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java | 1 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java | 105 |
2 files changed, 106 insertions, 0 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java index 3b12b701136..532547dc16d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java @@ -52,6 +52,7 @@ public class ActiveRulesProvider extends ProviderAdapter { newActiveRule.setSeverity(activeRule.severity()); newActiveRule.setLanguage(activeRule.language()); newActiveRule.setInternalKey(activeRule.internalKey()); + newActiveRule.setTemplateRuleKey(activeRule.templateRuleKey()); // load parameters for (Entry<String, String> param : activeRule.params().entrySet()) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java new file mode 100644 index 00000000000..54c2aab58b4 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java @@ -0,0 +1,105 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.batch.mediumtest.issues; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.batch.mediumtest.BatchMediumTester; +import org.sonar.batch.mediumtest.BatchMediumTester.TaskResult; +import org.sonar.batch.protocol.input.ActiveRule; +import org.sonar.xoo.XooPlugin; + +import java.io.File; +import java.io.IOException; + +import static org.fest.assertions.Assertions.assertThat; + +public class ChecksMediumTest { + + @org.junit.Rule + public TemporaryFolder temp = new TemporaryFolder(); + + public BatchMediumTester tester = BatchMediumTester.builder() + .registerPlugin("xoo", new XooPlugin()) + .addDefaultQProfile("xoo", "Sonar Way") + .activateRule(new ActiveRule("xoo", "TemplateRule_1234", "TemplateRule", "A template rule", "MAJOR", null, "xoo").addParam("line", "1")) + .activateRule(new ActiveRule("xoo", "TemplateRule_1235", "TemplateRule", "Another template rule", "MAJOR", null, "xoo").addParam("line", "2")) + .bootstrapProperties(ImmutableMap.of("sonar.analysis.mode", "sensor")) + .build(); + + @Before + public void prepare() { + tester.start(); + } + + @After + public void stop() { + tester.stop(); + } + + @Test + public void testCheckWithTemplate() throws IOException { + + File baseDir = temp.newFolder(); + File srcDir = new File(baseDir, "src"); + srcDir.mkdir(); + + File xooFile = new File(srcDir, "sample.xoo"); + FileUtils.write(xooFile, "foo"); + + TaskResult result = tester.newTask() + .properties(ImmutableMap.<String, String>builder() + .put("sonar.task", "scan") + .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) + .put("sonar.projectKey", "com.foo.project") + .put("sonar.projectName", "Foo Project") + .put("sonar.projectVersion", "1.0-SNAPSHOT") + .put("sonar.projectDescription", "Description of Foo Project") + .put("sonar.sources", "src") + .build()) + .start(); + + assertThat(result.issues()).hasSize(2); + + boolean foundIssueAtLine1 = false; + boolean foundIssueAtLine2 = false; + for (Issue issue : result.issues()) { + if (issue.line() == 1) { + foundIssueAtLine1 = true; + assertThat(issue.inputPath()).isEqualTo(new DefaultInputFile("com.foo.project", "src/sample.xoo")); + assertThat(issue.message()).isEqualTo("A template rule"); + } + if (issue.line() == 2) { + foundIssueAtLine2 = true; + assertThat(issue.inputPath()).isEqualTo(new DefaultInputFile("com.foo.project", "src/sample.xoo")); + assertThat(issue.message()).isEqualTo("Another template rule"); + } + } + assertThat(foundIssueAtLine1).isTrue(); + assertThat(foundIssueAtLine2).isTrue(); + } + +} |