@@ -269,10 +269,10 @@ public class WebhooksTest { | |||
private void setProperty(@Nullable String componentKey, String key, @Nullable String value) { | |||
if (value == null) { | |||
ResetRequest req = ResetRequest.builder().setKeys(key).setComponentKey(componentKey).build(); | |||
ResetRequest req = ResetRequest.builder().setKeys(key).setComponent(componentKey).build(); | |||
adminWs.settingsService().reset(req); | |||
} else { | |||
SetRequest req = SetRequest.builder().setKey(key).setValue(value).setComponentKey(componentKey).build(); | |||
SetRequest req = SetRequest.builder().setKey(key).setValue(value).setComponent(componentKey).build(); | |||
adminWs.settingsService().set(req); | |||
} | |||
} |
@@ -217,9 +217,9 @@ public class ItUtils { | |||
public static void setServerProperty(Orchestrator orchestrator, @Nullable String componentKey, String key, @Nullable String value) { | |||
if (value == null) { | |||
newAdminWsClient(orchestrator).settingsService().reset(ResetRequest.builder().setKeys(key).setComponentKey(componentKey).build()); | |||
newAdminWsClient(orchestrator).settingsService().reset(ResetRequest.builder().setKeys(key).setComponent(componentKey).build()); | |||
} else { | |||
newAdminWsClient(orchestrator).settingsService().set(SetRequest.builder().setKey(key).setValue(value).setComponentKey(componentKey).build()); | |||
newAdminWsClient(orchestrator).settingsService().set(SetRequest.builder().setKey(key).setValue(value).setComponent(componentKey).build()); | |||
} | |||
} | |||
@@ -230,7 +230,7 @@ public class ItUtils { | |||
} | |||
public static void resetSettings(Orchestrator orchestrator, @Nullable String componentKey, String... keys) { | |||
newAdminWsClient(orchestrator).settingsService().reset(ResetRequest.builder().setKeys(keys).setComponentKey(componentKey).build()); | |||
newAdminWsClient(orchestrator).settingsService().reset(ResetRequest.builder().setKeys(keys).setComponent(componentKey).build()); | |||
} | |||
public static void resetEmailSettings(Orchestrator orchestrator) { |
@@ -40,12 +40,10 @@ import org.sonarqube.ws.client.setting.ListDefinitionsRequest; | |||
import static com.google.common.base.Strings.emptyToNull; | |||
import static org.sonar.core.util.Protobuf.setNullable; | |||
import static org.sonar.server.component.ComponentFinder.ParamNames.ID_AND_KEY; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameters.addComponentParameters; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameter.addComponentParameter; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_LIST_DEFINITIONS; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
public class ListDefinitionsAction implements SettingsWsAction { | |||
@@ -64,18 +62,16 @@ public class ListDefinitionsAction implements SettingsWsAction { | |||
@Override | |||
public void define(WebService.NewController context) { | |||
WebService.NewAction action = context.createAction(ACTION_LIST_DEFINITIONS) | |||
.setDescription(String.format("List settings definitions.<br>" + | |||
"Either '%s' or '%s' can be provided, not both.<br> " + | |||
.setDescription("List settings definitions.<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>") | |||
.setResponseExample(getClass().getResource("list_definitions-example.json")) | |||
.setSince("6.1") | |||
.setInternal(true) | |||
.setHandler(this); | |||
addComponentParameters(action); | |||
addComponentParameter(action); | |||
} | |||
@Override | |||
@@ -96,8 +92,7 @@ public class ListDefinitionsAction implements SettingsWsAction { | |||
private static ListDefinitionsRequest toWsRequest(Request request) { | |||
return ListDefinitionsRequest.builder() | |||
.setComponentId(request.param(PARAM_COMPONENT_ID)) | |||
.setComponentKey(request.param(PARAM_COMPONENT_KEY)) | |||
.setComponent(request.param(PARAM_COMPONENT)) | |||
.build(); | |||
} | |||
@@ -113,12 +108,11 @@ public class ListDefinitionsAction implements SettingsWsAction { | |||
} | |||
private Optional<ComponentDto> getComponent(DbSession dbSession, ListDefinitionsRequest wsRequest) { | |||
String componentId = wsRequest.getComponentId(); | |||
String componentKey = wsRequest.getComponentKey(); | |||
if (componentId != null || componentKey != null) { | |||
return Optional.of(componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, ID_AND_KEY)); | |||
String componentKey = wsRequest.getComponent(); | |||
if (componentKey == null) { | |||
return Optional.empty(); | |||
} | |||
return Optional.empty(); | |||
return Optional.of(componentFinder.getByKey(dbSession, componentKey)); | |||
} | |||
private void checkAdminPermission(Optional<ComponentDto> component) { |
@@ -41,10 +41,9 @@ import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.client.setting.ResetRequest; | |||
import static java.util.Collections.emptyList; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameters.addComponentParameters; | |||
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameter.addComponentParameter; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_RESET; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS; | |||
public class ResetAction implements SettingsWsAction { | |||
@@ -70,14 +69,12 @@ public class ResetAction implements SettingsWsAction { | |||
public void define(WebService.NewController context) { | |||
WebService.NewAction action = context.createAction(ACTION_RESET) | |||
.setDescription("Remove a setting value.<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>") | |||
.setSince("6.1") | |||
.setInternal(true) | |||
.setPost(true) | |||
.setHandler(this); | |||
@@ -85,7 +82,7 @@ public class ResetAction implements SettingsWsAction { | |||
.setDescription("Setting keys") | |||
.setExampleValue("sonar.links.scm,sonar.debt.hoursInDay") | |||
.setRequired(true); | |||
addComponentParameters(action); | |||
addComponentParameter(action); | |||
} | |||
@Override | |||
@@ -126,17 +123,16 @@ public class ResetAction implements SettingsWsAction { | |||
private static ResetRequest toWsRequest(Request request) { | |||
return ResetRequest.builder() | |||
.setKeys(request.paramAsStrings(PARAM_KEYS)) | |||
.setComponentId(request.param(PARAM_COMPONENT_ID)) | |||
.setComponentKey(request.param(PARAM_COMPONENT_KEY)) | |||
.setComponent(request.param(PARAM_COMPONENT)) | |||
.build(); | |||
} | |||
private Optional<ComponentDto> getComponent(DbSession dbSession, ResetRequest request) { | |||
if (request.getComponentId() == null && request.getComponentKey() == null) { | |||
String componentKey = request.getComponent(); | |||
if (componentKey == null) { | |||
return Optional.empty(); | |||
} | |||
ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY); | |||
return Optional.of(project); | |||
return Optional.of(componentFinder.getByKey(dbSession, componentKey)); | |||
} | |||
private void checkPermissions(Optional<ComponentDto> component) { |
@@ -46,7 +46,6 @@ import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.web.UserRole; | |||
import org.sonar.core.permission.GlobalPermissions; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
@@ -57,13 +56,12 @@ import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.platform.SettingsChangeNotifier; | |||
import org.sonar.server.setting.ws.SettingValidations.SettingData; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonar.server.ws.KeyExamples; | |||
import org.sonarqube.ws.client.setting.SetRequest; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameter.addComponentParameter; | |||
import static org.sonar.server.ws.WsUtils.checkRequest; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_SET; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_FIELD_VALUES; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_VALUE; | |||
@@ -97,16 +95,13 @@ public class SetAction implements SettingsWsAction { | |||
WebService.NewAction action = context.createAction(ACTION_SET) | |||
.setDescription("Update a setting value.<br>" + | |||
"Either '%s' or '%s' must be provided, not both.<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_VALUE, PARAM_VALUES, | |||
PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY) | |||
PARAM_VALUE, PARAM_VALUES) | |||
.setSince("6.1") | |||
.setInternal(true) | |||
.setPost(true) | |||
.setHandler(this); | |||
@@ -127,13 +122,7 @@ public class SetAction implements SettingsWsAction { | |||
.setDescription("Setting field values. To set several values, the parameter must be called once for each value.") | |||
.setExampleValue(PARAM_FIELD_VALUES + "={\"firstField\":\"first value\", \"secondField\":\"second value\", \"thirdField\":\"third value\"}"); | |||
action.createParam(PARAM_COMPONENT_ID) | |||
.setDescription("Component id") | |||
.setExampleValue(Uuids.UUID_EXAMPLE_01); | |||
action.createParam(PARAM_COMPONENT_KEY) | |||
.setDescription("Component key") | |||
.setExampleValue(KeyExamples.KEY_PROJECT_EXAMPLE_001); | |||
addComponentParameter(action); | |||
} | |||
@Override | |||
@@ -291,8 +280,7 @@ public class SetAction implements SettingsWsAction { | |||
.setValue(request.param(PARAM_VALUE)) | |||
.setValues(request.multiParam(PARAM_VALUES)) | |||
.setFieldValues(request.multiParam(PARAM_FIELD_VALUES)) | |||
.setComponentId(request.param(PARAM_COMPONENT_ID)) | |||
.setComponentKey(request.param(PARAM_COMPONENT_KEY)) | |||
.setComponent(request.param(PARAM_COMPONENT)) | |||
.build(); | |||
} | |||
@@ -308,13 +296,11 @@ public class SetAction implements SettingsWsAction { | |||
} | |||
private Optional<ComponentDto> searchComponent(DbSession dbSession, SetRequest request) { | |||
if (request.getComponentId() == null && request.getComponentKey() == null) { | |||
String componentKey = request.getComponent(); | |||
if (componentKey == null) { | |||
return Optional.empty(); | |||
} | |||
ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY); | |||
return Optional.of(project); | |||
return Optional.of(componentFinder.getByKey(dbSession, componentKey)); | |||
} | |||
private PropertyDto toProperty(SetRequest request, Optional<ComponentDto> component) { |
@@ -21,23 +21,17 @@ package org.sonar.server.setting.ws; | |||
import org.sonar.api.server.ws.WebService; | |||
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
public class SettingsWsComponentParameters { | |||
class SettingsWsComponentParameter { | |||
private SettingsWsComponentParameters() { | |||
private SettingsWsComponentParameter() { | |||
// Only static methods | |||
} | |||
static void addComponentParameters(WebService.NewAction action) { | |||
action.createParam(PARAM_COMPONENT_ID) | |||
.setDescription("Component id") | |||
.setExampleValue(UUID_EXAMPLE_01); | |||
action.createParam(PARAM_COMPONENT_KEY) | |||
static void addComponentParameter(WebService.NewAction action) { | |||
action.createParam(PARAM_COMPONENT) | |||
.setDescription("Component key") | |||
.setExampleValue(KEY_PROJECT_EXAMPLE_001); | |||
} |
@@ -27,7 +27,7 @@ public class SettingsWsModule extends Module { | |||
add( | |||
SettingsWs.class, | |||
SetAction.class, | |||
SettingsWsComponentParameters.class, | |||
SettingsWsComponentParameter.class, | |||
ListDefinitionsAction.class, | |||
ValuesAction.class, | |||
SettingsFinder.class, |
@@ -57,12 +57,10 @@ import static org.sonar.api.PropertyType.LICENSE; | |||
import static org.sonar.api.PropertyType.PROPERTY_SET; | |||
import static org.sonar.api.web.UserRole.ADMIN; | |||
import static org.sonar.api.web.UserRole.USER; | |||
import static org.sonar.server.component.ComponentFinder.ParamNames.ID_AND_KEY; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameters.addComponentParameters; | |||
import static org.sonar.server.setting.ws.SettingsWsComponentParameter.addComponentParameter; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_VALUES; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS; | |||
public class ValuesAction implements SettingsWsAction { | |||
@@ -95,20 +93,17 @@ public class ValuesAction implements SettingsWsAction { | |||
WebService.NewAction action = context.createAction(ACTION_VALUES) | |||
.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 'Browse' permission when a component is specified<br/>", | |||
"To access licensed settings, authentication is required<br/>" + | |||
"To access secured settings, one of the following permissions is required: " + | |||
"<ul>" + | |||
"<li>'Administer System'</li>" + | |||
"<li>'Administer' rights on the specified component</li>" + | |||
"</ul>", | |||
PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY) | |||
"</ul>") | |||
.setResponseExample(getClass().getResource("values-example.json")) | |||
.setSince("6.1") | |||
.setInternal(true) | |||
.setHandler(this); | |||
addComponentParameters(action); | |||
addComponentParameter(action); | |||
action.createParam(PARAM_KEYS) | |||
.setDescription("List of setting keys") | |||
.setExampleValue("sonar.technicalDebt.hoursInDay,sonar.dbcleaner.cleanDirectory"); | |||
@@ -133,8 +128,7 @@ public class ValuesAction implements SettingsWsAction { | |||
private static ValuesRequest toWsRequest(Request request) { | |||
ValuesRequest.Builder builder = ValuesRequest.builder() | |||
.setComponentId(request.param(PARAM_COMPONENT_ID)) | |||
.setComponentKey(request.param(PARAM_COMPONENT_KEY)); | |||
.setComponent(request.param(PARAM_COMPONENT)); | |||
if (request.hasParam(PARAM_KEYS)) { | |||
builder.setKeys(request.paramAsStrings(PARAM_KEYS)); | |||
} | |||
@@ -161,14 +155,13 @@ public class ValuesAction implements SettingsWsAction { | |||
} | |||
private Optional<ComponentDto> loadComponent(DbSession dbSession, ValuesRequest valuesRequest) { | |||
String componentId = valuesRequest.getComponentId(); | |||
String componentKey = valuesRequest.getComponentKey(); | |||
if (componentId != null || componentKey != null) { | |||
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, ID_AND_KEY); | |||
userSession.checkComponentUuidPermission(USER, component.projectUuid()); | |||
return Optional.of(component); | |||
String componentKey = valuesRequest.getComponent(); | |||
if (componentKey == null) { | |||
return Optional.empty(); | |||
} | |||
return Optional.empty(); | |||
ComponentDto component = componentFinder.getByKey(dbSession, componentKey); | |||
userSession.checkComponentUuidPermission(USER, component.projectUuid()); | |||
return Optional.of(component); | |||
} | |||
private List<Setting> loadSettings(DbSession dbSession, Optional<ComponentDto> component, Set<String> keys) { |
@@ -252,20 +252,7 @@ public class ListDefinitionsActionTest { | |||
.onQualifiers(PROJECT) | |||
.build()); | |||
ListDefinitionsWsResponse result = executeRequest(null, project.key()); | |||
assertThat(result.getDefinitionsList()).hasSize(1); | |||
} | |||
@Test | |||
public void return_project_settings_def_by_project_id() { | |||
setUserAsProjectAdmin(); | |||
propertyDefinitions.addComponent(PropertyDefinition | |||
.builder("foo") | |||
.onQualifiers(PROJECT) | |||
.build()); | |||
ListDefinitionsWsResponse result = executeRequest(project.uuid(), null); | |||
ListDefinitionsWsResponse result = executeRequest(project.key()); | |||
assertThat(result.getDefinitionsList()).hasSize(1); | |||
} | |||
@@ -293,7 +280,7 @@ public class ListDefinitionsActionTest { | |||
PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build(), | |||
PropertyDefinition.builder("only-on-module").onlyOnQualifiers(MODULE).build())); | |||
ListDefinitionsWsResponse result = executeRequest(project.uuid(), null); | |||
ListDefinitionsWsResponse result = executeRequest(project.key()); | |||
assertThat(result.getDefinitionsList()).extracting("key").containsOnly("global-and-project", "only-on-project"); | |||
} | |||
@@ -318,15 +305,6 @@ public class ListDefinitionsActionTest { | |||
assertThat(result.getDefinitionsList()).extracting(Settings.Definition::getKey, Settings.Definition::getType).containsOnly(Tuple.tuple("license", LICENSE)); | |||
} | |||
@Test | |||
public void fail_when_id_and_key_are_set() throws Exception { | |||
setUserAsProjectAdmin(); | |||
expectedException.expect(IllegalArgumentException.class); | |||
executeRequest(project.uuid(), project.key()); | |||
} | |||
@Test | |||
public void fail_when_not_system_admin() throws Exception { | |||
userSession.login("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN); | |||
@@ -344,17 +322,17 @@ public class ListDefinitionsActionTest { | |||
expectedException.expect(ForbiddenException.class); | |||
executeRequest(project.uuid(), null); | |||
executeRequest(project.key()); | |||
} | |||
@Test | |||
public void test_ws_definition() { | |||
WebService.Action action = ws.getDef(); | |||
assertThat(action).isNotNull(); | |||
assertThat(action.isInternal()).isTrue(); | |||
assertThat(action.isInternal()).isFalse(); | |||
assertThat(action.isPost()).isFalse(); | |||
assertThat(action.responseExampleAsString()).isNotEmpty(); | |||
assertThat(action.params()).hasSize(2); | |||
assertThat(action.params()).hasSize(1); | |||
} | |||
@Test | |||
@@ -409,17 +387,14 @@ public class ListDefinitionsActionTest { | |||
} | |||
private ListDefinitionsWsResponse executeRequest() { | |||
return executeRequest(null, null); | |||
return executeRequest(null); | |||
} | |||
private ListDefinitionsWsResponse executeRequest(@Nullable String id, @Nullable String key) { | |||
private ListDefinitionsWsResponse executeRequest(@Nullable String key) { | |||
TestRequest request = ws.newRequest() | |||
.setMediaType(MediaTypes.PROTOBUF); | |||
if (id != null) { | |||
request.setParam("componentId", id); | |||
} | |||
if (key != null) { | |||
request.setParam("componentKey", key); | |||
request.setParam("component", key); | |||
} | |||
try { | |||
return ListDefinitionsWsResponse.parseFrom(request.execute().getInputStream()); |
@@ -217,10 +217,10 @@ public class ResetActionTest { | |||
public void test_ws_definition() { | |||
WebService.Action action = ws.getDef(); | |||
assertThat(action).isNotNull(); | |||
assertThat(action.isInternal()).isTrue(); | |||
assertThat(action.isInternal()).isFalse(); | |||
assertThat(action.isPost()).isTrue(); | |||
assertThat(action.responseExampleAsString()).isNull(); | |||
assertThat(action.params()).hasSize(3); | |||
assertThat(action.params()).hasSize(2); | |||
} | |||
@Test | |||
@@ -283,26 +283,23 @@ public class ResetActionTest { | |||
} | |||
private void executeRequestOnGlobalSetting(String key) { | |||
executeRequest(key, null, null); | |||
executeRequest(key, null); | |||
} | |||
private void executeRequestOnProjectSetting(String key) { | |||
executeRequest(key, project.uuid(), null); | |||
executeRequest(key, project.key()); | |||
} | |||
private void executeRequestOnComponentSetting(String key, ComponentDto componentDto) { | |||
executeRequest(key, componentDto.uuid(), null); | |||
executeRequest(key, componentDto.key()); | |||
} | |||
private void executeRequest(String key, @Nullable String componentId, @Nullable String componentKey) { | |||
private void executeRequest(String key, @Nullable String componentKey) { | |||
TestRequest request = ws.newRequest() | |||
.setMediaType(MediaTypes.PROTOBUF) | |||
.setParam("keys", key); | |||
if (componentId != null) { | |||
request.setParam("componentId", componentId); | |||
} | |||
if (componentKey != null) { | |||
request.setParam("componentKey", componentKey); | |||
request.setParam("component", componentKey); | |||
} | |||
request.execute(); | |||
} |
@@ -126,7 +126,7 @@ public class SetActionTest { | |||
propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value")); | |||
ComponentDto project = db.components().insertProject(); | |||
callForProjectSettingByUuid("my.key", "my project value", project.uuid()); | |||
callForProjectSettingByKey("my.key", "my project value", project.key()); | |||
assertGlobalSetting("my.key", "my global value"); | |||
assertComponentSetting("my.key", "my project value", project.getId()); | |||
@@ -138,7 +138,7 @@ public class SetActionTest { | |||
ComponentDto project = db.components().insertProject(); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); | |||
callForProjectSettingByUuid("my.key", "my value", project.uuid()); | |||
callForProjectSettingByKey("my.key", "my value", project.key()); | |||
assertComponentSetting("my.key", "my value", project.getId()); | |||
} | |||
@@ -285,10 +285,10 @@ public class SetActionTest { | |||
newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project), | |||
newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project)); | |||
callForComponentPropertySetByUuid("my.key", newArrayList( | |||
callForComponentPropertySet("my.key", newArrayList( | |||
GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")), | |||
GSON.toJson(ImmutableMap.of("firstField", "anotherFirstValue", "secondField", "anotherSecondValue"))), | |||
project.uuid()); | |||
project.key()); | |||
assertThat(dbClient.propertiesDao().selectGlobalProperties(dbSession)).hasSize(3); | |||
assertThat(dbClient.propertiesDao().selectProjectProperties(dbSession, project.key())).hasSize(5); | |||
@@ -535,7 +535,7 @@ public class SetActionTest { | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Setting 'my.key' cannot be set on a View"); | |||
callForProjectSettingByUuid("my.key", "My Value", view.uuid()); | |||
callForProjectSettingByKey("my.key", "My Value", view.key()); | |||
} | |||
@Test | |||
@@ -543,7 +543,7 @@ public class SetActionTest { | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("One and only one of 'value', 'values', 'fieldValues' must be provided"); | |||
call("my.key", "My Value", newArrayList("Another Value"), null, null, null); | |||
call("my.key", "My Value", newArrayList("Another Value"), null, null); | |||
} | |||
@Test | |||
@@ -782,8 +782,8 @@ public class SetActionTest { | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Setting 'my.key' cannot be set on a Project"); | |||
callForComponentPropertySetByUuid("my.key", newArrayList( | |||
GSON.toJson(ImmutableMap.of("firstField", "firstValue"))), project.uuid()); | |||
callForComponentPropertySet("my.key", newArrayList( | |||
GSON.toJson(ImmutableMap.of("firstField", "firstValue"))), project.key()); | |||
} | |||
@Test | |||
@@ -792,10 +792,10 @@ public class SetActionTest { | |||
assertThat(definition.key()).isEqualTo("set"); | |||
assertThat(definition.isPost()).isTrue(); | |||
assertThat(definition.isInternal()).isTrue(); | |||
assertThat(definition.isInternal()).isFalse(); | |||
assertThat(definition.since()).isEqualTo("6.1"); | |||
assertThat(definition.params()).extracting(Param::key) | |||
.containsOnly("key", "value", "values", "fieldValues", "componentId", "componentKey"); | |||
.containsOnly("key", "value", "values", "fieldValues", "component"); | |||
} | |||
private void assertGlobalSetting(String key, String value) { | |||
@@ -823,57 +823,42 @@ public class SetActionTest { | |||
} | |||
private void callForGlobalSetting(@Nullable String key, @Nullable String value) { | |||
call(key, value, null, null, null, null); | |||
call(key, value, null, null, null); | |||
} | |||
private void callForMultiValueGlobalSetting(@Nullable String key, @Nullable List<String> values) { | |||
call(key, null, values, null, null, null); | |||
call(key, null, values, null, null); | |||
} | |||
private void callForGlobalPropertySet(@Nullable String key, @Nullable List<String> fieldValues) { | |||
call(key, null, null, fieldValues, null, null); | |||
call(key, null, null, fieldValues, null); | |||
} | |||
private void callForComponentPropertySetByUuid(@Nullable String key, @Nullable List<String> fieldValues, @Nullable String componentUuid) { | |||
call(key, null, null, fieldValues, componentUuid, null); | |||
} | |||
private void callForProjectSettingByUuid(@Nullable String key, @Nullable String value, @Nullable String componentUuid) { | |||
call(key, value, null, null, componentUuid, null); | |||
private void callForComponentPropertySet(@Nullable String key, @Nullable List<String> fieldValues, @Nullable String componentKey) { | |||
call(key, null, null, fieldValues, componentKey); | |||
} | |||
private void callForProjectSettingByKey(@Nullable String key, @Nullable String value, @Nullable String componentKey) { | |||
call(key, value, null, null, null, componentKey); | |||
call(key, value, null, null, componentKey); | |||
} | |||
private void call(@Nullable String key, @Nullable String value, @Nullable List<String> values, @Nullable List<String> fieldValues, @Nullable String componentUuid, | |||
@Nullable String componentKey) { | |||
private void call(@Nullable String key, @Nullable String value, @Nullable List<String> values, @Nullable List<String> fieldValues, @Nullable String componentKey) { | |||
TestRequest request = ws.newRequest(); | |||
if (key != null) { | |||
request.setParam("key", key); | |||
} | |||
if (value != null) { | |||
request.setParam("value", value); | |||
} | |||
if (values != null) { | |||
request.setMultiParam("values", values); | |||
} | |||
if (fieldValues != null) { | |||
request.setMultiParam("fieldValues", fieldValues); | |||
} | |||
if (componentUuid != null) { | |||
request.setParam("componentId", componentUuid); | |||
} | |||
if (componentKey != null) { | |||
request.setParam("componentKey", componentKey); | |||
request.setParam("component", componentKey); | |||
} | |||
request.execute(); | |||
} | |||
@@ -576,16 +576,8 @@ public class ValuesActionTest { | |||
ValuesWsResponse result = executeRequestForGlobalProperties(); | |||
assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("sonar.server_id", "sonar.core.startTime", "plugin.license.secured", "plugin.licenseHash.secured"); | |||
} | |||
@Test | |||
public void fail_when_id_and_key_are_set() throws Exception { | |||
setAuthenticatedUser(); | |||
expectedException.expect(IllegalArgumentException.class); | |||
executeRequest(project.uuid(), project.key()); | |||
assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("sonar.server_id", "sonar.core.startTime", "plugin.license.secured", | |||
"plugin.licenseHash.secured"); | |||
} | |||
@Test | |||
@@ -595,7 +587,7 @@ public class ValuesActionTest { | |||
expectedException.expect(ForbiddenException.class); | |||
executeRequest(project.uuid(), null, "foo"); | |||
executeRequest(project.key(), "foo"); | |||
} | |||
@Test | |||
@@ -646,35 +638,32 @@ public class ValuesActionTest { | |||
public void test_ws_definition() { | |||
WebService.Action action = ws.getDef(); | |||
assertThat(action).isNotNull(); | |||
assertThat(action.isInternal()).isTrue(); | |||
assertThat(action.isInternal()).isFalse(); | |||
assertThat(action.isPost()).isFalse(); | |||
assertThat(action.responseExampleAsString()).isNotEmpty(); | |||
assertThat(action.params()).hasSize(3); | |||
assertThat(action.params()).hasSize(2); | |||
} | |||
private ValuesWsResponse executeRequestForComponentProperties(ComponentDto componentDto, String... keys) { | |||
return executeRequest(componentDto.uuid(), null, keys); | |||
return executeRequest(componentDto.key(), keys); | |||
} | |||
private ValuesWsResponse executeRequestForProjectProperties(String... keys) { | |||
return executeRequest(project.uuid(), null, keys); | |||
return executeRequest(project.key(), keys); | |||
} | |||
private ValuesWsResponse executeRequestForGlobalProperties(String... keys) { | |||
return executeRequest(null, null, keys); | |||
return executeRequest(null, keys); | |||
} | |||
private ValuesWsResponse executeRequest(@Nullable String componentId, @Nullable String componentKey, String... keys) { | |||
private ValuesWsResponse executeRequest(@Nullable String componentKey, String... keys) { | |||
TestRequest request = ws.newRequest() | |||
.setMediaType(MediaTypes.PROTOBUF); | |||
if (keys.length > 0) { | |||
request.setParam("keys", COMMA_JOINER.join(keys)); | |||
} | |||
if (componentId != null) { | |||
request.setParam("componentId", componentId); | |||
} | |||
if (componentKey != null) { | |||
request.setParam("componentKey", componentKey); | |||
request.setParam("component", componentKey); | |||
} | |||
try { | |||
return ValuesWsResponse.parseFrom(request.execute().getInputStream()); |
@@ -23,7 +23,10 @@ import { TYPE_PROPERTY_SET } from '../apps/settings/constants'; | |||
export function getDefinitions (componentKey) { | |||
const url = '/api/settings/list_definitions'; | |||
const data = componentKey ? { componentKey } : {}; | |||
const data = { }; | |||
if (componentKey) { | |||
data.component = componentKey; | |||
} | |||
return getJSON(url, data).then(r => r.definitions); | |||
} | |||
@@ -31,7 +34,7 @@ export function getValues (keys, componentKey) { | |||
const url = '/api/settings/values'; | |||
const data = { keys }; | |||
if (componentKey) { | |||
data.componentKey = componentKey; | |||
data.component = componentKey; | |||
} | |||
return getJSON(url, data).then(r => r.settings); | |||
} | |||
@@ -53,7 +56,7 @@ export function setSettingValue (definition, value, componentKey) { | |||
} | |||
if (componentKey) { | |||
data.componentKey = componentKey; | |||
data.component = componentKey; | |||
} | |||
return post(url, data); | |||
@@ -63,7 +66,7 @@ export function resetSettingValue (key, componentKey) { | |||
const url = '/api/settings/reset'; | |||
const data = { keys: key }; | |||
if (componentKey) { | |||
data.componentKey = componentKey; | |||
data.component = componentKey; | |||
} | |||
return post(url, data); | |||
} |
@@ -27,22 +27,15 @@ import javax.annotation.concurrent.Immutable; | |||
@Immutable | |||
public class ListDefinitionsRequest { | |||
private final String componentId; | |||
private final String componentKey; | |||
private final String component; | |||
private ListDefinitionsRequest(Builder builder) { | |||
this.componentId = builder.componentId; | |||
this.componentKey = builder.componentKey; | |||
this.component = builder.component; | |||
} | |||
@CheckForNull | |||
public String getComponentId() { | |||
return componentId; | |||
} | |||
@CheckForNull | |||
public String getComponentKey() { | |||
return componentKey; | |||
public String getComponent() { | |||
return component; | |||
} | |||
public static Builder builder() { | |||
@@ -50,20 +43,14 @@ public class ListDefinitionsRequest { | |||
} | |||
public static class Builder { | |||
private String componentId; | |||
private String componentKey; | |||
private String component; | |||
private Builder() { | |||
// enforce factory method use | |||
} | |||
public Builder setComponentId(@Nullable String componentId) { | |||
this.componentId = componentId; | |||
return this; | |||
} | |||
public Builder setComponentKey(@Nullable String componentKey) { | |||
this.componentKey = componentKey; | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@@ -29,13 +29,11 @@ import static java.util.Arrays.asList; | |||
public class ResetRequest { | |||
private final List<String> keys; | |||
private final String componentId; | |||
private final String componentKey; | |||
private final String component; | |||
private ResetRequest(Builder builder) { | |||
this.keys = builder.keys; | |||
this.componentId = builder.componentId; | |||
this.componentKey = builder.componentKey; | |||
this.component = builder.component; | |||
} | |||
public List<String> getKeys() { | |||
@@ -43,13 +41,8 @@ public class ResetRequest { | |||
} | |||
@CheckForNull | |||
public String getComponentId() { | |||
return componentId; | |||
} | |||
@CheckForNull | |||
public String getComponentKey() { | |||
return componentKey; | |||
public String getComponent() { | |||
return component; | |||
} | |||
public static Builder builder() { | |||
@@ -58,8 +51,7 @@ public class ResetRequest { | |||
public static class Builder { | |||
private List<String> keys; | |||
private String componentId; | |||
private String componentKey; | |||
private String component; | |||
private Builder() { | |||
// enforce factory method use | |||
@@ -75,13 +67,8 @@ public class ResetRequest { | |||
return this; | |||
} | |||
public Builder setComponentId(@Nullable String componentId) { | |||
this.componentId = componentId; | |||
return this; | |||
} | |||
public Builder setComponentKey(@Nullable String componentKey) { | |||
this.componentKey = componentKey; | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@@ -32,16 +32,14 @@ public class SetRequest { | |||
private final String value; | |||
private final List<String> values; | |||
private final List<String> fieldValues; | |||
private final String componentId; | |||
private final String componentKey; | |||
private final String component; | |||
private SetRequest(Builder builder) { | |||
this.key = builder.key; | |||
this.value = builder.value; | |||
this.values = builder.values; | |||
this.fieldValues = builder.fieldValues; | |||
this.componentId = builder.componentId; | |||
this.componentKey = builder.componentKey; | |||
this.component = builder.component; | |||
} | |||
public String getKey() { | |||
@@ -62,13 +60,8 @@ public class SetRequest { | |||
} | |||
@CheckForNull | |||
public String getComponentId() { | |||
return componentId; | |||
} | |||
@CheckForNull | |||
public String getComponentKey() { | |||
return componentKey; | |||
public String getComponent() { | |||
return component; | |||
} | |||
public static Builder builder() { | |||
@@ -80,8 +73,7 @@ public class SetRequest { | |||
private String value; | |||
private List<String> values = emptyList(); | |||
private List<String> fieldValues = emptyList(); | |||
private String componentId; | |||
private String componentKey; | |||
private String component; | |||
private Builder() { | |||
// enforce factory method use | |||
@@ -107,13 +99,8 @@ public class SetRequest { | |||
return this; | |||
} | |||
public Builder setComponentId(@Nullable String componentId) { | |||
this.componentId = componentId; | |||
return this; | |||
} | |||
public Builder setComponentKey(@Nullable String componentKey) { | |||
this.componentKey = componentKey; | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@@ -26,13 +26,12 @@ import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.PostRequest; | |||
import org.sonarqube.ws.client.WsConnector; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_LIST_DEFINITIONS; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_RESET; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_SET; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_VALUES; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.CONTROLLER_SETTINGS; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_FIELD_VALUES; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS; | |||
@@ -46,16 +45,14 @@ public class SettingsService extends BaseService { | |||
public ListDefinitionsWsResponse listDefinitions(ListDefinitionsRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_LIST_DEFINITIONS)) | |||
.setParam(PARAM_COMPONENT_ID, request.getComponentId()) | |||
.setParam(PARAM_COMPONENT_KEY, request.getComponentKey()); | |||
.setParam(PARAM_COMPONENT, request.getComponent()); | |||
return call(getRequest, ListDefinitionsWsResponse.parser()); | |||
} | |||
public ValuesWsResponse values(ValuesRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_VALUES)) | |||
.setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys())) | |||
.setParam(PARAM_COMPONENT_ID, request.getComponentId()) | |||
.setParam(PARAM_COMPONENT_KEY, request.getComponentKey()); | |||
.setParam(PARAM_COMPONENT, request.getComponent()); | |||
return call(getRequest, ValuesWsResponse.parser()); | |||
} | |||
@@ -65,15 +62,13 @@ public class SettingsService extends BaseService { | |||
.setParam(PARAM_VALUE, request.getValue()) | |||
.setParam(PARAM_VALUES, request.getValues()) | |||
.setParam(PARAM_FIELD_VALUES, request.getFieldValues()) | |||
.setParam(PARAM_COMPONENT_ID, request.getComponentId()) | |||
.setParam(PARAM_COMPONENT_KEY, request.getComponentKey())); | |||
.setParam(PARAM_COMPONENT, request.getComponent())); | |||
} | |||
public void reset(ResetRequest request) { | |||
call(new PostRequest(path(ACTION_RESET)) | |||
.setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys())) | |||
.setParam(PARAM_COMPONENT_ID, request.getComponentId()) | |||
.setParam(PARAM_COMPONENT_KEY, request.getComponentKey())); | |||
.setParam(PARAM_COMPONENT, request.getComponent())); | |||
} | |||
} |
@@ -28,8 +28,7 @@ public class SettingsWsParameters { | |||
public static final String ACTION_SET = "set"; | |||
public static final String ACTION_RESET = "reset"; | |||
public static final String PARAM_COMPONENT_ID = "componentId"; | |||
public static final String PARAM_COMPONENT_KEY = "componentKey"; | |||
public static final String PARAM_COMPONENT = "component"; | |||
public static final String PARAM_KEYS = "keys"; | |||
public static final String PARAM_KEY = "key"; | |||
public static final String PARAM_VALUE = "value"; |
@@ -30,24 +30,17 @@ import static java.util.Objects.requireNonNull; | |||
public class ValuesRequest { | |||
private final String componentId; | |||
private final String componentKey; | |||
private final String component; | |||
private final List<String> keys; | |||
private ValuesRequest(Builder builder) { | |||
this.componentId = builder.componentId; | |||
this.componentKey = builder.componentKey; | |||
this.component = builder.component; | |||
this.keys = builder.keys; | |||
} | |||
@CheckForNull | |||
public String getComponentId() { | |||
return componentId; | |||
} | |||
@CheckForNull | |||
public String getComponentKey() { | |||
return componentKey; | |||
public String getComponent() { | |||
return component; | |||
} | |||
public List<String> getKeys() { | |||
@@ -59,21 +52,15 @@ public class ValuesRequest { | |||
} | |||
public static class Builder { | |||
private String componentId; | |||
private String componentKey; | |||
private String component; | |||
private List<String> keys = new ArrayList<>(); | |||
private Builder() { | |||
// enforce factory method use | |||
} | |||
public Builder setComponentId(@Nullable String componentId) { | |||
this.componentId = componentId; | |||
return this; | |||
} | |||
public Builder setComponentKey(@Nullable String componentKey) { | |||
this.componentKey = componentKey; | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@@ -37,24 +37,14 @@ public class ListDefinitionsRequestTest { | |||
public void create_request_with_no_component() { | |||
ListDefinitionsRequest result = underTest.build(); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_id() { | |||
ListDefinitionsRequest result = underTest.setComponentId("projectId").build(); | |||
assertThat(result.getComponentId()).isEqualTo("projectId"); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getComponent()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_key() { | |||
ListDefinitionsRequest result = underTest.setComponentKey("projectKey").build(); | |||
ListDefinitionsRequest result = underTest.setComponent("projectKey").build(); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isEqualTo("projectKey"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
} | |||
} |
@@ -40,28 +40,16 @@ public class SetRequestTest { | |||
assertThat(result.getKey()).isEqualTo("my.key"); | |||
assertThat(result.getValue()).isEqualTo("my value"); | |||
assertThat(result.getValues()).isNotNull().isEmpty(); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getComponentId()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_id() { | |||
SetRequest result = underTest.setKey("my.key").setValue("my value").setComponentId("projectId").build(); | |||
assertThat(result.getKey()).isEqualTo("my.key"); | |||
assertThat(result.getValue()).isEqualTo("my value"); | |||
assertThat(result.getComponentId()).isEqualTo("projectId"); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getComponent()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_key() { | |||
SetRequest result = underTest.setKey("my.key").setValue("my value").setComponentKey("projectKey").build(); | |||
SetRequest result = underTest.setKey("my.key").setValue("my value").setComponent("projectKey").build(); | |||
assertThat(result.getKey()).isEqualTo("my.key"); | |||
assertThat(result.getValue()).isEqualTo("my value"); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isEqualTo("projectKey"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
} | |||
@Test |
@@ -31,8 +31,7 @@ import org.sonarqube.ws.client.WsConnector; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_FIELD_VALUES; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEY; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS; | |||
@@ -49,13 +48,13 @@ public class SettingsServiceTest { | |||
@Test | |||
public void list_definitions() { | |||
underTest.listDefinitions(ListDefinitionsRequest.builder() | |||
.setComponentKey("KEY") | |||
.setComponent("KEY") | |||
.build()); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(ListDefinitionsWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(PARAM_COMPONENT_KEY, "KEY") | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.andNoOtherParam(); | |||
} | |||
@@ -63,14 +62,14 @@ public class SettingsServiceTest { | |||
public void values() { | |||
underTest.values(ValuesRequest.builder() | |||
.setKeys("sonar.debt,sonar.issue") | |||
.setComponentKey("KEY") | |||
.setComponent("KEY") | |||
.build()); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(ValuesWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(PARAM_KEYS, "sonar.debt,sonar.issue") | |||
.hasParam(PARAM_COMPONENT_KEY, "KEY") | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.andNoOtherParam(); | |||
} | |||
@@ -80,9 +79,8 @@ public class SettingsServiceTest { | |||
.setKey("sonar.debt") | |||
.setValue("8h") | |||
.setValues(newArrayList("v1", "v2", "v3")) | |||
.setFieldValues(newArrayList("json1","json2","json3")) | |||
.setComponentId("UUID") | |||
.setComponentKey("KEY") | |||
.setFieldValues(newArrayList("json1", "json2", "json3")) | |||
.setComponent("KEY") | |||
.build()); | |||
serviceTester.assertThat(serviceTester.getPostRequest()) | |||
@@ -90,8 +88,7 @@ public class SettingsServiceTest { | |||
.hasParam(PARAM_VALUE, "8h") | |||
.hasParam(PARAM_VALUES, newArrayList("v1", "v2", "v3")) | |||
.hasParam(PARAM_FIELD_VALUES, newArrayList("json1", "json2", "json3")) | |||
.hasParam(PARAM_COMPONENT_ID, "UUID") | |||
.hasParam(PARAM_COMPONENT_KEY, "KEY") | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.andNoOtherParam(); | |||
} | |||
@@ -99,12 +96,12 @@ public class SettingsServiceTest { | |||
public void reset() { | |||
underTest.reset(ResetRequest.builder() | |||
.setKeys("sonar.debt") | |||
.setComponentKey("KEY") | |||
.setComponent("KEY") | |||
.build()); | |||
serviceTester.assertThat(serviceTester.getPostRequest()) | |||
.hasParam(PARAM_KEYS, "sonar.debt") | |||
.hasParam(PARAM_COMPONENT_KEY, "KEY") | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.andNoOtherParam(); | |||
} | |||
@@ -37,8 +37,7 @@ public class ValuesRequestTest { | |||
public void create_request_with_no_component() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").build(); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getKeys()).containsOnly("sonar.debt"); | |||
} | |||
@@ -46,26 +45,15 @@ public class ValuesRequestTest { | |||
public void create_request_with_no_keys() { | |||
ValuesRequest result = underTest.build(); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getKeys()).isEmpty(); | |||
} | |||
@Test | |||
public void create_request_with_component_id() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").setComponentId("projectId").build(); | |||
public void create_request_with_component() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").setComponent("projectKey").build(); | |||
assertThat(result.getComponentId()).isEqualTo("projectId"); | |||
assertThat(result.getComponentKey()).isNull(); | |||
assertThat(result.getKeys()).containsOnly("sonar.debt"); | |||
} | |||
@Test | |||
public void create_request_with_component_key() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").setComponentKey("projectKey").build(); | |||
assertThat(result.getComponentId()).isNull(); | |||
assertThat(result.getComponentKey()).isEqualTo("projectKey"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getKeys()).containsOnly("sonar.debt"); | |||
} | |||