import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
public class AppAction implements ComponentsWsAction {
- private static final String PARAM_COMPONENT_ID = "componentId";
- private static final String PARAM_COMPONENT = "component";
+ static final String PARAM_COMPONENT = "component";
private final DbClient dbClient;
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("app")
.setDescription("Coverage data required for rendering the component viewer.<br>" +
+ "Either branch or pull request can be provided, not both<br>" +
"Requires the following permission: 'Browse'.")
.setResponseExample(getClass().getResource("app-example.json"))
.setSince("4.4")
.setInternal(true)
.setHandler(this);
- action
- .createParam(PARAM_COMPONENT_ID)
- .setDescription("Component ID")
- .setDeprecatedSince("6.4")
- .setDeprecatedKey("uuid", "6.4")
- .setExampleValue(UUID_EXAMPLE_01);
-
action.createParam(PARAM_COMPONENT)
.setDescription("Component key")
.setExampleValue(KEY_PROJECT_EXAMPLE_001)
+ .setRequired(true)
.setSince("6.4");
action.createParam(PARAM_BRANCH)
try (DbSession session = dbClient.openSession(false)) {
ComponentDto component = loadComponent(session, request);
userSession.checkComponentPermission(UserRole.USER, component);
-
- JsonWriter json = response.newJsonWriter();
- json.beginObject();
- componentViewerJsonWriter.writeComponent(json, component, userSession, session);
- appendPermissions(json, userSession);
- componentViewerJsonWriter.writeMeasures(json, component, session);
- json.endObject();
- json.close();
+ writeJsonResponse(response, session, component);
}
}
private ComponentDto loadComponent(DbSession dbSession, Request request) {
- String componentUuid = request.param(PARAM_COMPONENT_ID);
String branch = request.param(PARAM_BRANCH);
String pullRequest = request.param(PARAM_PULL_REQUEST);
- checkArgument(componentUuid == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID,
- PARAM_BRANCH, PARAM_PULL_REQUEST);
- if (branch == null && pullRequest == null) {
- return componentFinder.getByUuidOrKey(dbSession, componentUuid, request.param(PARAM_COMPONENT), COMPONENT_ID_AND_COMPONENT);
+ String componentKey = request.mandatoryParam(PARAM_COMPONENT);
+
+ return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
+ }
+
+ private void writeJsonResponse(Response response, DbSession session, ComponentDto component) {
+ try (JsonWriter json = response.newJsonWriter()) {
+ json.beginObject();
+ componentViewerJsonWriter.writeComponent(json, component, userSession, session);
+ appendPermissions(json, userSession);
+ componentViewerJsonWriter.writeMeasures(json, component, session);
+ json.endObject();
}
- return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, request.mandatoryParam(PARAM_COMPONENT), branch, pullRequest);
}
private static void appendPermissions(JsonWriter json, UserSession userSession) {
private static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, Optional<SnapshotDto> lastAnalysis) {
Components.Component.Builder wsComponent = Components.Component.newBuilder()
.setOrganization(organizationDtoKey)
- .setId(dto.uuid())
.setKey(dto.getKey())
.setName(dto.name())
.setQualifier(dto.qualifier());
.setSince("6.3")
.setDescription("Search for components")
.addPagingParams(100, MAX_LIMIT)
- .setChangelog(new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)))
+ .setChangelog(
+ new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)),
+ new Change("8.0", "Field 'id' from response has been removed")
+ )
.setResponseExample(getClass().getResource("search-components-example.json"))
.setHandler(this);
Components.Component.Builder builder = Components.Component.newBuilder()
.setOrganization(organization.getKey())
- .setId(dto.uuid())
.setKey(dto.getDbKey())
.setProject(projectKey)
.setName(dto.name())
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SEARCH_PROJECTS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS;
.setDescription("Search for projects")
.addPagingParams(DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE)
.setInternal(true)
- .setResponseExample(getClass().getResource("search_projects-example.json"))
.setChangelog(
- new Change("6.4", format("The '%s' parameter accepts '%s' to filter by language", FILTER_LANGUAGES, PARAM_FILTER)),
- new Change("6.4", "The 'visibility' field is added"),
- new Change("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"),
- new Change("6.5", "Added the option 'analysisDate' for the 'sort' parameter"),
- new Change("6.5", format("Value '%s' is added to parameter '%s'", LEAK_PERIOD_DATE, FIELDS)))
+ new Change("8.0", "Field 'id' from response has been removed")
+ )
+ .setResponseExample(getClass().getResource("search_projects-example.json"))
.setHandler(this);
action.createFieldsParam(POSSIBLE_FIELDS)
wsComponent
.clear()
.setOrganization(organizationDto.getKey())
- .setId(dbComponent.uuid())
.setKey(dbComponent.getDbKey())
.setName(dbComponent.name())
.setVisibility(Visibility.getLabel(dbComponent.isPrivate()));
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Components.ShowWsResponse;
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.lang.String.format;
-import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
-import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
public class ShowAction implements ComponentsWsAction {
private final UserSession userSession;
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_SHOW)
- .setDescription(format("Returns a component (file, directory, project, view…) and its ancestors. " +
+ .setDescription("Returns a component (file, directory, project, portfolio…) and its ancestors. " +
"The ancestors are ordered from the parent to the root project. " +
- "The '%s' or '%s' parameter must be provided.<br>" +
- "Requires the following permission: 'Browse' on the project of the specified component.",
- PARAM_COMPONENT_ID, PARAM_COMPONENT))
+ "Requires the following permission: 'Browse' on the project of the specified component.")
.setResponseExample(getClass().getResource("show-example.json"))
.setSince("5.4")
.setChangelog(
- new Change("6.4", "Analysis date has been added to the response"),
- new Change("6.4", "The field 'id' is deprecated in the response"),
- new Change("6.4", "The 'visibility' field is added to the response"),
- new Change("6.5", "Leak period date is added to the response"),
- new Change("6.6", "'branch' is added to the response"),
- new Change("6.6", "'version' is added to the response"),
new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)))
.setHandler(this);
- action.createParam(PARAM_COMPONENT_ID)
- .setDescription("Component id")
- .setDeprecatedKey("id", "6.4")
- .setDeprecatedSince("6.4")
- .setExampleValue(UUID_EXAMPLE_01);
-
action.createParam(PARAM_COMPONENT)
.setDescription("Component key")
- .setDeprecatedKey("key", "6.4")
+ .setRequired(true)
.setExampleValue(KEY_PROJECT_EXAMPLE_001);
action.createParam(PARAM_BRANCH)
}
private ComponentDto loadComponent(DbSession dbSession, Request request) {
- String componentId = request.getId();
- String componentKey = request.getKey();
+ String componentKey = request.getComponentKey();
String branch = request.getBranch();
String pullRequest = request.getPullRequest();
- checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID,
- PARAM_BRANCH, PARAM_PULL_REQUEST);
- if (branch == null && pullRequest == null) {
- return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT);
- }
- checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT);
+
return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
}
private static Request toShowWsRequest(org.sonar.api.server.ws.Request request) {
return new Request()
- .setId(request.param(PARAM_COMPONENT_ID))
- .setKey(request.param(PARAM_COMPONENT))
+ .setComponentKey(request.mandatoryParam(PARAM_COMPONENT))
.setBranch(request.param(PARAM_BRANCH))
.setPullRequest(request.param(PARAM_PULL_REQUEST));
}
private static class Request {
- private String id;
- private String key;
+ private String componentKey;
private String branch;
private String pullRequest;
- @CheckForNull
- public String getId() {
- return id;
- }
-
- public Request setId(@Nullable String id) {
- this.id = id;
- return this;
- }
-
- @CheckForNull
- public String getKey() {
- return key;
+ public String getComponentKey() {
+ return componentKey;
}
- public Request setKey(@Nullable String key) {
- this.key = key;
+ public Request setComponentKey(String componentKey) {
+ this.componentKey = componentKey;
return this;
}
.setHandler(this)
.setResponseExample(Resources.getResource(this.getClass(), "suggestions-example.json"))
.setChangelog(
- new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)),
- new Change("6.4", "Parameter 's' is optional"));
+ new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)));
action.createParam(PARAM_QUERY)
.setRequired(false)
import org.sonarqube.ws.Components;
import org.sonarqube.ws.Components.TreeWsResponse;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.lang.String.format;
import static java.util.Collections.emptyMap;
import static org.sonar.api.utils.Paging.offset;
-import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
-import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
-import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
-import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY;
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_TREE)
- .setDescription(format("Navigate through components based on the chosen strategy. The %s or the %s parameter must be provided.<br>" +
+ .setDescription(format("Navigate through components based on the chosen strategy.<br>" +
"Requires the following permission: 'Browse' on the specified project.<br>" +
"When limiting search with the %s parameter, directories are not returned.",
- PARAM_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY))
+ Param.TEXT_QUERY))
.setSince("5.4")
.setResponseExample(getClass().getResource("tree-example.json"))
.setChangelog(
new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)),
- new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
- new Change("6.4", "The field 'id' is deprecated in the response"))
+ new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)))
.setHandler(this)
.addPagingParams(100, MAX_SIZE);
- action.createParam(PARAM_COMPONENT_ID)
- .setDescription("Base component id. The search is based on this component.")
- .setDeprecatedKey("baseComponentId", "6.4")
- .setDeprecatedSince("6.4")
- .setExampleValue(UUID_EXAMPLE_02);
-
action.createParam(PARAM_COMPONENT)
.setDescription("Base component key. The search is based on this component.")
- .setDeprecatedKey("baseComponentKey", "6.4")
+ .setRequired(true)
.setExampleValue(KEY_PROJECT_EXAMPLE_001);
action.createParam(PARAM_BRANCH)
}
private ComponentDto loadComponent(DbSession dbSession, Request request) {
- String componentId = request.getBaseComponentId();
String componentKey = request.getComponent();
String branch = request.getBranch();
String pullRequest = request.getPullRequest();
- checkArgument(componentId == null || (branch == null && pullRequest == null), "Parameter '%s' cannot be used at the same time as '%s' or '%s'", PARAM_COMPONENT_ID,
- PARAM_BRANCH, PARAM_PULL_REQUEST);
- if (branch == null && pullRequest == null) {
- return componentFinder.getByUuidOrKey(dbSession, componentId, componentKey, COMPONENT_ID_AND_COMPONENT);
- }
- checkRequest(componentKey != null, "The '%s' parameter is missing", PARAM_COMPONENT);
return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
}
private static Request toTreeWsRequest(org.sonar.api.server.ws.Request request) {
return new Request()
- .setBaseComponentId(request.param(PARAM_COMPONENT_ID))
- .setComponent(request.param(PARAM_COMPONENT))
+ .setComponent(request.mandatoryParam(PARAM_COMPONENT))
.setBranch(request.param(PARAM_BRANCH))
.setPullRequest(request.param(PARAM_PULL_REQUEST))
.setStrategy(request.mandatoryParam(PARAM_STRATEGY))
}
private static class Request {
- private String baseComponentId;
private String component;
private String branch;
private String pullRequest;
private Integer page;
private Integer pageSize;
- /**
- * @deprecated since 6.4, please use {@link #getComponent()} instead
- */
- @Deprecated
- @CheckForNull
- private String getBaseComponentId() {
- return baseComponentId;
- }
-
- /**
- * @deprecated since 6.4, please use {@link #setComponent(String)} instead
- */
- @Deprecated
- private Request setBaseComponentId(@Nullable String baseComponentId) {
- this.baseComponentId = baseComponentId;
- return this;
- }
-
- public Request setComponent(@Nullable String component) {
+ public Request setComponent(String component) {
this.component = component;
return this;
}
"components": [
{
"organization": "my-org-1",
- "id": "directory-uuid",
"key": "directory-key",
"qualifier": "DIR",
"name": "Directory Name",
},
{
"organization": "my-org-1",
- "id": "file-uuid",
"key": "file-key",
"qualifier": "FIL",
"name": "File Name",
},
{
"organization": "my-org-1",
- "id": "project-uuid",
"key": "project-key",
"qualifier": "TRK",
"name": "Project Name",
"components": [
{
"organization": "my-org-key-1",
- "id": "AU-Tpxb--iU5OvuD2FLy",
"key": "my_project",
"name": "My Project 1",
"isFavorite": true,
},
{
"organization": "my-org-key-1",
- "id": "AU-TpxcA-iU5OvuD2FLz",
"key": "another_project",
"name": "My Project 2",
"isFavorite": false,
},
{
"organization": "my-org-key-2",
- "id": "AU-TpxcA-iU5OvuD2FL0",
"key": "third_project",
"name": "My Project 3",
"isFavorite": false,
{
"component": {
"organization": "my-org-1",
- "id": "AVIF-FffA3Ax6PH2efPD",
"key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java",
"name": "Rule.java",
"qualifier": "FIL",
"ancestors": [
{
"organization": "my-org-1",
- "id": "AVIF-FfgA3Ax6PH2efPF",
"key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl",
"name": "src/main/java/com/sonarsource/markdown/impl",
"qualifier": "DIR",
},
{
"organization": "my-org-1",
- "id": "AVIF98jgA3Ax6PH2efOW",
"key": "com.sonarsource:java-markdown",
"name": "Java Markdown",
"description": "Java Markdown Project",
},
"baseComponent": {
"organization": "my-org-1",
- "id": "MY_PROJECT_ID",
"key": "MY_PROJECT_KEY",
- "name": "Project Name",
- "qualifier": "TRK"
+ "description": "DESCRIPTION_MY_PROJECT_ID",
+ "qualifier": "TRK",
+ "tags": [],
+ "visibility": "private"
},
"components": [
{
"organization": "my-org-1",
- "id": "AVHE6Jo2EplJjXTo0Rzw",
"key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParser.java",
"name": "BasicMarkdownParser.java",
"qualifier": "UTS",
},
{
"organization": "my-org-1",
- "id": "AVHE6Jo3EplJjXTo0Rzx",
"key": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/BasicMarkdownParserTest.java",
"name": "BasicMarkdownParserTest.java",
"qualifier": "UTS",
},
{
"organization": "my-org-1",
- "id": "AVHE6Jo1EplJjXTo0Rzj",
"key": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown",
"name": "src/main/java/com/sonarsource/markdown",
"qualifier": "DIR",
}
@Test
- public void get_by_uuid() {
+ public void get_by_component() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project, project));
MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
userSession.logIn("john").addProjectPermission(USER, project);
String result = ws.newRequest()
- .setParam("uuid", file.uuid())
+ .setParam("component", file.getDbKey())
.execute()
.getInput();
@Test
public void fail_if_no_parameter_provided() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'componentId' or 'component' must be provided");
+ expectedException.expectMessage("The 'component' parameter is missing");
ws.newRequest().execute();
}
@Test
- public void fail_if_both_componentId_and_branch_parameters_provided() {
+ public void component_and_branch_parameters_provided() {
ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn("john").addProjectPermission(USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'");
-
- ws.newRequest()
- .setParam("uuid", file.uuid())
+ String result = ws.newRequest()
+ .setParam("component", file.getDbKey())
.setParam("branch", file.getBranch())
- .execute();
+ .execute()
+ .getInput();
+
+ assertJson(result).isSimilarTo("{\n" +
+ " \"key\": \"" + file.getKey() + "\",\n" +
+ " \"branch\": \"" + file.getBranch() + "\",\n" +
+ " \"uuid\": \"" + file.uuid() + "\",\n" +
+ " \"path\": \"" + file.path() + "\",\n" +
+ " \"name\": \"" + file.name() + "\",\n" +
+ " \"longName\": \"" + file.longName() + "\",\n" +
+ " \"q\": \"" + file.qualifier() + "\",\n" +
+ " \"project\": \"" + project.getKey() + "\",\n" +
+ " \"projectName\": \"" + project.longName() + "\",\n" +
+ " \"fav\": false,\n" +
+ " \"canMarkAsFavorite\": true,\n" +
+ " \"measures\": {}\n" +
+ "}\n");
+ }
+
+ @Test
+ public void component_and_pull_request_parameters_provided() {
+ ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn("john").addProjectPermission(USER, project);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch));
+
+ String result = ws.newRequest()
+ .setParam("component", file.getDbKey())
+ .setParam("pullRequest", file.getPullRequest())
+ .execute()
+ .getInput();
+
+ assertJson(result).isSimilarTo("{\n" +
+ " \"key\": \"" + file.getKey() + "\",\n" +
+ " \"uuid\": \"" + file.uuid() + "\",\n" +
+ " \"path\": \"" + file.path() + "\",\n" +
+ " \"name\": \"" + file.name() + "\",\n" +
+ " \"longName\": \"" + file.longName() + "\",\n" +
+ " \"q\": \"" + file.qualifier() + "\",\n" +
+ " \"project\": \"" + project.getKey() + "\",\n" +
+ " \"projectName\": \"" + project.longName() + "\",\n" +
+ " \"pullRequest\": \"" + file.getPullRequest() + "\",\n" +
+ " \"fav\": false,\n" +
+ " \"canMarkAsFavorite\": true,\n" +
+ " \"measures\": {}\n" +
+ "}\n");
}
@Test
- public void fail_if_both_componentId_and_pull_request_parameters_provided() {
+ public void fail_if_component_and_pull_request_and_branch_parameters_provided() {
ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn("john").addProjectPermission(USER, project);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'");
+ expectedException.expectMessage("Either branch or pull request can be provided, not both");
ws.newRequest()
- .setParam("uuid", file.uuid())
- .setParam("pullRequest", file.getPullRequest())
- .execute();
+ .setParam("component", file.getDbKey())
+ .setParam("branch", "unknown_branch")
+ .setParam("pullRequest", "unknown_component")
+ .execute()
+ .getInput();
}
@Test
assertThat(action.isInternal()).isTrue();
assertThat(action.isPost()).isFalse();
assertThat(action.handler()).isNotNull();
- assertThat(action.params()).hasSize(4);
+ assertThat(action.responseExampleAsString()).isNotNull();
+
+ assertThat(action.params()).hasSize(3);
+
+ WebService.Param paramComponent = action.param(AppAction.PARAM_COMPONENT);
+ assertThat(paramComponent).isNotNull();
+ assertThat(paramComponent.isRequired()).isTrue();
+
+ WebService.Param paramBranch = action.param(MeasuresWsParameters.PARAM_BRANCH);
+ assertThat(paramBranch).isNotNull();
+ assertThat(paramBranch.isRequired()).isFalse();
+
+ WebService.Param paramPullRequest = action.param(MeasuresWsParameters.PARAM_PULL_REQUEST);
+ assertThat(paramPullRequest).isNotNull();
+ assertThat(paramPullRequest.isRequired()).isFalse();
}
}
assertThat(action.since()).isEqualTo("6.3");
assertThat(action.isPost()).isFalse();
assertThat(action.isInternal()).isFalse();
- assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
- tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"));
+ assertThat(action.changelog())
+ .extracting(Change::getVersion, Change::getDescription)
+ .containsExactlyInAnyOrder(
+ tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"),
+ tuple("8.0", "Field 'id' from response has been removed"));
assertThat(action.responseExampleAsString()).isNotEmpty();
assertThat(action.params()).hasSize(6);
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.sonar.api.measures.Metric;
-import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
assertThat(def.isPost()).isFalse();
assertThat(def.responseExampleAsString()).isNotEmpty();
assertThat(def.params().stream().map(Param::key).collect(toList())).containsOnly("organization", "filter", "facets", "s", "asc", "ps", "p", "f");
- assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
- tuple("6.4", "The 'languages' parameter accepts 'filter' to filter by language"),
- tuple("6.4", "The 'visibility' field is added"),
- tuple("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"),
- tuple("6.5", "Added the option 'analysisDate' for the 'sort' parameter"),
- tuple("6.5", "Value 'leakPeriodDate' is added to parameter 'f'"));
+ assertThat(def.changelog()).hasSize(1);
Param organization = def.param("organization");
assertThat(organization.isRequired()).isFalse();
.setParam(FACETS, COVERAGE)
.executeProtobuf(SearchProjectsWsResponse.class);
- assertThat(protobufResult.getComponentsList()).extracting(Component::getId)
- .containsExactly(project1.uuid(), project2.uuid(), project3.uuid());
+ assertThat(protobufResult.getComponentsList()).extracting(Component::getKey)
+ .containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey());
}
@Test
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
-import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST;
public class ShowActionTest {
assertThat(action.description()).isNotNull();
assertThat(action.responseExample()).isNotNull();
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
- tuple("6.4", "Analysis date has been added to the response"),
- tuple("6.4", "The field 'id' is deprecated in the response"),
- tuple("6.4", "The 'visibility' field is added to the response"),
- tuple("6.5", "Leak period date is added to the response"),
- tuple("6.6", "'branch' is added to the response"),
- tuple("6.6", "'version' is added to the response"),
tuple("7.6", "The use of module keys in parameter 'component' is deprecated"));
- assertThat(action.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("component", "componentId", "branch", "pullRequest");
-
- WebService.Param componentId = action.param(PARAM_COMPONENT_ID);
- assertThat(componentId.isRequired()).isFalse();
- assertThat(componentId.description()).isNotNull();
- assertThat(componentId.exampleValue()).isNotNull();
- assertThat(componentId.deprecatedSince()).isEqualTo("6.4");
- assertThat(componentId.deprecatedKey()).isEqualTo("id");
- assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4");
+ assertThat(action.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("component", "branch", "pullRequest");
WebService.Param component = action.param(PARAM_COMPONENT);
- assertThat(component.isRequired()).isFalse();
+ assertThat(component.isRequired()).isTrue();
assertThat(component.description()).isNotNull();
assertThat(component.exampleValue()).isNotNull();
- assertThat(component.deprecatedKey()).isEqualTo("key");
- assertThat(component.deprecatedKeySince()).isEqualTo("6.4");
WebService.Param branch = action.param(PARAM_BRANCH);
assertThat(branch.isInternal()).isTrue();
insertJsonExampleComponentsAndSnapshots();
String response = ws.newRequest()
- .setParam("id", "AVIF-FffA3Ax6PH2efPD")
+ .setParam("component", "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java")
.execute()
.getInput();
insertJsonExampleComponentsAndSnapshots();
String response = ws.newRequest()
- .setParam("id", "AVIF-FffA3Ax6PH2efPD")
+ .setParam(PARAM_COMPONENT, "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java")
.execute()
.getInput();
db.components().insertProjectAndSnapshot(project);
userSession.logIn().addProjectPermission(USER, project);
- ShowWsResponse response = newRequest("project-uuid", null);
-
- assertThat(response.getComponent().getId()).isEqualTo("project-uuid");
- }
-
- @Test
- public void show_provided_project() {
- userSession.logIn().setRoot();
- db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
+ ShowWsResponse response = newRequest(project.getDbKey());
- ShowWsResponse response = newRequest("project-uuid", null);
-
- assertThat(response.getComponent().getId()).isEqualTo("project-uuid");
- assertThat(response.getComponent().hasAnalysisDate()).isFalse();
- assertThat(response.getComponent().hasLeakPeriodDate()).isFalse();
+ assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
}
@Test
ComponentDto file = db.components().insertComponent(newFileDto(directory));
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, file.getDbKey());
+ ShowWsResponse response = newRequest(file.getDbKey());
assertThat(response.getComponent().getKey()).isEqualTo(file.getDbKey());
assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getDbKey(), module.getDbKey(), project.getDbKey());
db.components().insertComponent(newModuleDto(project));
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, project.getDbKey());
+ ShowWsResponse response = newRequest(project.getDbKey());
assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
assertThat(response.getAncestorsList()).isEmpty();
newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, project.getDbKey());
+ ShowWsResponse response = newRequest(project.getDbKey());
assertThat(response.getComponent().getAnalysisDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L)));
}
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, project.getDbKey());
+ ShowWsResponse response = newRequest(project.getDbKey());
assertThat(response.getComponent().getLeakPeriodDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L)));
}
ComponentDto file = db.components().insertComponent(newFileDto(directory));
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, file.getDbKey());
+ ShowWsResponse response = newRequest(file.getDbKey());
String expectedDate = formatDateTime(new Date(3_000_000_000L));
assertThat(response.getAncestorsList()).extracting(Component::getAnalysisDate)
userSession.logIn().setRoot();
ComponentDto privateProject = db.components().insertPrivateProject();
- ShowWsResponse result = newRequest(null, privateProject.getDbKey());
+ ShowWsResponse result = newRequest(privateProject.getDbKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
assertThat(result.getComponent().getVisibility()).isEqualTo("private");
}
userSession.logIn().setRoot();
ComponentDto publicProject = db.components().insertPublicProject();
- ShowWsResponse result = newRequest(null, publicProject.getDbKey());
+ ShowWsResponse result = newRequest(publicProject.getDbKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
assertThat(result.getComponent().getVisibility()).isEqualTo("public");
}
userSession.logIn().setRoot();
ComponentDto view = db.components().insertView();
- ShowWsResponse result = newRequest(null, view.getDbKey());
+ ShowWsResponse result = newRequest(view.getDbKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
}
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(privateProject));
- ShowWsResponse result = newRequest(null, module.getDbKey());
+ ShowWsResponse result = newRequest(module.getDbKey());
assertThat(result.getComponent().hasVisibility()).isFalse();
}
db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1"));
userSession.addProjectPermission(USER, project);
- ShowWsResponse response = newRequest(null, file.getDbKey());
+ ShowWsResponse response = newRequest(file.getDbKey());
assertThat(response.getComponent().getVersion()).isEqualTo("1.1");
assertThat(response.getAncestorsList())
userSession.logIn();
expectedException.expect(ForbiddenException.class);
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto componentDto = newPrivateProjectDto(db.organizations().insert(), "project-uuid");
+ db.components().insertProjectAndSnapshot(componentDto);
- newRequest("project-uuid", null);
+ newRequest(componentDto.getDbKey());
}
@Test
public void fail_if_component_does_not_exist() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Component id 'unknown-uuid' not found");
+ expectedException.expectMessage("Component key 'unknown-key' not found");
- newRequest("unknown-uuid", null);
+ newRequest("unknown-key");
}
@Test
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component key 'file-key' not found");
- newRequest(null, "file-key");
- }
-
- @Test
- public void fail_when_componentId_and_branch_params_are_used_together() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'");
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, branch.uuid())
- .setParam(PARAM_BRANCH, "my_branch")
- .execute();
+ newRequest("file-key");
}
@Test
.executeProtobuf(ShowWsResponse.class);
}
- @Test
- public void fail_when_using_branch_uuid() {
- ComponentDto project = db.components().insertMainBranch();
- userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
-
- expectedException.expect(NotFoundException.class);
- expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid()));
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, branch.uuid())
- .executeProtobuf(ShowWsResponse.class);
- }
-
- private ShowWsResponse newRequest(@Nullable String uuid, @Nullable String key) {
+ private ShowWsResponse newRequest(@Nullable String key) {
TestRequest request = ws.newRequest();
- if (uuid != null) {
- request.setParam(PARAM_COMPONENT_ID, uuid);
- }
if (key != null) {
request.setParam(PARAM_COMPONENT, key);
}
PARAM_QUERY,
PARAM_RECENTLY_BROWSED);
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
- tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"),
- tuple("6.4", "Parameter 's' is optional"));
+ tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"));
WebService.Param recentlyBrowsed = action.param(PARAM_RECENTLY_BROWSED);
assertThat(recentlyBrowsed.since()).isEqualTo("6.4");
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT;
-import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY;
assertThat(action.responseExample()).isNotNull();
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"),
- tuple("7.6", "The use of module keys in parameter 'component' is deprecated"),
- tuple("6.4", "The field 'id' is deprecated in the response"));
- assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("component", "componentId", "branch", "pullRequest", "qualifiers", "strategy",
+ tuple("7.6", "The use of module keys in parameter 'component' is deprecated"));
+ assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("component", "branch", "pullRequest", "qualifiers", "strategy",
"q", "s", "p", "asc", "ps");
- Param componentId = action.param(PARAM_COMPONENT_ID);
- assertThat(componentId.isRequired()).isFalse();
- assertThat(componentId.description()).isNotNull();
- assertThat(componentId.exampleValue()).isNotNull();
- assertThat(componentId.deprecatedSince()).isEqualTo("6.4");
- assertThat(componentId.deprecatedKey()).isEqualTo("baseComponentId");
- assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4");
-
Param component = action.param(PARAM_COMPONENT);
- assertThat(component.isRequired()).isFalse();
+ assertThat(component.isRequired()).isTrue();
assertThat(component.description()).isNotNull();
assertThat(component.exampleValue()).isNotNull();
- assertThat(component.deprecatedKey()).isEqualTo("baseComponentKey");
- assertThat(component.deprecatedKeySince()).isEqualTo("6.4");
Param branch = action.param(PARAM_BRANCH);
assertThat(branch.isInternal()).isTrue();
logInWithBrowsePermission(project);
String response = ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, project.uuid())
- .execute().getInput();
+ .setParam(PARAM_COMPONENT, project.getDbKey())
+ .execute()
+ .getInput();
JsonAssert.assertJson(response)
.withStrictArrayOrder()
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
- .setParam(PARAM_COMPONENT_ID, "module-uuid-1")
+ .setParam(PARAM_COMPONENT, module.getDbKey())
.setParam(Param.PAGE, "2")
.setParam(Param.PAGE_SIZE, "3")
.setParam(Param.TEXT_QUERY, "file-name")
assertThat(response.getComponentsCount()).isEqualTo(3);
assertThat(response.getPaging().getTotal()).isEqualTo(8);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-6", "file-uuid-5", "file-uuid-4");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-6", "file-key-5", "file-key-4");
}
@Test
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
- .setParam(PARAM_COMPONENT_ID, "module-uuid-1")
+ .setParam(PARAM_COMPONENT, module.getDbKey())
.setParam(Param.PAGE, "2")
.setParam(Param.PAGE_SIZE, "3")
.setParam(Param.TEXT_QUERY, "file-name")
assertThat(response.getComponentsCount()).isEqualTo(3);
assertThat(response.getPaging().getTotal()).isEqualTo(9);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-4", "file-uuid-5", "file-uuid-6");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-4", "file-key-5", "file-key-6");
}
@Test
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
.setParam(PARAM_QUALIFIERS, FILE)
- .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class);
+ .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2");
}
@Test
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "leaves")
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, project.getDbKey())
.setParam(PARAM_QUALIFIERS, FILE).executeProtobuf(TreeWsResponse.class);
assertThat(response.getComponentsCount()).isEqualTo(3);
assertThat(response.getPaging().getTotal()).isEqualTo(3);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2", "file-key-3");
}
@Test
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
.setParam(Param.SORT, "qualifier, name")
- .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class);
+ .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("module-uuid-1", "path/directory/", "file-uuid-1", "file-uuid-2");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("MODULE_KEY_module-uuid-1", "KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2");
}
@Test
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
- .setParam(PARAM_COMPONENT_ID, "view-uuid")
+ .setParam(PARAM_COMPONENT, view.getDbKey())
.setParam(Param.TEXT_QUERY, "name").executeProtobuf(TreeWsResponse.class);
- assertThat(response.getComponentsList()).extracting("id").containsExactly("project-uuid-1-copy", "sub-view-uuid");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_view-uuidproject-key-1", "sub-view-key");
assertThat(response.getComponentsList()).extracting("refId").containsExactly("project-uuid-1", "");
assertThat(response.getComponentsList()).extracting("refKey").containsExactly("project-key-1", "");
}
logInWithBrowsePermission(project);
TreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class);
+ .setParam(PARAM_COMPONENT, project.getDbKey()).executeProtobuf(TreeWsResponse.class);
- assertThat(response.getBaseComponent().getId()).isEqualTo("project-uuid");
+ assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getDbKey());
assertThat(response.getComponentsList()).isEmpty();
assertThat(response.getPaging().getTotal()).isEqualTo(0);
assertThat(response.getPaging().getPageSize()).isEqualTo(100);
db.components().insertProjectAndSnapshot(project);
ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
db.components().insertViewAndSnapshot(view);
- db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
+ ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
userSession.logIn()
.registerComponents(project, view);
- TreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_ID, view.uuid()).executeProtobuf(TreeWsResponse.class);
+ TreeWsResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT, view.getDbKey())
+ .executeProtobuf(TreeWsResponse.class);
- assertThat(response.getBaseComponent().getId()).isEqualTo(view.uuid());
+ assertThat(response.getBaseComponent().getKey()).isEqualTo(view.getDbKey());
assertThat(response.getComponentsCount()).isEqualTo(1);
- assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid");
- assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid");
+ assertThat(response.getComponents(0).getKey()).isEqualTo(projectCopy.getDbKey());
+ assertThat(response.getComponents(0).getRefKey()).isEqualTo(project.getDbKey());
}
@Test
}
@Test
- public void fail_when_using_branch_uuid() {
+ public void fail_when_using_branch_key() {
ComponentDto project = db.components().insertMainBranch();
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid()));
+ expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey()));
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, branch.uuid())
+ .setParam(PARAM_COMPONENT, branch.getDbKey())
.executeProtobuf(Components.ShowWsResponse.class);
}
expectedException.expect(ForbiddenException.class);
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, project.getDbKey())
.execute();
}
public void fail_when_page_size_above_500() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'ps' value (501) must be less than 500");
- db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
db.commit();
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, project.getDbKey())
.setParam(Param.PAGE_SIZE, "501")
.execute();
}
public void fail_when_search_query_has_less_than_3_characters() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'q' length (2) is shorter than the minimum authorized (3)");
- db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid"));
db.commit();
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, project.getDbKey())
.setParam(Param.TEXT_QUERY, "fi")
.execute();
}
db.commit();
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, "project-key")
.setParam(Param.SORT, "unknown-sort")
.execute();
}
db.commit();
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, "project-key")
.setParam(PARAM_STRATEGY, "unknown-strategy")
.execute();
}
expectedException.expect(NotFoundException.class);
ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, "project-uuid")
+ .setParam(PARAM_COMPONENT, "project-key")
.execute();
}
@Test
public void fail_when_no_base_component_parameter() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'componentId' or 'component' must be provided");
+ expectedException.expectMessage("The 'component' parameter is missing");
ws.newRequest().execute();
}
- @Test
- public void fail_when_componentId_and_branch_params_are_used_together() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'");
-
- ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, branch.uuid())
- .setParam(PARAM_BRANCH, "my_branch")
- .execute();
- }
-
@Test
public void fail_if_branch_does_not_exist() {
ComponentDto project = db.components().insertPrivateProject();
JsonParser jsonParser = new JsonParser();
JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8));
JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components");
- for (JsonElement componentAsJsonElement : components) {
+ for (int i = 0; i < components.size(); i++) {
+ JsonElement componentAsJsonElement = components.get(i);
JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject();
- String uuid = getJsonField(componentAsJsonObject, "id");
+ String uuid = String.format("child-component-uuid-%d", i);
db.components().insertComponent(newChildComponent(uuid, project, project)
.setDbKey(getJsonField(componentAsJsonObject, "key"))
.setName(getJsonField(componentAsJsonObject, "name"))
indexIssues();
TestResponse response = ws.newRequest()
- .setParam("sort", IssueQuery.SORT_BY_UPDATE_DATE)
+ .setParam("s", IssueQuery.SORT_BY_UPDATE_DATE)
.setParam("asc", "false")
.execute();
return createParam(Param.SORT)
.setDescription("Sort field")
- .setDeprecatedKey("sort", "5.4")
.setDefaultValue(defaultValue)
.setPossibleValues(possibleValues);
}
public static final String PARAM_LANGUAGE = "language";
public static final String PARAM_STRATEGY = "strategy";
public static final String PARAM_FILTER = "filter";
- public static final String PARAM_COMPONENT_ID = "componentId";
public static final String PARAM_COMPONENT = "component";
public static final String PARAM_BRANCH = "branch";
public static final String PARAM_PULL_REQUEST = "pullRequest";
message Component {
optional string organization = 12;
- optional string id = 1;
optional string key = 2;
optional string refId = 3;
optional string refKey = 4;