use of io.gravitee.rest.api.portal.rest.model.ErrorResponse in project gravitee-management-rest-api by gravitee-io.
the class AbstractExceptionMapper method convert.
protected ErrorResponse convert(final int status, final String message, final String code, final Map<String, String> parameters) {
final Error error = new Error();
error.setStatus(String.valueOf(status));
error.message(message);
error.code("errors." + code);
error.parameters(parameters);
ErrorResponse response = new ErrorResponse();
response.addErrorsItem(error);
return response;
}
use of io.gravitee.rest.api.portal.rest.model.ErrorResponse 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());
}
use of io.gravitee.rest.api.portal.rest.model.ErrorResponse 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());
}
use of io.gravitee.rest.api.portal.rest.model.ErrorResponse in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResourceTest method shouldNotFoundApiWhileGettingApiPageContent.
@Test
public void shouldNotFoundApiWhileGettingApiPageContent() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
doReturn(false).when(accessControlService).canAccessApiFromPortal(API);
// test
final Response response = target(API).path("pages").path(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.api.notFound", error.getCode());
assertEquals("404", error.getStatus());
assertEquals("Api [" + API + "] can not be found.", error.getMessage());
}
use of io.gravitee.rest.api.portal.rest.model.ErrorResponse in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResourceTest method shouldNotFoundPageWhileGettingApiPage.
@Test
public void shouldNotFoundPageWhileGettingApiPage() {
doThrow(new PageNotFoundException(UNKNOWN_PAGE)).when(pageService).findById(UNKNOWN_PAGE, null);
final Response response = target(API).path("pages").path(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);
assertEquals("errors.page.notFound", error.getCode());
assertEquals("404", error.getStatus());
assertEquals("Page [" + UNKNOWN_PAGE + "] can not be found.", error.getMessage());
}
Aggregations