]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9077 let api/components/suggestions return name instead longName
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 4 May 2017 15:37:36 +0000 (17:37 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Thu, 11 May 2017 07:31:11 +0000 (09:31 +0200)
server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java

index 5f18b74058dffaff9184ea50a0e881e05f023a26..e504af5bae191c4941f935d1d675cf61294e9eb7 100644 (file)
@@ -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();
index ae89d6f6c5e0351baadf7bf01595df14dd382951..2ffdd06bdf3329b91ceb9fcc87e91efc03b96843 100644 (file)
@@ -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"));