use of io.gravitee.rest.api.portal.rest.model.ErrorResponse in project gravitee-management-rest-api by gravitee-io.
the class ApiMetricsResourceTest method shouldNotFoundApiWhileGettingApiMetrics.
@Test
public void shouldNotFoundApiWhileGettingApiMetrics() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
doReturn(emptySet()).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
// test
final Response response = target(API).path("metrics").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 shouldNotFoundApiWhileGettingApiPage.
@Test
public void shouldNotFoundApiWhileGettingApiPage() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
doReturn(false).when(accessControlService).canAccessApiFromPortal(API);
// test
final Response response = target(API).path("pages").path(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.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 shouldNotFoundPageWhileGettingApiPageContent.
@Test
public void shouldNotFoundPageWhileGettingApiPageContent() {
doThrow(new PageNotFoundException(UNKNOWN_PAGE)).when(pageService).findById(UNKNOWN_PAGE, null);
final Response response = target(API).path("pages").path(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);
assertEquals("errors.page.notFound", error.getCode());
assertEquals("404", error.getStatus());
assertEquals("Page [" + UNKNOWN_PAGE + "] 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 ApiPlansResourceTest method shouldHaveNotFoundWhileGettingApiPlans.
@Test
public void shouldHaveNotFoundWhileGettingApiPlans() {
// init
ApiEntity userApi = new ApiEntity();
userApi.setId("1");
doReturn(emptySet()).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
// test
final Response response = target(API).path("plans").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 ConstraintValidationExceptionMapper method buildErrorList.
private ErrorResponse buildErrorList(ConstraintViolationException cve) {
ErrorResponse response = new ErrorResponse();
for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
String detail = violation.getMessage();
Object invalidValue = violation.getInvalidValue();
if (invalidValue != null) {
detail += "\n" + invalidValue;
}
Error error = new Error().code(violation.getPropertyPath().toString()).message(detail);
response.addErrorsItem(error);
}
return response;
}
Aggregations