import org.sonarqube.ws.client.setting.ListDefinitionsRequest;
import static com.google.common.base.Strings.emptyToNull;
+import static java.util.Comparator.comparing;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.server.setting.ws.SettingsWs.SETTING_ON_BRANCHES;
Optional<String> qualifier = getQualifier(component);
ListDefinitionsWsResponse.Builder wsResponse = ListDefinitionsWsResponse.newBuilder();
propertyDefinitions.getAll().stream()
- .filter(definition -> qualifier.isPresent() ? definition.qualifiers().contains(qualifier.get()) : definition.global())
+ .filter(definition -> qualifier.map(s -> definition.qualifiers().contains(s)).orElseGet(definition::global))
.filter(definition -> wsRequest.getBranch() == null || SETTING_ON_BRANCHES.contains(definition.key()))
.filter(settingsWsSupport.isDefinitionVisible(component))
+ .sorted(comparing(PropertyDefinition::category, String::compareToIgnoreCase)
+ .thenComparingInt(PropertyDefinition::index)
+ .thenComparing(PropertyDefinition::name, String::compareToIgnoreCase))
.forEach(definition -> addDefinition(definition, wsResponse));
return wsResponse.build();
}
import org.sonar.server.ws.WsActionTester;
import org.sonar.test.JsonAssert;
import org.sonarqube.ws.Settings;
+import org.sonarqube.ws.Settings.Definition;
import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
import static java.lang.String.format;
ListDefinitionsWsResponse result = executeRequest();
assertThat(result.getDefinitionsList()).hasSize(1);
- Settings.Definition definition = result.getDefinitions(0);
+ Definition definition = result.getDefinitions(0);
assertThat(definition.getKey()).isEqualTo("foo");
assertThat(definition.getName()).isEqualTo("Foo");
assertThat(definition.getDescription()).isEqualTo("desc");
ListDefinitionsWsResponse result = executeRequest();
assertThat(result.getDefinitionsList()).hasSize(1);
- Settings.Definition definition = result.getDefinitions(0);
+ Definition definition = result.getDefinitions(0);
assertThat(definition.getKey()).isEqualTo("foo");
assertThat(definition.getType()).isEqualTo(STRING);
assertThat(definition.getNameOneOfCase()).isEqualTo(NAMEONEOF_NOT_SET);
ListDefinitionsWsResponse result = executeRequest();
assertThat(result.getDefinitionsList()).hasSize(1);
- Settings.Definition definition = result.getDefinitions(0);
+ Definition definition = result.getDefinitions(0);
assertThat(definition.getKey()).isEqualTo("foo");
assertThat(definition.getName()).isEqualTo("Foo");
assertThat(definition.getDeprecatedKey()).isEqualTo("deprecated");
ListDefinitionsWsResponse result = executeRequest();
assertThat(result.getDefinitionsList()).hasSize(1);
- Settings.Definition definition = result.getDefinitions(0);
+ Definition definition = result.getDefinitions(0);
assertThat(definition.getType()).isEqualTo(SINGLE_SELECT_LIST);
assertThat(definition.getOptionsList()).containsExactly("one", "two");
}
ListDefinitionsWsResponse result = executeRequest();
assertThat(result.getDefinitionsList()).hasSize(1);
- Settings.Definition definition = result.getDefinitions(0);
+ Definition definition = result.getDefinitions(0);
assertThat(definition.getType()).isEqualTo(PROPERTY_SET);
assertThat(definition.getFieldsList()).hasSize(2);
assertThat(result.getDefinitionsList()).hasSize(1);
}
+ @Test
+ public void definitions_are_ordered_by_category_then_index_then_name_case_insensitive() {
+ logIn();
+ propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.11").category("cat-1").index(1).name("prop 1").build());
+ propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.12").category("cat-1").index(2).name("prop 2").build());
+ propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.13").category("CAT-1").index(1).name("prop 3").build());
+ propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.41").category("cat-0").index(25).name("prop 1").build());
+
+ ListDefinitionsWsResponse result = executeRequest();
+
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey)
+ .containsExactly("sonar.prop.41", "sonar.prop.11", "sonar.prop.13", "sonar.prop.12");
+ }
+
@Test
public void return_project_settings_def_by_project_key() {
logInAsProjectUser();
ListDefinitionsWsResponse result = executeRequest();
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey, Settings.Definition::getType)
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey, Definition::getType)
.containsOnly(tuple("plugin.license.secured", LICENSE), tuple("commercial.plugin", LICENSE));
}
ListDefinitionsWsResponse result = executeRequest();
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsOnly("foo");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo");
}
@Test
ListDefinitionsWsResponse result = executeRequest();
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsOnly("foo", "plugin.license.secured", "commercial.plugin");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo", "plugin.license.secured", "commercial.plugin");
}
@Test
ListDefinitionsWsResponse result = executeRequest();
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured", "commercial.plugin");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured", "commercial.plugin");
}
@Test
ListDefinitionsWsResponse result = executeRequest();
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured");
}
@Test
ListDefinitionsWsResponse result = executeRequest(project.getDbKey());
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo", "secret.secured", "plugin.license.secured");
}
@Test
.setParam("branch", branch.getBranch())
.executeProtobuf(Settings.ListDefinitionsWsResponse.class);
- assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey).containsExactlyInAnyOrder("sonar.leak.period");
+ assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsExactlyInAnyOrder("sonar.leak.period");
}
@Test