Search in sources :

Example 26 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class PermissionsResourceTest method shouldHaveApplicationNotFoundExceptionWithFakeApplicationId.

@Test
public void shouldHaveApplicationNotFoundExceptionWithFakeApplicationId() {
    final Response response = target().queryParam("applicationId", "fake").request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    List<Error> errors = response.readEntity(ErrorResponse.class).getErrors();
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.application.notFound", error.getCode());
    assertEquals("Application [fake] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 27 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ApiRatingResourceTest method shouldHaveApiNotFoundWhenDeleteWithFakeApiId.

@Test
public void shouldHaveApiNotFoundWhenDeleteWithFakeApiId() {
    final String fakeId = "fake";
    final Response response = target(fakeId).path("ratings").path(RATING).request().delete();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + fakeId + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 28 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ApiRatingResourceTest method shouldHaveApiNotFoundWhenUpdateWithFakeApiId.

@Test
public void shouldHaveApiNotFoundWhenUpdateWithFakeApiId() {
    RatingInput ratingInput = new RatingInput().comment(RATING).value(2);
    final String fakeId = "fake";
    final Response response = target(fakeId).path("ratings").path(RATING).request().put(Entity.json(ratingInput));
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + fakeId + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) RatingInput(io.gravitee.rest.api.portal.rest.model.RatingInput) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 29 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ApiRatingsResourceTest method shouldGetServiceUnavailable.

@Test
public void shouldGetServiceUnavailable() {
    doThrow(ApiRatingUnavailableException.class).when(ratingService).create(any());
    RatingInput ratingInput = new RatingInput().comment(RATING).value(1);
    final Response response = target(API).path("ratings").request().post(Entity.json(ratingInput));
    assertEquals(SERVICE_UNAVAILABLE_503, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.rating.disabled", error.getCode());
    assertEquals("503", error.getStatus());
    assertEquals("API rating service is unavailable.", error.getMessage());
}
Also used : Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Example 30 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ApiRatingsResourceTest method shouldNotFoundWhileCreatingApiRatings.

@Test
public void shouldNotFoundWhileCreatingApiRatings() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    doReturn(emptySet()).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    // test
    RatingInput ratingInput = new RatingInput().comment(RATING).value(1);
    final Response response = target(API).path("ratings").request().post(Entity.json(ratingInput));
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.api.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Api [" + API + "] can not be found.", error.getMessage());
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Collections.emptySet(java.util.Collections.emptySet) Assert.assertNotNull(org.junit.Assert.assertNotNull) RatingEntity(io.gravitee.rest.api.model.RatingEntity) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) List(java.util.List) Response(javax.ws.rs.core.Response) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Aggregations

Error (io.gravitee.rest.api.portal.rest.model.Error)41 Response (javax.ws.rs.core.Response)39 Test (org.junit.Test)39 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)24 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)11 IOException (java.io.IOException)5 Collections.emptySet (java.util.Collections.emptySet)5 Collections.singletonList (java.util.Collections.singletonList)5 Before (org.junit.Before)5 Mockito.doReturn (org.mockito.Mockito.doReturn)5 HashSet (java.util.HashSet)4 NOT_FOUND_404 (io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404)3 OK_200 (io.gravitee.common.http.HttpStatusCode.OK_200)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Set (java.util.Set)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 ArgumentMatchers (org.mockito.ArgumentMatchers)3 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)2