@Test public void define_template_groups() { WebService.Action action = controller().action("template_groups"); assertThat(action).isNotNull(); assertThat(action.isPost()).isFalse(); assertThat(action.isInternal()).isTrue(); assertThat(action.since()).isEqualTo("5.2"); }
@Test public void handle_request() throws Exception { MetricWs metricWs = new MetricWs(); metricWs.define(context); assertThat(metricWs.showCalled).isFalse(); assertThat(metricWs.createCalled).isFalse(); context.controller("api/metric").action("show").handler().handle(mock(Request.class), mock(Response.class)); assertThat(metricWs.showCalled).isTrue(); assertThat(metricWs.createCalled).isFalse(); context.controller("api/metric").action("create").handler().handle(mock(Request.class), mock(Response.class)); assertThat(metricWs.createCalled).isTrue(); }
@Test public void define_template_users() { WebService.Action action = controller().action("template_users"); assertThat(action).isNotNull(); assertThat(action.isPost()).isFalse(); assertThat(action.isInternal()).isTrue(); assertThat(action.since()).isEqualTo("5.2"); assertThat(action.param(PARAM_PERMISSION).isRequired()).isFalse(); }
@Test public void create_action_properties() { WebService.Action action = ws.controller(ENDPOINT).action("create"); assertThat(action.isPost()).isTrue(); }
@Test public void define_create_action() { WebService.Action action = controller.action("create"); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.params()).hasSize(3); } }
@Test public void define_change_password_action() { WebService.Action action = controller.action("change_password"); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); assertThat(action.params()).hasSize(3); }
@Test public void define_create_action() { WebService.Action action = controller.action("create"); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); assertThat(action.params()).hasSize(7); }
@Test public void param_with_maximum_length() { ((WebService) context -> { NewController newController = context.createController("api/custom_measures"); NewAction create = newDefaultAction(newController, "create"); create.createParam("string_value") .setMaximumLength(24); newController.done(); }).define(context); WebService.Action action = context.controller("api/custom_measures").action("create"); assertThat(action.param("string_value").maximumLength()).isEqualTo(24); }
@Test public void define_upload_action() { WebService.Controller controller = tester.controller("api/updatecenter"); WebService.Action action = controller.action("upload"); assertThat(action).isNotNull(); assertThat(action.handler()).isNotNull(); assertThat(action.isInternal()).isTrue(); assertThat(action.isPost()).isTrue(); assertThat(action.params()).hasSize(1); } }
@Test public void response_example() { MetricWs metricWs = new MetricWs(); metricWs.define(context); WebService.Action action = context.controller("api/metric").action("create"); assertThat(action.responseExampleFormat()).isEqualTo("txt"); assertThat(action.responseExample()).isNotNull(); assertThat(StringUtils.trim(action.responseExampleAsString())).isEqualTo("example of WS response"); }
@Test public void param_with_maximum_value() { ((WebService) context -> { NewController newController = context.createController("api/custom_measures"); NewAction create = newDefaultAction(newController, "create"); create.createParam("numeric_value") .setMaximumValue(10); newController.done(); }).define(context); WebService.Action action = context.controller("api/custom_measures").action("create"); assertThat(action.param("numeric_value").maximumValue()).isEqualTo(10); }
@CheckForNull public WebService.Action action(String controllerKey, String actionKey) { WebService.Controller controller = context.controller(controllerKey); if (controller != null) { return controller.action(actionKey); } return null; }
@Test public void define_list_action() { WebService.Controller controller = controller(); WebService.Action listProfiles = controller.action("list"); assertThat(listProfiles).isNotNull(); assertThat(listProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); assertThat(listProfiles.responseExampleAsString()).isNotEmpty(); assertThat(listProfiles.params()).isEmpty(); }
@Test public void define_update_action() { WebService.Action action = controller.action("update"); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); assertThat(action.params()).hasSize(5); }
@Test public void define_search_action() { WebService.Action action = controller.action("search"); assertThat(action).isNotNull(); assertThat(action.isPost()).isFalse(); assertThat(action.responseExampleAsString()).isNotEmpty(); assertThat(action.params()).hasSize(4); }
@Test public void define_index_action() { WebService.Action action = controller.action("index"); assertThat(action).isNotNull(); assertThat(action.responseExampleAsString()).isNotEmpty(); }
@Test public void create_update_properties() { WebService.Action action = ws.controller(ENDPOINT).action("update"); assertThat(action.isPost()).isTrue(); } }
@CheckForNull private WebService.Action getAction(ActionExtractor actionExtractor) { String controllerPath = actionExtractor.getController(); String actionKey = actionExtractor.getAction(); WebService.Controller controller = getContext().controller(controllerPath); return controller == null ? null : controller.action(actionKey); }
@Test public void delete_action_properties() { WebService.Action deleteAction = ws.controller(ENDPOINT).action("delete"); assertThat(deleteAction.isPost()).isTrue(); }
@Test public void define_version_action() { WebService.Controller controller = tester.controller("api/server"); assertThat(controller.actions()).hasSize(1); WebService.Action versionAction = controller.action("version"); assertThat(versionAction.since()).isEqualTo("2.10"); assertThat(versionAction.description()).isNotEmpty(); assertThat(versionAction.isPost()).isFalse(); }