Search in sources :

Example 6 with Error

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

the class ApiRatingAnswerResourceTest method shouldHaveApiNotFoundWhenDeleteWithFakeApi.

@Test
public void shouldHaveApiNotFoundWhenDeleteWithFakeApi() {
    final String fakeId = "fake";
    final Response response = target(fakeId).path("ratings").path(RATING).path("answers").path(ANSWER).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());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 7 with Error

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

the class ApiRatingAnswerResourceTest method shouldHaveRatingAnswerNotFoundWhenDeleteWithFakeId.

@Test
public void shouldHaveRatingAnswerNotFoundWhenDeleteWithFakeId() {
    final String fakeId = "fake";
    final Response response = target(API).path("ratings").path(fakeId).path("answers").path(ANSWER).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.rating.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Rating [" + fakeId + "] can not be found on the api [" + API + "]", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 8 with Error

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

the class ApiRatingAnswerResourceTest method shouldHaveRatingNotFoundWhenDeleteWithFakeRating.

@Test
public void shouldHaveRatingNotFoundWhenDeleteWithFakeRating() {
    final String fakeId = "fake";
    final Response response = target(API).path("ratings").path(fakeId).path("answers").path(ANSWER).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.rating.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Rating [" + fakeId + "] can not be found on the api [" + API + "]", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 9 with Error

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

the class ApiRatingResourceTest method shouldHaveRatingNotFoundWhenUpdateWithFakeRatingId.

@Test
public void shouldHaveRatingNotFoundWhenUpdateWithFakeRatingId() {
    RatingInput ratingInput = new RatingInput().comment(RATING).value(2);
    final String fakeId = "fake";
    final Response response = target(API).path("ratings").path(fakeId).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.rating.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Rating [" + fakeId + "] can not be found on the api [" + API + "]", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) RatingInput(io.gravitee.rest.api.portal.rest.model.RatingInput) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 10 with Error

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

the class ApiRatingResourceTest method shouldHaveRatingNotFoundWhenDeleteWithFakeRatingId.

@Test
public void shouldHaveRatingNotFoundWhenDeleteWithFakeRatingId() {
    final String fakeId = "fake";
    final Response response = target(API).path("ratings").path(fakeId).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.rating.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Rating [" + fakeId + "] can not be found on the api [" + API + "]", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) 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