SetSpaceResource { @POST @Produces(MediaType.APPLICATION_JSON) public SetSpaceResponse handlePost(@PathParam("host") String server, @PathParam("freeSpace") long freeSpace, @PathParam("maxSpace") long maxSpace) { SetSpaceResponse response; try { clusterManager.setDiskSpace(server, new DiskSpace(freeSpace, maxSpace)); response = SetSpaceResponse.okResponse(); } catch (DiskSpaceCheckerException e) { response = new SetSpaceResponse(SetSpaceResponse.ResponseCode.ERROR, e.getMessage()); } return response; } SetSpaceResource(ClusterDiskSpaceManager clusterManager); @POST @Produces(MediaType.APPLICATION_JSON) SetSpaceResponse handlePost(@PathParam("host") String server,
									   @PathParam("freeSpace") long freeSpace,
									   @PathParam("maxSpace") long maxSpace);  }
@Test public void returnsErrorOnException() throws Exception { final String server = "dummy"; doThrow(new DiskSpaceCheckerException("Error")).when(manager).setDiskSpace(eq(server), isA(DiskSpace.class)); SetSpaceResponse response = resource.handlePost(server, 128L, 1024L); assertThat(response).isNotNull(); assertThat(response.getResponseCode()).isEqualTo(SetSpaceResponse.ResponseCode.ERROR); assertThat(response.getMessage()).isEqualTo("Error"); verify(manager).setDiskSpace(eq(server), isA(DiskSpace.class)); }
@Test public void recordsUpdate() throws Exception { final String server = "dummy"; SetSpaceResponse response = resource.handlePost(server, 128L, 1024L); assertThat(response).isNotNull(); assertThat(response.getResponseCode()).isEqualTo(SetSpaceResponse.ResponseCode.OK); assertThat(response.getMessage()).isNull(); verify(manager).setDiskSpace(eq(server), isA(DiskSpace.class)); }