aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test/java
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@sonarsource.com>2015-12-03 18:37:23 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-12-04 10:01:59 +0100
commitfaa74b33eb99d62ad8c6ee760a9367ec62b8dc00 (patch)
tree720512f9d5e4605886f422d1bf2b9bf63e156248 /sonar-db/src/test/java
parent2a95bdb1fe32d66ebb71f7d5e506c94fb87a0551 (diff)
downloadsonarqube-faa74b33eb99d62ad8c6ee760a9367ec62b8dc00.tar.gz
sonarqube-faa74b33eb99d62ad8c6ee760a9367ec62b8dc00.zip
SONAR-7049 check max length of rule/rule param fields
Diffstat (limited to 'sonar-db/src/test/java')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java
index 7c170e7c8df..c6ac840691c 100644
--- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java
@@ -19,8 +19,14 @@
*/
package org.sonar.db.rule;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
+import java.util.Set;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import static org.apache.commons.lang.StringUtils.repeat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.rule.RuleDto.DISABLED_CHARACTERISTIC_ID;
@@ -29,6 +35,9 @@ public class RuleDtoTest {
public static final int FAKE_SUB_CHAR_1 = 27;
public static final int FAKE_SUB_CHAR_2 = 42;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
@Test
public void effective_sub_characteristic_id() {
RuleDto dto = new RuleDto();
@@ -57,4 +66,35 @@ public class RuleDtoTest {
dto.setSubCharacteristicId(DISABLED_CHARACTERISTIC_ID).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2);
assertThat(dto.getEffectiveSubCharacteristicId()).isNull();
}
+
+ @Test
+ public void fail_if_key_is_too_long() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Rule key is too long: ");
+
+ new RuleDto().setRuleKey(repeat("x", 250));
+ }
+
+ @Test
+ public void fail_if_name_is_too_long() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Rule name is too long: ");
+
+ new RuleDto().setName(repeat("x", 300));
+ }
+
+ @Test
+ public void fail_if_tags_are_too_long() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Rule tags are too long: ");
+
+ Set<String> tags = ImmutableSet.of(repeat("a", 2000), repeat("b", 1000), repeat("c", 2000));
+ new RuleDto().setTags(tags);
+ }
+
+ @Test
+ public void tags_are_optional() {
+ RuleDto dto = new RuleDto().setTags(Collections.<String>emptySet());
+ assertThat(dto.getTags()).isEmpty();
+ }
}