From: Julien Lancelot Date: Mon, 5 Sep 2016 09:54:43 +0000 (+0200) Subject: SONAR-7968 Return license in api/settings/list_definitions X-Git-Tag: 6.1-RC1~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=db897e3747439f6672ba66586371761a258422f6;p=sonarqube.git SONAR-7968 Return license in api/settings/list_definitions --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java index b542ef4540c..6c4f0a639f8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java @@ -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 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)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java index 5182de8666e..4a7530bb845 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java @@ -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 diff --git a/sonar-ws/src/main/protobuf/ws-settings.proto b/sonar-ws/src/main/protobuf/ws-settings.proto index 0d04c2c4f22..519357e522c 100644 --- a/sonar-ws/src/main/protobuf/ws-settings.proto +++ b/sonar-ws/src/main/protobuf/ws-settings.proto @@ -70,6 +70,7 @@ enum Type { METRIC_LEVEL = 10; SINGLE_SELECT_LIST = 11; PROPERTY_SET = 12; + LICENSE = 13; } // Response of GET api/settings/values