@Test public void list_anyError() { when(service.listByDomainAndClientAndUser(anyString(), anyString(), anyString())).thenReturn(Single.error(new RuntimeException())); endpoint.handle(context); verify(context, times(1)).fail(errCaptor.capture()); Assert.assertTrue("Error must be propagated", errCaptor.getValue() instanceof RuntimeException); }
@Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()) .flatMapPublisher(Flowable::fromIterable) .map(Resource::getId) .collect(JsonArray::new, JsonArray::add) .subscribe( buffer -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(buffer.isEmpty()?HttpStatusCode.NO_CONTENT_204:HttpStatusCode.OK_200) .end(Json.encodePrettily(buffer)) , error -> context.fail(error) ); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { @Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()) .flatMapPublisher(Flowable::fromIterable) .map(Resource::getId) .collect(JsonArray::new, JsonArray::add) .subscribe( buffer -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(buffer.isEmpty()?HttpStatusCode.NO_CONTENT_204:HttpStatusCode.OK_200) .end(Json.encodePrettily(buffer)) , error -> context.fail(error) ); } }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { @Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()) .flatMapPublisher(Flowable::fromIterable) .map(Resource::getId) .collect(JsonArray::new, JsonArray::add) .subscribe( buffer -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(buffer.isEmpty()?HttpStatusCode.NO_CONTENT_204:HttpStatusCode.OK_200) .end(Json.encodePrettily(buffer)) , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { @Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()) .flatMapPublisher(Flowable::fromIterable) .map(Resource::getId) .collect(JsonArray::new, JsonArray::add) .subscribe( buffer -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(buffer.isEmpty()?HttpStatusCode.NO_CONTENT_204:HttpStatusCode.OK_200) .end(Json.encodePrettily(buffer)) , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); @Override void handle(RoutingContext context); void create(RoutingContext context); void get(RoutingContext context); void update(RoutingContext context); void delete(RoutingContext context); }
ResourceRegistrationEndpoint implements Handler<RoutingContext> { @Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()) .flatMapPublisher(Flowable::fromIterable) .map(Resource::getId) .collect(JsonArray::new, JsonArray::add) .subscribe( buffer -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(buffer.isEmpty()?HttpStatusCode.NO_CONTENT_204:HttpStatusCode.OK_200) .end(Json.encodePrettily(buffer)) , error -> context.fail(error) ); } ResourceRegistrationEndpoint(Domain domain, ResourceService resourceService); @Override void handle(RoutingContext context); void create(RoutingContext context); void get(RoutingContext context); void update(RoutingContext context); void delete(RoutingContext context);  }