From e925b79babd5212b694d52a3d51b427276383d0b Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 4 May 2017 17:37:36 +0200 Subject: [PATCH] SONAR-9077 let api/components/suggestions return name instead longName --- .../component/ws/SuggestionsAction.java | 4 +-- .../component/ws/SuggestionsActionTest.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java index 5f18b74058d..e504af5bae1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java @@ -307,8 +307,8 @@ public class SuggestionsAction implements ComponentsWsAction { .setOrganization(organizationKey) .setProject(projectKey) .setKey(result.getKey()) - .setName(result.longName()) - .setMatch(hit.getHighlightedText().orElse(HtmlEscapers.htmlEscaper().escape(result.longName()))) + .setName(result.name()) + .setMatch(hit.getHighlightedText().orElse(HtmlEscapers.htmlEscaper().escape(result.name()))) .setIsRecentlyBrowsed(recentlyBrowsedKeys.contains(result.getKey())) .setIsFavorite(favoriteUuids.contains(result.uuid())) .build(); 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 ae89d6f6c5e..2ffdd06bdf3 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 @@ -249,10 +249,10 @@ public class SuggestionsActionTest { @Test public void suggestions_without_query_should_order_results() throws Exception { - ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Alpha").setLongName("Alpha")); - ComponentDto project2 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Bravo").setLongName("Bravo")); - ComponentDto project3 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Charlie").setLongName("Charlie")); - ComponentDto project4 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Delta").setLongName("Delta")); + ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Alpha")); + ComponentDto project2 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Bravo")); + ComponentDto project3 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Charlie")); + ComponentDto project4 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Delta")); doReturn(asList(project4, project2)).when(favoriteFinder).list(); componentIndexer.indexOnStartup(null); @@ -345,6 +345,25 @@ public class SuggestionsActionTest { assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING); } + @Test + public void should_contain_component_names() throws Exception { + OrganizationDto organization1 = db.organizations().insert(o -> o.setKey("org-1").setName("Organization One")); + + ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto(organization1).setName("Project1")); + componentIndexer.indexProject(project1.projectUuid(), ProjectIndexer.Cause.PROJECT_CREATION); + authorizationIndexerTester.allowOnlyAnyone(project1); + + SuggestionsWsResponse response = ws.newRequest() + .setMethod("POST") + .setParam(PARAM_QUERY, "Project") + .executeProtobuf(SuggestionsWsResponse.class); + + assertThat(response.getResultsList()) + .flatExtracting(Category::getItemsList) + .extracting(Suggestion::getKey, Suggestion::getName) + .containsExactlyInAnyOrder(tuple(project1.getKey(), project1.name())); + } + @Test public void should_contain_organization_names() throws Exception { OrganizationDto organization1 = db.organizations().insert(o -> o.setKey("org-1").setName("Organization One")); -- 2.39.5