private Action(Controller controller, NewAction newAction) { this.key = newAction.key; this.deprecatedKey = newAction.deprecatedKey; this.path = format("%s/%s", controller.path(), key); this.description = newAction.description; this.since = newAction.since; this.deprecatedSince = newAction.deprecatedSince; this.post = newAction.post; this.isInternal = newAction.isInternal; this.responseExample = newAction.responseExample; this.handler = newAction.handler; this.changelog = newAction.changelog; checkState(this.handler != null, "RequestHandler is not set on action %s", path); logWarningIf(isNullOrEmpty(this.description), "Description is not set on action " + path); logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path); logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path); Map<String, Param> paramsBuilder = new HashMap<>(); for (NewParam newParam : newAction.newParams.values()) { paramsBuilder.put(newParam.key, new Param(this, newParam)); } this.params = Collections.unmodifiableMap(paramsBuilder); }
private void initWebServiceEngine(WsUrl... wsUrls) { List<WebService.Controller> controllers = new ArrayList<>(); for (WsUrl wsUrl : wsUrls) { String controller = wsUrl.getController(); WebService.Controller wsController = mock(WebService.Controller.class); when(wsController.path()).thenReturn(controller); List<WebService.Action> actions = new ArrayList<>(); for (String action : wsUrl.getActions()) { WebService.Action wsAction = mock(WebService.Action.class); when(wsAction.path()).thenReturn(controller + "/" + action); when(wsAction.key()).thenReturn(action); when(wsAction.handler()).thenReturn(wsUrl.getRequestHandler()); actions.add(wsAction); } when(wsController.actions()).thenReturn(actions); controllers.add(wsController); } when(webServiceEngine.controllers()).thenReturn(controllers); underTest = new WebServiceFilter(webServiceEngine, runtime); }
@Test public void definition() { assertThat(underTest.path()).isEqualTo("api/project_tags"); assertThat(underTest.since()).isEqualTo("6.4"); assertThat(underTest.description()).isNotEmpty(); }
private Action(Controller controller, NewAction newAction) { this.key = newAction.key; this.deprecatedKey = newAction.deprecatedKey; this.path = format("%s/%s", controller.path(), key); this.description = newAction.description; this.since = newAction.since; this.deprecatedSince = newAction.deprecatedSince; this.post = newAction.post; this.isInternal = newAction.isInternal; this.responseExample = newAction.responseExample; this.handler = newAction.handler; this.changelog = newAction.changelog; checkState(this.handler != null, "RequestHandler is not set on action %s", path); logWarningIf(isNullOrEmpty(this.description), "Description is not set on action " + path); logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path); logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path); Map<String, Param> paramsBuilder = new HashMap<>(); for (NewParam newParam : newAction.newParams.values()) { paramsBuilder.put(newParam.key, new Param(this, newParam)); } this.params = Collections.unmodifiableMap(paramsBuilder); }
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 Action(Controller controller, NewAction newAction) { this.key = newAction.key; this.deprecatedKey = newAction.deprecatedKey; this.path = String.format("%s/%s", controller.path(), key); this.description = newAction.description; this.since = StringUtils.defaultIfBlank(newAction.since, controller.since); this.post = newAction.post; this.isInternal = newAction.isInternal; this.responseExample = newAction.responseExample; if (newAction.handler == null) { throw new IllegalArgumentException("RequestHandler is not set on action " + path); } this.handler = newAction.handler; ImmutableMap.Builder<String, Param> paramsBuilder = ImmutableMap.builder(); for (NewParam newParam : newAction.newParams.values()) { paramsBuilder.put(newParam.key, new Param(this, newParam)); } this.params = paramsBuilder.build(); }
assertThat(controller.path()).isEqualTo("api/metric"); assertThat(controller.description()).isEqualTo("Metrics"); assertThat(controller.since()).isEqualTo("3.2");
@Test public void define_ws() { WsTester tester = new WsTester(underTest); WebService.Controller controller = tester.controller("api/webservices"); assertThat(controller).isNotNull(); assertThat(controller.path()).isEqualTo("api/webservices"); assertThat(controller.since()).isEqualTo("4.2"); assertThat(controller.description()).isNotEmpty(); assertThat(controller.actions()).hasSize(2); WebService.Action index = controller.action("list"); assertThat(index).isNotNull(); assertThat(index.key()).isEqualTo("list"); assertThat(index.handler()).isNotNull(); assertThat(index.since()).isEqualTo("4.2"); assertThat(index.isPost()).isFalse(); assertThat(index.isInternal()).isFalse(); assertThat(controller.action("response_example")).isNotNull(); }
@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); }
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 definition() { assertThat(underTest.path()).isEqualTo("api/favorites"); } }
@Test public void definition() { assertThat(underTest.path()).isEqualTo("api/notifications"); }
@Test public void define_controller() { WebService.Controller controller = controller(); assertThat(controller).isNotNull(); assertThat(controller.path()).isEqualTo("api/profiles"); assertThat(controller.description()).isNotEmpty(); assertThat(controller.actions()).hasSize(2); }