From aa1c78266501b7ae53a6d553182f816aab28c362 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 14 Oct 2019 16:28:14 -0500 Subject: [PATCH] SONAR-11154 Remove parameters deprecated before 6.7 and enforce mandatory parameters --- .../qualityprofile/ws/ActivateRuleAction.java | 2 - .../ws/ActivateRulesAction.java | 2 - .../qualityprofile/ws/AddProjectAction.java | 17 +--- .../qualityprofile/ws/BackupAction.java | 2 +- .../qualityprofile/ws/ChangeParentAction.java | 23 ++--- .../qualityprofile/ws/ChangelogAction.java | 2 +- .../qualityprofile/ws/CreateAction.java | 3 +- .../ws/DeactivateRuleAction.java | 2 - .../ws/DeactivateRulesAction.java | 1 - .../qualityprofile/ws/DeleteAction.java | 2 +- .../qualityprofile/ws/ExportAction.java | 24 +----- .../qualityprofile/ws/InheritanceAction.java | 2 +- .../qualityprofile/ws/ProjectsAction.java | 6 +- .../qualityprofile/ws/QProfileReference.java | 35 ++------ .../qualityprofile/ws/QProfileWsSupport.java | 4 +- .../ws/RemoveProjectAction.java | 16 +--- .../qualityprofile/ws/SearchAction.java | 2 - .../qualityprofile/ws/SetDefaultAction.java | 2 +- .../server/qualityprofile/ws/ShowAction.java | 1 - .../ws/ActivateRuleActionTest.java | 4 - .../ws/ActivateRulesActionTest.java | 4 - .../ws/AddProjectActionTest.java | 54 ++++-------- .../qualityprofile/ws/BackupActionTest.java | 35 ++------ .../ws/ChangeParentActionTest.java | 85 +++++++------------ .../ws/ChangelogActionTest.java | 30 +++++-- .../qualityprofile/ws/CreateActionTest.java | 3 - .../ws/DeactivateRuleActionTest.java | 4 - .../ws/DeactivateRulesActionTest.java | 2 - .../qualityprofile/ws/DeleteActionTest.java | 76 +++++------------ .../qualityprofile/ws/ExportActionTest.java | 50 +---------- .../ws/InheritanceActionTest.java | 30 ++++--- .../qualityprofile/ws/ProjectsActionTest.java | 1 - .../ws/QProfileReferenceTest.java | 31 ++----- .../ws/QProfilesWsModuleTest.java | 2 +- .../ws/RemoveProjectActionTest.java | 67 ++++++--------- .../qualityprofile/ws/SearchActionTest.java | 17 ++-- .../ws/SetDefaultActionTest.java | 67 ++------------- .../DefaultQualityProfileLoader.java | 2 +- .../DefaultQualityProfileLoaderTest.java | 14 +-- .../QualityProfileWsParameters.java | 3 - 40 files changed, 207 insertions(+), 522 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java index 3ab2fee8ad9..350269d4bac 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java @@ -74,13 +74,11 @@ public class ActivateRuleAction implements QProfileWsAction { activate.createParam(PARAM_KEY) .setDescription("Quality Profile key. Can be obtained through api/qualityprofiles/search") - .setDeprecatedKey("profile_key", "6.5") .setRequired(true) .setExampleValue(UUID_EXAMPLE_01); activate.createParam(PARAM_RULE) .setDescription("Rule key") - .setDeprecatedKey("rule_key", "6.5") .setRequired(true) .setExampleValue("squid:AvoidCycles"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java index 4604753938b..fde89a3efc1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java @@ -74,13 +74,11 @@ public class ActivateRulesAction implements QProfileWsAction { activate.createParam(PARAM_TARGET_KEY) .setDescription("Quality Profile key on which the rule activation is done. To retrieve a quality profile key please see api/qualityprofiles/search") - .setDeprecatedKey("profile_key", "6.5") .setRequired(true) .setExampleValue(UUID_EXAMPLE_03); activate.createParam(PARAM_TARGET_SEVERITY) .setDescription("Severity to set on the activated rules") - .setDeprecatedKey("activation_severity", "6.5") .setPossibleValues(Severity.ALL); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java index 7bcabfd2887..1842c793228 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java @@ -33,13 +33,10 @@ import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_08; -import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_UUID_AND_KEY; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_PROJECT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_UUID; public class AddProjectAction implements QProfileWsAction { @@ -77,13 +74,8 @@ public class AddProjectAction implements QProfileWsAction { action.createParam(PARAM_PROJECT) .setDescription("Project key") - .setDeprecatedKey("projectKey", "6.5") + .setRequired(true) .setExampleValue(KEY_PROJECT_EXAMPLE_001); - - action.createParam(PARAM_PROJECT_UUID) - .setDescription("Project ID. Either this parameter or '%s' must be set.", PARAM_PROJECT) - .setDeprecatedSince("6.5") - .setExampleValue(UUID_EXAMPLE_08); } @Override @@ -92,7 +84,7 @@ public class AddProjectAction implements QProfileWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = loadProject(dbSession, request); - QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request)); + QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request)); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); checkPermissions(dbSession, organization, profile, project); @@ -115,9 +107,8 @@ public class AddProjectAction implements QProfileWsAction { } private ComponentDto loadProject(DbSession dbSession, Request request) { - String projectKey = request.param(PARAM_PROJECT); - String projectUuid = request.param(PARAM_PROJECT_UUID); - return componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_UUID_AND_KEY); + String projectKey = request.mandatoryParam(PARAM_PROJECT); + return componentFinder.getByKey(dbSession, projectKey); } private void checkPermissions(DbSession dbSession, OrganizationDto organization, QProfileDto profile, ComponentDto project) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java index 0cd9f483237..0e885835f29 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java @@ -69,7 +69,7 @@ public class BackupAction implements QProfileWsAction { try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), UTF_8); DbSession dbSession = dbClient.openSession(false)) { - QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request)); + QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request)); response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee())); backuper.backup(dbSession, profile, writer); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java index c43c283b7d8..7a9c1974474 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java @@ -33,9 +33,7 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters; import static org.apache.commons.lang.StringUtils.isEmpty; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_KEY; public class ChangeParentAction implements QProfileWsAction { @@ -71,36 +69,29 @@ public class ChangeParentAction implements QProfileWsAction { .setSince("6.4"); QProfileReference.defineParams(inheritance, languages); - inheritance.createParam(PARAM_PARENT_KEY) - .setDescription("New parent profile key.
" + - "If no profile is provided, the inheritance link with current parent profile (if any) is broken, which deactivates all rules " + - "which come from the parent and are not overridden.") - .setDeprecatedSince("6.6") - .setExampleValue(UUID_EXAMPLE_02); - inheritance.createParam(QualityProfileWsParameters.PARAM_PARENT_QUALITY_PROFILE) - .setDescription("Quality profile name. If this parameter is set, '%s' must not be set and '%s' must be set to disambiguate.", PARAM_PARENT_KEY, PARAM_LANGUAGE) + .setDescription("New parent profile name.
" + + "If no profile is provided, the inheritance link with current parent profile (if any) is broken, which deactivates all rules " + + "which come from the parent and are not overridden.") .setExampleValue("Sonar way"); } @Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); - QProfileReference reference = QProfileReference.from(request); + QProfileReference reference = QProfileReference.fromName(request); try (DbSession dbSession = dbClient.openSession(false)) { QProfileDto profile = wsSupport.getProfile(dbSession, reference); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); wsSupport.checkCanEdit(dbSession, organization, profile); - String parentKey = request.param(PARAM_PARENT_KEY); String parentName = request.param(QualityProfileWsParameters.PARAM_PARENT_QUALITY_PROFILE); - if (isEmpty(parentKey) && isEmpty(parentName)) { + if (isEmpty(parentName)) { ruleActivator.removeParentAndCommit(dbSession, profile); } else { - String parentOrganizationKey = parentKey == null ? organization.getKey() : null; - String parentLanguage = parentKey == null ? request.param(PARAM_LANGUAGE) : null; - QProfileReference parentRef = QProfileReference.from(parentKey, parentOrganizationKey, parentLanguage, parentName); + String parentLanguage = request.mandatoryParam(PARAM_LANGUAGE); + QProfileReference parentRef = QProfileReference.fromName(organization.getKey(), parentLanguage, parentName); QProfileDto parent = wsSupport.getProfile(dbSession, parentRef); ruleActivator.setParentAndCommit(dbSession, profile, parent); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java index 22150b14b3c..836091ff9a7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java @@ -93,7 +93,7 @@ public class ChangelogAction implements QProfileWsAction { @Override public void handle(Request request, Response response) throws Exception { - QProfileReference reference = QProfileReference.from(request); + QProfileReference reference = QProfileReference.fromName(request); try (DbSession dbSession = dbClient.openSession(false)) { QProfileDto profile = wsSupport.getProfile(dbSession, reference); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java index 0b5ccf1df15..b6ebcc3dc55 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java @@ -97,8 +97,7 @@ public class CreateAction implements QProfileWsAction { .setRequired(true) .setMaximumLength(NAME_MAXIMUM_LENGTH) .setDescription("Quality profile name") - .setExampleValue("My Sonar way") - .setDeprecatedKey("profileName", "6.6"); + .setExampleValue("My Sonar way"); create.createParam(PARAM_LANGUAGE) .setRequired(true) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java index 2475395eb02..e7ac7c6b7ab 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java @@ -66,13 +66,11 @@ public class DeactivateRuleAction implements QProfileWsAction { deactivate.createParam(PARAM_KEY) .setDescription("Quality Profile key. Can be obtained through api/qualityprofiles/search") - .setDeprecatedKey("profile_key", "6.5") .setRequired(true) .setExampleValue(UUID_EXAMPLE_01); deactivate.createParam(PARAM_RULE) .setDescription("Rule key") - .setDeprecatedKey("rule_key", "6.5") .setRequired(true) .setExampleValue("squid:AvoidCycles"); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java index 661debe20fe..7422fd85c75 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java @@ -71,7 +71,6 @@ public class DeactivateRulesAction implements QProfileWsAction { deactivate.createParam(PARAM_TARGET_KEY) .setDescription("Quality Profile key on which the rule deactivation is done. To retrieve a profile key please see api/qualityprofiles/search") - .setDeprecatedKey("profile_key", "6.5") .setRequired(true) .setExampleValue(UUID_EXAMPLE_04); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java index b957b37c084..b48111a1b0a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java @@ -80,7 +80,7 @@ public class DeleteAction implements QProfileWsAction { userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { - QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request)); + QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request)); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); wsSupport.checkCanEdit(dbSession, organization, profile); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java index 110d2e8484f..f9f27c46cb8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java @@ -47,12 +47,9 @@ import org.sonar.server.qualityprofile.QProfileExporters; import org.sonarqube.ws.MediaTypes; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; -import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; @@ -82,19 +79,13 @@ public class ExportAction implements QProfileWsAction { .setResponseExample(getClass().getResource("export-example.xml")) .setHandler(this); - action.createParam(PARAM_KEY) - .setDescription("Quality profile key") - .setSince("6.5") - .setDeprecatedSince("6.6") - .setExampleValue(UUID_EXAMPLE_01); - action.createParam(PARAM_QUALITY_PROFILE) .setDescription("Quality profile name to export. If left empty, the default profile for the language is exported.") - .setDeprecatedKey("name", "6.6") .setExampleValue("My Sonar way"); action.createParam(PARAM_LANGUAGE) .setDescription("Quality profile language") + .setRequired(true) .setExampleValue(LanguageParamUtils.getExampleValue(languages)) .setPossibleValues(LanguageParamUtils.getOrderedLanguageKeys(languages)); @@ -118,14 +109,12 @@ public class ExportAction implements QProfileWsAction { @Override public void handle(Request request, Response response) throws Exception { - String key = request.param(PARAM_KEY); String name = request.param(PARAM_QUALITY_PROFILE); - String language = request.param(PARAM_LANGUAGE); - checkRequest(key != null ^ language != null, "Either '%s' or '%s' must be provided.", PARAM_KEY, PARAM_LANGUAGE); + String language = request.mandatoryParam(PARAM_LANGUAGE); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION)); - QProfileDto profile = loadProfile(dbSession, organization, key, language, name); + QProfileDto profile = loadProfile(dbSession, organization, language, name); String exporterKey = exporters.exportersForLanguage(profile.getLanguage()).isEmpty() ? null : request.param(PARAM_EXPORTER_KEY); writeResponse(dbSession, profile, exporterKey, response); } @@ -148,14 +137,9 @@ public class ExportAction implements QProfileWsAction { IOUtils.write(bufferStream.toByteArray(), output); } - private QProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, @Nullable String key, @Nullable String language, @Nullable String name) { + private QProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) { QProfileDto profile; - if (key != null) { - profile = dbClient.qualityProfileDao().selectByUuid(dbSession, key); - return checkFound(profile, "Could not find profile with key '%s'", key); - } - checkRequest(language != null, "Parameter '%s' must be provided", PARAM_LANGUAGE); if (name == null) { // return the default profile profile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, organization, language); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java index 458c6dd0aed..f387f3b174a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java @@ -70,7 +70,7 @@ public class InheritanceAction implements QProfileWsAction { @Override public void handle(Request request, Response response) throws Exception { - QProfileReference reference = QProfileReference.from(request); + QProfileReference reference = QProfileReference.fromName(request); try (DbSession dbSession = dbClient.openSession(false)) { QProfileDto profile = wsSupport.getProfile(dbSession, reference); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java index 3ded50637ea..fe2815c51ea 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java @@ -80,11 +80,9 @@ public class ProjectsAction implements QProfileWsAction { .setExampleValue(UUID_EXAMPLE_01); action.addSelectionModeParam(); - action.createSearchQuery("sonar", "projects") - .setDeprecatedKey("query", "6.5"); + action.createSearchQuery("sonar", "projects"); - action.createPageParam() - .setDeprecatedKey("page", "6.5"); + action.createPageParam(); action.createPageSize(100, MAX_PAGE_SIZE); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileReference.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileReference.java index 4f14e909639..2db85e0728a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileReference.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileReference.java @@ -28,13 +28,9 @@ import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.WebService; import org.sonar.core.util.stream.MoreCollectors; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; -import static org.apache.commons.lang.StringUtils.isEmpty; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; @@ -149,22 +145,10 @@ public class QProfileReference { return result; } - public static QProfileReference from(Request request) { - String key = request.param(PARAM_KEY); + public static QProfileReference fromName(Request request) { String organizationKey = request.param(PARAM_ORGANIZATION); - String lang = request.param(PARAM_LANGUAGE); - String name = request.param(PARAM_QUALITY_PROFILE); - return from(key, organizationKey, lang, name); - } - - public static QProfileReference from(@Nullable String key, @Nullable String organizationKey, @Nullable String lang, @Nullable String name) { - if (key != null) { - checkArgument(isEmpty(organizationKey) && isEmpty(lang) && isEmpty(name), - "When a quality profile key is set, '%s' '%s' and '%s' can't be set", PARAM_ORGANIZATION, PARAM_LANGUAGE, PARAM_QUALITY_PROFILE); - return fromKey(key); - } - checkArgument(!isEmpty(lang) && !isEmpty(name), - "If '%s' is not specified, '%s' and '%s' must be set", PARAM_KEY, PARAM_QUALITY_PROFILE, PARAM_LANGUAGE); + String lang = request.mandatoryParam(PARAM_LANGUAGE); + String name = request.mandatoryParam(PARAM_QUALITY_PROFILE); return fromName(organizationKey, lang, name); } @@ -177,19 +161,14 @@ public class QProfileReference { } public static void defineParams(WebService.NewAction action, Languages languages) { - action.createParam(PARAM_KEY) - .setDescription("Quality profile key. Mandatory unless 'qualityProfile' and 'language' are specified.") - .setDeprecatedKey("profileKey", "6.5") - .setDeprecatedSince("6.6") - .setExampleValue(UUID_EXAMPLE_01); - action.createParam(PARAM_QUALITY_PROFILE) - .setDescription("Quality profile name. Mandatory if 'key' is not set.") - .setDeprecatedKey("profileName", "6.6") + .setDescription("Quality profile name.") + .setRequired(true) .setExampleValue("Sonar way"); action.createParam(PARAM_LANGUAGE) - .setDescription("Quality profile language. Mandatory if 'key' is not set.") + .setDescription("Quality profile language.") + .setRequired(true) .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(MoreCollectors.toSet())); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java index 7aa34505534..91429597bb3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java @@ -40,10 +40,10 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import static org.sonar.db.organization.OrganizationDto.Subscription.PAID; -import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; -import static org.sonar.server.exceptions.BadRequestException.checkRequest; +import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; @ServerSide diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java index 5fd81105995..90de7e90ccb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java @@ -33,12 +33,10 @@ import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; -import static org.sonar.core.util.Uuids.UUID_EXAMPLE_09; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_PROJECT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_UUID; public class RemoveProjectAction implements QProfileWsAction { @@ -74,13 +72,8 @@ public class RemoveProjectAction implements QProfileWsAction { action.createParam(PARAM_PROJECT) .setDescription("Project key") - .setDeprecatedKey("projectKey", "6.5") + .setRequired(true) .setExampleValue(KEY_PROJECT_EXAMPLE_001); - - action.createParam(PARAM_PROJECT_UUID) - .setDescription("Project ID. Either this parameter, or '%s' must be set.", PARAM_PROJECT) - .setDeprecatedSince("6.5") - .setExampleValue(UUID_EXAMPLE_09); } @Override @@ -89,7 +82,7 @@ public class RemoveProjectAction implements QProfileWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = loadProject(dbSession, request); - QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request)); + QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request)); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); checkPermissions(dbSession, organization, profile, project); if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) { @@ -104,9 +97,8 @@ public class RemoveProjectAction implements QProfileWsAction { } private ComponentDto loadProject(DbSession dbSession, Request request) { - String projectKey = request.param(PARAM_PROJECT); - String projectUuid = request.param(PARAM_PROJECT_UUID); - return componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, ComponentFinder.ParamNames.PROJECT_UUID_AND_PROJECT); + String projectKey = request.mandatoryParam(PARAM_PROJECT); + return componentFinder.getByKey(dbSession, projectKey); } private void checkPermissions(DbSession dbSession, OrganizationDto organization, QProfileDto profile, ComponentDto project) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index 27e7c9b27f6..2c2a1be92ed 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -114,7 +114,6 @@ public class SearchAction implements QProfileWsAction { action.createParam(PARAM_PROJECT) .setDescription("Project key") - .setDeprecatedKey("projectKey", "6.5") .setExampleValue(KEY_PROJECT_EXAMPLE_001); action @@ -124,7 +123,6 @@ public class SearchAction implements QProfileWsAction { action.createParam(PARAM_QUALITY_PROFILE) .setDescription("Quality profile name") - .setDeprecatedKey("profileName", "6.6") .setExampleValue("SonarQube Way"); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java index 7832cfc51d1..e346590cfc2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java @@ -64,7 +64,7 @@ public class SetDefaultAction implements QProfileWsAction { @Override public void handle(Request request, Response response) { userSession.checkLoggedIn(); - QProfileReference reference = QProfileReference.from(request); + QProfileReference reference = QProfileReference.fromName(request); try (DbSession dbSession = dbClient.openSession(false)) { QProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference); dbClient.organizationDao().selectByUuid(dbSession, qualityProfile.getOrganizationUuid()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java index 5c4822be8f5..234d42af69f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java @@ -83,7 +83,6 @@ public class ShowAction implements QProfileWsAction { show.createParam(PARAM_KEY) .setDescription("Quality profile key") .setExampleValue(UUID_EXAMPLE_01) - .setDeprecatedKey("profile", "6.6") .setRequired(true); show.createParam(PARAM_COMPARE_TO_SONAR_WAY) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java index 5ec1ad9885c..11204636001 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java @@ -94,10 +94,6 @@ public class ActivateRuleActionTest { assertThat(definition).isNotNull(); assertThat(definition.isPost()).isTrue(); assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("severity", "key", "reset", "rule", "params"); - WebService.Param profileKey = definition.param("key"); - assertThat(profileKey.deprecatedKey()).isEqualTo("profile_key"); - WebService.Param ruleKey = definition.param("rule"); - assertThat(ruleKey.deprecatedKey()).isEqualTo("rule_key"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java index 38e1f83d456..f9f30644f47 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java @@ -107,10 +107,6 @@ public class ActivateRulesActionTest { "owaspTop10", "sansTop25", "sonarsourceSecurity"); - WebService.Param targetProfile = definition.param("targetKey"); - assertThat(targetProfile.deprecatedKey()).isEqualTo("profile_key"); - WebService.Param targetSeverity = definition.param("targetSeverity"); - assertThat(targetSeverity.deprecatedKey()).isEqualTo("activation_severity"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java index 0b68c7fd08f..ad2bbcc9ea6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java @@ -73,17 +73,12 @@ public class AddProjectActionTest { // parameters assertThat(definition.params()).extracting(WebService.Param::key) - .containsExactlyInAnyOrder("key", "qualityProfile", "project", "language", "projectUuid", "organization"); - WebService.Param profile = definition.param("key"); - assertThat(profile.deprecatedKey()).isEqualTo("profileKey"); - assertThat(profile.deprecatedSince()).isEqualTo("6.6"); + .containsExactlyInAnyOrder("qualityProfile", "project", "language", "organization"); + WebService.Param project = definition.param("project"); + assertThat(project.isRequired()).isTrue(); WebService.Param languageParam = definition.param("language"); assertThat(languageParam.possibleValues()).containsOnly(LANGUAGE_1, LANGUAGE_2); assertThat(languageParam.exampleValue()).isNull(); - WebService.Param project = definition.param("project"); - assertThat(project.deprecatedKey()).isEqualTo("projectKey"); - WebService.Param projectUuid = definition.param("projectUuid"); - assertThat(projectUuid.deprecatedSince()).isEqualTo("6.5"); WebService.Param organizationParam = definition.param("organization"); assertThat(organizationParam.since()).isEqualTo("6.4"); assertThat(organizationParam.isInternal()).isTrue(); @@ -93,7 +88,7 @@ public class AddProjectActionTest { public void add_project_on_profile_of_default_organization() { logInAsProfileAdmin(db.getDefaultOrganization()); ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); TestResponse response = call(project, profile); assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT); @@ -191,7 +186,7 @@ public class AddProjectActionTest { @Test public void project_administrator_can_change_profile() { ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project); call(project, profile); @@ -203,7 +198,7 @@ public class AddProjectActionTest { public void throw_ForbiddenException_if_not_project_nor_organization_administrator() { userSession.logIn(db.users().insertUser()); ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); @@ -229,10 +224,10 @@ public class AddProjectActionTest { QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Component id 'unknown' not found"); + expectedException.expectMessage("Component key 'unknown' not found"); tester.newRequest() - .setParam("projectUuid", "unknown") + .setParam("project", "unknown") .setParam("profileKey", profile.getKee()) .execute(); } @@ -243,16 +238,17 @@ public class AddProjectActionTest { ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Quality Profile with key 'unknown' does not exist"); + expectedException.expectMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist"); tester.newRequest() - .setParam("projectUuid", project.uuid()) - .setParam("profileKey", "unknown") + .setParam("project", project.getKey()) + .setParam("language", "xoo") + .setParam("qualityProfile", "unknown") .execute(); } @Test - public void fail_when_using_branch_db_key() throws Exception { + public void fail_when_using_branch_db_key() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertMainBranch(organization); userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project); @@ -268,23 +264,6 @@ public class AddProjectActionTest { .execute(); } - @Test - public void fail_when_using_branch_uuid() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertMainBranch(organization); - userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - QProfileDto profile = db.qualityProfiles().insert(organization); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); - - tester.newRequest() - .setParam("projectUuid", branch.uuid()) - .setParam("profileKey", profile.getKee()) - .execute(); - } - private void assertProjectIsAssociatedToProfile(ComponentDto project, QProfileDto profile) { QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage()); assertThat(loaded.getKee()).isEqualTo(profile.getKee()); @@ -301,15 +280,16 @@ public class AddProjectActionTest { private TestResponse call(ComponentDto project, QProfileDto qualityProfile) { TestRequest request = tester.newRequest() - .setParam("projectUuid", project.uuid()) - .setParam("key", qualityProfile.getKee()); + .setParam("project", project.getKey()) + .setParam("language", qualityProfile.getLanguage()) + .setParam("qualityProfile", qualityProfile.getName()); return request.execute(); } private TestResponse call(OrganizationDto organization, ComponentDto project, QProfileDto qualityProfile) { TestRequest request = tester.newRequest() .setParam("organization", organization.getKey()) - .setParam("projectUuid", project.uuid()) + .setParam("project", project.getKey()) .setParam("language", qualityProfile.getLanguage()) .setParam("qualityProfile", qualityProfile.getName()); return request.execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java index 1d9cd581d36..66b83cf7e62 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java @@ -66,9 +66,12 @@ public class BackupActionTest { @Test public void returns_backup_of_profile_with_specified_key() { - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); - TestResponse response = tester.newRequest().setParam(PARAM_KEY, profile.getKee()).execute(); + TestResponse response = tester.newRequest() + .setParam("language", profile.getLanguage()) + .setParam("qualityProfile", profile.getName()) + .execute(); assertThat(response.getMediaType()).isEqualTo("application/xml"); assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile)); assertThat(response.getHeader("Content-Disposition")).isEqualTo("attachment; filename=" + profile.getKee() + ".xml"); @@ -128,14 +131,6 @@ public class BackupActionTest { assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile)); } - @Test - public void throws_NotFoundException_if_profile_with_specified_key_does_not_exist() { - expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Quality Profile with key 'missing' does not exist"); - - tester.newRequest().setParam(PARAM_KEY, "missing").execute(); - } - @Test public void throws_NotFoundException_if_specified_organization_does_not_exist() { expectedException.expect(NotFoundException.class); @@ -188,20 +183,6 @@ public class BackupActionTest { .execute(); } - @Test - public void fail_on_paid_organization_when_not_member_using_deprecated_profile_key() { - OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID)); - QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE)); - userSession.logIn(); - - expectedException.expect(ForbiddenException.class); - expectedException.expectMessage(format("You're not member of organization '%s'", organization.getKey())); - - tester.newRequest() - .setParam("key", profile.getKee()) - .execute(); - } - @Test public void test_definition() { WebService.Action definition = tester.getDef(); @@ -212,13 +193,9 @@ public class BackupActionTest { assertThat(definition.isPost()).isFalse(); // parameters - assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("key", "organization", "qualityProfile", "language"); - Param key = definition.param("key"); - assertThat(key.deprecatedKey()).isEqualTo("profileKey"); - assertThat(key.deprecatedSince()).isEqualTo("6.6"); + assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("organization", "qualityProfile", "language"); Param language = definition.param("language"); assertThat(language.deprecatedSince()).isNullOrEmpty(); - Param profileName = definition.param("qualityProfile"); Param orgParam = definition.param("organization"); assertThat(orgParam.since()).isEqualTo("6.4"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java index 8e2516b6cdc..dd7ca435cb5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java @@ -71,7 +71,6 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_KEY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_QUALITY_PROFILE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; @@ -128,13 +127,8 @@ public class ChangeParentActionTest { WebService.Action definition = ws.getDef(); assertThat(definition.isPost()).isTrue(); assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder( - "organization", "key", "qualityProfile", "language", "parentKey", "parentQualityProfile"); + "organization", "qualityProfile", "language", "parentQualityProfile"); assertThat(definition.param("organization").since()).isEqualTo("6.4"); - Param profile = definition.param("key"); - assertThat(profile.deprecatedKey()).isEqualTo("profileKey"); - assertThat(profile.deprecatedSince()).isEqualTo("6.6"); - Param parentProfile = definition.param("parentKey"); - assertThat(parentProfile.deprecatedKey()).isNullOrEmpty(); } @Test @@ -152,8 +146,10 @@ public class ChangeParentActionTest { // Set parent ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_KEY, parent1.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_PARENT_QUALITY_PROFILE, parent1.getName()) .execute(); // Check rule 1 enabled @@ -183,8 +179,10 @@ public class ChangeParentActionTest { // Set parent 2 through WS ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_KEY, parent2.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_PARENT_QUALITY_PROFILE, parent2.getName()) .execute(); // Check rule 2 enabled @@ -211,7 +209,9 @@ public class ChangeParentActionTest { // Remove parent through WS ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) .execute(); // Check no rule enabled @@ -300,8 +300,10 @@ public class ChangeParentActionTest { // Remove parent ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_KEY, "") + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_PARENT_QUALITY_PROFILE, "") .execute(); // Check no rule enabled @@ -329,8 +331,10 @@ public class ChangeParentActionTest { ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_KEY, parent2.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_PARENT_QUALITY_PROFILE, parent2.getName()) .execute(); List activeRules2 = dbClient.activeRuleDao().selectByProfile(dbSession, child); @@ -351,49 +355,16 @@ public class ChangeParentActionTest { TestRequest request = ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_KEY, "palap"); + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_PARENT_QUALITY_PROFILE, "palap"); expectedException.expect(BadRequestException.class); request.execute(); } - @Test - public void fail_if_parent_key_and_name_both_set() { - QProfileDto child = createProfile(); - - assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty(); - assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty(); - - TestRequest request = ws.newRequest() - .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_PARENT_QUALITY_PROFILE, "polop") - .setParam(PARAM_PARENT_KEY, "palap"); - expectedException.expect(IllegalArgumentException.class); - request - .execute(); - } - - @Test - public void fail_if_profile_key_and_name_both_set() { - QProfileDto child = createProfile(); - - assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty(); - assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getIds()).isEmpty(); - - TestRequest request = ws.newRequest() - .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()) - .setParam(PARAM_QUALITY_PROFILE, child.getName()) - .setParam(PARAM_ORGANIZATION, organization.getKey()) - .setParam(PARAM_PARENT_KEY, "palap"); - - expectedException.expect(IllegalArgumentException.class); - request.execute(); - } - @Test public void fail_if_missing_permission() { userSession.logIn(db.users().insertUser()); @@ -402,7 +373,9 @@ public class ChangeParentActionTest { TestRequest request = ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()); + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); @@ -418,7 +391,9 @@ public class ChangeParentActionTest { TestRequest request = ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, child.getKee()); + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java index 7c8b2b93bcc..074448c81f5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java @@ -88,7 +88,9 @@ public class ChangelogActionTest { "param_bar", "bar_value")); String response = ws.newRequest() - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -126,7 +128,9 @@ public class ChangelogActionTest { "severity", "MINOR")); String response = ws.newRequest() - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -218,7 +222,9 @@ public class ChangelogActionTest { QProfileDto qualityProfile = db.qualityProfiles().insert(organization); String response = ws.newRequest() - .setParam(PARAM_KEY, qualityProfile.getKee()) + .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -238,7 +244,9 @@ public class ChangelogActionTest { "severity", "MINOR")); assertJson(ws.newRequest() - .setParam(PARAM_KEY, qualityProfile.getKee()) + .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SINCE, "2011-04-25T01:15:42+0100") .execute() .getInput()).isSimilarTo("{\n" + @@ -254,7 +262,9 @@ public class ChangelogActionTest { "}"); assertJson(ws.newRequest() - .setParam(PARAM_KEY, qualityProfile.getKee()) + .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SINCE, "2011-04-25T01:15:43+0100") .execute() .getInput()).isSimilarTo("{\n" + @@ -279,7 +289,9 @@ public class ChangelogActionTest { ImmutableMap.of("ruleId", valueOf(rule2.getId()))); String response = ws.newRequest() - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -460,7 +472,9 @@ public class ChangelogActionTest { String response = ws.newRequest() .setMethod("GET") - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam("ps", "10") .execute() .getInput(); @@ -475,7 +489,7 @@ public class ChangelogActionTest { assertThat(definition.isPost()).isFalse(); assertThat(definition.responseExampleAsString()).isNotEmpty(); assertThat(definition.params()).extracting(WebService.Param::key) - .containsExactlyInAnyOrder("key", "qualityProfile", "language", "organization", "since", "to", "p", "ps"); + .containsExactlyInAnyOrder("qualityProfile", "language", "organization", "since", "to", "p", "ps"); WebService.Param profileName = definition.param("qualityProfile"); assertThat(profileName.deprecatedSince()).isNullOrEmpty(); WebService.Param language = definition.param("language"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java index 7d1b67d69dc..8497ba3e01c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java @@ -117,9 +117,6 @@ public class CreateActionTest { assertThat(definition.isPost()).isTrue(); assertThat(definition.params()).extracting(Param::key) .containsExactlyInAnyOrder("language", "organization", "name", "backup_with_messages", "backup_with_errors", "backup_xoo_lint"); - Param name = definition.param("name"); - assertThat(name.deprecatedKey()).isEqualTo("profileName"); - assertThat(name.deprecatedKeySince()).isEqualTo("6.6"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java index 456a3a2e5cd..24c95e78f29 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java @@ -91,10 +91,6 @@ public class DeactivateRuleActionTest { assertThat(definition).isNotNull(); assertThat(definition.isPost()).isTrue(); assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("key", "rule"); - WebService.Param profileKey = definition.param("key"); - assertThat(profileKey.deprecatedKey()).isEqualTo("profile_key"); - WebService.Param ruleKey = definition.param("rule"); - assertThat(ruleKey.deprecatedKey()).isEqualTo("rule_key"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java index 4f0311aff96..892c77f883a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java @@ -105,8 +105,6 @@ public class DeactivateRulesActionTest { "owaspTop10", "sansTop25", "sonarsourceSecurity"); - WebService.Param targetProfile = definition.param("targetKey"); - assertThat(targetProfile.deprecatedKey()).isEqualTo("profile_key"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java index 2b68cec4651..ca8fe4c8201 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java @@ -76,26 +76,6 @@ public class DeleteActionTest { new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db))); private WsActionTester ws = new WsActionTester(underTest); - @Test - public void delete_profile_by_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); - QProfileDto profile1 = createProfile(organization); - QProfileDto profile2 = createProfile(organization); - db.qualityProfiles().associateWithProject(project, profile1); - - logInAsQProfileAdministrator(organization); - - TestResponse response = ws.newRequest() - .setMethod("POST") - .setParam(PARAM_KEY, profile1.getKee()) - .execute(); - assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT); - - verifyProfileDoesNotExist(profile1, organization); - verifyProfileExists(profile2); - } - @Test public void delete_profile_by_language_and_name_in_default_organization() { OrganizationDto organization = db.getDefaultOrganization(); @@ -161,14 +141,16 @@ public class DeleteActionTest { @Test public void fail_if_built_in_profile() { OrganizationDto organization = db.organizations().insert(); - QProfileDto profile1 = db.qualityProfiles().insert(organization, p -> p.setIsBuiltIn(true)); + QProfileDto profile1 = db.qualityProfiles().insert(organization, p -> p.setIsBuiltIn(true).setLanguage(A_LANGUAGE)); logInAsQProfileAdministrator(organization); expectedException.expect(BadRequestException.class); ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, profile1.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, profile1.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile1.getName()) .execute(); } @@ -183,7 +165,9 @@ public class DeleteActionTest { ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, qprofile.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, qprofile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, qprofile.getName()) .execute(); } @@ -204,7 +188,7 @@ public class DeleteActionTest { userSession.logIn(); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("If 'key' is not specified, 'qualityProfile' and 'language' must be set"); + expectedException.expectMessage("The 'language' parameter is missing"); ws.newRequest() .setMethod("POST") @@ -218,7 +202,7 @@ public class DeleteActionTest { logInAsQProfileAdministrator(organization); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("If 'key' is not specified, 'qualityProfile' and 'language' must be set"); + expectedException.expectMessage("The 'language' parameter is missing"); ws.newRequest() .setMethod("POST") @@ -234,7 +218,7 @@ public class DeleteActionTest { logInAsQProfileAdministrator(organization); expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("If 'key' is not specified, 'qualityProfile' and 'language' must be set"); + expectedException.expectMessage("The 'qualityProfile' parameter is missing"); ws.newRequest() .setMethod("POST") @@ -243,34 +227,17 @@ public class DeleteActionTest { .execute(); } - @Test - public void fail_if_too_many_parameters_to_reference_profile() { - OrganizationDto organization = db.organizations().insert(); - QProfileDto profile = createProfile(organization); - logInAsQProfileAdministrator(organization); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("When a quality profile key is set, 'organization' 'language' and 'qualityProfile' can't be set"); - - ws.newRequest() - .setMethod("POST") - .setParam(PARAM_ORGANIZATION, organization.getKey()) - .setParam(PARAM_LANGUAGE, profile.getLanguage()) - .setParam("profileName", profile.getName()) - .setParam(PARAM_KEY, profile.getKee()) - .execute(); - } - @Test public void fail_if_profile_does_not_exist() { userSession.logIn(); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Quality Profile with key 'does_not_exist' does not exist"); + expectedException.expectMessage("Quality Profile for language 'xoo' and name 'does_not_exist' does not exist"); ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, "does_not_exist") + .setParam(PARAM_QUALITY_PROFILE, "does_not_exist") + .setParam(PARAM_LANGUAGE, "xoo") .execute(); } @@ -286,7 +253,9 @@ public class DeleteActionTest { ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) .execute(); } @@ -304,7 +273,9 @@ public class DeleteActionTest { ws.newRequest() .setMethod("POST") - .setParam(PARAM_KEY, parentProfile.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_LANGUAGE, parentProfile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, parentProfile.getName()) .execute(); } @@ -313,14 +284,7 @@ public class DeleteActionTest { WebService.Action definition = ws.getDef(); assertThat(definition.isPost()).isTrue(); - assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("language", "organization", "key", "qualityProfile"); - Param key = definition.param("key"); - assertThat(key.deprecatedKey()).isEqualTo("profileKey"); - assertThat(key.deprecatedSince()).isEqualTo("6.6"); - Param profileName = definition.param("qualityProfile"); - assertThat(profileName.deprecatedSince()).isNullOrEmpty(); - Param language = definition.param("language"); - assertThat(language.deprecatedSince()).isNullOrEmpty(); + assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("language", "organization", "qualityProfile"); } private void logInAsQProfileAdministrator(OrganizationDto organization) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java index 7b7fdb5db59..9beeeb2e4d3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java @@ -72,20 +72,6 @@ public class ExportActionTest { private QProfileBackuper backuper = new TestBackuper(); private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)); - @Test - public void export_profile_with_key() { - QProfileDto profile = createProfile(db.getDefaultOrganization(), false); - - WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap")); - String result = tester.newRequest() - .setParam(PARAM_KEY, profile.getKee()) - .setParam("exporterKey", "polop") - .execute() - .getInput(); - - assertThat(result).isEqualTo("Profile " + profile.getLanguage() + "/" + profile.getName() + " exported by polop"); - } - @Test public void export_profile_in_default_organization() { QProfileDto profile = createProfile(db.getDefaultOrganization(), false); @@ -234,33 +220,6 @@ public class ExportActionTest { .execute(); } - @Test - public void fail_if_profile_key_is_unknown() { - expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Could not find profile with key 'PROFILE-KEY-404'"); - - WsActionTester ws = newWsActionTester(newExporter("polop"), newExporter("palap")); - ws.newRequest() - .setParam(PARAM_KEY, "PROFILE-KEY-404") - .setParam("exporterKey", "polop").execute() - .getInput(); - } - - @Test - public void fail_if_profile_key_and_language_provided() { - QProfileDto profile = createProfile(db.getDefaultOrganization(), false); - - expectedException.expect(BadRequestException.class); - expectedException.expectMessage("Either 'key' or 'language' must be provided"); - - WsActionTester ws = newWsActionTester(newExporter("polop"), newExporter("palap")); - ws.newRequest() - .setParam(PARAM_KEY, profile.getKee()) - .setParam(PARAM_LANGUAGE, profile.getLanguage()) - .setParam("exporterKey", "polop").execute() - .getInput(); - } - @Test public void fail_on_paid_organization_when_not_member() { WsActionTester tester = newWsActionTester(newExporter("foo")); @@ -284,19 +243,14 @@ public class ExportActionTest { assertThat(definition.isPost()).isFalse(); assertThat(definition.isInternal()).isFalse(); - assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("key", "language", "qualityProfile", "organization"); + assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("language", "qualityProfile", "organization"); WebService.Param organizationParam = definition.param("organization"); assertThat(organizationParam.since()).isEqualTo("6.4"); assertThat(organizationParam.isInternal()).isTrue(); - WebService.Param key = definition.param("key"); - assertThat(key.since()).isEqualTo("6.5"); - assertThat(key.deprecatedSince()).isEqualTo("6.6"); - WebService.Param name = definition.param("qualityProfile"); assertThat(name.deprecatedSince()).isNullOrEmpty(); - assertThat(name.deprecatedKey()).isEqualTo("name"); WebService.Param language = definition.param("language"); assertThat(language.deprecatedSince()).isNullOrEmpty(); @@ -308,7 +262,7 @@ public class ExportActionTest { assertThat(definition.isPost()).isFalse(); assertThat(definition.isInternal()).isFalse(); - assertThat(definition.params()).extracting("key").containsExactlyInAnyOrder("key", "language", "qualityProfile", "organization", "exporterKey"); + assertThat(definition.params()).extracting("key").containsExactlyInAnyOrder("language", "qualityProfile", "organization", "exporterKey"); WebService.Param exportersParam = definition.param("exporterKey"); assertThat(exportersParam.possibleValues()).containsOnly("polop", "palap"); assertThat(exportersParam.deprecatedKey()).isEqualTo("format"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java index 03eefdc608a..3e054a4fe68 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java @@ -134,7 +134,9 @@ public class InheritanceActionTest { overrideActiveRuleSeverity(rule2, forProject2, Severity.CRITICAL); String response = ws.newRequest() - .setParam(PARAM_KEY, buWide.getKee()) + .setParam(PARAM_LANGUAGE, buWide.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, buWide.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -162,7 +164,9 @@ public class InheritanceActionTest { InputStream response = ws.newRequest() .setMediaType(PROTOBUF) - .setParam(PARAM_KEY, child.getKee()) + .setParam(PARAM_LANGUAGE, child.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, child.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInputStream(); @@ -189,7 +193,9 @@ public class InheritanceActionTest { InputStream response = ws.newRequest() .setMediaType(PROTOBUF) - .setParam(PARAM_KEY, profile.getKee()) + .setParam(PARAM_LANGUAGE, profile.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, profile.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInputStream(); @@ -205,7 +211,9 @@ public class InheritanceActionTest { QProfileDto remi = createProfile(organization,"xoo", "Nobodys Boy", "xoo-nobody-s-boy-01234"); String response = ws.newRequest() - .setParam(PARAM_KEY, remi.getKee()) + .setParam(PARAM_LANGUAGE, remi.getLanguage()) + .setParam(PARAM_QUALITY_PROFILE, remi.getName()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute() .getInput(); @@ -228,7 +236,10 @@ public class InheritanceActionTest { @Test(expected = NotFoundException.class) public void fail_if_not_found() { - ws.newRequest().setParam(PARAM_KEY, "polop").execute(); + ws.newRequest() + .setParam(PARAM_LANGUAGE, "xoo") + .setParam(PARAM_QUALITY_PROFILE, "asd") + .execute(); } @Test @@ -251,14 +262,7 @@ public class InheritanceActionTest { WebService.Action definition = ws.getDef(); assertThat(definition.key()).isEqualTo("inheritance"); - assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("key", "language", "qualityProfile", "organization"); - Param key = definition.param("key"); - assertThat(key.deprecatedKey()).isEqualTo("profileKey"); - assertThat(key.deprecatedSince()).isEqualTo("6.6"); - Param profileName = definition.param("qualityProfile"); - assertThat(profileName.deprecatedSince()).isNullOrEmpty(); - Param language = definition.param("language"); - assertThat(language.deprecatedSince()).isNullOrEmpty(); + assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("language", "qualityProfile", "organization"); } private QProfileDto createProfile(OrganizationDto organization, String lang, String name, String key) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java index 1179f9edebe..cd61833bf63 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java @@ -358,7 +358,6 @@ public class ProjectsActionTest { assertThat(definition.param("p")).isNotNull(); assertThat(definition.param("ps")).isNotNull(); Param query = definition.param("q"); - assertThat(query.deprecatedKey()).isEqualTo("query"); } private void associateProjectsWithProfile(QProfileDto profile, ComponentDto... projects) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java index 1fdb8c069ae..bc64e99f0d2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java @@ -98,56 +98,36 @@ public class QProfileReferenceTest { } @Test - public void from_reads_request_parameters_and_creates_reference_by_key() { - SimpleGetRequest req = new SimpleGetRequest(); - req.setParam("key", "foo"); - - QProfileReference ref = QProfileReference.from(req); - assertThat(ref.getKey()).isEqualTo("foo"); - } - - @Test - public void from_reads_request_parameters_and_creates_reference_by_name_on_default_organization() { + public void fromName_reads_request_parameters_and_creates_reference_by_name_on_default_organization() { SimpleGetRequest req = new SimpleGetRequest(); req.setParam("language", "js"); req.setParam("qualityProfile", "Sonar way"); - QProfileReference ref = QProfileReference.from(req); + QProfileReference ref = QProfileReference.fromName(req); assertThat(ref.getOrganizationKey()).isEmpty(); assertThat(ref.getLanguage()).isEqualTo("js"); assertThat(ref.getName()).isEqualTo("Sonar way"); } @Test - public void from_reads_request_parameters_and_creates_reference_by_name_on_specified_organization() { + public void fromName_reads_request_parameters_and_creates_reference_by_name_on_specified_organization() { SimpleGetRequest req = new SimpleGetRequest(); req.setParam("organization", "my-org"); req.setParam("language", "js"); req.setParam("qualityProfile", "Sonar way"); - QProfileReference ref = QProfileReference.from(req); + QProfileReference ref = QProfileReference.fromName(req); assertThat(ref.getOrganizationKey()).hasValue("my-org"); assertThat(ref.getLanguage()).isEqualTo("js"); assertThat(ref.getName()).isEqualTo("Sonar way"); } - @Test - public void from_reads_request_parameters_and_throws_IAE_if_language_is_missing() { - SimpleGetRequest req = new SimpleGetRequest(); - req.setParam("profileName", "the name"); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("If 'key' is not specified, 'qualityProfile' and 'language' must be set"); - - QProfileReference.from(req); - } - @Test public void throw_IAE_if_request_does_not_define_ref() { SimpleGetRequest req = new SimpleGetRequest(); expectedException.expect(IllegalArgumentException.class); - QProfileReference.from(req); + QProfileReference.fromName(req); } @Test @@ -164,7 +144,6 @@ public class QProfileReferenceTest { WebService.Action action = context.controller("api/qualityprofiles").action("do"); assertThat(action.param("language")).isNotNull(); assertThat(action.param("language").possibleValues()).containsOnly("java", "js"); - assertThat(action.param("key")).isNotNull(); assertThat(action.param("qualityProfile")).isNotNull(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java index 4f924f19ac2..16bc67f44ca 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java @@ -29,6 +29,6 @@ public class QProfilesWsModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new QProfilesWsModule().configure(container); - assertThat(container.size()).isEqualTo(32 + 2); + assertThat(container.size()).isEqualTo(31 + 2); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java index 9a397d0b482..002c724d68e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java @@ -65,7 +65,7 @@ public class RemoveProjectActionTest { private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)); private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages, - new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport); + new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport); private WsActionTester ws = new WsActionTester(underTest); @Test @@ -76,7 +76,7 @@ public class RemoveProjectActionTest { assertThat(definition.isPost()).isTrue(); assertThat(definition.key()).isEqualTo("remove_project"); - assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("key", "qualityProfile", "project", "language", "projectUuid", "organization"); + assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("qualityProfile", "project", "language", "organization"); WebService.Param languageParam = definition.param("language"); assertThat(languageParam.possibleValues()).containsOnly(LANGUAGE_1, LANGUAGE_2); assertThat(languageParam.exampleValue()).isNull(); @@ -84,14 +84,8 @@ public class RemoveProjectActionTest { WebService.Param organizationParam = definition.param("organization"); assertThat(organizationParam.since()).isEqualTo("6.4"); assertThat(organizationParam.isInternal()).isTrue(); - WebService.Param profile = definition.param("key"); - assertThat(profile.deprecatedKey()).isEqualTo("profileKey"); WebService.Param profileName = definition.param("qualityProfile"); assertThat(profileName.deprecatedSince()).isNullOrEmpty(); - WebService.Param project = definition.param("project"); - assertThat(project.deprecatedKey()).isEqualTo("projectKey"); - WebService.Param projectUuid = definition.param("projectUuid"); - assertThat(projectUuid.deprecatedSince()).isEqualTo("6.5"); } @Test @@ -116,9 +110,9 @@ public class RemoveProjectActionTest { logInAsProfileAdmin(); ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); - TestResponse response = call(project, profile); + TestResponse response = call(db.getDefaultOrganization(), project, profile); assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT); assertProjectIsNotAssociatedToProfile(project, profile); @@ -127,11 +121,11 @@ public class RemoveProjectActionTest { @Test public void project_administrator_can_remove_profile() { ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); db.qualityProfiles().associateWithProject(project, profile); userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project); - call(project, profile); + call(db.getDefaultOrganization(), project, profile); assertProjectIsNotAssociatedToProfile(project, profile); } @@ -146,7 +140,7 @@ public class RemoveProjectActionTest { db.qualityProfiles().addUserPermission(profile, user); userSession.logIn(user); - call(project, profile); + call(organization, project, profile); assertProjectIsNotAssociatedToProfile(project, profile); } @@ -155,7 +149,7 @@ public class RemoveProjectActionTest { public void fail_if_not_enough_permissions() { userSession.logIn(db.users().insertUser()); ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); - QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); + QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), qp -> qp.setLanguage("xoo")); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); @@ -181,10 +175,10 @@ public class RemoveProjectActionTest { QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Component id 'unknown' not found"); + expectedException.expectMessage("Component key 'unknown' not found"); ws.newRequest() - .setParam("projectUuid", "unknown") + .setParam("project", "unknown") .setParam("profileKey", profile.getKee()) .execute(); } @@ -195,11 +189,12 @@ public class RemoveProjectActionTest { ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Quality Profile with key 'unknown' does not exist"); + expectedException.expectMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist"); ws.newRequest() - .setParam("projectUuid", project.uuid()) - .setParam("profileKey", "unknown") + .setParam("project", project.getDbKey()) + .setParam("language", "xoo") + .setParam("qualityProfile", "unknown") .execute(); } @@ -216,24 +211,8 @@ public class RemoveProjectActionTest { ws.newRequest() .setParam("project", branch.getDbKey()) - .setParam("profileKey", profile.getKee()) - .execute(); - } - - @Test - public void fail_when_using_branch_uuid() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertMainBranch(organization); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - QProfileDto profile = db.qualityProfiles().insert(organization); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); - - ws.newRequest() - .setParam("projectUuid", branch.uuid()) - .setParam("profileKey", profile.getKee()) + .setParam("language", profile.getLanguage()) + .setParam("qualityProfile", profile.getName()) .execute(); } @@ -253,8 +232,18 @@ public class RemoveProjectActionTest { private TestResponse call(ComponentDto project, QProfileDto qualityProfile) { TestRequest request = ws.newRequest() - .setParam("projectUuid", project.uuid()) - .setParam("profileKey", qualityProfile.getKee()); + .setParam("project", project.getDbKey()) + .setParam("language", qualityProfile.getLanguage()) + .setParam("qualityProfile", qualityProfile.getName()); + return request.execute(); + } + + private TestResponse call(OrganizationDto organization, ComponentDto project, QProfileDto qualityProfile) { + TestRequest request = ws.newRequest() + .setParam("project", project.getDbKey()) + .setParam("organization", organization.getKey()) + .setParam("language", qualityProfile.getLanguage()) + .setParam("qualityProfile", qualityProfile.getName()); return request.execute(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index 6c2cc25845f..48aaffc97a6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -67,7 +67,7 @@ import static org.sonar.test.JsonAssert.assertJson; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; public class SearchActionTest { @@ -229,7 +229,7 @@ public class SearchActionTest { db.qualityProfiles().associateWithProject(project, profileOnXoo1); db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2); - SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, project.getDbKey())); + SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT, project.getDbKey())); assertThat(result.getProfilesList()) .extracting(QualityProfile::getKey) @@ -247,7 +247,7 @@ public class SearchActionTest { db.qualityProfiles().associateWithProject(project, profileOnXoo1); db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2); - SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, module.getDbKey())); + SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT, module.getDbKey())); assertThat(result.getProfilesList()) .extracting(QualityProfile::getKey) @@ -265,7 +265,7 @@ public class SearchActionTest { db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2); SearchWsResponse result = call(ws.newRequest() - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT, project.getDbKey()) .setParam(PARAM_DEFAULTS, "true")); assertThat(result.getProfilesList()) @@ -283,7 +283,7 @@ public class SearchActionTest { db.qualityProfiles().associateWithProject(project, profileOnXoo1); SearchWsResponse result = call(ws.newRequest() - .setParam(PARAM_PROJECT_KEY, project.getDbKey()) + .setParam(PARAM_PROJECT, project.getDbKey()) .setParam(PARAM_DEFAULTS, "true")); assertThat(result.getProfilesList()).isEmpty(); @@ -437,7 +437,7 @@ public class SearchActionTest { expectedException.expect(NotFoundException.class); expectedException.expectMessage("Component key 'unknown-project' not found"); - call(ws.newRequest().setParam(PARAM_PROJECT_KEY, "unknown-project")); + call(ws.newRequest().setParam(PARAM_PROJECT, "unknown-project")); } @Test @@ -448,7 +448,7 @@ public class SearchActionTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(format("Project uuid of component uuid '%s' does not exist", module.uuid())); - call(ws.newRequest().setParam(PARAM_PROJECT_KEY, module.getDbKey())); + call(ws.newRequest().setParam(PARAM_PROJECT, module.getDbKey())); } @Test @@ -462,7 +462,7 @@ public class SearchActionTest { call(ws.newRequest() .setParam(PARAM_ORGANIZATION, organization.getKey()) - .setParam(PARAM_PROJECT_KEY, project.getDbKey())); + .setParam(PARAM_PROJECT, project.getDbKey())); } @Test @@ -562,7 +562,6 @@ public class SearchActionTest { WebService.Param projectKey = definition.param("project"); assertThat(projectKey.description()).isEqualTo("Project key"); - assertThat(projectKey.deprecatedKey()).isEqualTo("projectKey"); WebService.Param language = definition.param("language"); assertThat(language.possibleValues()).containsExactly("xoo1", "xoo2"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java index fc23a0b1ee8..5db7f93f651 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java @@ -45,6 +45,9 @@ import org.sonar.server.ws.WsActionTester; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; public class SetDefaultActionTest { @@ -106,38 +109,8 @@ public class SetDefaultActionTest { assertThat(definition).isNotNull(); assertThat(definition.isPost()).isTrue(); - assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("key", "qualityProfile", "language", "organization"); + assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("qualityProfile", "language", "organization"); assertThat(definition.param("organization").since()).isEqualTo("6.4"); - Param profile = definition.param("key"); - assertThat(profile.deprecatedKey()).isEqualTo("profileKey"); - assertThat(definition.param("qualityProfile").deprecatedSince()).isNullOrEmpty(); - assertThat(definition.param("language").deprecatedSince()).isNullOrEmpty(); - } - - @Test - public void set_default_profile_using_key() { - logInAsQProfileAdministrator(); - - checkDefaultProfile(organization, XOO_1_KEY, xoo1Profile.getKee()); - checkDefaultProfile(organization, XOO_2_KEY, xoo2Profile2.getKee()); - - TestResponse response = ws.newRequest() - .setMethod("POST") - .setParam(PARAM_KEY, xoo2Profile.getKee()).execute(); - - assertThat(response.getInput()).isEmpty(); - - checkDefaultProfile(organization, XOO_1_KEY, xoo1Profile.getKee()); - checkDefaultProfile(organization, XOO_2_KEY, xoo2Profile.getKee()); - - // One more time! - TestResponse response2 = ws.newRequest() - .setMethod("POST") - .setParam(PARAM_KEY, xoo2Profile.getKee()).execute(); - - assertThat(response2.getInput()).isEmpty(); - checkDefaultProfile(organization, XOO_1_KEY, xoo1Profile.getKee()); - checkDefaultProfile(organization, XOO_2_KEY, xoo2Profile.getKee()); } @Test @@ -196,21 +169,6 @@ public class SetDefaultActionTest { checkDefaultProfile(organization2, XOO_1_KEY, profileOrg2.getKee()); } - @Test - public void fail_to_set_default_profile_using_invalid_key() { - logInAsQProfileAdministrator(); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage("Quality Profile with key 'unknown-profile-666' does not exist"); - - ws.newRequest().setMethod("POST") - .setParam(PARAM_KEY, "unknown-profile-666") - .execute(); - - checkDefaultProfile(organization, XOO_1_KEY, xoo1Profile.getKee()); - checkDefaultProfile(organization, XOO_2_KEY, xoo2Profile2.getKee()); - } - @Test public void fail_to_set_default_profile_using_language_and_invalid_name() { logInAsQProfileAdministrator(); @@ -228,19 +186,6 @@ public class SetDefaultActionTest { } } - @Test - public void fail_if_parameter_profile_key_is_combined_with_parameter_organization() { - userSessionRule.logIn(); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("When a quality profile key is set, 'organization' 'language' and 'qualityProfile' can't be set"); - - ws.newRequest().setMethod("POST") - .setParam(PARAM_KEY, xoo2Profile.getKee()) - .setParam("organization", organization.getKey()) - .execute(); - } - @Test public void throw_ForbiddenException_if_not_profile_administrator() { userSessionRule.logIn(); @@ -249,7 +194,9 @@ public class SetDefaultActionTest { expectedException.expectMessage("Insufficient privileges"); ws.newRequest().setMethod("POST") - .setParam(PARAM_KEY, xoo2Profile.getKee()) + .setParam(PARAM_ORGANIZATION, organization.getKey()) + .setParam(PARAM_QUALITY_PROFILE, xoo2Profile.getName()) + .setParam(PARAM_LANGUAGE, xoo2Profile.getLanguage()) .execute(); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java index 7bf41b77a93..5fe74d33d93 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java @@ -57,7 +57,7 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader { @Override public List load(String projectKey) { - StringBuilder url = new StringBuilder(WS_URL + "?projectKey=").append(encodeForUrl(projectKey)); + StringBuilder url = new StringBuilder(WS_URL + "?project=").append(encodeForUrl(projectKey)); return handleErrors(url, () -> String.format("Failed to load the quality profiles of project '%s'", projectKey), true); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java index edfc14e5bd6..f5d3661dff9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java @@ -51,14 +51,14 @@ public class DefaultQualityProfileLoaderTest { public void load_gets_all_profiles_for_specified_project() throws IOException { prepareCallWithResults(); underTest.load("foo"); - verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo"); + verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo"); } @Test public void load_encodes_url_parameters() throws IOException { - WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232", createStreamOfProfiles("qp")); + WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?project=foo%232", createStreamOfProfiles("qp")); underTest.load("foo#2"); - verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo%232"); + verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo%232"); } @Test @@ -66,18 +66,18 @@ public class DefaultQualityProfileLoaderTest { when(properties.organizationKey()).thenReturn(Optional.of("my-org")); prepareCallWithResults(); underTest.load("foo"); - verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo&organization=my-org"); + verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo&organization=my-org"); } @Test public void load_tries_default_if_no_profiles_found_for_project() throws IOException { HttpException e = new HttpException("", 404, "{\"errors\":[{\"msg\":\"No project found with key 'foo'\"}]}"); - WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo", e); + WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?project=foo", e); WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", createStreamOfProfiles("qp")); underTest.load("foo"); - verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo"); + verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo"); verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true"); } @@ -86,7 +86,7 @@ public class DefaultQualityProfileLoaderTest { when(properties.organizationKey()).thenReturn(Optional.of("my-org")); HttpException e = new HttpException("", 404, "{\"errors\":[{\"msg\":\"No organization with key 'myorg'\"}]}"); - WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo&organization=my-org", e); + WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?project=foo&organization=my-org", e); WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true&organization=my-org", createStreamOfProfiles("qp")); underTest.load("foo"); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java index d5e7d86e015..691cc75743f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java @@ -56,13 +56,10 @@ public class QualityProfileWsParameters { public static final String PARAM_LOGIN = "login"; public static final String PARAM_NAME = "name"; public static final String PARAM_PARAMS = "params"; - public static final String PARAM_PARENT_KEY = "parentKey"; public static final String PARAM_PARENT_QUALITY_PROFILE = "parentQualityProfile"; public static final String PARAM_KEY = "key"; public static final String PARAM_QUALITY_PROFILE = "qualityProfile"; public static final String PARAM_PROJECT = "project"; - public static final String PARAM_PROJECT_KEY = "projectKey"; - public static final String PARAM_PROJECT_UUID = "projectUuid"; public static final String PARAM_QUERY = "q"; public static final String PARAM_RESET = "reset"; public static final String PARAM_RULE = "rule"; -- 2.39.5