From: Simon Brandhof Date: Thu, 9 Mar 2017 22:50:11 +0000 (+0100) Subject: Add response example to api/roots/search X-Git-Tag: 6.3~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f5860f19cbb9056dbea692aaecdf4dcc2eb4c91d;p=sonarqube.git Add response example to api/roots/search That also allows to remove a WARN log at startup. --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java index 2ba5c9f9f3b..a3a7b5ce0f6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java @@ -47,9 +47,10 @@ public class SearchAction implements RootsWsAction { controller.createAction("search") .setInternal(true) .setPost(false) - .setDescription("Search for root user.
" + + .setDescription("Search for root users.
" + "Requires to be root.") .setSince("6.2") + .setResponseExample(getClass().getResource("search-example.json")) .setHandler(this); } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/root/ws/search-example.json b/server/sonar-server/src/main/resources/org/sonar/server/root/ws/search-example.json new file mode 100644 index 00000000000..3299aa305ff --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/root/ws/search-example.json @@ -0,0 +1,9 @@ +{ + "roots": [ + { + "login": "daniel", + "name": "Daniel", + "email": "daniel@corp.com" + } + ] +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java index ac5020da77d..be6571c7dc0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java @@ -34,11 +34,13 @@ import org.sonar.db.user.UserTesting; import org.sonar.server.exceptions.ForbiddenException; 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.sonarqube.ws.MediaTypes; import org.sonarqube.ws.WsRoot; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.test.JsonAssert.assertJson; public class SearchActionTest { @@ -61,9 +63,9 @@ public class SearchActionTest { assertThat(action.isInternal()).isTrue(); assertThat(action.isPost()).isFalse(); assertThat(action.since()).isEqualTo("6.2"); - assertThat(action.description()).isEqualTo("Search for root user.
" + + assertThat(action.description()).isEqualTo("Search for root users.
" + "Requires to be root."); - assertThat(action.responseExample()).isNull(); + assertThat(action.responseExample()).isNotNull(); assertThat(action.deprecatedKey()).isNull(); assertThat(action.deprecatedSince()).isNull(); assertThat(action.handler()).isSameAs(underTest); @@ -93,6 +95,18 @@ public class SearchActionTest { assertThat(executeRequest()).isEmpty(); } + @Test + public void test_response_example() { + logInAsRoot(); + UserDto user = UserTesting.newUserDto().setLogin("daniel").setName("Daniel").setEmail("daniel@corp.com"); + UserDto rootDto = userDao.insert(dbSession, user); + userDao.setRoot(dbSession, rootDto.getLogin(), true); + dbSession.commit(); + + TestResponse response = wsTester.newRequest().setMediaType(MediaTypes.JSON).execute(); + assertJson(response.getInput()).isSimilarTo(wsTester.getDef().responseExampleAsString()); + } + @Test public void execute_succeeds_when_root_user_has_neither_email_nor_name() { logInAsRoot();