]> source.dussan.org Git - sonarqube.git/commitdiff
Add response example to api/roots/search
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 9 Mar 2017 22:50:11 +0000 (23:50 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 9 Mar 2017 22:50:11 +0000 (23:50 +0100)
That also allows to remove a WARN log at startup.

server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java
server/sonar-server/src/main/resources/org/sonar/server/root/ws/search-example.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/root/ws/SearchActionTest.java

index 2ba5c9f9f3b4e463f531fbb1879839abfc2b2a80..a3a7b5ce0f6494d92e0fe22d67ffce5c78644221 100644 (file)
@@ -47,9 +47,10 @@ public class SearchAction implements RootsWsAction {
     controller.createAction("search")
       .setInternal(true)
       .setPost(false)
-      .setDescription("Search for root user.<br/>" +
+      .setDescription("Search for root users.<br/>" +
         "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 (file)
index 0000000..3299aa3
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "roots": [
+    {
+      "login": "daniel",
+      "name": "Daniel",
+      "email": "daniel@corp.com"
+    }
+  ]
+}
index ac5020da77d610e39a21f55d12657322e37a39c8..be6571c7dc0549c2852d04ce29c99d880c6ed4b2 100644 (file)
@@ -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.<br/>" +
+    assertThat(action.description()).isEqualTo("Search for root users.<br/>" +
       "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();