/**
* Defines a web service implemented in Java (no Ruby on Rails at all).
+ *
* @since 4.2
*/
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 {
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");
}
}
+ @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();
+ }
}