aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java/org/sonar/api/config
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-09-28 13:35:23 +0200
committerDavid Gageot <david@gageot.net>2012-09-28 15:08:45 +0200
commit9c854f825217360854b7878a28a21dc9a8c5c19b (patch)
tree787736e26eb3dc744d4b27faa39b2117c9ed1c6a /sonar-plugin-api/src/test/java/org/sonar/api/config
parentf31d5fd1a99b5b3dca8cc450d97203206a06de5a (diff)
downloadsonarqube-9c854f825217360854b7878a28a21dc9a8c5c19b.tar.gz
sonarqube-9c854f825217360854b7878a28a21dc9a8c5c19b.zip
SONAR-3529 Get rid of property sets. Use PropertyFields instead
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar/api/config')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java22
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java54
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java48
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java39
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java63
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java59
6 files changed, 38 insertions, 247 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java
index 59d3927aa33..caea3a388b7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.api.config;
+import org.sonar.api.PropertyField;
+
import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
@@ -47,11 +49,12 @@ public class PropertyDefinitionTest {
assertThat(def.isOnProject()).isTrue();
assertThat(def.isOnModule()).isTrue();
assertThat(def.isMultiValues()).isTrue();
- assertThat(def.getPropertySetName()).isEmpty();
+ assertThat(def.getPropertySetKey()).isEqualTo("set");
+ assertThat(def.getFields()).isEmpty();
}
@Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
- options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true))
+ options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true, propertySetKey = "set"))
static class Init {
}
@@ -73,9 +76,13 @@ public class PropertyDefinitionTest {
assertThat(def.isOnProject()).isFalse();
assertThat(def.isOnModule()).isFalse();
assertThat(def.isMultiValues()).isFalse();
+ assertThat(def.getPropertySetKey()).isEmpty();
+ assertThat(def.getFields()).isEmpty();
}
- @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, propertySetName = "set1"))
+ @Properties(@Property(key = "hello", name = "Hello", fields = {
+ @PropertyField(key = "first", name = "First"),
+ @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)}))
static class WithPropertySet {
}
@@ -86,8 +93,13 @@ public class PropertyDefinitionTest {
PropertyDefinition def = PropertyDefinition.create(prop);
- assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET);
- assertThat(def.getPropertySetName()).isEqualTo("set1");
+ assertThat(def.getFields()).hasSize(2);
+ assertThat(def.getFields()[0].getKey()).isEqualTo("first");
+ assertThat(def.getFields()[0].getName()).isEqualTo("First");
+ assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING);
+ assertThat(def.getFields()[1].getKey()).isEqualTo("second");
+ assertThat(def.getFields()[1].getName()).isEqualTo("Second");
+ assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER);
}
@Properties(@Property(key = "hello", name = "Hello"))
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java
deleted file mode 100644
index cd0a3c39112..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetDefinitionsTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.config;
-
-import org.junit.Test;
-
-import java.util.NoSuchElementException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PropertySetDefinitionsTest {
- PropertySetDefinitions definitions = new PropertySetDefinitions();
-
- @Test
- public void should_register_by_name() {
- PropertySet set = new PropertySet();
- PropertySet other = new PropertySet();
-
- definitions.register("name", set);
- definitions.register("other", other);
-
- assertThat(definitions.findByName("name")).isSameAs(set);
- assertThat(definitions.findByName("other")).isSameAs(other);
- assertThat(definitions.findAll()).containsOnly(set, other);
- }
-
- @Test(expected = IllegalStateException.class)
- public void should_fail_to_register_twice() {
- definitions.register("name", new PropertySet());
- definitions.register("name", new PropertySet());
- }
-
- @Test(expected = NoSuchElementException.class)
- public void should_fail_to_find_unknown_set() {
- definitions.findByName("UNKNOWN");
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java
deleted file mode 100644
index c1a06cb1d96..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetFieldTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.config;
-
-import org.junit.Test;
-import org.sonar.api.PropertyType;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PropertySetFieldTest {
- @Test
- public void should_set_name_and_type() {
- PropertySetField field = PropertySetField.create("name", PropertyType.STRING);
-
- assertThat(field.getName()).isEqualTo("name");
- assertThat(field.getType()).isEqualTo(PropertyType.STRING);
- assertThat(field.getDefaultValue()).isEmpty();
- assertThat(field.getDescription()).isEmpty();
- }
-
- @Test
- public void should_set_optional_characteristics() {
- PropertySetField field = PropertySetField.create("name", PropertyType.STRING);
-
- field.setDefaultValue("default");
- field.setDescription("description");
-
- assertThat(field.getDefaultValue()).isEqualTo("default");
- assertThat(field.getDescription()).isEqualTo("description");
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java
deleted file mode 100644
index cd999147ed7..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.config;
-
-import org.junit.Test;
-import org.sonar.api.PropertyType;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PropertySetTest {
- @Test
- public void should_add_fields() {
- PropertySetField firstField = PropertySetField.create("first", PropertyType.STRING);
- PropertySetField secondField = PropertySetField.create("second", PropertyType.STRING);
-
- PropertySet set = new PropertySet();
- set.add(firstField);
- set.add(secondField);
-
- assertThat(set.getFields()).containsExactly(firstField, secondField);
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java
deleted file mode 100644
index b59ac26fbe5..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertySetValueTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.config;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PropertySetValueTest {
- @Test
- public void should_get_default_values() {
- PropertySetValue value = PropertySetValue.create(Maps.<String, String>newHashMap());
-
- assertThat(value.getString("UNKNOWN")).isEmpty();
- assertThat(value.getInt("UNKNOWN")).isZero();
- assertThat(value.getFloat("UNKNOWN")).isZero();
- assertThat(value.getLong("UNKNOWN")).isZero();
- assertThat(value.getDate("UNKNOWN")).isNull();
- assertThat(value.getDateTime("UNKNOWN")).isNull();
- assertThat(value.getStringArray("UNKNOWN")).isEmpty();
- }
-
- @Test
- public void should_get_values() {
- PropertySetValue value = PropertySetValue.create(ImmutableMap.<String, String>builder()
- .put("age", "12")
- .put("child", "true")
- .put("size", "12.4")
- .put("distance", "1000000000")
- .put("array", "1,2,3,4,5")
- .put("birth", "1975-01-29")
- .put("now", "2012-09-25T10:08:30+0100")
- .build());
-
- assertThat(value.getString("age")).isEqualTo("12");
- assertThat(value.getInt("age")).isEqualTo(12);
- assertThat(value.getBoolean("child")).isTrue();
- assertThat(value.getFloat("size")).isEqualTo(12.4f);
- assertThat(value.getLong("distance")).isEqualTo(1000000000L);
- assertThat(value.getStringArray("array")).contains("1", "2", "3", "4", "5");
- assertThat(value.getDate("birth")).isNotNull();
- assertThat(value.getDateTime("now")).isNotNull();
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
index 137e76a8b4f..2e5259a4995 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java
@@ -19,8 +19,6 @@
*/
package org.sonar.api.config;
-import org.junit.Ignore;
-
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Rule;
@@ -45,7 +43,7 @@ public class SettingsTest {
@Property(key = "integer", name = "Integer", defaultValue = "12345"),
@Property(key = "array", name = "Array", defaultValue = "one,two,three"),
@Property(key = "multi_values", name = "Array", defaultValue = "1,2,3", multiValues = true),
- @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetName = "jira")
+ @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetKey = "jira")
})
static class Init {
}
@@ -155,53 +153,53 @@ public class SettingsTest {
public void getStringArray() {
Settings settings = new Settings(definitions);
String[] array = settings.getStringArray("array");
- assertThat(array).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
public void setStringArray() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A", "B"});
+ settings.setProperty("multi_values", new String[] {"A", "B"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A", "B"});
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
}
@Test
public void setStringArrayTrimValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{" A ", " B "});
+ settings.setProperty("multi_values", new String[] {" A ", " B "});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A", "B"});
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
}
@Test
public void setStringArrayEscapeCommas() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "C,D"});
}
@Test
public void setStringArrayWithEmptyValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", "", "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", "", "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
}
@Test
public void setStringArrayWithNullValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", null, "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", null, "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
}
@Test(expected = IllegalStateException.class)
public void shouldFailToSetArrayValueOnSingleValueProperty() {
Settings settings = new Settings(definitions);
- settings.setProperty("array", new String[]{"A", "B", "C"});
+ settings.setProperty("array", new String[] {"A", "B", "C"});
}
@Test
@@ -216,7 +214,7 @@ public class SettingsTest {
Settings settings = new Settings();
settings.setProperty("foo", " one, two, three ");
String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
@@ -224,7 +222,7 @@ public class SettingsTest {
Settings settings = new Settings();
settings.setProperty("foo", " one, , two");
String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[]{"one", "", "two"});
+ assertThat(array).isEqualTo(new String[] {"one", "", "two"});
}
@Test
@@ -282,34 +280,34 @@ public class SettingsTest {
public void getStringLines_single_line() {
Settings settings = new Settings();
settings.setProperty("foo", "the line");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"the line"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"the line"});
}
@Test
public void getStringLines_linux() {
Settings settings = new Settings();
settings.setProperty("foo", "one\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
settings.setProperty("foo", "one\ntwo\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
}
@Test
public void getStringLines_windows() {
Settings settings = new Settings();
settings.setProperty("foo", "one\r\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
settings.setProperty("foo", "one\r\ntwo\r\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
}
@Test
public void getStringLines_mix() {
Settings settings = new Settings();
settings.setProperty("foo", "one\r\ntwo\nthree");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
@@ -323,19 +321,4 @@ public class SettingsTest {
assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username");
assertThat(settings.getKeysStartingWith("other")).hasSize(0);
}
-
- @Test
- @Ignore
- public void should_get_property_set_value() {
- Settings settings = new Settings(definitions);
- settings.setProperty("sonar.property_set.jira",
- "[{\"set\": {\"name\": \"codehaus_jira\", \"values\": {\"key1\":\"value1\", \"key2\":\"value2\"}}},{\"set\": {\"name\": \"other\", \"values\": {\"key3\":\"value3\"}}}]");
-
- settings.setProperty("sonar.jira", "codehaus_jira");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key1")).isEqualTo("value1");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key2")).isEqualTo("value2");
-
- settings.setProperty("sonar.jira", "other");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key3")).isEqualTo("value3");
- }
}