]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7129 Apply feedback
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 22 Dec 2015 13:51:49 +0000 (14:51 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 22 Dec 2015 14:01:58 +0000 (15:01 +0100)
- more explicit message when base component parameters are not provided
- projectId removed from the response
- f parameter removed
- better response example

14 files changed:
server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java
server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java
server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json
server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java

index 6c17563e99cf8a12cac29b20e3d33106e34b9f8d..c8e52e6ef89ea9806788b1168c6a1c9395cc649e 100644 (file)
@@ -37,6 +37,7 @@ import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_
 import static org.sonar.server.ws.WsUtils.checkRequest;
 
 public class ComponentFinder {
+  private static final String MSG_COMPONENT_ID_OR_KEY_TEMPLATE = "Either '%s' or '%s' must be provided, not both";
 
   private final DbClient dbClient;
 
@@ -44,8 +45,8 @@ public class ComponentFinder {
     this.dbClient = dbClient;
   }
 
-  public ComponentDto getByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey) {
-    checkArgument(componentUuid != null ^ componentKey != null, "Either 'componentKey' or 'componentId' must be provided, not both");
+  public ComponentDto getByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey, ParamNames parameterNames) {
+    checkArgument(componentUuid != null ^ componentKey != null, MSG_COMPONENT_ID_OR_KEY_TEMPLATE, parameterNames.getUuidParam(), parameterNames.getKeyParam());
 
     if (componentUuid != null) {
       return getByUuid(dbSession, componentUuid);
@@ -97,4 +98,27 @@ public class ComponentFinder {
     checkRequest(rootQualifiers.contains(qualifier) || Qualifiers.MODULE.equals(qualifier),
       format("Component '%s' (id: %s) must be a project or a module.", component.key(), component.uuid()));
   }
+
+  public enum ParamNames {
+    PROJECT_ID_AND_KEY("projectId", "projectKey"),
+    UUID_AND_KEY("uuid", "key"),
+    ID_AND_KEY("id", "key"),
+    BASE_COMPONENT_ID_AND_KEY("baseComponentId", "baseComponentKey");
+
+    private final String uuidParamName;
+    private final String keyParamName;
+
+    ParamNames(String uuidParamName, String keyParamName) {
+      this.uuidParamName = uuidParamName;
+      this.keyParamName = keyParamName;
+    }
+
+    public String getUuidParam() {
+      return uuidParamName;
+    }
+
+    public String getKeyParam() {
+      return keyParamName;
+    }
+  }
 }
index 8a8c4ede070a3d6b5d849b33411ac986a88772c1..bf3a35414ee2a8837766bc0f2de210592baa5843 100644 (file)
@@ -48,6 +48,7 @@ import static com.google.common.base.Objects.firstNonNull;
 import static com.google.common.collect.Sets.newHashSet;
 import static java.lang.String.format;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
+import static org.sonar.server.component.ComponentFinder.ParamNames.BASE_COMPONENT_ID_AND_KEY;
 import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
 import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
 import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
@@ -101,11 +102,11 @@ public class TreeAction implements ComponentsWsAction {
       .addPagingParams(100, MAX_SIZE);
 
     action.createParam(PARAM_BASE_COMPONENT_ID)
-      .setDescription("base component id. The search is based on this component. It is not included in the response.")
+      .setDescription("Base component id. The search is based on this component. It is not included in the response.")
       .setExampleValue(UUID_EXAMPLE_02);
 
     action.createParam(PARAM_BASE_COMPONENT_KEY)
-      .setDescription("base component key.The search is based on this component. It is not included in the response.")
+      .setDescription("Base component key.The search is based on this component. It is not included in the response.")
       .setExampleValue("org.apache.hbas:hbase");
 
     createQualifiersParameter(action, newQualifierParameterContext(userSession, i18n, resourceTypes));
@@ -130,7 +131,7 @@ public class TreeAction implements ComponentsWsAction {
   private TreeWsResponse doHandle(TreeWsRequest treeWsRequest) {
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, treeWsRequest.getBaseComponentId(), treeWsRequest.getBaseComponentKey());
+      ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, treeWsRequest.getBaseComponentId(), treeWsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY);
       checkPermissions(baseComponent);
       SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, baseComponent.getId());
       if (baseSnapshot == null) {
@@ -178,9 +179,6 @@ public class TreeAction implements ComponentsWsAction {
       .setTotal(paging.total())
       .build();
 
-    if (!components.isEmpty()) {
-      response.setProjectId(components.get(0).projectUuid());
-    }
     for (ComponentDto dto : components) {
       response.addComponents(componentDtoToWsComponent(dto));
     }
index 3c064d0150b3e975478ea7941f1e5387044aa179..4dc70dd5db3efe9499fadde0d5c73b974790e3eb 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.server.duplication.ws;
 
-import com.google.common.base.Preconditions;
 import com.google.common.io.Resources;
 import java.util.List;
 import javax.annotation.CheckForNull;
@@ -33,13 +32,14 @@ import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.measure.MeasureDao;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.user.UserSession;
 
+import static org.sonar.server.component.ComponentFinder.ParamNames.UUID_AND_KEY;
+
 public class ShowAction implements RequestHandler {
 
   private final DbClient dbClient;
@@ -79,22 +79,18 @@ public class ShowAction implements RequestHandler {
 
   @Override
   public void handle(Request request, Response response) {
-    String fileKey = request.param("key");
-    String fileUuid = request.param("uuid");
-    Preconditions.checkArgument(fileKey != null || fileUuid != null, "At least one of 'key' or 'uuid' must be provided");
-
-    DbSession session = dbClient.openSession(false);
+    DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto component = componentFinder.getByUuidOrKey(session, fileUuid, fileKey);
+      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param("uuid"), request.param("key"), UUID_AND_KEY);
       String componentKey = component.key();
       userSession.checkComponentPermission(UserRole.CODEVIEWER, componentKey);
       JsonWriter json = response.newJsonWriter().beginObject();
-      String duplications = findDataFromComponent(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY, session);
-      List<DuplicationsParser.Block> blocks = parser.parse(component, duplications, session);
-      duplicationsJsonWriter.write(blocks, json, session);
+      String duplications = findDataFromComponent(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY, dbSession);
+      List<DuplicationsParser.Block> blocks = parser.parse(component, duplications, dbSession);
+      duplicationsJsonWriter.write(blocks, json, dbSession);
       json.endObject().close();
     } finally {
-      MyBatis.closeQuietly(session);
+      dbClient.closeSession(dbSession);
     }
   }
 
index 95fd49fcc89ff962368d25fad759583981eae4eb..34ddcf8479e2cda7a2bc7eaf03444390d80ffed2 100644 (file)
@@ -39,6 +39,7 @@ import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
 import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions;
 import static org.sonar.server.measure.custom.ws.CustomMeasureValueDescription.measureValueDescription;
 
@@ -114,7 +115,7 @@ public class CreateAction implements CustomMeasuresWsAction {
     long now = system.now();
 
     try {
-      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
+      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
       MetricDto metric = searchMetric(dbSession, request);
       checkPermissions(userSession, component);
       checkIsProjectOrModule(component);
index cb757ebc1d88ec02126eac9419ef73e5edc54a5d..7fdc6af46941ba05f911d39e5aa82c3252a3eb4d 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.metric.ws.MetricJsonWriter;
 import org.sonar.server.user.UserSession;
 
+import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
 import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions;
 
 public class MetricsAction implements CustomMeasuresWsAction {
@@ -77,7 +78,7 @@ public class MetricsAction implements CustomMeasuresWsAction {
     DbSession dbSession = dbClient.openSession(false);
 
     try {
-      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
       checkPermissions(userSession, project);
       List<MetricDto> metrics = searchMetrics(dbSession, project);
 
index 6d28e6923fc16279d16e120044a8477903d0aed5..e9fec9d279593316b4302f4b9ee0618cb428c563 100644 (file)
@@ -47,6 +47,7 @@ import org.sonar.server.user.UserSession;
 import org.sonar.server.user.index.UserIndex;
 
 import static com.google.common.collect.Sets.newHashSet;
+import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
 import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
 import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions;
 
@@ -101,7 +102,7 @@ public class SearchAction implements CustomMeasuresWsAction {
 
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey);
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY);
       checkPermissions(userSession, project);
       Long lastAnalysisDateMs = searchLastSnapshot(dbSession, project);
       List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, project, searchOptions);
index 3f65691fc2c7dc80185be9730d72c69855b8fea7..d3dca1583b2abbc5c5a5bdcfd852dc1289a5a90c 100644 (file)
@@ -35,6 +35,8 @@ import org.sonar.server.component.ComponentCleanerService;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.user.UserSession;
 
+import static org.sonar.server.component.ComponentFinder.ParamNames.ID_AND_KEY;
+
 public class DeleteAction implements ProjectsWsAction {
   private static final String ACTION = "delete";
 
@@ -81,7 +83,7 @@ public class DeleteAction implements ProjectsWsAction {
 
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, uuid, key);
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, uuid, key, ID_AND_KEY);
       componentCleanerService.delete(dbSession, Arrays.asList(project));
     } finally {
       MyBatis.closeQuietly(dbSession);
index efdfe79ad5b01c8ced0b3a6cb31ce3fb738e04e1..d35f2389293b8c650e8b1a26bf64d1fd9c4ce15d 100644 (file)
@@ -39,6 +39,8 @@ import org.sonar.server.source.HtmlSourceDecorator;
 import org.sonar.server.source.SourceService;
 import org.sonar.server.user.UserSession;
 
+import static org.sonar.server.component.ComponentFinder.ParamNames.UUID_AND_KEY;
+
 public class LinesAction implements SourcesWsAction {
 
   private static final String PARAM_UUID = "uuid";
@@ -112,7 +114,7 @@ public class LinesAction implements SourcesWsAction {
   public void handle(Request request, Response response) {
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto file = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_UUID), request.param(PARAM_KEY));
+      ComponentDto file = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_UUID), request.param(PARAM_KEY), UUID_AND_KEY);
       userSession.checkProjectUuidPermission(UserRole.CODEVIEWER, file.projectUuid());
 
       int from = request.mandatoryParamAsInt(PARAM_FROM);
index 8e36801bed31b608e5ce4058e14b818ae2ea38f3..3aa6687fa0148ff622d07c1bf3623fcf2f320ae9 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.server.ws;
 
-import java.util.Collections;
 import java.util.Set;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.resources.ResourceTypes;
@@ -47,7 +46,6 @@ public class WsParameterBuilder {
   }
 
   public static WebService.NewParam createQualifiersParameter(WebService.NewAction action, QualifierParameterContext context) {
-    action.addFieldsParam(Collections.emptyList());
     return action.createParam(PARAM_QUALIFIERS)
       .setDescription(
         "Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are:" + buildAllQualifiersDescription(context))
index e5e4ef1d2f51017d5d8cf70dd0a3e9d8514652ca..2b83387b4f62cc5fea47e50f8603e1f13dfb4a30 100644 (file)
   "paging": {
     "pageIndex": 1,
     "pageSize": 100,
-    "total": 10
+    "total": 29
   },
-  "projectId": "project-id",
   "components": [
     {
-      "id": "file-id-1",
-      "key": "file-key-1",
-      "name": "file-name-1",
-      "description": "description 1",
+      "id": "AVHE6Jo2EplJjXTo0Rzw",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParser.java",
+      "name": "BasicMarkdownParser.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/BasicMarkdownParser.java"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rzx",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParserTest.java",
+      "name": "BasicMarkdownParserTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/BasicMarkdownParserTest.java"
+    },
+    {
+      "id": "AVHE6Jo1EplJjXTo0Rzf",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/Element.java",
+      "name": "Element.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-1"
+      "path": "src/main/java/com/sonarsource/markdown/Element.java"
     },
     {
-      "id": "file-id-10",
-      "key": "file-key-10",
-      "name": "file-name-10",
-      "description": "description 10",
+      "id": "AVHE6Jo2EplJjXTo0Rzk",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java",
+      "name": "ElementImpl.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-10"
+      "path": "src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz0",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java",
+      "name": "ElementImplTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"
     },
     {
-      "id": "file-id-2",
-      "key": "file-key-2",
-      "name": "file-name-2",
-      "description": "description 2",
+      "id": "AVHE6Jo1EplJjXTo0Rzg",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/ElementType.java",
+      "name": "ElementType.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-2"
+      "path": "src/main/java/com/sonarsource/markdown/ElementType.java"
     },
     {
-      "id": "file-id-3",
-      "key": "file-key-3",
-      "name": "file-name-3",
-      "description": "description 3",
+      "id": "AVHE6Jo1EplJjXTo0Rzh",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/GrammarDefinition.java",
+      "name": "GrammarDefinition.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-3"
+      "path": "src/main/java/com/sonarsource/markdown/GrammarDefinition.java"
     },
     {
-      "id": "file-id-4",
-      "key": "file-key-4",
-      "name": "file-name-4",
-      "description": "description 4",
+      "id": "AVHE6Jo3EplJjXTo0Rzy",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/GrammarDefinitionTest.java",
+      "name": "GrammarDefinitionTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/GrammarDefinitionTest.java"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz5",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/sq/HtmlDecoratorTest.java",
+      "name": "HtmlDecoratorTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/sq/HtmlDecoratorTest.java"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzt",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/sq/HtmlGenerator.java",
+      "name": "HtmlGenerator.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-4"
+      "path": "src/main/java/com/sonarsource/markdown/sq/HtmlGenerator.java"
     },
     {
-      "id": "file-id-5",
-      "key": "file-key-5",
-      "name": "file-name-5",
-      "description": "description 5",
+      "id": "AVHE6Jo2EplJjXTo0Rzo",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/mark/Mark.java",
+      "name": "Mark.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-5"
+      "path": "src/main/java/com/sonarsource/markdown/mark/Mark.java"
     },
     {
-      "id": "file-id-6",
-      "key": "file-key-6",
-      "name": "file-name-6",
-      "description": "description 6",
+      "id": "AVHE6Jo2EplJjXTo0Rzp",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/mark/MarkHighlighter.java",
+      "name": "MarkHighlighter.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-6"
+      "path": "src/main/java/com/sonarsource/markdown/mark/MarkHighlighter.java"
     },
     {
-      "id": "file-id-7",
-      "key": "file-key-7",
-      "name": "file-name-7",
-      "description": "description 7",
+      "id": "AVHE6Jo3EplJjXTo0Rz3",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/mark/MarkHighlighterTest.java",
+      "name": "MarkHighlighterTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/mark/MarkHighlighterTest.java"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzq",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/mark/MarkType.java",
+      "name": "MarkType.java",
+      "qualifier": "FIL",
+      "path": "src/main/java/com/sonarsource/markdown/mark/MarkType.java"
+    },
+    {
+      "id": "AVHE6Jo1EplJjXTo0Rzi",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/Parser.java",
+      "name": "Parser.java",
+      "qualifier": "FIL",
+      "path": "src/main/java/com/sonarsource/markdown/Parser.java"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzr",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/mark/RegexMarker.java",
+      "name": "RegexMarker.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-7"
+      "path": "src/main/java/com/sonarsource/markdown/mark/RegexMarker.java"
     },
     {
-      "id": "file-id-8",
-      "key": "file-key-8",
-      "name": "file-name-8",
-      "description": "description 8",
+      "id": "AVHE6Jo2EplJjXTo0Rzl",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java",
+      "name": "Rule.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-8"
+      "path": "src/main/java/com/sonarsource/markdown/impl/Rule.java"
     },
     {
-      "id": "file-id-9",
-      "key": "file-key-9",
-      "name": "file-name-9",
-      "description": "description 9",
+      "id": "AVHE6Jo2EplJjXTo0Rzm",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/RuleBuilder.java",
+      "name": "RuleBuilder.java",
       "qualifier": "FIL",
-      "path": "path/to/file-name-9"
+      "path": "src/main/java/com/sonarsource/markdown/impl/RuleBuilder.java"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz1",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/RuleBuilderTest.java",
+      "name": "RuleBuilderTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/impl/RuleBuilderTest.java"
+    },
+    {
+      "id": "AVHE6Jo1EplJjXTo0Rzj",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown",
+      "name": "src/main/java/com/sonarsource/markdown",
+      "qualifier": "DIR",
+      "path": "src/main/java/com/sonarsource/markdown"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzn",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl",
+      "name": "src/main/java/com/sonarsource/markdown/impl",
+      "qualifier": "DIR",
+      "path": "src/main/java/com/sonarsource/markdown/impl"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzs",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/mark",
+      "name": "src/main/java/com/sonarsource/markdown/mark",
+      "qualifier": "DIR",
+      "path": "src/main/java/com/sonarsource/markdown/mark"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzv",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/sq",
+      "name": "src/main/java/com/sonarsource/markdown/sq",
+      "qualifier": "DIR",
+      "path": "src/main/java/com/sonarsource/markdown/sq"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rzz",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown",
+      "name": "src/test/java/com/sonarsource/markdown",
+      "qualifier": "DIR",
+      "path": "src/test/java/com/sonarsource/markdown"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz2",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl",
+      "name": "src/test/java/com/sonarsource/markdown/impl",
+      "qualifier": "DIR",
+      "path": "src/test/java/com/sonarsource/markdown/impl"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz4",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/mark",
+      "name": "src/test/java/com/sonarsource/markdown/mark",
+      "qualifier": "DIR",
+      "path": "src/test/java/com/sonarsource/markdown/mark"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz7",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/sq",
+      "name": "src/test/java/com/sonarsource/markdown/sq",
+      "qualifier": "DIR",
+      "path": "src/test/java/com/sonarsource/markdown/sq"
+    },
+    {
+      "id": "AVHE6Jo2EplJjXTo0Rzu",
+      "key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/sq/WikiParser.java",
+      "name": "WikiParser.java",
+      "qualifier": "FIL",
+      "path": "src/main/java/com/sonarsource/markdown/sq/WikiParser.java"
+    },
+    {
+      "id": "AVHE6Jo3EplJjXTo0Rz6",
+      "key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/sq/WikiParserTest.java",
+      "name": "WikiParserTest.java",
+      "qualifier": "UTS",
+      "path": "src/test/java/com/sonarsource/markdown/sq/WikiParserTest.java"
     }
   ]
 }
index 6a979e975587d092fa47cddbb4802a7f50bab23b..bdde220e428bc3eb90aa25db13fa14fd6b64b793 100644 (file)
 
 package org.sonar.server.component.ws;
 
+import com.google.common.base.Charsets;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Date;
+import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -31,7 +38,6 @@ import org.mockito.Mockito;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.permission.GlobalPermissions;
@@ -88,23 +94,10 @@ public class TreeActionTest {
 
   @Test
   public void json_example() throws IOException {
-    ComponentDto project = newProjectDto("project-id");
-    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
-    for (int i = 1; i <= 10; i++) {
-      componentDb.insertComponentAndSnapshot(ComponentTesting.newFileDto(project, "file-id-" + i)
-        .setKey("file-key-" + i)
-        .setName("file-name-" + i)
-        .setPath("path/to/file-name-" + i)
-        .setProjectUuid("project-id")
-        .setDescription("description " + i)
-        .setCreatedAt(DateUtils.parseDateTime("2015-12-17T22:07:14+0100")),
-        projectSnapshot);
-    }
-    db.commit();
-    componentDb.indexProjects();
+    ComponentDto project = initJsonExampleComponents();
 
     String response = ws.newRequest()
-      .setParam(PARAM_BASE_COMPONENT_ID, "project-id")
+      .setParam(PARAM_BASE_COMPONENT_ID, project.uuid())
       .execute().getInput();
 
     JsonAssert.assertJson(response)
@@ -346,6 +339,7 @@ public class TreeActionTest {
   @Test
   public void fail_when_no_base_component_parameter() {
     expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("Either 'baseComponentId' or 'baseComponentKey' must be provided, not both");
 
     ws.newRequest().execute();
   }
@@ -356,4 +350,35 @@ public class TreeActionTest {
       .setKey("file-key-" + i)
       .setPath("file-path-" + i);
   }
+
+  private ComponentDto initJsonExampleComponents() throws IOException {
+    ComponentDto project = newProjectDto("AVHE6JiwEplJjXTo0Rza");
+    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
+    Date now = new Date();
+    JsonParser jsonParser = new JsonParser();
+    JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), Charsets.UTF_8));
+    JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components");
+    for (JsonElement componentAsJsonElement : components) {
+      JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject();
+      componentDb.insertComponentAndSnapshot(new ComponentDto()
+          .setUuid(getJsonField(componentAsJsonObject, "id"))
+          .setKey(getJsonField(componentAsJsonObject, "key"))
+          .setName(getJsonField(componentAsJsonObject, "name"))
+          .setPath(getJsonField(componentAsJsonObject, "path"))
+          .setProjectUuid(project.projectUuid())
+          .setQualifier(getJsonField(componentAsJsonObject, "qualifier"))
+          .setDescription(getJsonField(componentAsJsonObject, "description"))
+          .setEnabled(true)
+          .setCreatedAt(now),
+        projectSnapshot);
+    }
+    db.commit();
+    componentDb.indexProjects();
+    return project;
+  }
+
+  private static String getJsonField(JsonObject jsonObject, String field) {
+    JsonElement jsonElement = jsonObject.get(field);
+    return jsonElement == null ? null : jsonElement.getAsString();
+  }
 }
index 5f261649a37c3d22368c7c0dc18fae25258166f2..53e4c95e72403a5ff6a393724c50ee99db3769ad 100644 (file)
@@ -335,7 +335,7 @@ public class CreateActionTest {
   @Test
   public void fail_when_project_id_nor_project_key_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Either 'componentKey' or 'componentId' must be provided, not both");
+    expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
     insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
@@ -348,7 +348,7 @@ public class CreateActionTest {
   @Test
   public void fail_when_project_id_and_project_key_are_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Either 'componentKey' or 'componentId' must be provided, not both");
+    expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
     insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
index 3e2472abf7e710f1bbb63c43ca04f05da3524911..77b0382d56b491be5f6bb1054168c03f56506f2a 100644 (file)
@@ -243,7 +243,7 @@ public class SearchActionTest {
   @Test
   public void fail_when_project_id_and_project_key_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Either 'componentKey' or 'componentId' must be provided, not both");
+    expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
 
     newRequest()
       .setParam(SearchAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
@@ -254,7 +254,7 @@ public class SearchActionTest {
   @Test
   public void fail_when_project_id_nor_project_key_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Either 'componentKey' or 'componentId' must be provided, not both");
+    expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
     newRequest().execute();
   }
 
index a8b8aa4c55fcd8b1a49a78dcdca5c61c8d0342b7..ab923352635a288035539b0a98919a5576136ea6 100644 (file)
@@ -140,7 +140,7 @@ public class LinesActionTest {
   @Test
   public void fail_when_no_uuid_or_key_param() throws Exception {
     thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Either 'componentKey' or 'componentId' must be provided, not both");
+    thrown.expectMessage("Either 'uuid' or 'key' must be provided, not both");
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/sources", "lines");
     request.execute();