]> source.dussan.org Git - sonarqube.git/commitdiff
Add WebService.Controller#isInternal()
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 3 Mar 2014 22:58:36 +0000 (23:58 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 3 Mar 2014 22:58:36 +0000 (23:58 +0100)
Returns true if all actions are marked as internal use

sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java

index 78d0d5aad7f4ca357f2d0fa4bd8662d9f751b975..ea888d0766fd22fa4398ac710db2ef4ceb3ccf52 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Map;
 
 /**
  * Defines a web service implemented in Java (no Ruby on Rails at all).
+ *
  * @since 4.2
  */
 public interface WebService extends ServerExtension {
@@ -147,6 +148,21 @@ public interface WebService extends ServerExtension {
     public Collection<Action> actions() {
       return actions.values();
     }
+
+    /**
+     * Returns true if all the actions are for internal use
+     *
+     * @see org.sonar.api.server.ws.WebService.Action#isInternal()
+     * @since 4.3
+     */
+    public boolean isInternal() {
+      for (Action action : actions()) {
+        if (!action.isInternal()) {
+          return false;
+        }
+      }
+      return true;
+    }
   }
 
   class NewAction {
index a0713aa03445c15cb2bb3fc621e8c6c0e6eac02d..4efe73e3355d305683f3c76b72bfd0c5e9b530bf 100644 (file)
@@ -90,6 +90,7 @@ public class WebServiceTest {
     assertThat(controller.description()).isEqualTo("Metrics");
     assertThat(controller.since()).isEqualTo("3.2");
     assertThat(controller.actions()).hasSize(2);
+    assertThat(controller.isInternal()).isFalse();
     WebService.Action showAction = controller.action("show");
     assertThat(showAction).isNotNull();
     assertThat(showAction.key()).isEqualTo("show");
@@ -252,4 +253,18 @@ public class WebServiceTest {
     }
   }
 
+  @Test
+  public void ws_is_internal_if_all_actions_are_internal() {
+    new WebService() {
+      @Override
+      public void define(Context context) {
+        NewController newController = context.newController("api/rule");
+        newController.newAction("create").setInternal(true).setHandler(mock(RequestHandler.class));
+        newController.newAction("update").setInternal(true).setHandler(mock(RequestHandler.class));
+        newController.done();
+      }
+    }.define(context);
+
+    assertThat(context.controller("api/rule").isInternal()).isTrue();
+  }
 }