TableManagerResource { @POST @Timed @ApiOperation("Save Table") public Response save(@Valid final Table table, @QueryParam("forceCreate") @DefaultValue("false") boolean forceCreate) { table.setName(ElasticsearchUtils.getValidTableName(table.getName())); tableManager.save(table, forceCreate); return Response.ok(table) .build(); } @Inject  TableManagerResource(TableManager tableManager); @POST @Timed @ApiOperation("Save Table") Response save(@Valid final Table table, @QueryParam("forceCreate") @DefaultValue("false") boolean forceCreate); @GET @Timed @Path("/{name}") @ApiOperation("Get Table") Response get(@PathParam("name") String name); @PUT @Timed @Path("/{name}") @ApiOperation("Update Table") Response get(@PathParam("name") final String name, @Valid final Table table); @DELETE @Timed @Path("/{name}/delete") @ApiOperation("Delete Table") Response delete(@PathParam("name") String name); @GET @Timed @ApiOperation("Get all Tables") Response getAll();  }
@Test public void testSave() throws Exception { doNothing().when(getDataStore()) .initializeTable(any(Table.class), anyBoolean()); doNothing().when(getQueryStore()) .initializeTable(any(String.class)); Table table = Table.builder() .name(TEST_TABLE_NAME) .ttl(7) .build(); Entity<Table> tableEntity = Entity.json(table); resources.client() .target("/v1/tables") .request() .post(tableEntity); Table response = tableManager.get(table.getName()); assertNotNull(response); assertEquals(table.getName(), response.getName()); assertEquals(table.getTtl(), response.getTtl()); reset(tableManager); reset(getQueryStore()); reset(getDataStore()); }
@Test public void testSaveBackendError() throws Exception { Table table = Table.builder() .name(UUID.randomUUID() .toString()) .ttl(30) .build(); Entity<Table> tableEntity = Entity.json(table); doThrow(FoxtrotExceptions.createExecutionException("dummy", new IOException())).when(tableManager) .save(Matchers.<Table>any()); Response response = resources.client() .target("/v1/tables") .request() .post(tableEntity); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); reset(tableManager); }