Search in sources :

Example 1 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 shouldBadRequestWhileCreatingApiRatings.

@Test
public void shouldBadRequestWhileCreatingApiRatings() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(userApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any());
    // test
    final Response response = target(API).path("ratings").request().post(Entity.json(null));
    assertEquals(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);
    assertNotNull(error);
    assertEquals("errors.unexpected", error.getCode());
    assertEquals("400", error.getStatus());
    assertEquals("Input must not be null.", 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Error

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

the class ApiResourceTest method shouldHaveNotFoundWhileGettingApiPicture.

@Test
public void shouldHaveNotFoundWhileGettingApiPicture() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(userApi));
    doReturn(mockApis).when(apiService).findByUser(any(), any(), eq(true));
    // test
    final Response response = target(API).path("picture").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 3 with Error

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

the class ApiResourceTest method shouldHaveNotFoundWhileGettingApi.

@Test
public void shouldHaveNotFoundWhileGettingApi() {
    // init
    ApiEntity userApi = new ApiEntity();
    userApi.setId("1");
    doReturn(false).when(accessControlService).canAccessApiFromPortal(API);
    // test
    final Response response = target(API).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 4 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 shouldHaveBadRequestWhileUpdatingMemberToPrimaryOwner.

@Test
public void shouldHaveBadRequestWhileUpdatingMemberToPrimaryOwner() {
    MemberInput memberInput = new MemberInput().role("PRIMARY_OWNER").user(MEMBER_1);
    final Response response = target(APPLICATION).path("members").path(MEMBER_1).request().put(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 5 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 shouldHaveBadRequestWhileTransferingOwnerShipToPrimaryOwner.

// 400 POST /members/_transfer_ownership
@Test
public void shouldHaveBadRequestWhileTransferingOwnerShipToPrimaryOwner() {
    TransferOwnershipInput input = new TransferOwnershipInput().newPrimaryOwnerId(MEMBER_1).primaryOwnerNewrole("PRIMARY_OWNER");
    final Response response = target(APPLICATION).path("members").path("_transfer_ownership").request().post(Entity.json(input));
    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)

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