Search in sources :

Example 1 with ResourceNotFoundException

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);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ResourceNotFoundException(io.gravitee.am.service.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 2 with 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);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ResourceNotFoundException(io.gravitee.am.service.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 3 with 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));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) ResourceNotFoundException(io.gravitee.am.service.exception.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (io.gravitee.am.service.exception.ResourceNotFoundException)3 JsonObject (io.vertx.core.json.JsonObject)2 Test (org.junit.Test)2 JWT (io.gravitee.am.common.jwt.JWT)1 Client (io.gravitee.am.model.oidc.Client)1