Search in sources :

Example 1 with RatingEntity

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

the class ApiRatingsResourceTest method init.

@Before
public void init() throws IOException {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    RatingEntity rating1 = new RatingEntity();
    RatingEntity rating2 = new RatingEntity();
    List<RatingEntity> ratingEntityPage = Arrays.asList(rating1, rating2);
    doReturn(ratingEntityPage).when(ratingService).findByApi(eq(API));
    Rating rating = new Rating();
    rating.setId(RATING);
    rating.setComment(RATING);
    rating.setValue(1);
    doReturn(rating).when(ratingMapper).convert(any(), any());
    RatingEntity createdRating = new RatingEntity();
    createdRating.setId(RATING);
    createdRating.setComment(RATING);
    createdRating.setRate((byte) 1);
    doReturn(createdRating).when(ratingService).create(any());
}
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) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 2 with RatingEntity

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

the class RatingMapperTest method testConvert.

@Test
public void testConvert() {
    Instant now = Instant.now();
    Date nowDate = Date.from(now);
    // init
    RatingEntity ratingEntity = new RatingEntity();
    RatingAnswerEntity ratingAnswerEntity = new RatingAnswerEntity();
    ratingAnswerEntity.setComment(RATING_RESPONSE_COMMENT);
    ratingAnswerEntity.setCreatedAt(nowDate);
    ratingAnswerEntity.setId(RATING_RESPONSE_ID);
    ratingAnswerEntity.setUser(RATING_RESPONSE_AUTHOR);
    ratingAnswerEntity.setUserDisplayName(RATING_RESPONSE_AUTHOR_DISPLAY_NAME);
    ratingEntity.setAnswers(Arrays.asList(ratingAnswerEntity));
    ratingEntity.setApi(RATING_API);
    ratingEntity.setComment(RATING_COMMENT);
    ratingEntity.setCreatedAt(nowDate);
    ratingEntity.setId(RATING_ID);
    ratingEntity.setRate((byte) 1);
    ratingEntity.setTitle(RATING_TITLE);
    ratingEntity.setUpdatedAt(nowDate);
    ratingEntity.setUser(RATING_AUTHOR);
    ratingEntity.setUserDisplayName(RATING_AUTHOR_DISPLAY_NAME);
    UserEntity authorEntity = new UserEntity();
    authorEntity.setId(RATING_AUTHOR);
    UserEntity responseAuthorEntity = new UserEntity();
    responseAuthorEntity.setId(RATING_RESPONSE_AUTHOR);
    User author = new User();
    author.setId(RATING_AUTHOR);
    User responseAuthor = new User();
    responseAuthor.setId(RATING_RESPONSE_AUTHOR);
    doReturn(authorEntity).when(userService).findById(RATING_AUTHOR);
    doReturn(responseAuthorEntity).when(userService).findById(RATING_RESPONSE_AUTHOR);
    doReturn(author).when(userMapper).convert(authorEntity);
    doReturn(responseAuthor).when(userMapper).convert(responseAuthorEntity);
    Rating responseRating = ratingMapper.convert(ratingEntity, uriInfo);
    assertNotNull(responseRating);
    List<RatingAnswer> answers = responseRating.getAnswers();
    assertNotNull(answers);
    assertEquals(1, answers.size());
    RatingAnswer ratingAnswer = answers.get(0);
    assertNotNull(ratingAnswer);
    assertEquals(RATING_RESPONSE_COMMENT, ratingAnswer.getComment());
    assertEquals(now.toEpochMilli(), ratingAnswer.getDate().toInstant().toEpochMilli());
    assertEquals(responseAuthor, ratingAnswer.getAuthor());
    assertEquals(author, responseRating.getAuthor());
    assertEquals(RATING_COMMENT, responseRating.getComment());
    assertEquals(RATING_TITLE, responseRating.getTitle());
    assertEquals(now.toEpochMilli(), responseRating.getDate().toInstant().toEpochMilli());
    assertEquals(RATING_ID, responseRating.getId());
    assertEquals(Integer.valueOf(1), responseRating.getValue());
}
Also used : RatingAnswer(io.gravitee.rest.api.portal.rest.model.RatingAnswer) User(io.gravitee.rest.api.portal.rest.model.User) Instant(java.time.Instant) Rating(io.gravitee.rest.api.portal.rest.model.Rating) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Date(java.util.Date) RatingAnswerEntity(io.gravitee.rest.api.model.RatingAnswerEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 3 with RatingEntity

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

the class ApiRatingAnswerResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    RatingEntity ratingEntity = new RatingEntity();
    ratingEntity.setId(RATING);
    ratingEntity.setComment(RATING);
    ratingEntity.setApi(API);
    ratingEntity.setRate(Integer.valueOf(1).byteValue());
    RatingAnswerEntity answer = new RatingAnswerEntity();
    answer.setId(ANSWER);
    ratingEntity.setAnswers(Arrays.asList(answer));
    doReturn(ratingEntity).when(ratingService).findById(eq(RATING));
    doReturn(ratingEntity).when(ratingService).createAnswer(any());
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Assert.assertNotNull(org.junit.Assert.assertNotNull) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Set(java.util.Set) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) HashSet(java.util.HashSet) List(java.util.List) RatingAnswerInput(io.gravitee.rest.api.portal.rest.model.RatingAnswerInput) Response(javax.ws.rs.core.Response) Rating(io.gravitee.rest.api.portal.rest.model.Rating) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) RatingAnswerEntity(io.gravitee.rest.api.model.RatingAnswerEntity) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) RatingAnswerEntity(io.gravitee.rest.api.model.RatingAnswerEntity) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 4 with RatingEntity

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

