Search in sources :

Example 1 with ErrorResponse

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

the class PageResourceTest method shouldNotGetPageContent.

@Test
public void shouldNotGetPageContent() {
    final Response response = target(UNKNOWN_PAGE).path("content").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.page.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Page [" + UNKNOWN_PAGE + "] 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 2 with ErrorResponse

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

the class PageResourceTest method shouldNotGetPage.

@Test
public void shouldNotGetPage() {
    final Response response = target(UNKNOWN_PAGE).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.page.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Page [" + UNKNOWN_PAGE + "] 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 3 with ErrorResponse

use of io.gravitee.rest.api.portal.rest.model.ErrorResponse 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 4 with ErrorResponse

use of io.gravitee.rest.api.portal.rest.model.ErrorResponse 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 5 with ErrorResponse

use of io.gravitee.rest.api.portal.rest.model.ErrorResponse 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)

Aggregations

Error (io.gravitee.rest.api.portal.rest.model.Error)21 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)21 Response (javax.ws.rs.core.Response)19 Test (org.junit.Test)19 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 NOT_FOUND_404 (io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404)3 OK_200 (io.gravitee.common.http.HttpStatusCode.OK_200)3 IOException (java.io.IOException)3 Collections.emptySet (java.util.Collections.emptySet)3 Collections.singletonList (java.util.Collections.singletonList)3 Before (org.junit.Before)3 Mockito.doReturn (org.mockito.Mockito.doReturn)3 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)2 RatingInput (io.gravitee.rest.api.portal.rest.model.RatingInput)2 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)2 java.util (java.util)2 Assert (org.junit.Assert)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1