]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9676 Clean component parameters in api/measures/component
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 3 Aug 2017 17:12:44 +0000 (19:12 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 08:55:10 +0000 (10:55 +0200)
- deprecate componentId
- rename componentKey to component
- deprecate id in response

server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
server/sonar-server/src/main/resources/org/sonar/server/measure/ws/component-example.json
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentWsRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java

index 0aff113cd62d66c8190191d4756e7c564cc79b8f..5bcfd73345f5719ae0470f279ebbb43374087439 100644 (file)
@@ -33,6 +33,7 @@ import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -73,9 +74,10 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_METRICS;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
@@ -98,18 +100,23 @@ public class ComponentAction implements MeasuresWsAction {
     WebService.NewAction action = context.createAction(ACTION_COMPONENT)
       .setDescription(format("Return component with specified measures. The %s or the %s parameter must be provided.<br>" +
         "Requires the following permission: 'Browse' on the project of specified component.",
-        PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY))
+        DEPRECATED_PARAM_COMPONENT_ID, PARAM_COMPONENT))
       .setResponseExample(getClass().getResource("component-example.json"))
       .setSince("5.4")
+      .setChangelog(
+        new Change("6.6", "the response field id is deprecated. Use key instead."),
+        new Change("6.6", "the response field refId is deprecated. Use refKey instead."))
       .setHandler(this);
 
-    action.createParam(PARAM_COMPONENT_ID)
-      .setDescription("Component id")
-      .setExampleValue(UUID_EXAMPLE_01);
-
-    action.createParam(PARAM_COMPONENT_KEY)
+    action.createParam(PARAM_COMPONENT)
       .setDescription("Component key")
-      .setExampleValue(KEY_PROJECT_EXAMPLE_001);
+      .setExampleValue(KEY_PROJECT_EXAMPLE_001)
+      .setDeprecatedKey(DEPRECATED_PARAM_COMPONENT_KEY, "6.6");
+
+    action.createParam(DEPRECATED_PARAM_COMPONENT_ID)
+      .setDescription("Component id")
+      .setExampleValue(UUID_EXAMPLE_01)
+      .setDeprecatedSince("6.6");
 
     createMetricKeysParameter(action);
     createAdditionalFieldsParameter(action);
@@ -124,7 +131,7 @@ public class ComponentAction implements MeasuresWsAction {
 
   private ComponentWsResponse doHandle(ComponentWsRequest request) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), COMPONENT_ID_AND_KEY);
+      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponent(), COMPONENT_ID_AND_KEY);
       Long developerId = searchDeveloperId(dbSession, request);
       Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component);
       checkPermissions(component);
@@ -242,8 +249,8 @@ public class ComponentAction implements MeasuresWsAction {
 
   private static ComponentWsRequest toComponentWsRequest(Request request) {
     ComponentWsRequest componentWsRequest = new ComponentWsRequest()
-      .setComponentId(request.param(PARAM_COMPONENT_ID))
-      .setComponentKey(request.param(PARAM_COMPONENT_KEY))
+      .setComponentId(request.param(DEPRECATED_PARAM_COMPONENT_ID))
+      .setComponent(request.param(PARAM_COMPONENT))
       .setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS))
       .setMetricKeys(request.mandatoryParamAsStrings(PARAM_METRIC_KEYS))
       .setDeveloperId(request.param(PARAM_DEVELOPER_ID))
