@Test public void testAdd() throws IllegalArgumentException, URISyntaxException { UriBuilder uriBuilder = new UriBuilderImpl(new URI(RESOURCE_PATH)); when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder); Response resp = taskRes.addTask(task1); verify(taskService).addOrUpdate(task1); assertThat(resp.getStatus(), equalTo(201)); URI expectedRedirect = new URI(RESOURCE_PATH + "/1"); assertThat(resp.getHeaders().get("Location"), contains(expectedRedirect)); }
@Operation(description = "Add task") @POST public Response addTask(Task task) { taskService.addOrUpdate(task); URI taskURI = uriInfo.getRequestUriBuilder().path(TaskResource.class, "getTask").build(task.getId()); return Response.created(taskURI).build(); }
TaskResource { @Operation(description = "Add task") @POST public Response addTask(Task task) { taskService.addOrUpdate(task); URI taskURI = uriInfo.getRequestUriBuilder().path(TaskResource.class, "getTask").build(task.getId()); return Response.created(taskURI).build(); } }
TaskResource { @Operation(description = "Add task") @POST public Response addTask(Task task) { taskService.addOrUpdate(task); URI taskURI = uriInfo.getRequestUriBuilder().path(TaskResource.class, "getTask").build(task.getId()); return Response.created(taskURI).build(); } TaskResource(TaskService taskService, MetricRegistry metricRegistry); }
TaskResource { @Operation(description = "Add task") @POST public Response addTask(Task task) { taskService.addOrUpdate(task); URI taskURI = uriInfo.getRequestUriBuilder().path(TaskResource.class, "getTask").build(task.getId()); return Response.created(taskURI).build(); } TaskResource(TaskService taskService, MetricRegistry metricRegistry); @Operation(summary = "Get single task by id", description = "Get single task by id") @GET @Path("{id}") Response getTask(@PathParam("id") Integer id); @Operation(description = "Add task") @POST Response addTask(Task task); @Operation(description = "Get all tasks") @GET @Produces(MediaType.APPLICATION_JSON) Collection<Task> getTasks(); @Operation(description = "Change task") @PUT @Path("{id}") void updateTask(@PathParam("id") Integer id, Task task); @Operation(description = "Delete task") @DELETE @Path("{id}") void deleteTask(@PathParam("id") Integer id); }
TaskResource { @Operation(description = "Add task") @POST public Response addTask(Task task) { taskService.addOrUpdate(task); URI taskURI = uriInfo.getRequestUriBuilder().path(TaskResource.class, "getTask").build(task.getId()); return Response.created(taskURI).build(); } TaskResource(TaskService taskService, MetricRegistry metricRegistry); @Operation(summary = "Get single task by id", description = "Get single task by id") @GET @Path("{id}") Response getTask(@PathParam("id") Integer id); @Operation(description = "Add task") @POST Response addTask(Task task); @Operation(description = "Get all tasks") @GET @Produces(MediaType.APPLICATION_JSON) Collection<Task> getTasks(); @Operation(description = "Change task") @PUT @Path("{id}") void updateTask(@PathParam("id") Integer id, Task task); @Operation(description = "Delete task") @DELETE @Path("{id}") void deleteTask(@PathParam("id") Integer id);  }