use of io.gravitee.am.service.exception.ResourceNotFoundException in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpointTest method create_noResource.
@Test
public void create_noResource() {
when(context.getBodyAsJson()).thenReturn(new JsonObject("{\"id\":\"rs_id\",\"resource_scopes\":[\"scope\"]}"));
when(service.create(any(), eq(DOMAIN_ID), eq(CLIENT_ID), eq(USER_ID))).thenReturn(Single.error(new ResourceNotFoundException(RESOURCE_ID)));
endpoint.create(context);
verify(context).fail(errCaptor.capture());
Assert.assertTrue(errCaptor.getValue() instanceof ResourceNotFoundException);
}
use of io.gravitee.am.service.exception.ResourceNotFoundException in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpointTest method update_noResource.
@Test
public void update_noResource() {
when(context.getBodyAsJson()).thenReturn(new JsonObject("{\"id\":\"rs_id\",\"resource_scopes\":[\"scope\"]}"));
when(service.update(any(), eq(DOMAIN_ID), eq(CLIENT_ID), eq(USER_ID), eq(RESOURCE_ID))).thenReturn(Single.error(new ResourceNotFoundException(RESOURCE_ID)));
endpoint.update(context);
verify(context).fail(errCaptor.capture());
Assert.assertTrue(errCaptor.getValue() instanceof ResourceNotFoundException);
}
use of io.gravitee.am.service.exception.ResourceNotFoundException in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpoint method get.
public void get(RoutingContext context) {
JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
String resource_id = context.request().getParam(RESOURCE_ID);
this.resourceService.findByDomainAndClientAndUserAndResource(domain.getId(), client.getId(), accessToken.getSub(), resource_id).switchIfEmpty(Single.error(new ResourceNotFoundException(resource_id))).subscribe(resource -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setStatusCode(HttpStatusCode.OK_200).end(Json.encodePrettily(ResourceResponse.from(resource))), error -> context.fail(error));
}
Aggregations