Search in sources :

Example 11 with Error

use of io.gravitee.rest.api.portal.rest.model.Error 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) Collections.emptySet(java.util.Collections.emptySet) ApiMetrics(io.gravitee.rest.api.portal.rest.model.ApiMetrics) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) IOException(java.io.IOException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Collections.singletonList(java.util.Collections.singletonList) Response(javax.ws.rs.core.Response) StatsQuery(io.gravitee.rest.api.model.analytics.query.StatsQuery) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Before(org.junit.Before) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 12 with Error

use of io.gravitee.rest.api.portal.rest.model.Error 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());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 13 with Error

use of io.gravitee.rest.api.portal.rest.model.Error 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());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 14 with Error

use of io.gravitee.rest.api.portal.rest.model.Error 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Collections.emptySet(java.util.Collections.emptySet) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assert.assertNotNull(org.junit.Assert.assertNotNull) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) Set(java.util.Set) Plan(io.gravitee.rest.api.portal.rest.model.Plan) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) List(java.util.List) Response(javax.ws.rs.core.Response) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 15 with Error

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

the class ApiRatingAnswersResourceTest method shouldHaveRatingNotFoundWhenCreateApiRatingAnswerWithFakeRatingId.

@Test
public void shouldHaveRatingNotFoundWhenCreateApiRatingAnswerWithFakeRatingId() {
    RatingAnswerInput ratingAnswerInput = new RatingAnswerInput().comment(RATING);
    final String fakeId = "fake";
    final Response response = target(API).path("ratings").path(fakeId).path("answers").request().post(Entity.json(ratingAnswerInput));
    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.rating.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Rating [" + fakeId + "] can not be found on the api [" + API + "]", error.getMessage());
}
Also used : Response(javax.ws.rs.core.Response) 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