]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7969 Return property set values in /api/settings/values WS
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 19 Aug 2016 16:35:30 +0000 (18:35 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 25 Aug 2016 08:03:39 +0000 (10:03 +0200)
server/sonar-server/src/main/java/org/sonar/server/settings/ws/ListDefinitionsAction.java
server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java
server/sonar-server/src/main/resources/org/sonar/server/settings/ws/values-example.json
server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java
sonar-ws/src/main/protobuf/ws-settings.proto

index b098a1c9c598ab28d044047690e95314f92ce87c..db554d019fe7f9844ceb3d1ecaae62a3383ea1ee 100644 (file)
@@ -55,8 +55,8 @@ public class ListDefinitionsAction implements SettingsWsAction {
   @Override
   public void define(WebService.NewController context) {
     WebService.NewAction action = context.createAction("list_definitions")
-      .setDescription(String.format("Returns definitions of properties.<br>" +
-        "Either '%s' or '%s' could be provided, not both.<br> " +
+      .setDescription(String.format("List settings definitions.<br>" +
+        "Either '%s' or '%s' can be provided, not both.<br> " +
         "Requires one of the following permissions: " +
         "<ul>" +
         "<li>'Administer System'</li>" +
index 83dec424f604b767ddf2ce7aa1aca96db87859db..98f982c1fd99c4ffe7d19d286eee282d14b41dc1 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.settings.ws;
 
 import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableTable;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -41,6 +42,7 @@ import org.sonarqube.ws.Settings;
 import org.sonarqube.ws.Settings.ValuesWsResponse;
 
 import static org.elasticsearch.common.Strings.isNullOrEmpty;
+import static org.sonar.api.PropertyType.PROPERTY_SET;
 import static org.sonar.server.settings.ws.SettingsWsComponentParameters.PARAM_COMPONENT_ID;
 import static org.sonar.server.settings.ws.SettingsWsComponentParameters.PARAM_COMPONENT_KEY;
 import static org.sonar.server.settings.ws.SettingsWsComponentParameters.addComponentParameters;
@@ -48,7 +50,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class ValuesAction implements SettingsWsAction {
 
-  private static final Splitter MULTI_VALUE_SPLITTER = Splitter.on(",");
+  private static final Splitter COMMA_SPLITTER = Splitter.on(",");
 
   static final String PARAM_KEYS = "keys";
 
@@ -65,14 +67,14 @@ public class ValuesAction implements SettingsWsAction {
   @Override
   public void define(WebService.NewController context) {
     WebService.NewAction action = context.createAction("values")
-      .setDescription(String.format("Returns values of given properties.<br>" +
-        "If no value have been set for a property, then the default value is returned.<br>" +
-        "Either '%s' or '%s' could be provided, not both.<br> " +
+      .setDescription("List settings values.<br>" +
+        "If no value has been set for a setting, then the default value is returned.<br>" +
+        "Either '%s' or '%s' can be provided, not both.<br> " +
         "Requires one of the following permissions: " +
         "<ul>" +
         "<li>'Administer System'</li>" +
         "<li>'Administer' rights on the specified component</li>" +
-        "</ul>", PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY))
+        "</ul>", PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY)
       .setResponseExample(getClass().getResource("values-example.json"))
       .setSince("6.1")
       .setHandler(this);
@@ -95,43 +97,48 @@ public class ValuesAction implements SettingsWsAction {
       settingsWsComponentParameters.checkAdminPermission(component);
       Set<String> keys = new HashSet<>(request.mandatoryParamAsStrings(PARAM_KEYS));
 
-      List<PropertyDefinition> definitions = getDefinitions(keys);
-      Map<String, PropertyDefinition> definitionsByKey = definitions.stream()
-        .collect(Collectors.toMap(PropertyDefinition::key, Function.identity()));
-
       ValuesWsResponse.Builder valuesBuilder = ValuesWsResponse.newBuilder();
-      new ValuesBuilder(dbSession, valuesBuilder, definitionsByKey, keys, component).build();
-      return valuesBuilder.build();
+      new SettingsBuilder(dbSession, valuesBuilder, getDefinitions(keys), keys, component).build();
+      ValuesWsResponse response = valuesBuilder.build();
+      return response;
     } finally {
       dbClient.closeSession(dbSession);
     }
   }
 
-  private class ValuesBuilder {
+  private class SettingsBuilder {
     private final DbSession dbSession;
+    private final ComponentDto component;
+
     private final ValuesWsResponse.Builder valuesWsBuilder;
     private final Map<String, PropertyDefinition> definitionsByKey;
     private final Set<String> keys;
-    private final ComponentDto component;
+    private final Set<String> propertySetKeys;
 
-    private final Map<String, Settings.Value.Builder> valueBuilderByKey = new HashMap<>();
+    private final Map<String, Settings.Setting.Builder> settingsBuilderByKey = new HashMap<>();
 
-    ValuesBuilder(DbSession dbSession, ValuesWsResponse.Builder valuesWsBuilder, Map<String, PropertyDefinition> definitionsByKey,
+    SettingsBuilder(DbSession dbSession, ValuesWsResponse.Builder valuesWsBuilder, List<PropertyDefinition> definitions,
       Set<String> keys, @Nullable ComponentDto component) {
       this.dbSession = dbSession;
       this.valuesWsBuilder = valuesWsBuilder;
-      this.definitionsByKey = definitionsByKey;
+      this.definitionsByKey = definitions.stream()
+        .collect(Collectors.toMap(PropertyDefinition::key, Function.identity()));
       this.keys = keys;
       this.component = component;
+
+      this.propertySetKeys = definitions.stream()
+        .filter(definition -> definition.type().equals(PROPERTY_SET))
+        .map(PropertyDefinition::key)
+        .collect(Collectors.toSet());
     }
 
     void build() {
       processDefinitions();
-      processPropertyDtos(dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys));
+      processPropertyDtos(true);
       if (component != null) {
-        processPropertyDtos(dbClient.propertiesDao().selectComponentPropertiesByKeys(dbSession, keys, component.getId()));
+        processPropertyDtos(false);
       }
-      valueBuilderByKey.values().forEach(Settings.Value.Builder::build);
+      settingsBuilderByKey.values().forEach(Settings.Setting.Builder::build);
     }
 
     private void processDefinitions() {
@@ -141,38 +148,103 @@ public class ValuesAction implements SettingsWsAction {
     }
 
     private void processDefaultValue(PropertyDefinition definition) {
-      Settings.Value.Builder valueBuilder = valuesWsBuilder.addValuesBuilder()
+      Settings.Setting.Builder settingBuilder = valuesWsBuilder.addSettingsBuilder()
         .setKey(definition.key())
-        .setIsDefault(true);
-      setValue(valueBuilder, definition.defaultValue());
-      valueBuilderByKey.put(definition.key(), valueBuilder);
+        .setInherited(false)
+        .setDefault(true);
+      setValue(settingBuilder, definition.defaultValue());
+      settingsBuilderByKey.put(definition.key(), settingBuilder);
     }
 
-    private void processPropertyDtos(List<PropertyDto> properties) {
-      properties.stream()
-        .filter(propertyDto -> !isNullOrEmpty(propertyDto.getValue()))
-        .forEach(this::processDtoValue);
+    private void processPropertyDtos(boolean loadGlobal) {
+      List<PropertyDto> properties = loadProperties(dbSession, loadGlobal, keys);
+      PropertySetValues propertySetValues = new PropertySetValues(properties, loadGlobal);
+
+      properties.forEach(property -> {
+        String key = property.getKey();
+        Settings.Setting.Builder valueBuilder = getOrCreateValueBuilder(key);
+        valueBuilder.setInherited(component != null && property.getResourceId() == null);
+        valueBuilder.setDefault(false);
+
+        PropertyDefinition definition = definitionsByKey.get(key);
+        if (definition != null && definition.type().equals(PROPERTY_SET)) {
+          Settings.FieldsValues.Builder builder = Settings.FieldsValues.newBuilder();
+          for (Map<String, String> propertySetMap : propertySetValues.get(key)) {
+            builder.addFieldsValuesBuilder().putAllValue(propertySetMap);
+          }
+          valueBuilder.setFieldsValues(builder);
+        } else {
+          setValue(valueBuilder, property.getValue());
+        }
+      });
     }
 
-    private void processDtoValue(PropertyDto property) {
-      Settings.Value.Builder valueBuilder = valueBuilderByKey.get(property.getKey());
+    private Settings.Setting.Builder getOrCreateValueBuilder(String propertyKey) {
+      Settings.Setting.Builder valueBuilder = settingsBuilderByKey.get(propertyKey);
       if (valueBuilder == null) {
-        valueBuilder = valuesWsBuilder.addValuesBuilder().setKey(property.getKey());
-        valueBuilderByKey.put(property.getKey(), valueBuilder);
+        valueBuilder = valuesWsBuilder.addSettingsBuilder().setKey(propertyKey);
+        settingsBuilderByKey.put(propertyKey, valueBuilder);
       }
-      valueBuilder.setIsInherited(component != null && property.getResourceId() == null);
-      valueBuilder.setIsDefault(false);
-      setValue(valueBuilder, property.getValue());
+      return valueBuilder;
     }
 
-    private void setValue(Settings.Value.Builder valueBuilder, String value) {
+    private void setValue(Settings.Setting.Builder valueBuilder, String value) {
       PropertyDefinition definition = definitionsByKey.get(valueBuilder.getKey());
       if (definition != null && definition.multiValues()) {
-        valueBuilder.addAllValues(MULTI_VALUE_SPLITTER.split(value));
+        valueBuilder.setValues(Settings.Values.newBuilder().addAllValues(COMMA_SPLITTER.split(value)));
       } else {
         valueBuilder.setValue(value);
       }
     }
+
+    private List<PropertyDto> loadProperties(DbSession dbSession, boolean loadGlobal, Set<String> keys) {
+      if (loadGlobal) {
+        return dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys);
+      }
+      return dbClient.propertiesDao().selectComponentPropertiesByKeys(dbSession, keys, component.getId());
+    }
+
+    private class PropertySetValues {
+      private final Map<String, PropertyKeyWithFieldAndSetId> propertyKeyWithFieldAndSetIds = new HashMap<>();
+      private final Map<String, PropertySetValue> propertySetValuesByPropertyKey = new HashMap<>();
+
+      PropertySetValues(List<PropertyDto> properties, boolean loadGlobal) {
+        properties.stream()
+          .filter(propertyDto -> propertySetKeys.contains(propertyDto.getKey()))
+          .forEach(propertyDto -> definitionsByKey.get(propertyDto.getKey()).fields()
+            .forEach(field -> COMMA_SPLITTER.splitToList(propertyDto.getValue())
+              .forEach(value -> add(propertyDto.getKey(), field.key(), value))));
+
+        loadProperties(dbSession, loadGlobal, propertyKeyWithFieldAndSetIds.keySet())
+          .forEach(propertySetDto -> {
+            PropertyKeyWithFieldAndSetId propertyKeyWithFieldAndSetIdKey = propertyKeyWithFieldAndSetIds.get(propertySetDto.getKey());
+            PropertySetValue propertySetValue = getOrCreatePropertySetValue(propertyKeyWithFieldAndSetIdKey.getPropertyKey());
+            propertySetValue.add(propertyKeyWithFieldAndSetIdKey.getSetId(), propertyKeyWithFieldAndSetIdKey.getFieldKey(), propertySetDto.getValue());
+          });
+      }
+
+      private void add(String propertyKey, String fieldKey, String value) {
+        String propertySetKey = generatePropertySetKey(propertyKey, value, fieldKey);
+        propertyKeyWithFieldAndSetIds.put(propertySetKey, new PropertyKeyWithFieldAndSetId(propertyKey, fieldKey, value));
+      }
+
+      private PropertySetValue getOrCreatePropertySetValue(String propertyKey) {
+        PropertySetValue propertySetValue = propertySetValuesByPropertyKey.get(propertyKey);
+        if (propertySetValue == null) {
+          propertySetValue = new PropertySetValue();
+          propertySetValuesByPropertyKey.put(propertyKey, propertySetValue);
+        }
+        return propertySetValue;
+      }
+
+      List<Map<String, String>> get(String propertyKey) {
+        return propertySetValuesByPropertyKey.get(propertyKey).get();
+      }
+
+      private String generatePropertySetKey(String propertyKey, String id, String fieldKey) {
+        return propertyKey + "." + id + "." + fieldKey;
+      }
+    }
   }
 
   private List<PropertyDefinition> getDefinitions(Set<String> keys) {
@@ -181,4 +253,43 @@ public class ValuesAction implements SettingsWsAction {
       .collect(Collectors.toList());
   }
 
+  private static class PropertyKeyWithFieldAndSetId {
+    private final String propertyKey;
+    private final String fieldKey;
+    private final String setId;
+
+    PropertyKeyWithFieldAndSetId(String propertyKey, String fieldKey, String setId) {
+      this.propertyKey = propertyKey;
+      this.fieldKey = fieldKey;
+      this.setId = setId;
+    }
+
+    public String getPropertyKey() {
+      return propertyKey;
+    }
+
+    public String getFieldKey() {
+      return fieldKey;
+    }
+
+    public String getSetId() {
+      return setId;
+    }
+  }
+
+  private static class PropertySetValue {
+    ImmutableTable.Builder<String, String, String> tableBuilder = new ImmutableTable.Builder<>();
+
+    public void add(String setId, String fieldKey, String value) {
+      tableBuilder.put(setId, fieldKey, value);
+    }
+
+    public List<Map<String, String>> get() {
+      ImmutableTable<String, String, String> table = tableBuilder.build();
+      return table.rowKeySet().stream()
+        .map(table::row)
+        .collect(Collectors.toList());
+    }
+  }
+
 }
index 11d7e50851d0998d26d75c9ac4add3c6ebcaa71f..45fbda86e0c2a44e7f989ef995be569709ebb66d 100644 (file)
@@ -1,9 +1,10 @@
 {
-  "values": [
+  "settings": [
     {
       "key": "sonar.test.jira",
       "value": "abc",
-      "isDefault": true
+      "default": true,
+      "inherited": false
     },
     {
       "key": "sonar.autogenerated",
         "val2",
         "val3"
       ],
-      "isDefault": false
+      "default": false,
+      "inherited": false
     },
     {
       "key": "sonar.demo",
-      "setValues": {
-        "text": {
-          "values": [
-            "foo",
-            "bar"
-          ]
+      "fieldsValues": [
+        {
+          "boolean": "true",
+          "text": "foo"
         },
-        "boolean": {
-          "values": [
-            "true",
-            "false"
-          ]
+        {
+          "boolean": "false",
+          "text": "bar"
         }
-      },
-      "isDefault": false
+      ],
+      "default": false,
+      "inherited": false
     }
   ]
 }
index 792005321e7962e7fdfb1719790d77f2a75b2f78..65b220877374812717b4514586bae1f376250bbd 100644 (file)
@@ -24,12 +24,13 @@ import com.google.common.base.Joiner;
 import java.io.IOException;
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.PropertyType;
 import org.sonar.api.config.PropertyDefinition;
 import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.PropertyFieldDefinition;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -48,7 +49,9 @@ import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.Settings;
 import org.sonarqube.ws.Settings.ValuesWsResponse;
 
+import static java.util.Arrays.asList;
 import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.assertj.core.api.Java6Assertions.entry;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.core.permission.GlobalPermissions.DASHBOARD_SHARING;
@@ -95,14 +98,14 @@ public class ValuesActionTest {
     insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
 
     ValuesWsResponse result = newRequestForGlobalProperties("foo");
-    assertThat(result.getValuesList()).hasSize(1);
+    assertThat(result.getSettingsList()).hasSize(1);
 
-    Settings.Value value = result.getValues(0);
+    Settings.Setting value = result.getSettings(0);
     assertThat(value.getKey()).isEqualTo("foo");
     assertThat(value.getValue()).isEqualTo("one");
-    assertThat(value.getValuesCount()).isZero();
-    assertThat(value.getSetValues()).isEmpty();
-    assertThat(value.getIsDefault()).isFalse();
+    assertThat(value.hasValues()).isFalse();
+    assertThat(value.hasFieldsValues()).isFalse();
+    assertThat(value.getDefault()).isFalse();
   }
 
   @Test
@@ -122,19 +125,77 @@ public class ValuesActionTest {
     insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four"));
 
     ValuesWsResponse result = newRequestForGlobalProperties("default", "global");
-    assertThat(result.getValuesList()).hasSize(2);
+    assertThat(result.getSettingsList()).hasSize(2);
 
-    Settings.Value foo = result.getValues(0);
+    Settings.Setting foo = result.getSettings(0);
     assertThat(foo.getKey()).isEqualTo("default");
     assertThat(foo.hasValue()).isFalse();
-    assertThat(foo.getValuesList()).containsOnly("one", "two");
-    assertThat(foo.getSetValues()).isEmpty();
+    assertThat(foo.getValues().getValuesList()).containsOnly("one", "two");
+    assertThat(foo.hasFieldsValues()).isFalse();
 
-    Settings.Value bar = result.getValues(1);
+    Settings.Setting bar = result.getSettings(1);
     assertThat(bar.getKey()).isEqualTo("global");
     assertThat(bar.hasValue()).isFalse();
-    assertThat(bar.getValuesList()).containsOnly("three", "four");
-    assertThat(bar.getSetValues()).isEmpty();
+    assertThat(bar.getValues().getValuesList()).containsOnly("three", "four");
+    assertThat(bar.hasFieldsValues()).isFalse();
+  }
+
+  @Test
+  public void return_property_set() throws Exception {
+    setUserAsSystemAdmin();
+    propertyDefinitions.addComponent(PropertyDefinition
+      .builder("foo")
+      .type(PropertyType.PROPERTY_SET)
+      .fields(asList(
+        PropertyFieldDefinition.build("key").name("Key").build(),
+        PropertyFieldDefinition.build("size").name("Size").build()))
+      .build());
+    insertProperties(
+      newGlobalPropertyDto().setKey("foo").setValue("1,2"),
+      newGlobalPropertyDto().setKey("foo.1.key").setValue("key1"),
+      newGlobalPropertyDto().setKey("foo.1.size").setValue("size1"),
+      newGlobalPropertyDto().setKey("foo.2.key").setValue("key2"));
+
+    ValuesWsResponse result = newRequestForGlobalProperties("foo");
+    assertThat(result.getSettingsList()).hasSize(1);
+
+    Settings.Setting value = result.getSettings(0);
+    assertThat(value.getKey()).isEqualTo("foo");
+    assertThat(value.hasValue()).isFalse();
+    assertThat(value.hasValues()).isFalse();
+
+    assertThat(value.getFieldsValues().getFieldsValuesList()).hasSize(2);
+    assertThat(value.getFieldsValues().getFieldsValuesList().get(0).getValue()).containsOnly(entry("key", "key1"), entry("size", "size1"));
+    assertThat(value.getFieldsValues().getFieldsValuesList().get(1).getValue()).containsOnly(entry("key", "key2"));
+  }
+
+  @Test
+  public void return_property_set_for_component() throws Exception {
+    setUserAsSystemAdmin();
+    propertyDefinitions.addComponent(PropertyDefinition
+      .builder("foo")
+      .type(PropertyType.PROPERTY_SET)
+      .fields(asList(
+        PropertyFieldDefinition.build("key").name("Key").build(),
+        PropertyFieldDefinition.build("size").name("Size").build()))
+      .build());
+    insertProperties(
+      newComponentPropertyDto(project).setKey("foo").setValue("1,2"),
+      newComponentPropertyDto(project).setKey("foo.1.key").setValue("key1"),
+      newComponentPropertyDto(project).setKey("foo.1.size").setValue("size1"),
+      newComponentPropertyDto(project).setKey("foo.2.key").setValue("key2"));
+
+    ValuesWsResponse result = newRequestForProjectProperties("foo");
+    assertThat(result.getSettingsList()).hasSize(1);
+
+    Settings.Setting value = result.getSettings(0);
+    assertThat(value.getKey()).isEqualTo("foo");
+    assertThat(value.hasValue()).isFalse();
+    assertThat(value.hasValues()).isFalse();
+
+    assertThat(value.getFieldsValues().getFieldsValuesList()).hasSize(2);
+    assertThat(value.getFieldsValues().getFieldsValuesList().get(0).getValue()).containsOnly(entry("key", "key1"), entry("size", "size1"));
+    assertThat(value.getFieldsValues().getFieldsValuesList().get(1).getValue()).containsOnly(entry("key", "key2"));
   }
 
   @Test
@@ -146,13 +207,13 @@ public class ValuesActionTest {
       .build());
 
     ValuesWsResponse result = newRequestForGlobalProperties("foo");
-    assertThat(result.getValuesList()).hasSize(1);
+    assertThat(result.getSettingsList()).hasSize(1);
 
-    Settings.Value value = result.getValues(0);
+    Settings.Setting value = result.getSettings(0);
     assertThat(value.getKey()).isEqualTo("foo");
     assertThat(value.getValue()).isEqualTo("default");
-    assertThat(value.getIsDefault()).isTrue();
-    assertThat(value.getIsInherited()).isFalse();
+    assertThat(value.getDefault()).isTrue();
+    assertThat(value.getInherited()).isFalse();
   }
 
   @Test
@@ -164,17 +225,17 @@ public class ValuesActionTest {
       newGlobalPropertyDto().setKey("property").setValue("one"));
 
     ValuesWsResponse result = newRequestForGlobalProperties("property");
-    assertThat(result.getValuesList()).hasSize(1);
+    assertThat(result.getSettingsList()).hasSize(1);
 
-    Settings.Value globalPropertyValue = result.getValues(0);
+    Settings.Setting globalPropertyValue = result.getSettings(0);
     assertThat(globalPropertyValue.getKey()).isEqualTo("property");
     assertThat(globalPropertyValue.getValue()).isEqualTo("one");
-    assertThat(globalPropertyValue.getIsDefault()).isFalse();
-    assertThat(globalPropertyValue.getIsInherited()).isFalse();
+    assertThat(globalPropertyValue.getDefault()).isFalse();
+    assertThat(globalPropertyValue.getInherited()).isFalse();
   }
 
   @Test
-  public void return_component_values() throws Exception {
+  public void return_project_values() throws Exception {
     setUserAsSystemAdmin();
     propertyDefinitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build());
     insertProperties(
@@ -183,13 +244,13 @@ public class ValuesActionTest {
       newComponentPropertyDto(project).setKey("property").setValue("two"));
 
     ValuesWsResponse result = newRequestForProjectProperties("property");
-    assertThat(result.getValuesList()).hasSize(1);
+    assertThat(result.getSettingsList()).hasSize(1);
 
-    Settings.Value globalPropertyValue = result.getValues(0);
+    Settings.Setting globalPropertyValue = result.getSettings(0);
     assertThat(globalPropertyValue.getKey()).isEqualTo("property");
     assertThat(globalPropertyValue.getValue()).isEqualTo("two");
-    assertThat(globalPropertyValue.getIsDefault()).isFalse();
-    assertThat(globalPropertyValue.getIsInherited()).isFalse();
+    assertThat(globalPropertyValue.getDefault()).isFalse();
+    assertThat(globalPropertyValue.getInherited()).isFalse();
   }
 
   @Test
@@ -200,13 +261,13 @@ public class ValuesActionTest {
     insertProperties(newGlobalPropertyDto().setKey("property").setValue("one"));
 
     ValuesWsResponse result = newRequestForProjectProperties("property");
-    assertThat(result.getValuesList()).hasSize(1);
+    assertThat(result.getSettingsList()).hasSize(1);
 
-    Settings.Value globalPropertyValue = result.getValues(0);
+    Settings.Setting globalPropertyValue = result.getSettings(0);
     assertThat(globalPropertyValue.getKey()).isEqualTo("property");
     assertThat(globalPropertyValue.getValue()).isEqualTo("one");
-    assertThat(globalPropertyValue.getIsDefault()).isFalse();
-     assertThat(globalPropertyValue.getIsInherited()).isTrue();
+    assertThat(globalPropertyValue.getDefault()).isFalse();
+    assertThat(globalPropertyValue.getInherited()).isTrue();
   }
 
   @Test
@@ -215,10 +276,10 @@ public class ValuesActionTest {
     insertProperties(newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value"));
 
     ValuesWsResponse result = newRequestForGlobalProperties("globalPropertyWithoutDefinition");
-    Settings.Value globalPropertyWithoutDefinitionValue = result.getValues(0);
+    Settings.Setting globalPropertyWithoutDefinitionValue = result.getSettings(0);
     assertThat(globalPropertyWithoutDefinitionValue.getKey()).isEqualTo("globalPropertyWithoutDefinition");
     assertThat(globalPropertyWithoutDefinitionValue.getValue()).isEqualTo("value");
-    assertThat(globalPropertyWithoutDefinitionValue.getIsDefault()).isFalse();
+    assertThat(globalPropertyWithoutDefinitionValue.getDefault()).isFalse();
   }
 
   @Test
@@ -227,10 +288,9 @@ public class ValuesActionTest {
     propertyDefinitions.addComponent(PropertyDefinition
       .builder("foo")
       .build());
-    insertProperties(newGlobalPropertyDto().setKey("bar").setValue(""));
 
-    ValuesWsResponse result = newRequestForGlobalProperties("foo", "bar");
-    assertThat(result.getValuesList()).isEmpty();
+    ValuesWsResponse result = newRequestForGlobalProperties("foo");
+    assertThat(result.getSettingsList()).isEmpty();
   }
 
   @Test
@@ -243,17 +303,34 @@ public class ValuesActionTest {
     insertProperties(newGlobalPropertyDto().setKey("bar").setValue(""));
 
     ValuesWsResponse result = newRequestForGlobalProperties("unknown");
-    assertThat(result.getValuesList()).isEmpty();
+    assertThat(result.getSettingsList()).isEmpty();
   }
 
   @Test
-  @Ignore
   public void test_example_json_response() {
     setUserAsSystemAdmin();
     propertyDefinitions.addComponent(PropertyDefinition
       .builder("sonar.test.jira")
       .defaultValue("abc")
       .build());
+    propertyDefinitions.addComponent(PropertyDefinition
+      .builder("sonar.autogenerated")
+      .multiValues(true)
+      .build());
+    insertProperties(newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3"));
+
+    propertyDefinitions.addComponent(PropertyDefinition
+      .builder("sonar.demo")
+      .type(PropertyType.PROPERTY_SET)
+      .fields(PropertyFieldDefinition.build("text").name("Text").build(),
+        PropertyFieldDefinition.build("boolean").name("Boolean").build())
+      .build());
+    insertProperties(
+      newGlobalPropertyDto().setKey("sonar.demo").setValue("1,2"),
+      newGlobalPropertyDto().setKey("sonar.demo.1.text").setValue("foo"),
+      newGlobalPropertyDto().setKey("sonar.demo.1.boolean").setValue("true"),
+      newGlobalPropertyDto().setKey("sonar.demo.2.text").setValue("bar"),
+      newGlobalPropertyDto().setKey("sonar.demo.2.boolean").setValue("false"));
 
     String result = ws.newRequest()
       .setParam("keys", "sonar.test.jira,sonar.autogenerated,sonar.demo")
index 345aef7c675bcd421fde9e16983412247ab466a8..181c12a16de6b93e50326c57355274f85f09f808 100644 (file)
@@ -68,19 +68,29 @@ enum Type {
 
 // Response of GET api/settings/values
 message ValuesWsResponse {
-  repeated Value values = 1;
+  repeated Setting settings = 1;
 }
 
-message Value {
+message Setting {
   optional string key = 1;
   optional string value = 2;
-  repeated string values = 3;
-  map<string, SetValue> setValues = 4;
-  optional bool isDefault = 5;
-  optional bool isInherited = 6;
+  optional Values values = 3;
+  optional FieldsValues fieldsValues = 4;
+  optional bool default = 5;
+  optional bool inherited = 6;
 }
 
-message SetValue {
+message Values {
   repeated string values = 1;
 }
 
+message FieldsValues {
+  repeated Value fieldsValues = 1;
+
+  message Value {
+    map<string, string> value = 1;
+  }
+}
+
+
+