Search in sources :

Example 31 with Error

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

the class ApiRatingsResourceTest method shouldNotFoundWhileGettingApiRatings.

@Test
public void shouldNotFoundWhileGettingApiRatings() {
    // 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("ratings").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 : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Collections.emptySet(java.util.Collections.emptySet) Assert.assertNotNull(org.junit.Assert.assertNotNull) RatingEntity(io.gravitee.rest.api.model.RatingEntity) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) List(java.util.List) Response(javax.ws.rs.core.Response) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Example 32 with Error

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

the class ApplicationMembersResourceTest method shouldHaveBadRequestWhileCreatingNewMemberAsPrimaryOwner.

// 400 POST /members
@Test
public void shouldHaveBadRequestWhileCreatingNewMemberAsPrimaryOwner() {
    MemberInput memberInput = new MemberInput().role("PRIMARY_OWNER").user(MEMBER_1);
    final Response response = target(APPLICATION).path("members").request().post(Entity.json(memberInput));
    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("An APPLICATION must always have only one PRIMARY_OWNER !", error.getMessage());
}
Also used : Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Example 33 with Error

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

the class ApiPagesResourceTest method shouldNotFoundWhileGettingApiPages.

@Test
public void shouldNotFoundWhileGettingApiPages() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    when(accessControlService.canAccessApiFromPortal(API)).thenReturn(false);
    // test
    final Response response = target(API).path("pages").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 : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Example 34 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 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());
}
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 35 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 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());
}
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)

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