diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-05-11 12:04:35 +0200 |
---|---|---|
committer | Daniel Schwarz <bartfastiel@users.noreply.github.com> | 2017-05-11 22:50:14 +0200 |
commit | 71322861fe6d19a1dd7054be8168ae41a53c3eb1 (patch) | |
tree | 6ebc70df6e0586d96d9cfa12c0321cb0be0d9e54 | |
parent | 36af9beabb4407a79dc2924be905ea79908ce704 (diff) | |
download | sonarqube-71322861fe6d19a1dd7054be8168ae41a53c3eb1.tar.gz sonarqube-71322861fe6d19a1dd7054be8168ae41a53c3eb1.zip |
SONAR-9073 fix response example of api/components/suggestions
2 files changed, 84 insertions, 12 deletions
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-suggestions.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-suggestions.json index 6aece7da3c0..9bcb023e561 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-suggestions.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-suggestions.json @@ -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": [ + ] } 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 c8331873834..ed48e8aae29 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 @@ -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; @@ -121,6 +124,25 @@ public class SuggestionsActionTest { } @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)); @@ -146,6 +168,30 @@ public class SuggestionsActionTest { } @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)); |