Search in sources :

Example 1 with Member

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());
}
Also used : RoleEntity(io.gravitee.rest.api.model.RoleEntity) User(io.gravitee.rest.api.portal.rest.model.User) Instant(java.time.Instant) MemberEntity(io.gravitee.rest.api.model.MemberEntity) Member(io.gravitee.rest.api.portal.rest.model.Member) Date(java.util.Date) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 2 with Member

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;
}
Also used : User(io.gravitee.rest.api.portal.rest.model.User) Member(io.gravitee.rest.api.portal.rest.model.Member) UserEntity(io.gravitee.rest.api.model.UserEntity)

Aggregations

UserEntity (io.gravitee.rest.api.model.UserEntity)2 Member (io.gravitee.rest.api.portal.rest.model.Member)2 User (io.gravitee.rest.api.portal.rest.model.User)2 MemberEntity (io.gravitee.rest.api.model.MemberEntity)1 RoleEntity (io.gravitee.rest.api.model.RoleEntity)1 Instant (java.time.Instant)1 Date (java.util.Date)1 Test (org.junit.Test)1