@Test public void handle_unableToParse() { when(context.getBody()).thenReturn(null); endpoint.handle(context); verify(context,times(1)).fail(errCaptor.capture()); Assert.assertTrue(errCaptor.getValue() instanceof InvalidRequestException); }
@Override public void handle(RoutingContext context) { JWT accessToken = context.get(OAuth2AuthHandler.TOKEN_CONTEXT_KEY); Client client = context.get(OAuth2AuthHandler.CLIENT_CONTEXT_KEY); this.extractRequest(context) .flatMap(this::bodyValidation) .map(this::toPermissionRequest) .flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())) .map(PermissionTicketResponse::from) .subscribe( permission -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(permission)) , error -> context.fail(error) ); }
PermissionEndpoint 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.extractRequest(context) .flatMap(this::bodyValidation) .map(this::toPermissionRequest) .flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())) .map(PermissionTicketResponse::from) .subscribe( permission -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(permission)) , error -> context.fail(error) ); } }
PermissionEndpoint 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.extractRequest(context) .flatMap(this::bodyValidation) .map(this::toPermissionRequest) .flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())) .map(PermissionTicketResponse::from) .subscribe( permission -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(permission)) , error -> context.fail(error) ); } PermissionEndpoint(Domain domain, PermissionTicketService permissionTicketService); }
PermissionEndpoint 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.extractRequest(context) .flatMap(this::bodyValidation) .map(this::toPermissionRequest) .flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())) .map(PermissionTicketResponse::from) .subscribe( permission -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(permission)) , error -> context.fail(error) ); } PermissionEndpoint(Domain domain, PermissionTicketService permissionTicketService); @Override void handle(RoutingContext context); }
PermissionEndpoint 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.extractRequest(context) .flatMap(this::bodyValidation) .map(this::toPermissionRequest) .flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())) .map(PermissionTicketResponse::from) .subscribe( permission -> context.response() .putHeader(HttpHeaders.CACHE_CONTROL, "no-store") .putHeader(HttpHeaders.PRAGMA, "no-cache") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setStatusCode(HttpStatusCode.CREATED_201) .end(Json.encodePrettily(permission)) , error -> context.fail(error) ); } PermissionEndpoint(Domain domain, PermissionTicketService permissionTicketService); @Override void handle(RoutingContext context);  }