aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java/org/sonar
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-18 10:27:16 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-18 10:27:16 +0100
commit6723d2eacd59bc102b4133b9c8c76e82d9dad7a4 (patch)
treeab9549e805e5c0f69d2af0ce1e93dbbe0b45eb85 /sonar-batch/src/test/java/org/sonar
parent72bf960a39ec08483e3bf5ab35ea38ab54ee5308 (diff)
downloadsonarqube-6723d2eacd59bc102b4133b9c8c76e82d9dad7a4.tar.gz
sonarqube-6723d2eacd59bc102b4133b9c8c76e82d9dad7a4.zip
SONAR-3583 Do not save violation if rule does not exist in DB (= no ID)
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index 87cb9361e11..8ea5f04e9c1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -77,8 +77,9 @@ public class DefaultIndexTest {
};
RulesProfile rulesProfile = RulesProfile.create();
rule = Rule.create("repoKey", "ruleKey", "Rule");
+ rule.setId(1);
rulesProfile.activateRule(rule, null);
- index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] { filter }), new ViolationFilters(), rulesProfile);
+ index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] {filter}), new ViolationFilters(), rulesProfile);
index.doStart(project);
}
@@ -202,6 +203,20 @@ public class DefaultIndexTest {
assertThat(index.getViolations(file).size(), is(0));
}
+ /**
+ * See https://jira.codehaus.org/browse/SONAR-3583
+ */
+ @Test
+ public void shouldNotFailWhenSavingViolationOnRuleThatDoesNotExistInDB() {
+ Rule ruleWithoutID = Rule.create("repoKey", "ruleKey", "Rule");
+
+ File file = new File("org/foo/Bar.java");
+ Violation violation = Violation.create(ruleWithoutID, file);
+ index.addViolation(violation);
+
+ assertThat(index.getViolations(file).size(), is(0));
+ }
+
@Test
public void testGetViolations() {
File file = new File("org/foo/Bar.java");