index 8e7080ce4a44fd392bbc5aaa7e0e2eca1d6936c1..dbac846a7e7f084793956136d95f4d721ab6c12e 100644 (file)
@@ -1,6 +1,5 @@
 {
   "component": {
-    "id": "AVIwDXE-bJbJqrw6wFv5",
     "key": "MY_PROJECT:ElementImpl.java",
     "name": "ElementImpl.java",
     "qualifier": "FIL",
index 53f6bc7c87e7406131597b6fabd69269e2e8f5ef..0e7ba8748a3908d860c9e2445760ee9baf9275ee 100644 (file)
  */
 package org.sonar.server.measure.ws;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.measures.Metric.ValueType;
-import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
+import org.sonar.api.web.UserRole;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotTesting;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.server.component.TestComponentFinder;
+import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.Common;
+import org.sonarqube.ws.Common;
+import org.sonarqube.ws.WsMeasures;
+import org.sonarqube.ws.WsMeasures.Component;
 import org.sonarqube.ws.WsMeasures.ComponentWsResponse;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
-import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
-import static org.sonar.db.metric.MetricTesting.newMetricDto;
 import static org.sonar.test.JsonAssert.assertJson;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;
 
 public class ComponentActionTest {
-  private static final String PROJECT_UUID = "project-uuid";
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
@@ -72,16 +64,7 @@ public class ComponentActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private ComponentDbTester componentDb = new ComponentDbTester(db);
-  private DbClient dbClient = db.getDbClient();
-  private final DbSession dbSession = db.getSession();
-
-  private WsActionTester ws = new WsActionTester(new ComponentAction(dbClient, TestComponentFinder.from(db), userSession));
-
-  @Before
-  public void setUp() {
-    userSession.logIn().setRoot();
-  }
+  private WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession));
 
   @Test
   public void definition() {
@@ -89,45 +72,34 @@ public class ComponentActionTest {
 
     assertThat(def.since()).isEqualTo("5.4");
     assertThat(def.params()).extracting(Param::key)
-      .containsExactlyInAnyOrder("componentId", "componentKey", "metricKeys", "additionalFields", "developerId", "developerKey");
+      .containsExactlyInAnyOrder("componentId", "component", "metricKeys", "additionalFields", "developerId", "developerKey");
     assertThat(def.param("developerId").deprecatedSince()).isEqualTo("6.4");
     assertThat(def.param("developerKey").deprecatedSince()).isEqualTo("6.4");
-  }
-
-  @Test
-  public void json_example() {
-    insertJsonExampleData();
-
-    String response = ws.newRequest()
-      .setParam(PARAM_COMPONENT_ID, "AVIwDXE-bJbJqrw6wFv5")
-      .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
-      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods")
-      .execute()
-      .getInput();
-
-    assertJson(response).isSimilarTo(getClass().getResource("component-example.json"));
+    assertThat(def.param("componentId").deprecatedSince()).isEqualTo("6.6");
   }
 
   @Test
   public void provided_project() {
-    ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
-    userSession.addProjectPermission(USER, project);
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
     insertNclocMetric();
 
-    ComponentWsResponse response = newRequest(PROJECT_UUID, "ncloc");
+    ComponentWsResponse response = newRequest(project.getKey(), "ncloc");
 
     assertThat(response.getMetrics().getMetricsCount()).isEqualTo(1);
     assertThat(response.getPeriods().getPeriodsCount()).isEqualTo(0);
-    assertThat(response.getComponent().getId()).isEqualTo(PROJECT_UUID);
+    assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
   }
 
   @Test
   public void without_additional_fields() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    db.components().insertSnapshot(project);
     insertNclocMetric();
 
     String response = ws.newRequest()
-      .setParam(PARAM_COMPONENT_ID, "project-uuid")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .execute().getInput();
 
@@ -138,31 +110,73 @@ public class ComponentActionTest {
 
   @Test
   public void reference_uuid_in_the_response() {
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid").setDbKey("project-key");
-    componentDb.insertProjectAndSnapshot(project);
-    ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
-    componentDb.insertViewAndSnapshot(view);
-    componentDb.insertComponent(newProjectCopy("project-uuid-copy", project, view));
+    userSession.logIn().setRoot();
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto view = db.components().insertView();
+    db.components().insertSnapshot(view);
+    ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", project, view));
+    insertNclocMetric();
+
+    ComponentWsResponse response = newRequest(projectCopy.getKey(), "ncloc");
+
+    assertThat(response.getComponent().getRefId()).isEqualTo(project.uuid());
+    assertThat(response.getComponent().getRefKey()).isEqualTo(project.getKey());
+  }
+
+  @Test
+  public void return_deprecated_id_in_the_response() {
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    db.components().insertSnapshot(project);
+    insertNclocMetric();
+
+    ComponentWsResponse response = newRequest(project.getKey(), "ncloc");
+
+    assertThat(response.getComponent().getId()).isEqualTo(project.uuid());
+  }
+
+  @Test
+  public void use_deprecated_component_id_parameter() {
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    userSession.addProjectPermission(USER, project);
+    insertNclocMetric();
+
+    ComponentWsResponse response = ws.newRequest()
+      .setParam("componentId", project.uuid())
+      .setParam(PARAM_METRIC_KEYS, "ncloc")
+      .executeProtobuf(ComponentWsResponse.class);
+
+    assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
+  }
+
+  @Test
+  public void use_deprecated_component_key_parameter() {
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    userSession.addProjectPermission(USER, project);
     insertNclocMetric();
 
-    ComponentWsResponse response = newRequest("project-uuid-copy", "ncloc");
+    ComponentWsResponse response = ws.newRequest()
+      .setParam("componentKey", project.getKey())
+      .setParam(PARAM_METRIC_KEYS, "ncloc")
+      .executeProtobuf(ComponentWsResponse.class);
 
-    assertThat(response.getComponent().getId()).isEqualTo("project-uuid-copy");
-    assertThat(response.getComponent().getRefId()).isEqualTo("project-uuid");
-    assertThat(response.getComponent().getRefKey()).isEqualTo("project-key");
+    assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
   }
 
   @Test
   public void metric_without_a_domain() {
     ComponentDto project = db.components().insertPrivateProject();
-    SnapshotDto analysis = db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project));
+    logAsUser(project);
+    SnapshotDto analysis = db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(project));
     MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m
-      .setValueType(ValueType.INT.name())
+      .setValueType(Measure.ValueType.INT.name())
       .setDomain(null));
     db.measures().insertMeasure(project, analysis, metricWithoutDomain);
 
     ComponentWsResponse response = ws.newRequest()
