From b69088512c840c6e52c73879749b2dc6ade5e649 Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Fri, 16 Nov 2018 16:41:05 +0100 Subject: [PATCH] SONAR-11476 deprecate/drop support for providing module/dir keys as parameters to WS --- .../org/sonar/server/batch/IssuesAction.java | 4 +- .../org/sonar/server/batch/ProjectAction.java | 3 + .../sonar/server/ce/ws/ActivityAction.java | 10 +-- .../server/ce/ws/ActivityStatusAction.java | 5 +- .../server/ce/ws/AnalysisStatusAction.java | 6 +- .../sonar/server/ce/ws/ComponentAction.java | 3 +- .../sonar/server/component/ws/AppAction.java | 2 + .../server/component/ws/SearchAction.java | 11 +++- .../sonar/server/component/ws/ShowAction.java | 5 +- .../component/ws/SuggestionCategory.java | 1 - .../component/ws/SuggestionsAction.java | 7 ++- .../sonar/server/component/ws/TreeAction.java | 10 ++- .../sonar/server/favorite/ws/AddAction.java | 4 +- .../server/favorite/ws/RemoveAction.java | 4 +- .../sonar/server/issue/ws/SearchAction.java | 6 +- .../server/measure/ws/ComponentAction.java | 1 + .../measure/ws/ComponentTreeAction.java | 1 + .../measure/ws/SearchHistoryAction.java | 2 + .../setting/ws/ListDefinitionsAction.java | 14 +++-- .../sonar/server/setting/ws/ResetAction.java | 4 +- .../sonar/server/setting/ws/SetAction.java | 6 +- .../sonar/server/setting/ws/ValuesAction.java | 4 +- .../sonar/server/ui/ws/ComponentAction.java | 9 +-- .../java/org/sonar/server/ws/WsUtils.java | 10 +++ .../ws/search-components-example.json | 10 +-- .../component/ws/suggestions-example.json | 5 -- .../server/component/ws/SearchActionTest.java | 2 +- .../server/component/ws/ShowActionTest.java | 3 +- .../component/ws/SuggestionsActionTest.java | 45 ++++++-------- .../server/component/ws/TreeActionTest.java | 7 ++- .../server/ui/ws/ComponentActionTest.java | 61 +++++-------------- .../return_breadcrumbs_on_module.json | 14 ----- .../client/navigation/ComponentRequest.java | 1 - 33 files changed, 135 insertions(+), 145 deletions(-) delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentActionTest/return_breadcrumbs_on_module.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java index 9877b755b25..bb6af68da8d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java @@ -20,15 +20,14 @@ package org.sonar.server.batch; import com.google.common.base.Splitter; - import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; - import org.sonar.api.resources.Scopes; import org.sonar.api.rules.RuleType; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -74,6 +73,7 @@ public class IssuesAction implements BatchWsAction { .setDescription("Return open issues") .setResponseExample(getClass().getResource("issues-example.proto")) .setSince("5.1") + .setChangelog(new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_KEY))) .setInternal(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectAction.java index b15b8b76a63..2d6439ec78b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectAction.java @@ -22,6 +22,7 @@ package org.sonar.server.batch; import java.util.Date; import java.util.HashMap; import java.util.Map; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -56,6 +57,8 @@ public class ProjectAction implements BatchWsAction { .setDescription("Return project repository") .setResponseExample(getClass().getResource("project-example.json")) .setSince("4.5") + .setChangelog(new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_KEY))) + .setChangelog(new Change("7.6", "Stop returning settings")) .setInternal(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java index 3928e8865c8..c956af8c87d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java @@ -56,6 +56,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.apache.commons.lang.StringUtils.defaultString; +import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime; import static org.sonar.core.util.stream.MoreCollectors.toList; @@ -103,7 +104,8 @@ public class ActivityAction implements CeWsAction { new Change("5.5", "it's no more possible to specify the page parameter."), new Change("6.1", "field \"logs\" is deprecated and its value is always false"), new Change("6.6", "fields \"branch\" and \"branchType\" added"), - new Change("7.1", "field \"pullRequest\" added")) + new Change("7.1", "field \"pullRequest\" added"), + new Change("7.6", String.format("The use of module keys in parameters '%s' and '%s' is deprecated", TEXT_QUERY, PARAM_COMPONENT_QUERY))) .setSince("5.2"); action.createParam(PARAM_COMPONENT_ID) @@ -115,10 +117,10 @@ public class ActivityAction implements CeWsAction { "
  • component keys that are exactly the same as the supplied string
  • " + "" + "Must not be set together with %s.
    " + - "Deprecated and replaced by '%s'", PARAM_COMPONENT_ID, Param.TEXT_QUERY)) + "Deprecated and replaced by '%s'", PARAM_COMPONENT_ID, TEXT_QUERY)) .setExampleValue("Apache") .setDeprecatedSince("5.5"); - action.createParam(Param.TEXT_QUERY) + action.createParam(TEXT_QUERY) .setDescription(format("Limit search to: ") .setSince("6.1") - .setChangelog(new Change("7.1", "The settings defined in config/sonar.properties are read-only and can't be changed")) + .setChangelog( + new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), + new Change("7.1", "The settings defined in config/sonar.properties are read-only and can't be changed")) .setPost(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java index be22168c142..38991fd6c27 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -101,7 +101,7 @@ public class SetAction implements SettingsWsAction { WebService.NewAction action = context.createAction("set") .setDescription("Update a setting value.
    " + "Either '%s' or '%s' must be provided.
    " + - "The settings defined in config/sonar.properties are read-only and can't be changed.
    " + + "The settings defined in config/sonar.properties are read-only and can't be changed.
    " + "Requires one of the following permissions: " + "", PARAM_VALUE, PARAM_VALUES) .setSince("6.1") - .setChangelog(new Change("7.1", "The settings defined in config/sonar.properties are read-only and can't be changed")) + .setChangelog( + new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), + new Change("7.1", "The settings defined in config/sonar.properties are read-only and can't be changed")) .setPost(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index b276a2d9f22..c3b0b47cf51 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -112,7 +112,9 @@ public class ValuesAction implements SettingsWsAction { "") .setResponseExample(getClass().getResource("values-example.json")) .setSince("6.3") - .setChangelog(new Change("7.1", "The settings from conf/sonar.properties are excluded from results.")) + .setChangelog( + new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), + new Change("7.1", "The settings from conf/sonar.properties are excluded from results.")) .setHandler(this); action.createParam(PARAM_KEYS) .setDescription("List of setting keys") diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index a5774c20d38..469ab761b3d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -76,6 +76,7 @@ import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesEx 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.checkComponentNotAModuleAndNotADirectory; public class ComponentAction implements NavigationWsAction { @@ -121,8 +122,9 @@ public class ComponentAction implements NavigationWsAction { .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.2") .setChangelog( - new Change("6.4", "The 'visibility' field is added"), - new Change("7.3", "The 'almRepoUrl' and 'almId' fields are added")); + new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), + new Change("7.3", "The 'almRepoUrl' and 'almId' fields are added"), + new Change("6.4", "The 'visibility' field is added")); action.createParam(PARAM_COMPONENT) .setDescription("A component key.") @@ -132,13 +134,11 @@ public class ComponentAction implements NavigationWsAction { action .createParam(PARAM_BRANCH) .setDescription("Branch key") - .setInternal(true) .setExampleValue(KEY_BRANCH_EXAMPLE_001); action .createParam(PARAM_PULL_REQUEST) .setDescription("Pull request id") - .setInternal(true) .setExampleValue(KEY_PULL_REQUEST_EXAMPLE_001); } @@ -149,6 +149,7 @@ public class ComponentAction implements NavigationWsAction { String branch = request.param(PARAM_BRANCH); String pullRequest = request.param(PARAM_PULL_REQUEST); ComponentDto component = componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, componentKey, branch, pullRequest); + checkComponentNotAModuleAndNotADirectory(component); ComponentDto rootProjectOrBranch = getRootProjectOrBranch(component, session); ComponentDto rootProject = rootProjectOrBranch.getMainBranchProjectUuid() == null ? rootProjectOrBranch : componentFinder.getByUuid(session, rootProjectOrBranch.getMainBranchProjectUuid()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java index 2a198a26b74..9c144754ba3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java @@ -20,16 +20,20 @@ package org.sonar.server.ws; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; import com.google.protobuf.Message; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.List; +import java.util.Set; import javax.annotation.Nullable; import org.apache.commons.io.IOUtils; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.util.ProtobufJsonFormat; +import org.sonar.db.component.ComponentDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; @@ -40,6 +44,8 @@ import static org.sonarqube.ws.MediaTypes.PROTOBUF; public class WsUtils { + private static final Set MODULE_OR_DIR_QUALIFIERS = ImmutableSet.of(Qualifiers.MODULE, Qualifiers.DIRECTORY); + private WsUtils() { // only statics } @@ -117,4 +123,8 @@ public class WsUtils { return value.get(); } + + public static void checkComponentNotAModuleAndNotADirectory(ComponentDto component) { + checkRequest(!MODULE_OR_DIR_QUALIFIERS.contains(component.qualifier()), "Operation not supported for module or directory components"); + } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json index 4811ba96637..c717cc3631e 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search-components-example.json @@ -2,7 +2,7 @@ "paging": { "pageIndex": 1, "pageSize": 100, - "total": 4 + "total": 3 }, "components": [ { @@ -22,14 +22,6 @@ "language": "java", "project": "project-key" }, - { - "organization": "my-org-1", - "id": "module-uuid", - "key": "module-key", - "qualifier": "BRC", - "name": "Module Name", - "project": "project-key" - }, { "organization": "my-org-1", "id": "project-uuid", diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/suggestions-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/suggestions-example.json index 3c7bbd44454..48a24e137b7 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/suggestions-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/suggestions-example.json @@ -39,11 +39,6 @@ ], "more": 0 }, - { - "q": "BRC", - "items": [], - "more": 0 - }, { "q": "FIL", "items": [], diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 3a968673e60..8838d5cdda7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -266,7 +266,7 @@ public class SearchActionTest { String response = ws.newRequest() .setMediaType(MediaTypes.JSON) .setParam(PARAM_ORGANIZATION, organizationDto.getKey()) - .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, MODULE, DIRECTORY, FILE)) + .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY, FILE)) .execute().getInput(); assertJson(response).isSimilarTo(ws.getDef().responseExampleAsString()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 0053e1a5d4d..cfffc69da66 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -81,7 +81,8 @@ public class ShowActionTest { 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("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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index a98c328f65b..f1348372ef2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -347,7 +347,8 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .extracting(Category::getQ, Category::getItemsCount) - .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1), tuple("BRC", 0), tuple("FIL", 0), tuple("UTS", 0)); + .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0)) + .doesNotContain(tuple("BRC", 0)); } @Test @@ -364,7 +365,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .extracting(Category::getQ) - .containsExactlyInAnyOrder(PROJECT, MODULE, FILE); + .containsExactlyInAnyOrder(PROJECT, FILE).doesNotContain(MODULE); } @Test @@ -503,8 +504,8 @@ public class SuggestionsActionTest { } @Test - public void should_contain_project_names() { - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); + public void should_not_return_modules() { + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("ProjectWithModules")); db.components().insertComponent(newModuleDto(project).setName("Module1")); db.components().insertComponent(newModuleDto(project).setName("Module2")); componentIndexer.indexOnAnalysis(project.projectUuid()); @@ -517,18 +518,13 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) - .extracting(Suggestion::getProject) + .extracting(Suggestion::getKey) .containsOnly(project.getDbKey()); - - assertThat(response.getProjectsList()) - .extracting(Project::getKey, Project::getName) - .containsExactlyInAnyOrder( - tuple(project.getDbKey(), project.longName())); } @Test public void should_mark_recently_browsed_items() { - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("ProjectModule")); ComponentDto module1 = newModuleDto(project).setName("Module1"); db.components().insertComponent(module1); ComponentDto module2 = newModuleDto(project).setName("Module2"); @@ -539,36 +535,34 @@ public class SuggestionsActionTest { SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .setParam(PARAM_QUERY, "Module") - .setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getDbKey()).collect(joining(","))) + .setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getDbKey(), project.getDbKey()).collect(joining(","))) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getIsRecentlyBrowsed) - .containsExactly(true, false); + .containsExactly(true); } @Test public void should_mark_favorite_items() { - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); - ComponentDto favorite = newModuleDto(project).setName("Module1"); - db.components().insertComponent(favorite); - doReturn(singletonList(favorite)).when(favoriteFinder).list(); + ComponentDto favouriteProject = db.components().insertComponent(newPrivateProjectDto(organization).setName("Project1")); + ComponentDto nonFavouriteProject = db.components().insertComponent(newPublicProjectDto(organization).setName("Project2")); - ComponentDto nonFavorite = newModuleDto(project).setName("Module2"); - db.components().insertComponent(nonFavorite); - componentIndexer.indexOnAnalysis(project.projectUuid()); - authorizationIndexerTester.allowOnlyAnyone(project); + doReturn(singletonList(favouriteProject)).when(favoriteFinder).list(); + componentIndexer.indexOnAnalysis(favouriteProject.projectUuid()); + componentIndexer.indexOnAnalysis(nonFavouriteProject.projectUuid()); + authorizationIndexerTester.allowOnlyAnyone(favouriteProject, nonFavouriteProject); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") - .setParam(PARAM_QUERY, "Module") + .setParam(PARAM_QUERY, "Project") .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsFavorite) - .containsExactly(tuple(favorite.getDbKey(), true), tuple(nonFavorite.getDbKey(), false)); + .containsExactly(tuple(favouriteProject.getDbKey(), true), tuple(nonFavouriteProject.getDbKey(), false)); } @Test @@ -584,7 +578,7 @@ public class SuggestionsActionTest { assertThat(response.getResultsList()) .extracting(Category::getQ, Category::getItemsCount) - .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1), tuple("BRC", 0), tuple("FIL", 0), tuple("UTS", 0)); + .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0)); } @Test @@ -615,7 +609,6 @@ public class SuggestionsActionTest { tuple(SuggestionCategory.VIEW.getName(), false), tuple(SuggestionCategory.SUBVIEW.getName(), false), tuple(SuggestionCategory.PROJECT.getName(), false), - tuple(SuggestionCategory.MODULE.getName(), true), tuple(SuggestionCategory.FILE.getName(), true), tuple(SuggestionCategory.UNIT_TEST_FILE.getName(), true)); } @@ -737,7 +730,7 @@ public class SuggestionsActionTest { } private void check_proposal_to_show_more_results(int numberOfProjects, int expectedNumberOfResults, long expectedNumberOfMoreResults, @Nullable SuggestionCategory more, - boolean useQuery) { + boolean useQuery) { String namePrefix = "MyProject"; List projects = range(0, numberOfProjects) 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 de5d739cc78..ca4e5904ed9 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 @@ -100,7 +100,8 @@ public class TreeActionTest { assertThat(action.description()).isNotNull(); assertThat(action.responseExample()).isNotNull(); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( - tuple("6.4", "The field 'id' is deprecated in the response")); + tuple("6.4", "The field 'id' is deprecated in the response"), + tuple("7.6", "The use of module keys in parameter 'component' is deprecated")); assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("component", "componentId", "branch", "pullRequest", "qualifiers", "strategy", "q", "s", "p", "asc", "ps"); @@ -258,7 +259,9 @@ public class TreeActionTest { .setParam(Param.SORT, "qualifier, name") .setParam(PARAM_COMPONENT_ID, "project-uuid").executeProtobuf(TreeWsResponse.class); - assertThat(response.getComponentsList()).extracting("id").containsExactly("module-uuid-1", "path/directory/", "file-uuid-1", "file-uuid-2"); + assertThat(response.getComponentsList()).extracting("id") + .containsExactly("path/directory/", "file-uuid-1", "file-uuid-2") + .doesNotContain("module-uuid-1"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index d4e18f020b2..89200f810cc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -45,7 +45,6 @@ import org.sonar.db.alm.ALM; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.organization.OrganizationDto; @@ -56,6 +55,7 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.BillingValidations; @@ -386,18 +386,6 @@ public class ComponentActionTest { executeAndVerify(project.getDbKey(), "return_configuration_with_all_properties.json"); } - @Test - public void return_breadcrumbs_on_module() { - ComponentDto project = insertOrganizationAndProject(); - ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); - userSession.anonymous() - .addProjectPermission(UserRole.USER, project) - .addProjectPermission(UserRole.ADMIN, project); - init(); - - executeAndVerify(module.getDbKey(), "return_breadcrumbs_on_module.json"); - } - @Test public void return_configuration_for_quality_profile_admin() { ComponentDto project = insertOrganizationAndProject(); @@ -469,21 +457,6 @@ public class ComponentActionTest { assertJson(execute(project.getDbKey())).isSimilarTo("{\"visibility\": \"public\"}"); } - @Test - public void should_not_return_private_flag_for_module() { - OrganizationDto org = db.organizations().insert(); - db.qualityGates().createDefaultQualityGate(org); - ComponentDto project = db.components().insertPrivateProject(org); - ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project)); - init(); - - userSession.logIn() - .addProjectPermission(UserRole.ADMIN, project) - .addPermission(OrganizationPermission.ADMINISTER, org); - String json = execute(module.getDbKey()); - assertThat(json).doesNotContain("visibility"); - } - @Test public void canApplyPermissionTemplate_is_true_if_logged_in_as_organization_administrator() { OrganizationDto org = db.organizations().insert(); @@ -588,7 +561,8 @@ public class ComponentActionTest { assertThat(action.responseExample()).isNotNull(); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( tuple("6.4", "The 'visibility' field is added"), - tuple("7.3", "The 'almRepoUrl' and 'almId' fields are added")); + tuple("7.3", "The 'almRepoUrl' and 'almId' fields are added"), + tuple("7.6", "The use of module keys in parameter 'component' is deprecated")); WebService.Param componentId = action.param(PARAM_COMPONENT); assertThat(componentId.isRequired()).isFalse(); @@ -621,27 +595,24 @@ public class ComponentActionTest { "}\n"); } - @Test - public void return_alm_info_on_module() { + @Test(expected = BadRequestException.class) + public void fail_on_module_key_as_param() { ComponentDto project = insertOrganizationAndProject(); ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); - dbClient.projectAlmBindingsDao().insertOrUpdate(db.getSession(), ALM.BITBUCKETCLOUD, "{123456789}", project.uuid(), null, "http://bitbucket.org/foo/bar"); - db.getSession().commit(); - userSession.addProjectPermission(UserRole.USER, project); init(); - String json = execute(module.getKey()); + execute(module.getKey()); + } - assertJson(json).isSimilarTo("{\n" + - " \"organization\": \"my-org\",\n" + - " \"key\": \"palap\",\n" + - " \"id\": \"bcde\",\n" + - " \"name\": \"Palap\",\n" + - " \"alm\": {\n" + - " \"key\": \"bitbucketcloud\",\n" + - " \"url\": \"http://bitbucket.org/foo/bar\"\n" + - " }\n" + - "}\n"); + @Test(expected = BadRequestException.class) + public void fail_on_directory_key_as_param() { + ComponentDto project = insertOrganizationAndProject(); + ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); + ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); + userSession.addProjectPermission(UserRole.USER, project); + init(); + + execute(directory.getDbKey()); } @Test diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentActionTest/return_breadcrumbs_on_module.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentActionTest/return_breadcrumbs_on_module.json deleted file mode 100644 index 5054f144064..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentActionTest/return_breadcrumbs_on_module.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "breadcrumbs": [ - { - "key": "polop", - "name": "Polop", - "qualifier": "TRK" - }, - { - "key": "palap", - "name": "Palap", - "qualifier": "BRC" - } - ] -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/navigation/ComponentRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/navigation/ComponentRequest.java index c7d451bc891..bfbe35d887f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/navigation/ComponentRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/navigation/ComponentRequest.java @@ -19,7 +19,6 @@ */ package org.sonarqube.ws.client.navigation; -import java.util.List; import javax.annotation.Generated; /** -- 2.39.5