]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9151 param componentKey => component in api/navigation/component
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Fri, 21 Apr 2017 15:26:22 +0000 (17:26 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java

index 6e8055dc6f3776e75c44291784da1f3d1c4e43d3..94518b9d788aa2d3aa6047b81b83245bc9397d16 100644 (file)
@@ -67,7 +67,7 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
 
 public class ComponentAction implements NavigationWsAction {
 
-  private static final String PARAM_COMPONENT_KEY = "componentKey";
+  static final String PARAM_COMPONENT = "component";
 
   private static final String PROPERTY_CONFIGURABLE = "configurable";
   private static final String PROPERTY_HAS_ROLE_POLICY = "hasRolePolicy";
@@ -120,14 +120,15 @@ public class ComponentAction implements NavigationWsAction {
       .setResponseExample(getClass().getResource("component-example.json"))
       .setSince("5.2");
 
-    projectNavigation.createParam(PARAM_COMPONENT_KEY)
+    projectNavigation.createParam(PARAM_COMPONENT)
       .setDescription("A component key.")
+      .setDeprecatedKey("componentKey", "6.4")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001);
   }
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    String componentKey = request.mandatoryParam(PARAM_COMPONENT_KEY);
+    String componentKey = request.mandatoryParam(PARAM_COMPONENT);
     try (DbSession session = dbClient.openSession(false)) {
       ComponentDto component = componentFinder.getByKey(session, componentKey);
       if (!userSession.hasComponentPermission(USER, component) &&
index 0f261f50ddec141c27bcfa00f5317f6cef91ea4f..9b59d6749b3fa605b6115c2aa1ae97dc6ba5a5a1 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
+import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
@@ -73,6 +74,7 @@ import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
 import static org.sonar.db.metric.MetricTesting.newMetricDto;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
+import static org.sonar.server.ui.ws.ComponentAction.PARAM_COMPONENT;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class ComponentActionTest {
@@ -101,6 +103,26 @@ public class ComponentActionTest {
       .setLanguage("xoo");
   }
 
+  @Test
+  public void check_definition() throws Exception {
+    init();
+    WebService.Action action = ws.getDef();
+
+    assertThat(action.since()).isEqualTo("5.2");
+    assertThat(action.isPost()).isFalse();
+    assertThat(action.isInternal()).isTrue();
+    assertThat(action.description()).isNotNull();
+    assertThat(action.responseExample()).isNotNull();
+    assertThat(action.changelog()).isEmpty();
+
+    WebService.Param componentId = action.param(PARAM_COMPONENT);
+    assertThat(componentId.isRequired()).isFalse();
+    assertThat(componentId.description()).isNotNull();
+    assertThat(componentId.exampleValue()).isNotNull();
+    assertThat(componentId.deprecatedKey()).isEqualTo("componentKey");
+    assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4");
+  }
+
   @Test
   public void fail_on_missing_parameters() throws Exception {
     init();