]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9073 fix response example of api/components/suggestions
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 11 May 2017 10:04:35 +0000 (12:04 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Thu, 11 May 2017 20:50:14 +0000 (22:50 +0200)
server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-suggestions.json
server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java

index 6aece7da3c013cb62dd59f6ae48565cb42e3f4ff..9bcb023e561ff403137d4b3448f66375acc9ce6e 100644 (file)
@@ -1,28 +1,53 @@
 {
-  "suggestions": [
+  "results": [
     {
-      "category": "projects",
+      "q": "VW",
+      "items": [],
+      "more": 0
+    },
+    {
+      "q": "SVW",
+      "items": [],
+      "more": 0
+    },
+    {
+      "q": "TRK",
       "items": [
         {
-          "organization": "default-organization",
           "key": "org.sonarsource:sonarqube",
           "name": "SonarSource :: SonarQube",
-          "match": "<mark>Sonar</mark>Source :: SonarQube",
-          "recentlyBrowsed": true
+          "match": "<mark>Sonar</mark>Source :: <mark>Sonar</mark>Qube",
+          "organization": "default-organization",
+          "project": "",
+          "isRecentlyBrowsed": true,
+          "isFavorite": false
         },
         {
-          "organization": "default-organization",
           "key": "org.sonarsource:sonarlint",
           "name": "SonarSource :: SonarLint",
-          "match": "<mark>Sonar</mark>Source :: SonarLint"
+          "match": "<mark>Sonar</mark>Source :: <mark>Sonar</mark>Lint",
+          "organization": "default-organization",
+          "project": "",
+          "isRecentlyBrowsed": false,
+          "isFavorite": false
         }
       ],
-      "more": 74
+      "more": 0
     },
     {
-      "category": "files",
-      "items": [
-      ]
+      "q": "BRC",
+      "items": [],
+      "more": 0
+    },
+    {
+      "q": "FIL",
+      "items": [],
+      "more": 0
+    },
+    {
+      "q": "UTS",
+      "items": [],
+      "more": 0
     }
   ],
   "organizations": [
@@ -31,5 +56,6 @@
       "name": "Default Organization"
     }
   ],
-  "warning": "short_input"
+  "projects": [
+  ]
 }
index c833187383460f29396fbdc4de97eea9ee150614..ed48e8aae291c1b4c99ddd6b774a45c2525b85b2 100644 (file)
@@ -45,7 +45,10 @@ import org.sonar.server.permission.index.AuthorizationTypeSupport;
 import org.sonar.server.permission.index.PermissionIndexerTester;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
+import org.sonar.test.JsonAssert;
+import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Project;
 import org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Suggestion;
@@ -120,6 +123,25 @@ public class SuggestionsActionTest {
     assertThat(query.isRequired()).isFalse();
   }
 
+  @Test
+  public void test_example_json_response() {
+    OrganizationDto organization = db.organizations().insert(o -> o.setKey("default-organization").setName("Default Organization"));
+    ComponentDto project1 = db.components().insertPublicProject(organization, p -> p.setKey("org.sonarsource:sonarqube").setName("SonarSource :: SonarQube"));
+    ComponentDto project2 = db.components().insertPublicProject(organization, p -> p.setKey("org.sonarsource:sonarlint").setName("SonarSource :: SonarLint"));
+    componentIndexer.indexOnStartup(null);
+    authorizationIndexerTester.allowOnlyAnyone(project1);
+    authorizationIndexerTester.allowOnlyAnyone(project2);
+
+    TestResponse wsResponse = ws.newRequest()
+      .setParam(PARAM_QUERY, "Sonar")
+      .setParam(PARAM_RECENTLY_BROWSED, project1.key())
+      .setMethod("POST")
+      .setMediaType(MediaTypes.JSON)
+      .execute();
+
+    JsonAssert.assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(wsResponse.getInput());
+  }
+
   @Test
   public void suggestions_without_query_should_contain_recently_browsed() throws Exception {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
@@ -145,6 +167,30 @@ public class SuggestionsActionTest {
       .containsExactly(tuple(project.getKey(), true));
   }
 
+  @Test
+  public void suggestions_without_query_should_contain_recently_browsed_public_project() throws Exception {
+    ComponentDto project = db.components().insertComponent(newPublicProjectDto(organization));
+
+    componentIndexer.indexOnStartup(null);
+
+    SuggestionsWsResponse response = ws.newRequest()
+      .setMethod("POST")
+      .setParam(PARAM_RECENTLY_BROWSED, project.getKey())
+      .executeProtobuf(SuggestionsWsResponse.class);
+
+    // assert match in qualifier "TRK"
+    assertThat(response.getResultsList())
+      .filteredOn(q -> q.getItemsCount() > 0)
+      .extracting(Category::getQ)
+      .containsExactly(Qualifiers.PROJECT);
+
+    // assert correct id to be found
+    assertThat(response.getResultsList())
+      .flatExtracting(Category::getItemsList)
+      .extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed)
+      .containsExactly(tuple(project.getKey(), true));
+  }
+
   @Test
   public void suggestions_without_query_should_not_contain_recently_browsed_without_permission() throws Exception {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));