FileMetadataRegistryOnPostgres implements FileMetadataRegistry { @Override public Single<UUID> delete(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable("DELETE FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { if (rs.getUpdated() == 0) { throw new BrownieFileNotFoundException(fileId); } return fileId; }); }  @Override Observable<FileMetadata> iterate(); @Override Single<FileMetadata> store(FileMetadata metadata); @Override Single<FileMetadata> update(FileMetadata metadata); @Override Single<FileMetadata> load(UUID fileId); @Override Single<UUID> delete(UUID fileId);  }
@Test public void testDelete(TestContext context) { UUID fileId = UUID.randomUUID(); Async async = context.async(); FileMetadata metadata = new FileMetadata(fileId, "name", MimeType.valueOf("text/plain"), 6, Instant.now()); registry.store(metadata).flatMap(v -> { return registry.delete(fileId); }).flatMap(v -> { return registry.load(fileId); }).subscribe(v -> { context.fail(); }, error -> { context.assertTrue(error instanceof BrownieFileNotFoundException); async.complete(); }); }
@Test public void testDeleteWhichDoesNotExist(TestContext context) { UUID fileId = UUID.randomUUID(); Async async = context.async(); registry.delete(fileId).subscribe(v -> { context.fail(); }, error -> { context.assertTrue(error instanceof BrownieFileNotFoundException); async.complete(); }); }