aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-12-22 14:51:49 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-12-22 15:01:58 +0100
commit7f5a8542ce2f3041ad476e91b702ea41815fce0c (patch)
treec5238ddacfb1983a10f7daf4a4538614768ab59e
parent978d830fe9b5c584c8ae0e0d97044498528dd8a9 (diff)
downloadsonarqube-7f5a8542ce2f3041ad476e91b702ea41815fce0c.tar.gz
sonarqube-7f5a8542ce2f3041ad476e91b702ea41815fce0c.zip
SONAR-7129 Apply feedback
- more explicit message when base component parameters are not provided - projectId removed from the response - f parameter removed - better response example
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java28
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java20
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java2
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json226
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java57
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java2
14 files changed, 270 insertions, 100 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
index 6c17563e99c..c8e52e6ef89 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
@@ -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;
+ }
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
index 8a8c4ede070..bf3a35414ee 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java
@@ -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));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
index 3c064d0150b..4dc70dd5db3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
@@ -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);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
index 95fd49fcc89..34ddcf8479e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java
index cb757ebc1d8..7fdc6af4694 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
index 6d28e6923fc..e9fec9d2795 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java
index 3f65691fc2c..d3dca1583b2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java
index efdfe79ad5b..d35f2389293 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java
@@ -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);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java
index 8e36801bed3..3aa6687fa01 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WsParameterBuilder.java
@@ -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))
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json
index e5e4ef1d2f5..2b83387b4f6 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/tree-example.json
@@ -2,89 +2,211 @@
"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"
}
]
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
index 6a979e97558..bdde220e428 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
@@ -20,8 +20,15 @@
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();
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
index 5f261649a37..53e4c95e724 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
index 3e2472abf7e..77b0382d56b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
@@ -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();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
index a8b8aa4c55f..ab923352635 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
@@ -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();