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;
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);
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;
+ }
+ }
}
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;
.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));
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) {
.setTotal(paging.total())
.build();
- if (!components.isEmpty()) {
- response.setProjectId(components.get(0).projectUuid());
- }
for (ComponentDto dto : components) {
response.addComponents(componentDtoToWsComponent(dto));
}
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;
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;
@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);
}
}
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;
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);
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 {
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);
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;
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);
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";
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);
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";
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);
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;
}
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))
"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"
}
]
}
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;
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;
@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)
@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();
}
.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();
+ }
}
@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);
@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);
@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)
@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();
}
@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();