use of io.gravitee.rest.api.portal.rest.model.Member 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.Member in project gravitee-management-rest-api by gravitee-io.
the class MemberMapper method convert.
public Member convert(MemberEntity member, UriInfo uriInfo) {
final Member memberItem = new Member();
memberItem.setCreatedAt(member.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
UserEntity userEntity = userService.findById(member.getId());
User memberUser = userMapper.convert(userEntity);
memberUser.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), userEntity.getId()), userEntity.getUpdatedAt()));
memberItem.setUser(memberUser);
if (member.getRoles() != null && !member.getRoles().isEmpty()) {
memberItem.setRole(member.getRoles().get(0).getName());
}
memberItem.setUpdatedAt(member.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
return memberItem;
}
Aggregations