TableMetadataResource { @POST public Table save(@Valid final Table table) { try { tableMetadataManager.save(table); } catch (Exception e) { logger.error(String.format("Unable to save table %s", table), e); throw new WebApplicationException(Response.serverError().entity(Collections.singletonMap("error", e.getMessage())).build()); } return table; } TableMetadataResource(TableMetadataManager tableMetadataManager); @POST Table save(@Valid final Table table); @GET @Path("/{name}") Table get(@PathParam("name") final String name); @DELETE @Path("/{name}/delete") void delete(@PathParam("name") final String name); @GET List<Table> get();  }
@Test public void testSave() throws Exception { Table table = new Table(TestUtils.TEST_TABLE_NAME, 30); client().resource("/v1/tables").type(MediaType.APPLICATION_JSON_TYPE).post(table); Table response = tableMetadataManager.get(table.getName()); assertNotNull(response); assertEquals(table.getName(), response.getName()); assertEquals(table.getTtl(), response.getTtl()); }
@Test public void testSaveBackendError() throws Exception { Table table = new Table(UUID.randomUUID().toString(), 30); doThrow(new Exception()).when(tableMetadataManager).save(Matchers.<Table>any()); try { client().resource("/v1/tables").type(MediaType.APPLICATION_JSON_TYPE).post(table); } catch (UniformInterfaceException ex) { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ex.getResponse().getStatus()); } }