-      .setParam(PARAM_COMPONENT_KEY, project.getKey())
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, metricWithoutDomain.getKey())
       .setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
       .executeProtobuf(ComponentWsResponse.class);
@@ -175,49 +189,57 @@ public class ComponentActionTest {
 
   @Test
   public void fail_when_developer_is_not_found() {
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("Component id 'unknown-developer-id' not found");
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    db.components().insertSnapshot(project);
 
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
     insertNclocMetric();
 
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage("Component id 'unknown-developer-id' not found");
+
     ws.newRequest()
-      .setParam(PARAM_COMPONENT_ID, PROJECT_UUID)
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .setParam(PARAM_DEVELOPER_ID, "unknown-developer-id").executeProtobuf(ComponentWsResponse.class);
   }
 
   @Test
   public void fail_when_a_metric_is_not_found() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID));
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    db.components().insertSnapshot(project);
     insertNclocMetric();
     insertComplexityMetric();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("The following metric keys are not found: unknown-metric, another-unknown-metric");
 
-    newRequest(PROJECT_UUID, "ncloc, complexity, unknown-metric, another-unknown-metric");
+    newRequest(project.getKey(), "ncloc, complexity, unknown-metric, another-unknown-metric");
   }
 
   @Test
   public void fail_when_empty_metric_keys_parameter() {
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    db.components().insertSnapshot(project);
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("At least one metric key must be provided");
 
-    newRequest(PROJECT_UUID, "");
+    newRequest(project.getKey(), "");
   }
 
   @Test
   public void fail_when_not_enough_permission() {
     userSession.logIn();
-    componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID));
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(project);
     insertNclocMetric();
 
     expectedException.expect(ForbiddenException.class);
 
-    newRequest(PROJECT_UUID, "ncloc");
+    newRequest(project.getKey(), "ncloc");
   }
 
   @Test
@@ -228,45 +250,76 @@ public class ComponentActionTest {
     expectedException.expectMessage("Component key 'project-key' not found");
 
     ws.newRequest()
-      .setParam(PARAM_COMPONENT_KEY, "project-key")
+      .setParam(PARAM_COMPONENT, "project-key")
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .execute();
   }
 
   @Test
   public void fail_when_component_is_removed() {
-    ComponentDto project = componentDb.insertComponent(newPrivateProjectDto(db.getDefaultOrganization()));
-    componentDb.insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false));
+    ComponentDto project = db.components().insertPrivateProject(p -> p.setEnabled(false));
+    logAsUser(project);
     userSession.addProjectPermission(USER, project);
     insertNclocMetric();
 
     expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("Component key 'file-key' not found");
+    expectedException.expectMessage(String.format("Component key '%s' not found", project.getKey()));
 
     ws.newRequest()
-      .setParam(PARAM_COMPONENT_KEY, "file-key")
+      .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc")
       .execute();
   }
 
