@Test public void success_extendedRequest() { PermissionTicket success = new PermissionTicket().setId("success"); final String extendedRequest = "[{\"resource_id\":\"{{set_one}}\", \"resource_scopes\":[\"profile:read\"]}, {\"resource_id\":\"{{set_two}}\",\"resource_scopes\":[\"avatar:write\"]}]"; when(context.getBody()).thenReturn(Buffer.buffer(extendedRequest)); when(context.response()).thenReturn(response); when(response.putHeader(anyString(),anyString())).thenReturn(response); when(response.setStatusCode(anyInt())).thenReturn(response); when(permissionTicketService.create(anyList(), eq(DOMAIN_ID), eq(CLIENT_ID))).thenReturn(Single.just(success)); endpoint.handle(context); verify(response, times(1)).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); verify(context.response(), times(1)).setStatusCode(intCaptor.capture()); verify(context.response(), times(1)).end(strCaptor.capture()); Assert.assertEquals("Expecting 201 creation status",intCaptor.getValue().intValue(),201); Assert.assertTrue("Expect success id", strCaptor.getValue().contains("success")); }
@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);  }