use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.
the class MemberMapperTest method testConvert.
@Test
public void testConvert() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
RoleEntity ownerRoleEntity = new RoleEntity();
ownerRoleEntity.setName("OWNER");
memberEntity = new MemberEntity();
memberEntity.setCreatedAt(nowDate);
memberEntity.setDisplayName(MEMBER_DISPLAYNAME);
memberEntity.setEmail(MEMBER_EMAIL);
memberEntity.setId(MEMBER_ID);
memberEntity.setRoles(Arrays.asList(ownerRoleEntity));
memberEntity.setUpdatedAt(nowDate);
UserEntity userEntity = Mockito.mock(UserEntity.class);
when(userEntity.getDisplayName()).thenReturn(MEMBER_DISPLAYNAME);
when(userEntity.getEmail()).thenReturn(MEMBER_EMAIL);
when(userEntity.getId()).thenReturn(MEMBER_ID);
when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(""));
when(userService.findById(MEMBER_ID)).thenReturn(userEntity);
when(userMapper.convert(userEntity)).thenCallRealMethod();
when(userMapper.computeUserLinks(anyString(), any())).thenCallRealMethod();
// Test
Member responseMember = memberMapper.convert(memberEntity, uriInfo);
assertNotNull(responseMember);
assertEquals(now.toEpochMilli(), responseMember.getCreatedAt().toInstant().toEpochMilli());
assertNull(responseMember.getId());
assertEquals("OWNER", responseMember.getRole());
assertEquals(now.toEpochMilli(), responseMember.getUpdatedAt().toInstant().toEpochMilli());
User user = responseMember.getUser();
assertNotNull(user);
assertEquals(MEMBER_DISPLAYNAME, user.getDisplayName());
assertEquals(MEMBER_EMAIL, user.getEmail());
assertEquals(MEMBER_ID, user.getId());
assertEquals("environments/DEFAULT/users/" + MEMBER_ID + "/avatar?", user.getLinks().getAvatar());
}
use of io.gravitee.rest.api.portal.rest.model.User 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.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.
the class ApiMapperTest method testConvert.
@Test
public void testConvert() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
apiEntity = new ApiEntity();
apiEntity.setId(API_ID);
apiEntity.setDescription(API_DESCRIPTION);
apiEntity.setName(API_NAME);
apiEntity.setLabels(new ArrayList<>(Arrays.asList(API_LABEL)));
doThrow(CategoryNotFoundException.class).when(categoryService).findNotHiddenById(API_CATEGORY_HIDDEN);
apiEntity.setCategories(new HashSet<>(Arrays.asList(API_CATEGORY, API_CATEGORY_HIDDEN)));
apiEntity.setEntrypoints(Arrays.asList(new ApiEntrypointEntity(API_ENTRYPOINT_1), new ApiEntrypointEntity(API + "/foo")));
Map<String, Object> metadata = new HashMap<>();
metadata.put("meta", API);
apiEntity.setMetadata(metadata);
apiEntity.setVersion(API_VERSION);
UserEntity ownerEntity = new UserEntity();
ownerEntity.setId(API_OWNER_ID);
ownerEntity.setEmail(API_OWNER_EMAIL);
ownerEntity.setFirstname(API_OWNER_FIRSTNAME);
ownerEntity.setLastname(API_OWNER_LASTNAME);
apiEntity.setPrimaryOwner(new PrimaryOwnerEntity(ownerEntity));
RatingSummaryEntity ratingSummaryEntity = new RatingSummaryEntity();
ratingSummaryEntity.setAverageRate(Double.valueOf(4.2));
ratingSummaryEntity.setNumberOfRatings(10);
doReturn(true).when(ratingService).isEnabled();
doReturn(ratingSummaryEntity).when(ratingService).findSummaryByApi(API_ID);
doReturn(true).when(parameterService).findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED, ParameterReferenceType.ENVIRONMENT);
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/foo")));
apiEntity.setProxy(proxy);
apiEntity.setLifecycleState(ApiLifecycleState.PUBLISHED);
apiEntity.setUpdatedAt(nowDate);
// Test
Api responseApi = apiMapper.convert(apiEntity);
assertNotNull(responseApi);
assertNull(responseApi.getPages());
assertNull(responseApi.getPlans());
assertEquals(API_DESCRIPTION, responseApi.getDescription());
assertEquals(API_ID, responseApi.getId());
assertEquals(API_NAME, responseApi.getName());
assertEquals(API_VERSION, responseApi.getVersion());
assertFalse(responseApi.getDraft());
List<String> entrypoints = responseApi.getEntrypoints();
assertNotNull(entrypoints);
assertEquals(2, entrypoints.size());
assertEquals(API_ENTRYPOINT_1, entrypoints.get(0));
assertEquals(API + "/foo", entrypoints.get(1));
List<String> labels = responseApi.getLabels();
assertNotNull(labels);
assertTrue(labels.contains(API_LABEL));
User owner = responseApi.getOwner();
assertNotNull(owner);
assertEquals(API_OWNER_ID, owner.getId());
assertEquals(API_OWNER_EMAIL, owner.getEmail());
assertEquals(API_OWNER_FIRSTNAME + ' ' + API_OWNER_LASTNAME, owner.getDisplayName());
assertEquals(now.toEpochMilli(), responseApi.getUpdatedAt().toInstant().toEpochMilli());
List<String> categories = responseApi.getCategories();
assertNotNull(categories);
assertTrue(categories.contains(API_CATEGORY));
RatingSummary ratingSummary = responseApi.getRatingSummary();
assertNotNull(ratingSummary);
assertEquals(Double.valueOf(4.2), ratingSummary.getAverage());
assertEquals(BigDecimal.valueOf(10), ratingSummary.getCount());
}
use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.
the class UserMapperTest method testConvertUserEntity.
@Test
public void testConvertUserEntity() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
UserEntity userEntity = new UserEntity();
userEntity.setCreatedAt(nowDate);
userEntity.setEmail(USER_EMAIL);
userEntity.setFirstname(USER_FIRSTNAME);
userEntity.setId(USER_ID);
userEntity.setLastConnectionAt(nowDate);
userEntity.setLastname(USER_LASTNAME);
userEntity.setPassword(USER_PASSWORD);
userEntity.setPicture(USER_PICTURE);
userEntity.setRoles(null);
userEntity.setSource(USER_SOURCE);
userEntity.setSourceId(USER_SOURCE_ID);
userEntity.setStatus(USER_STATUS);
userEntity.setUpdatedAt(nowDate);
// Test
User responseUser = userMapper.convert(userEntity);
assertNotNull(responseUser);
assertEquals(USER_ID, responseUser.getId());
assertEquals(USER_EMAIL, responseUser.getEmail());
assertEquals(USER_FIRSTNAME, responseUser.getFirstName());
assertEquals(USER_LASTNAME, responseUser.getLastName());
assertEquals(USER_FIRSTNAME + ' ' + USER_LASTNAME, responseUser.getDisplayName());
}
use of io.gravitee.rest.api.portal.rest.model.User in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapper method convert.
public Application convert(ApplicationListItem applicationListItem, UriInfo uriInfo) {
final Application application = new Application();
application.setApplicationType(applicationListItem.getType());
application.setCreatedAt(applicationListItem.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setDescription(applicationListItem.getDescription());
Set<String> groupEntities = applicationListItem.getGroups();
if (groupEntities != null && !groupEntities.isEmpty()) {
List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
application.setGroups(groups);
}
application.setId(applicationListItem.getId());
application.setName(applicationListItem.getName());
UserEntity primaryOwnerUserEntity = userService.findById(applicationListItem.getPrimaryOwner().getId());
User owner = userMapper.convert(primaryOwnerUserEntity);
owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
application.setOwner(owner);
application.setUpdatedAt(applicationListItem.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
ApplicationSettings settings = applicationListItem.getSettings();
application.setHasClientId(settings != null && ((settings.getoAuthClient() != null && settings.getoAuthClient().getClientId() != null && !settings.getoAuthClient().getClientId().isEmpty()) || (settings.getApp() != null && settings.getApp().getClientId() != null && !settings.getApp().getClientId().isEmpty())));
return application;
}
Aggregations