the class ApiRatingResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    RatingEntity ratingEntity = new RatingEntity();
    ratingEntity.setId(RATING);
    ratingEntity.setComment(RATING);
    ratingEntity.setApi(API);
    ratingEntity.setRate(Integer.valueOf(1).byteValue());
    doReturn(ratingEntity).when(ratingService).findById(eq(RATING));
    doReturn(ratingEntity).when(ratingService).update(any());
}
Also used : RatingInput(io.gravitee.rest.api.portal.rest.model.RatingInput) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Assert.assertNotNull(org.junit.Assert.assertNotNull) NOT_FOUND_404(io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Set(java.util.Set) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) NO_CONTENT_204(io.gravitee.common.http.HttpStatusCode.NO_CONTENT_204) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) List(java.util.List) Response(javax.ws.rs.core.Response) Rating(io.gravitee.rest.api.portal.rest.model.Rating) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 5 with RatingEntity

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

the class ApiRatingAnswersResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    RatingEntity ratingEntity = new RatingEntity();
    ratingEntity.setId(RATING);
    ratingEntity.setApi(API);
    ratingEntity.setComment(RATING);
    ratingEntity.setRate(Integer.valueOf(1).byteValue());
    doReturn(ratingEntity).when(ratingService).findById(eq(RATING));
    doReturn(ratingEntity).when(ratingService).createAnswer(any());
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) 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) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) Entity(javax.ws.rs.client.Entity) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Response(javax.ws.rs.core.Response) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) RatingEntity(io.gravitee.rest.api.model.RatingEntity) Before(org.junit.Before)

Aggregations

RatingEntity (io.gravitee.rest.api.model.RatingEntity)12 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)10 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)6 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)6 Rating (io.gravitee.rest.api.portal.rest.model.Rating)5 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)5 Test (org.junit.Test)5 Error (io.gravitee.rest.api.portal.rest.model.Error)4 RatingNotFoundException (io.gravitee.rest.api.service.exceptions.RatingNotFoundException)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Entity (javax.ws.rs.client.Entity)4 Response (javax.ws.rs.core.Response)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Before (org.junit.Before)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 Mockito.doReturn (org.mockito.Mockito.doReturn)4 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)3 RatingAnswerEntity (io.gravitee.rest.api.model.RatingAnswerEntity)3