]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19935 Rename ws param projectKey to project
authorEric Giffon <eric.giffon@sonarsource.com>
Tue, 18 Jul 2023 13:28:21 +0000 (15:28 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:05 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java

index 85dc8b69cb7d3a2a805a663b18b2b0cb110b9bfd..0721fe906f4a96dc6ea530b3ad7d5a7c28e03289 100644 (file)
@@ -119,7 +119,7 @@ import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
 @RunWith(DataProviderRunner.class)
 public class SearchActionIT {
 
-  private static final String PARAM_PROJECT_KEY = "projectKey";
+  private static final String PARAM_PROJECT = "project";
   private static final String PARAM_STATUS = "status";
   private static final String PARAM_RESOLUTION = "resolution";
   private static final String PARAM_HOTSPOTS = "hotspots";
@@ -195,40 +195,40 @@ public class SearchActionIT {
   }
 
   @Test
-  public void fails_with_IAE_if_parameters_projectKey_and_hotspots_are_missing() {
+  public void fails_with_IAE_if_parameters_project_and_hotspots_are_missing() {
     TestRequest request = actionTester.newRequest();
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("A value must be provided for either parameter 'projectKey' or parameter 'hotspots'");
+      .hasMessage("A value must be provided for either parameter 'project' or parameter 'hotspots'");
   }
 
   @Test
-  public void fail_with_IAE_if_parameter_branch_is_used_without_parameter_projectKey() {
+  public void fail_with_IAE_if_parameter_branch_is_used_without_parameter_project() {
     TestRequest request = actionTester.newRequest()
       .setParam(PARAM_HOTSPOTS, randomAlphabetic(2))
       .setParam(PARAM_BRANCH, randomAlphabetic(1));
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Parameter 'branch' must be used with parameter 'projectKey'");
+      .hasMessage("Parameter 'branch' must be used with parameter 'project'");
   }
 
   @Test
-  public void fail_with_IAE_if_parameter_pullRequest_is_used_without_parameter_projectKey() {
+  public void fail_with_IAE_if_parameter_pullRequest_is_used_without_parameter_project() {
     TestRequest request = actionTester.newRequest()
       .setParam(PARAM_HOTSPOTS, randomAlphabetic(2))
       .setParam(PARAM_PULL_REQUEST, randomAlphabetic(1));
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Parameter 'pullRequest' must be used with parameter 'projectKey'");
+      .hasMessage("Parameter 'pullRequest' must be used with parameter 'project'");
   }
 
   @Test
   public void fail_with_IAE_if_both_parameters_pullRequest_and_branch_are_provided() {
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, randomAlphabetic(2))
+      .setParam(PARAM_PROJECT, randomAlphabetic(2))
       .setParam(PARAM_BRANCH, randomAlphabetic(1))
       .setParam(PARAM_PULL_REQUEST, randomAlphabetic(1));
 
@@ -241,7 +241,7 @@ public class SearchActionIT {
   @UseDataProvider("badStatuses")
   public void fails_with_IAE_if_status_parameter_is_neither_TO_REVIEW_or_REVIEWED(String badStatus) {
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, randomAlphabetic(13))
+      .setParam(PARAM_PROJECT, randomAlphabetic(13))
       .setParam(PARAM_STATUS, badStatus);
 
     assertThatThrownBy(request::execute)
@@ -276,7 +276,7 @@ public class SearchActionIT {
   @UseDataProvider("badResolutions")
   public void fails_with_IAE_if_resolution_parameter_is_neither_FIXED_nor_SAFE(String badResolution) {
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, randomAlphabetic(13))
+      .setParam(PARAM_PROJECT, randomAlphabetic(13))
       .setParam(PARAM_STATUS, STATUS_TO_REVIEW)
       .setParam(PARAM_RESOLUTION, badResolution);
 
@@ -301,7 +301,7 @@ public class SearchActionIT {
   @UseDataProvider("fixedOrSafeResolution")
   public void fails_with_IAE_if_resolution_is_provided_with_status_TO_REVIEW(String resolution) {
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, randomAlphabetic(13))
+      .setParam(PARAM_PROJECT, randomAlphabetic(13))
       .setParam(PARAM_STATUS, STATUS_TO_REVIEW)
       .setParam(PARAM_RESOLUTION, resolution);
 
@@ -334,7 +334,7 @@ public class SearchActionIT {
   public void fails_with_NotFoundException_if_project_does_not_exist() {
     String key = randomAlphabetic(12);
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, key);
+      .setParam(PARAM_PROJECT, key);
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(NotFoundException.class)
@@ -350,7 +350,7 @@ public class SearchActionIT {
     TestRequest request = actionTester.newRequest();
 
     for (ComponentDto component : Arrays.asList(directory, file, portfolio)) {
-      request.setParam(PARAM_PROJECT_KEY, component.getKey());
+      request.setParam(PARAM_PROJECT, component.getKey());
 
       assertThatThrownBy(request::execute)
         .isInstanceOf(NotFoundException.class)
@@ -823,7 +823,7 @@ public class SearchActionIT {
       .setParam(PARAM_ONLY_MINE, "true");
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Parameter 'onlyMine' can be used with parameter 'projectKey' only");
+      .hasMessage("Parameter 'onlyMine' can be used with parameter 'project' only");
   }
 
   @Test
@@ -833,7 +833,7 @@ public class SearchActionIT {
     userSessionRule.anonymous();
 
     TestRequest request = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, project.getKey())
+      .setParam(PARAM_PROJECT, project.getKey())
       .setParam(PARAM_ONLY_MINE, "true");
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
@@ -2135,7 +2135,7 @@ public class SearchActionIT {
   private TestRequest newRequest(ComponentDto project, @Nullable String status, @Nullable String resolution,
     @Nullable String branch, @Nullable String pullRequest, Consumer<TestRequest> consumer) {
     TestRequest res = actionTester.newRequest()
-      .setParam(PARAM_PROJECT_KEY, project.getKey());
+      .setParam(PARAM_PROJECT, project.getKey());
     if (branch != null) {
       res.setParam(PARAM_BRANCH, branch);
     }
index 4176e5c4b0734b53e626712ccbaec5c6bef3c69a..28a9b01e19ec783e278965867fbf0a2f0cbac51c 100644 (file)
@@ -94,6 +94,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class SearchAction implements HotspotsWsAction {
   private static final Set<String> SUPPORTED_QUALIFIERS = Set.of(Qualifiers.PROJECT, Qualifiers.APP);
+  private static final String PARAM_PROJECT = "project";
   private static final String PARAM_PROJECT_KEY = "projectKey";
   private static final String PARAM_STATUS = "status";
   private static final String PARAM_RESOLUTION = "resolution";
@@ -155,7 +156,7 @@ public class SearchAction implements HotspotsWsAction {
     Set<String> files = setFromList(request.paramAsStrings(PARAM_FILES));
 
     return new WsRequest(
-      request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE), request.param(PARAM_PROJECT_KEY), request.param(PARAM_BRANCH),
+      request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE), request.param(PARAM_PROJECT), request.param(PARAM_BRANCH),
       request.param(PARAM_PULL_REQUEST), hotspotKeys, request.param(PARAM_STATUS), request.param(PARAM_RESOLUTION),
       request.paramAsBoolean(PARAM_IN_NEW_CODE_PERIOD), request.paramAsBoolean(PARAM_ONLY_MINE), request.paramAsInt(PARAM_OWASP_ASVS_LEVEL),
       pciDss32, pciDss40, owaspAsvs40, owasp2017Top10, owasp2021Top10, sansTop25, sonarsourceSecurity, cwes, files);
@@ -223,6 +224,7 @@ public class SearchAction implements HotspotsWsAction {
         + "When issue indexation is in progress returns 503 service unavailable HTTP code.")
       .setSince("8.1")
       .setChangelog(
+        new Change("10.2", format("Parameter '%s' renamed to '%s'", PARAM_PROJECT_KEY, PARAM_PROJECT)),
         new Change("10.0", "Parameter 'sansTop25' is deprecated"),
         new Change("9.6", "Added parameters 'pciDss-3.2' and 'pciDss-4.0"),
         new Change("9.7", "Hotspot flows in the response may contain a description and a type"),
@@ -231,7 +233,8 @@ public class SearchAction implements HotspotsWsAction {
         new Change("9.8", "Add message formatting to issue and locations response"));
 
     action.addPagingParams(100);
-    action.createParam(PARAM_PROJECT_KEY)
+    action.createParam(PARAM_PROJECT)
+      .setDeprecatedKey(PARAM_PROJECT_KEY, "10.2")
       .setDescription(format(
         "Key of the project or application. This parameter is required unless %s is provided.",
         PARAM_HOTSPOTS))
@@ -245,16 +248,16 @@ public class SearchAction implements HotspotsWsAction {
     action.createParam(PARAM_HOTSPOTS)
       .setDescription(format(
         "Comma-separated list of Security Hotspot keys. This parameter is required unless %s is provided.",
-        PARAM_PROJECT_KEY))
+        PARAM_PROJECT))
       .setExampleValue("AWhXpLoInp4On-Y3xc8x");
     action.createParam(PARAM_STATUS)
-      .setDescription("If '%s' is provided, only Security Hotspots with the specified status are returned.", PARAM_PROJECT_KEY)
+      .setDescription("If '%s' is provided, only Security Hotspots with the specified status are returned.", PARAM_PROJECT)
       .setPossibleValues(STATUSES)
       .setRequired(false);
     action.createParam(PARAM_RESOLUTION)
       .setDescription(format(
         "If '%s' is provided and if status is '%s', only Security Hotspots with the specified resolution are returned.",
-        PARAM_PROJECT_KEY, STATUS_REVIEWED))
+        PARAM_PROJECT, STATUS_REVIEWED))
       .setPossibleValues(RESOLUTION_FIXED, RESOLUTION_SAFE, RESOLUTION_ACKNOWLEDGED)
       .setRequired(false);
     action.createParam(PARAM_IN_NEW_CODE_PERIOD)
@@ -414,14 +417,14 @@ public class SearchAction implements HotspotsWsAction {
     Set<String> hotspotKeys = wsRequest.getHotspotKeys();
     checkArgument(
       projectKey.isPresent() || !hotspotKeys.isEmpty(),
-      "A value must be provided for either parameter '%s' or parameter '%s'", PARAM_PROJECT_KEY, PARAM_HOTSPOTS);
+      "A value must be provided for either parameter '%s' or parameter '%s'", PARAM_PROJECT, PARAM_HOTSPOTS);
 
     checkArgument(
       branch.isEmpty() || projectKey.isPresent(),
-      "Parameter '%s' must be used with parameter '%s'", PARAM_BRANCH, PARAM_PROJECT_KEY);
+      "Parameter '%s' must be used with parameter '%s'", PARAM_BRANCH, PARAM_PROJECT);
     checkArgument(
       pullRequest.isEmpty() || projectKey.isPresent(),
-      "Parameter '%s' must be used with parameter '%s'", PARAM_PULL_REQUEST, PARAM_PROJECT_KEY);
+      "Parameter '%s' must be used with parameter '%s'", PARAM_PULL_REQUEST, PARAM_PROJECT);
     checkArgument(
       !(branch.isPresent() && pullRequest.isPresent()),
       "Only one of parameters '%s' and '%s' can be provided", PARAM_BRANCH, PARAM_PULL_REQUEST);
@@ -442,7 +445,7 @@ public class SearchAction implements HotspotsWsAction {
       checkArgument(userSession.isLoggedIn(),
         "Parameter '%s' requires user to be logged in", PARAM_ONLY_MINE);
       checkArgument(wsRequest.getProjectKey().isPresent(),
-        "Parameter '%s' can be used with parameter '%s' only", PARAM_ONLY_MINE, PARAM_PROJECT_KEY);
+        "Parameter '%s' can be used with parameter '%s' only", PARAM_ONLY_MINE, PARAM_PROJECT);
     }
   }