@Test public void should_be_well_defined() { Controller controller = tester.controller(CONTROLLER_LANGUAGES); assertThat(controller).isNotNull(); assertThat(controller.description()).isNotEmpty(); assertThat(controller.isInternal()).isFalse(); assertThat(controller.path()).isEqualTo(CONTROLLER_LANGUAGES); assertThat(controller.since()).isEqualTo("5.1"); assertThat(controller.actions()).hasSize(1); Action list = controller.action(ACTION_LIST); assertThat(list).isNotNull(); assertThat(list.description()).isNotEmpty(); assertThat(list.handler()).isInstanceOf(ListAction.class); assertThat(list.isInternal()).isFalse(); assertThat(list.isPost()).isFalse(); assertThat(list.responseExampleAsString()).isNotEmpty(); assertThat(list.params()).hasSize(2); }
assertThat(controller.since()).isEqualTo("3.2"); assertThat(controller.actions()).hasSize(2); assertThat(controller.isInternal()).isFalse(); WebService.Action showAction = controller.action("show"); assertThat(showAction).isNotNull();
private static void writeController(JsonWriter writer, WebService.Controller controller, boolean includeInternals) { if (includeInternals || !controller.isInternal()) { writer.beginObject(); writer.prop("path", controller.path()); writer.prop("since", controller.since()); writer.prop("description", controller.description()); // sort actions by key Ordering<WebService.Action> ordering = Ordering.natural().onResultOf(WebService.Action::key); writer.name("actions").beginArray(); for (WebService.Action action : ordering.sortedCopy(controller.actions())) { writeAction(writer, action, includeInternals); } writer.endArray(); writer.endObject(); } }
private static void writeController(JsonWriter writer, WebService.Controller controller, boolean includeInternals) { if (includeInternals || !controller.isInternal()) { writer.beginObject(); writer.prop("path", controller.path()); writer.prop("since", controller.since()); writer.prop("description", controller.description()); // sort actions by key Ordering<WebService.Action> ordering = Ordering.natural().onResultOf(WebService.Action::key); writer.name("actions").beginArray(); for (WebService.Action action : ordering.sortedCopy(controller.actions())) { writeAction(writer, action, includeInternals); } writer.endArray(); writer.endObject(); } }
@Test public void ws_is_internal_if_all_actions_are_internal() { ((WebService) context -> { NewController newController = context.createController("api/rule"); newDefaultAction(newController, "create").setInternal(true); newDefaultAction(newController, "update").setInternal(true); newController.done(); }).define(context); assertThat(context.controller("api/rule").isInternal()).isTrue(); }