Search in sources :

Example 21 with Error

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

the class CategoriesResourceTest method shouldGetNoCategory.

@Test
public void shouldGetNoCategory() {
    final Response response = target().queryParam("page", 10).queryParam("size", 1).request().get();
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertEquals("errors.pagination.invalid", error.getCode());
    assertEquals("400", error.getStatus());
    assertEquals("Pagination is not valid", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) CategoriesResponse(io.gravitee.rest.api.portal.rest.model.CategoriesResponse) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 22 with Error

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

the class CategoryResourceTest method shouldNotGetCategory.

@Test
public void shouldNotGetCategory() {
    doThrow(new CategoryNotFoundException(UNKNOWN_CATEGORY)).when(categoryService).findNotHiddenById(UNKNOWN_CATEGORY);
    final Response response = target(UNKNOWN_CATEGORY).request().get();
    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.category.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Category [" + UNKNOWN_CATEGORY + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) CategoryNotFoundException(io.gravitee.rest.api.service.exceptions.CategoryNotFoundException) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 23 with Error

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

the class SubscriptionResourceTest method shouldNotGetSubscription.

@Test
public void shouldNotGetSubscription() {
    final Response response = target(UNKNOWN_SUBSCRIPTION).request().get();
    assertEquals(HttpStatusCode.NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
}
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 24 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 shouldHaveBadRequestExceptionWithoutQueryParam.

@Test
public void shouldHaveBadRequestExceptionWithoutQueryParam() {
    final Response response = target().request().get();
    assertEquals(BAD_REQUEST_400, response.getStatus());
    List<Error> errors = response.readEntity(ErrorResponse.class).getErrors();
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.unexpected", error.getCode());
    assertEquals("One of the two parameters appId or applicationId must not be null.", 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 25 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 shouldHaveApiNotFoundExceptionWithFakeApiId.

@Test
public void shouldHaveApiNotFoundExceptionWithFakeApiId() {
    final Response response = target().queryParam("apiId", "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.api.notFound", error.getCode());
    assertEquals("Api [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)

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