Search in sources :

Example 1 with RatingInput

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

the class ApiRatingResourceTest method shouldUpdateApiRating.

@Test
public void shouldUpdateApiRating() {
    RatingInput ratingInput = new RatingInput().comment(RATING).value(2);
    Rating rating = new Rating();
    rating.setId(RATING);
    rating.setValue(2);
    doReturn(rating).when(ratingMapper).convert(any(), any());
    final Response response = target(API).path("ratings").path(RATING).request().put(Entity.json(ratingInput));
    Rating updatedRatingResponse = response.readEntity(Rating.class);
    assertNotNull(updatedRatingResponse);
    assertEquals(rating.getValue(), updatedRatingResponse.getValue());
}
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) Rating(io.gravitee.rest.api.portal.rest.model.Rating) Test(org.junit.Test)

Example 2 with RatingInput

use of io.gravitee.rest.api.portal.rest.model.RatingInput 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 3 with RatingInput

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

the class ApiRatingResourceTest method shouldHaveApiNotFoundWhenUpdateWithFakeApiId.

@Test
public void shouldHaveApiNotFoundWhenUpdateWithFakeApiId() {
    RatingInput ratingInput = new RatingInput().comment(RATING).value(2);
    final String fakeId = "fake";
    final Response response = target(fakeId).path("ratings").path(RATING).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.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) 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)

Aggregations

ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)3 RatingInput (io.gravitee.rest.api.portal.rest.model.RatingInput)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 Error (io.gravitee.rest.api.portal.rest.model.Error)2 Rating (io.gravitee.rest.api.portal.rest.model.Rating)1