-  private ComponentWsResponse newRequest(String componentUuid, String metricKeys) {
-    return ws.newRequest()
-      .setParam(PARAM_COMPONENT_ID, componentUuid)
-      .setParam(PARAM_METRIC_KEYS, metricKeys)
-      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods").executeProtobuf(ComponentWsResponse.class);
+  @Test
+  public void json_example() {
+    ComponentDto project = db.components().insertPrivateProject();
+    logAsUser(project);
+    SnapshotDto analysis = db.components().insertSnapshot(project,
+      s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
+        .setPeriodMode("previous_version")
+        .setPeriodParam("1.0-SNAPSHOT"));
+    ComponentDto file = db.components().insertComponent(newFileDto(project)
+      .setDbKey("MY_PROJECT:ElementImpl.java")
+      .setName("ElementImpl.java")
+      .setLanguage("java")
+      .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
+    MetricDto complexity = insertComplexityMetric();
+    db.measures().insertMeasure(file, analysis, complexity,
+      m -> m.setValue(12.0d)
+        .setVariation(2.0d)
+        .setData(null));
+    MetricDto ncloc = insertNclocMetric();
+    db.measures().insertMeasure(file, analysis, ncloc,
+      m -> m.setValue(114.0d)
+        .setVariation(3.0d)
+        .setData(null));
+    MetricDto newViolations = insertNewViolationMetric();
+    db.measures().insertMeasure(file, analysis, newViolations,
+      m -> m.setVariation(25.0d)
+        .setValue(null)
+        .setData(null));
+
+    String response = ws.newRequest()
+      .setParam(PARAM_COMPONENT, file.getKey())
+      .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
+      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods")
+      .execute()
+      .getInput();
+
+    assertJson(response).isSimilarTo(getClass().getResource("component-example.json"));
   }
 
-  private static MetricDto newMetricDtoWithoutOptimization() {
-    return newMetricDto()
-      .setWorstValue(null)
-      .setOptimizedBestValue(false)
-      .setBestValue(null)
-      .setUserManaged(false);
+  private ComponentWsResponse newRequest(String componentKey, String metricKeys) {
+    return ws.newRequest()
+      .setParam(PARAM_COMPONENT, componentKey)
+      .setParam(PARAM_METRIC_KEYS, metricKeys)
+      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods")
+      .executeProtobuf(ComponentWsResponse.class);
   }
 
   private MetricDto insertNclocMetric() {
-    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization()
-      .setKey("ncloc")
+    return db.measures().insertMetric(m -> m.setKey("ncloc")
       .setShortName("Lines of code")
       .setDescription("Non Commenting Lines of Code")
       .setDomain("Size")
@@ -275,13 +328,10 @@ public class ComponentActionTest {
       .setQualitative(false)
       .setHidden(false)
       .setUserManaged(false));
-    db.commit();
-    return metric;
   }
 
   private MetricDto insertComplexityMetric() {
-    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization()
-      .setKey("complexity")
+    return db.measures().insertMetric(m -> m.setKey("complexity")
       .setShortName("Complexity")
       .setDescription("Cyclomatic complexity")
       .setDomain("Complexity")
@@ -290,13 +340,10 @@ public class ComponentActionTest {
       .setQualitative(false)
       .setHidden(false)
       .setUserManaged(false));
-    db.commit();
-    return metric;
   }
 
   private MetricDto insertNewViolationMetric() {
-    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization()
-      .setKey("new_violations")
+    return db.measures().insertMetric(m -> m.setKey("new_violations")
       .setShortName("New issues")
       .setDescription("New Issues")
       .setDomain("Issues")
@@ -305,43 +352,10 @@ public class ComponentActionTest {
       .setQualitative(true)
       .setHidden(false)
       .setUserManaged(false));
-    db.commit();
-    return metric;
   }
 
-  private void insertJsonExampleData() {
-    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
-    SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project)
-      .setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
-      .setPeriodMode("previous_version")
-      .setPeriodParam("1.0-SNAPSHOT");
-    ComponentDto file = newFileDto(project, null)
-      .setUuid("AVIwDXE-bJbJqrw6wFv5")
-      .setDbKey("MY_PROJECT:ElementImpl.java")
-      .setName("ElementImpl.java")
-      .setQualifier(Qualifiers.FILE)
-      .setLanguage("java")
-      .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java");
-    componentDb.insertComponents(project, file);
-    dbClient.snapshotDao().insert(dbSession, projectSnapshot);
-
-    MetricDto complexity = insertComplexityMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(complexity, file, projectSnapshot)
-        .setValue(12.0d)
-        .setVariation(2.0d));
-
-    MetricDto ncloc = insertNclocMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(ncloc, file, projectSnapshot)
-        .setValue(114.0d)
-        .setVariation(3.0d));
-
-    MetricDto newViolations = insertNewViolationMetric();
-    dbClient.measureDao().insert(dbSession,
-      newMeasureDto(newViolations, file, projectSnapshot)
-        .setVariation(25.0d));
-    db.commit();
+  private void logAsUser(ComponentDto project) {
+    userSession.addProjectPermission(UserRole.USER, project);
   }
 
 }
index 4c2fbf2ce2edffc27583ee9fd833c887d117c56a..998ac57209fee0d63d11827013f07b8e5325a759 100644 (file)
@@ -26,31 +26,58 @@ import javax.annotation.Nullable;
 public class ComponentWsRequest {
   private String componentId;
   private String componentKey;
+  private String component;
   private List<String> metricKeys;
   private List<String> additionalFields;
   private String developerId;
   private String developerKey;
 
+  /**
+   * @deprecated since 6.6, please use {@link #getComponent()} instead
+   */
+  @Deprecated
   @CheckForNull
   public String getComponentId() {
     return componentId;
   }
 
+  /**
+   * @deprecated since 6.6, please use {@link #setComponent(String)} instead
+   */
+  @Deprecated
   public ComponentWsRequest setComponentId(@Nullable String componentId) {
     this.componentId = componentId;
     return this;
   }
 
+  /**
+   * @deprecated since 6.6, please use {@link #getComponent()} instead
+   */
+  @Deprecated
   @CheckForNull
   public String getComponentKey() {
     return componentKey;
   }
 
+  /**
+   * @deprecated since 6.6, please use {@link #setComponent(String)} instead
+   */
+  @Deprecated
   public ComponentWsRequest setComponentKey(@Nullable String componentKey) {
     this.componentKey = componentKey;
     return this;
   }
 
+  @CheckForNull
+  public String getComponent() {
+    return component;
+  }
+
+  public ComponentWsRequest setComponent(@Nullable String component) {
+    this.component = component;
+    return this;
+  }
+
   public List<String> getMetricKeys() {
     return metricKeys;
   }
index 470dfa7fa291a0b2bbec3bc258f4f8910edacb8e..f81d8b9a72ba05017a6620454830d4956d7863ac 100644 (file)
@@ -32,13 +32,13 @@ import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPON
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.CONTROLLER_MEASURES;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
-import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY;
 import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM;
@@ -79,8 +79,9 @@ public class MeasuresService extends BaseService {
 
   public ComponentWsResponse component(ComponentWsRequest request) {
     GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT))
-      .setParam(PARAM_COMPONENT_ID, request.getComponentId())
-      .setParam(PARAM_COMPONENT_KEY, request.getComponentKey())
+      .setParam(DEPRECATED_PARAM_COMPONENT_ID, request.getComponentId())
+      .setParam(DEPRECATED_PARAM_COMPONENT_KEY, request.getComponentKey())
+      .setParam(PARAM_COMPONENT, request.getComponent())
       .setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields()))
       .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys()))
       .setParam(PARAM_DEVELOPER_ID, request.getDeveloperId())
index 48599358cc4761c94f4fcfaf40df60c6bce1efcf..70b7c27496d6419415c101e9a0c6c56b459a042a 100644 (file)
@@ -43,8 +43,8 @@ public class MeasuresWsParameters {
   public static final String PARAM_METRIC_PERIOD_SORT = "metricPeriodSort";
   public static final String PARAM_METRIC_SORT_FILTER = "metricSortFilter";
   public static final String PARAM_ADDITIONAL_FIELDS = "additionalFields";
-  public static final String PARAM_COMPONENT_ID = "componentId";
-  public static final String PARAM_COMPONENT_KEY = "componentKey";
+  public static final String DEPRECATED_PARAM_COMPONENT_ID = "componentId";
+  public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey";
   public static final String PARAM_PROJECT_KEYS = "projectKeys";
   public static final String PARAM_DEVELOPER_ID = "developerId";
   public static final String PARAM_DEVELOPER_KEY = "developerKey";