]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7300 Add IT on multi values and property set in SettingsTest
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 4 Jan 2017 12:46:51 +0000 (13:46 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 10 Jan 2017 08:56:54 +0000 (09:56 +0100)
it/it-plugins/server-plugin/src/main/java/ServerPlugin.java
it/it-tests/src/test/java/it/settings/SettingsTest.java

index b74b0d6a8e0af37afd56e97b2fd52ac857ef1217..1b77a575c8a6ac51b2c9903f9f3816c1762e534f 100644 (file)
@@ -23,26 +23,45 @@ import java.util.Arrays;
 import java.util.List;
 import org.sonar.api.Properties;
 import org.sonar.api.Property;
-import org.sonar.api.PropertyType;
+import org.sonar.api.PropertyField;
 import org.sonar.api.SonarPlugin;
 
+import static org.sonar.api.PropertyType.BOOLEAN;
+import static org.sonar.api.PropertyType.FLOAT;
+import static org.sonar.api.PropertyType.INTEGER;
+import static org.sonar.api.PropertyType.LICENSE;
+import static org.sonar.api.PropertyType.LONG;
+import static org.sonar.api.PropertyType.METRIC;
+import static org.sonar.api.PropertyType.METRIC_LEVEL;
+import static org.sonar.api.PropertyType.PASSWORD;
+import static org.sonar.api.PropertyType.PROPERTY_SET;
+import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
+import static org.sonar.api.PropertyType.STRING;
+import static org.sonar.api.PropertyType.TEXT;
+import static org.sonar.api.PropertyType.USER_LOGIN;
+
 @Properties({
   @Property(key = "some-property", name = "Some Property", defaultValue = "aDefaultValue", global = true, project = false),
-  @Property(key = "boolean", name = "Boolean", defaultValue = "true", type = PropertyType.BOOLEAN, global = true, project = false),
-  @Property(key = "user", name = "User", type = PropertyType.USER_LOGIN, global = true, project = false),
-  @Property(key = "list", name = "List", type = PropertyType.SINGLE_SELECT_LIST, options = {"A", "B", "C"}, global = true, project = false),
-  @Property(key = "metric", name = "Metric", type = PropertyType.METRIC, global = true, project = false),
-  @Property(key = "metric_level", name = "Metric Level", type = PropertyType.METRIC_LEVEL, global = true, project = false),
-  @Property(key = "float", name = "Float", type = PropertyType.FLOAT, global = true, project = false),
-  @Property(key = "int", name = "Integer", type = PropertyType.INTEGER, global = true, project = false),
-  @Property(key = "string", name = "String", type = PropertyType.STRING, global = true, project = false),
-  @Property(key = "setting.license.secured", name = "License", type = PropertyType.LICENSE, global = true, project = false),
-  @Property(key = "long", name = "Long", type = PropertyType.LONG, global = true, project = false),
-  @Property(key = "password", name = "Password", type = PropertyType.PASSWORD, global = true, project = false),
-  @Property(key = "text", name = "Text", type = PropertyType.TEXT, global = true, project = false),
-  @Property(key = "multi", name = "Multi", type = PropertyType.STRING, multiValues = true, global = true, project = false),
-  @Property(key = "hidden", name = "Hidden", type = PropertyType.STRING, global = false, project = false),
-  @Property(key = "setting.secured", name = "Secured", type = PropertyType.STRING, global = true, project = false)
+  @Property(key = "boolean", name = "Boolean", defaultValue = "true", type = BOOLEAN, global = true, project = false),
+  @Property(key = "user", name = "User", type = USER_LOGIN, global = true, project = false),
+  @Property(key = "list", name = "List", type = SINGLE_SELECT_LIST, options = {"A", "B", "C"}, global = true, project = false),
+  @Property(key = "metric", name = "Metric", type = METRIC, global = true, project = false),
+  @Property(key = "metric_level", name = "Metric Level", type = METRIC_LEVEL, global = true, project = false),
+  @Property(key = "float", name = "Float", type = FLOAT, global = true, project = false),
+  @Property(key = "int", name = "Integer", type = INTEGER, global = true, project = false),
+  @Property(key = "string", name = "String", type = STRING, global = true, project = false),
+  @Property(key = "setting.license", name = "License", type = LICENSE, global = true, project = false),
+  @Property(key = "long", name = "Long", type = LONG, global = true, project = false),
+  @Property(key = "password", name = "Password", type = PASSWORD, global = true, project = false),
+  @Property(key = "text", name = "Text", type = TEXT, global = true, project = false),
+  @Property(key = "multi", name = "Multi", type = STRING, multiValues = true, global = true, project = false),
+  @Property(key = "hidden", name = "Hidden", type = STRING, global = false, project = false),
+  @Property(key = "setting.secured", name = "Secured", type = STRING, global = true, project = false),
+  @Property(key = "sonar.jira", name = "Jira Server", type = PROPERTY_SET, propertySetKey = "jira", fields = {
+    @PropertyField(key = "key", name = "Key", description = "Server key"),
+    @PropertyField(key = "type", name = "Type", options = {"A", "B"}),
+    @PropertyField(key = "url", name = "URL"),
+    @PropertyField(key = "port", name = "Port", type = INTEGER)}),
 })
 public class ServerPlugin extends SonarPlugin {
   public List getExtensions() {
index 035ba9fd069da8adb6d9444c36e33e0df5f36546..c3e94c7b3561b7906286867213f1315e6e6482e9 100644 (file)
@@ -19,6 +19,7 @@
  */
 package it.settings;
 
+import com.google.common.collect.ImmutableMap;
 import com.sonar.orchestrator.Orchestrator;
 import it.Category1Suite;
 import java.io.IOException;
@@ -37,6 +38,7 @@ import org.sonarqube.ws.client.setting.SettingsService;
 import org.sonarqube.ws.client.setting.ValuesRequest;
 import util.user.UserRule;
 
+import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.sonarqube.ws.Settings.Setting;
@@ -138,6 +140,24 @@ public class SettingsTest {
     assertThat(getSetting("setting.license.secured", adminSettingsService).getValue()).isEqualTo("test");
   }
 
+  @Test
+  public void multi_values_setting() throws Exception {
+    adminSettingsService.set(SetRequest.builder().setKey("multi").setValues(asList("value1", "value2", "value3")).build());
+    assertThat(getSetting("multi", anonymousSettingsService).getValues().getValuesList()).containsOnly("value1", "value2", "value3");
+  }
+
+  @Test
+  public void property_set_setting() throws Exception {
+    adminSettingsService.set(SetRequest.builder().setKey("sonar.jira").setFieldValues(asList(
+      "{\"key\":\"jira1\", \"url\":\"http://jira1\", \"port\":\"12345\", \"type\":\"A\"}",
+      "{\"key\":\"jira2\", \"url\":\"http://jira2\", \"port\":\"54321\"}"))
+      .build());
+
+    assertThat(getSetting("sonar.jira", anonymousSettingsService).getFieldValues().getFieldValuesList()).extracting(Settings.FieldValues.Value::getValue).containsOnly(
+      ImmutableMap.of("key", "jira1", "url", "http://jira1", "port", "12345", "type", "A"),
+      ImmutableMap.of("key", "jira2", "url", "http://jira2", "port", "54321"));
+  }
+
   @Test
   public void return_defined_settings_when_no_key_provided() throws Exception {
     adminSettingsService.set(SetRequest.builder().setKey(PLUGIN_SETTING_KEY).setValue("some value").build());