Search in sources :

Example 1 with User

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

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

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());
}
Also used : RatingSummary(io.gravitee.rest.api.portal.rest.model.RatingSummary) ApiEntrypointEntity(io.gravitee.rest.api.model.api.ApiEntrypointEntity) User(io.gravitee.rest.api.portal.rest.model.User) Instant(java.time.Instant) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) RatingSummaryEntity(io.gravitee.rest.api.model.RatingSummaryEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Proxy(io.gravitee.definition.model.Proxy) VirtualHost(io.gravitee.definition.model.VirtualHost) Api(io.gravitee.rest.api.portal.rest.model.Api) Test(org.junit.Test)

Example 4 with User

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

Example 5 with User

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;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Group(io.gravitee.rest.api.portal.rest.model.Group) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) GroupService(io.gravitee.rest.api.service.GroupService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) User(io.gravitee.rest.api.portal.rest.model.User) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.portal.rest.model.Application) List(java.util.List) Component(org.springframework.stereotype.Component) OffsetDateTime(java.time.OffsetDateTime) UserService(io.gravitee.rest.api.service.UserService) ZoneOffset(java.time.ZoneOffset) UriInfo(javax.ws.rs.core.UriInfo) PortalApiLinkHelper.usersURL(io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationLinks(io.gravitee.rest.api.portal.rest.model.ApplicationLinks) Group(io.gravitee.rest.api.portal.rest.model.Group) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) User(io.gravitee.rest.api.portal.rest.model.User) Application(io.gravitee.rest.api.portal.rest.model.Application) UserEntity(io.gravitee.rest.api.model.UserEntity)

Aggregations

User (io.gravitee.rest.api.portal.rest.model.User)20 UserEntity (io.gravitee.rest.api.model.UserEntity)15 Test (org.junit.Test)11 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)6 Instant (java.time.Instant)5 Response (javax.ws.rs.core.Response)5 Date (java.util.Date)4 SearchableUser (io.gravitee.rest.api.idp.api.identity.SearchableUser)3 ConsoleSettingsEntity (io.gravitee.rest.api.model.settings.ConsoleSettingsEntity)3 Group (io.gravitee.rest.api.portal.rest.model.Group)3 PortalApiLinkHelper.usersURL (io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL)3 UserService (io.gravitee.rest.api.service.UserService)3 ZoneOffset (java.time.ZoneOffset)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 UriInfo (javax.ws.rs.core.UriInfo)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Component (org.springframework.stereotype.Component)3 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)2 NewExternalUserEntity (io.gravitee.rest.api.model.NewExternalUserEntity)2