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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations