]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7968 Return license in api/settings/list_definitions
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 5 Sep 2016 09:54:43 +0000 (11:54 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 5 Sep 2016 13:23:36 +0000 (15:23 +0200)
server/sonar-server/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java
sonar-ws/src/main/protobuf/ws-settings.proto

index b542ef4540c2a45cbbf5d6ba461f5b6548de5681..6c4f0a639f8431a10e3e31b55eee36ff8db0d01f 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.setting.ws;
 
 import java.util.List;
 import java.util.Optional;
-import org.sonar.api.PropertyType;
 import org.sonar.api.config.PropertyDefinition;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.PropertyFieldDefinition;
@@ -90,7 +89,6 @@ public class ListDefinitionsAction implements SettingsWsAction {
 
     propertyDefinitions.getAll().stream()
       .filter(definition -> qualifier.isPresent() ? definition.qualifiers().contains(qualifier.get()) : definition.global())
-      .filter(definition -> !definition.type().equals(PropertyType.LICENSE))
       .forEach(definition -> addDefinition(definition, wsResponse));
     return wsResponse.build();
   }
@@ -166,9 +164,7 @@ public class ListDefinitionsAction implements SettingsWsAction {
     }
     List<PropertyFieldDefinition> fields = definition.fields();
     if (!fields.isEmpty()) {
-      fields.stream()
-        .filter(fieldDefinition -> !fieldDefinition.type().equals(PropertyType.LICENSE))
-        .forEach(fieldDefinition -> addField(fieldDefinition, builder));
+      fields.forEach(fieldDefinition -> addField(fieldDefinition, builder));
     }
   }
 
index 5182de8666e67585cd5f6f67b39339fa04b2ff9e..4a7530bb845a02e3aa7f37c4ae102be351193f49 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.setting.ws;
 
 import java.io.IOException;
 import javax.annotation.Nullable;
+import org.assertj.core.groups.Tuple;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -57,6 +58,7 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonarqube.ws.MediaTypes.JSON;
 import static org.sonarqube.ws.Settings.Type.BOOLEAN;
+import static org.sonarqube.ws.Settings.Type.LICENSE;
 import static org.sonarqube.ws.Settings.Type.PROPERTY_SET;
 import static org.sonarqube.ws.Settings.Type.SINGLE_SELECT_LIST;
 import static org.sonarqube.ws.Settings.Type.STRING;
@@ -218,7 +220,7 @@ public class ListDefinitionsActionTest {
   }
 
   @Test
-  public void does_not_return_license_type_property_set() throws Exception {
+  public void return_license_type_property_set() throws Exception {
     setUserAsSystemAdmin();
     propertyDefinitions.addComponent(PropertyDefinition
       .builder("foo")
@@ -229,7 +231,7 @@ public class ListDefinitionsActionTest {
     ListDefinitionsWsResponse result = executeRequest();
 
     assertThat(result.getDefinitionsList()).hasSize(1);
-    assertThat(result.getDefinitions(0).getFieldsList()).isEmpty();
+    assertThat(result.getDefinitions(0).getFieldsList()).extracting(Settings.Field::getKey, Settings.Field::getType).containsOnly(Tuple.tuple("license", LICENSE));
   }
 
   @Test
@@ -307,13 +309,13 @@ public class ListDefinitionsActionTest {
   }
 
   @Test
-  public void does_not_return_license_type() throws Exception {
+  public void return_license_type() throws Exception {
     setUserAsSystemAdmin();
     propertyDefinitions.addComponent(PropertyDefinition.builder("license").type(PropertyType.LICENSE).build());
 
     ListDefinitionsWsResponse result = executeRequest();
 
-    assertThat(result.getDefinitionsList()).isEmpty();
+    assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey, Settings.Definition::getType).containsOnly(Tuple.tuple("license", LICENSE));
   }
 
   @Test
index 0d04c2c4f22fc5bc1066d46e97b3a44de18eb9cf..519357e522cd9ced91a6082ec71835efc85bacac 100644 (file)
@@ -70,6 +70,7 @@ enum Type {
   METRIC_LEVEL = 10;
   SINGLE_SELECT_LIST = 11;
   PROPERTY_SET = 12;
+  LICENSE = 13;
 }
 
 // Response of GET api/settings/values