Search in sources :

Example 16 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class MembershipCommandHandlerTest method handleWithUserRole.

@Test
public void handleWithUserRole() {
    MembershipPayload membershipPayload = new MembershipPayload();
    membershipPayload.setUserId("user#1");
    membershipPayload.setOrganizationId("orga#1");
    membershipPayload.setReferenceType(MembershipReferenceType.ENVIRONMENT.name());
    membershipPayload.setReferenceId("env#1");
    membershipPayload.setRole("ENVIRONMENT_USER");
    MembershipCommand command = new MembershipCommand(membershipPayload);
    UserEntity user = new UserEntity();
    user.setId(UUID.random().toString());
    RoleEntity role = new RoleEntity();
    role.setId(UUID.random().toString());
    role.setScope(RoleScope.ENVIRONMENT);
    role.setName("USER");
    when(userService.findBySource(COCKPIT_SOURCE, membershipPayload.getUserId(), false)).thenReturn(user);
    when(roleService.findByScopeAndName(RoleScope.ENVIRONMENT, "USER")).thenReturn(Optional.of(role));
    TestObserver<MembershipReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertNoErrors();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
    ArgumentCaptor<MembershipService.MembershipReference> membershipReference = ArgumentCaptor.forClass(MembershipService.MembershipReference.class);
    ArgumentCaptor<MembershipService.MembershipMember> membershipMember = ArgumentCaptor.forClass(MembershipService.MembershipMember.class);
    ArgumentCaptor<List<MembershipService.MembershipRole>> membershipRoles = ArgumentCaptor.forClass(List.class);
    verify(membershipService).updateRolesToMemberOnReference(membershipReference.capture(), membershipMember.capture(), membershipRoles.capture(), eq(COCKPIT_SOURCE), eq(false));
    assertEquals(MembershipReferenceType.ENVIRONMENT, membershipReference.getValue().getType());
    assertEquals(membershipPayload.getReferenceId(), membershipReference.getValue().getId());
    assertEquals(MembershipMemberType.USER, membershipMember.getValue().getMemberType());
    assertEquals(user.getId(), membershipMember.getValue().getMemberId());
    assertTrue(membershipRoles.getValue().size() == 1 && membershipRoles.getValue().stream().allMatch(membershipRole -> membershipRole.getScope() == role.getScope() && membershipRole.getName().equals(role.getName())));
}
Also used : MembershipReply(io.gravitee.cockpit.api.command.membership.MembershipReply) UserEntity(io.gravitee.rest.api.model.UserEntity) RoleEntity(io.gravitee.rest.api.model.RoleEntity) MembershipService(io.gravitee.rest.api.service.MembershipService) MembershipPayload(io.gravitee.cockpit.api.command.membership.MembershipPayload) List(java.util.List) MembershipCommand(io.gravitee.cockpit.api.command.membership.MembershipCommand) Test(org.junit.Test)

Example 17 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class UserCommandHandlerTest method handleWithUpdateException.

@Test
public void handleWithUpdateException() {
    UserPayload userPayload = new UserPayload();
    UserCommand command = new UserCommand(userPayload);
    final String sourceId = "user#1";
    userPayload.setId(sourceId);
    userPayload.setOrganizationId("orga#1");
    when(userService.findBySource("cockpit", sourceId, false)).thenReturn(new UserEntity());
    when(userService.update(any(), any(UpdateUserEntity.class))).thenThrow(new RuntimeException("fake error"));
    TestObserver<UserReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
Also used : UserCommand(io.gravitee.cockpit.api.command.user.UserCommand) UserPayload(io.gravitee.cockpit.api.command.user.UserPayload) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) NewExternalUserEntity(io.gravitee.rest.api.model.NewExternalUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) UserReply(io.gravitee.cockpit.api.command.user.UserReply) Test(org.junit.Test)

Example 18 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiDocumentTransformerTest method getApiEntity.

@NotNull
private ApiEntity getApiEntity() {
    ApiEntity toTransform = new ApiEntity();
    toTransform.setId("apiId");
    toTransform.setName("name");
    toTransform.setDescription("description");
    toTransform.setReferenceId("xxxxxx");
    toTransform.setReferenceType("env1");
    UserEntity userEntity = new UserEntity();
    userEntity.setId("userId");
    userEntity.setEmail("userMail");
    userEntity.setFirstname("userFirstname");
    userEntity.setLastname("userLastname");
    PrimaryOwnerEntity primaryOwnerEntity = new PrimaryOwnerEntity(userEntity);
    toTransform.setPrimaryOwner(primaryOwnerEntity);
    Proxy proxy = new Proxy();
    proxy.setVirtualHosts(Arrays.asList(new VirtualHost("host", "path"), new VirtualHost("host2", "path2")));
    toTransform.setProxy(proxy);
    toTransform.setLabels(Arrays.asList("label1", "label2", "label2"));
    toTransform.setCategories(new HashSet<>(Arrays.asList("cat1", "cat2")));
    toTransform.setTags(new HashSet<>(Arrays.asList("tag1", "tag2")));
    Date date = new Date();
    toTransform.setCreatedAt(date);
    toTransform.setUpdatedAt(date);
    HashMap<String, Object> metadatas = new HashMap<>();
    metadatas.put("metadata1", "value1");
    metadatas.put("metadata2", "value2");
    metadatas.put("metadata3", "value3");
    toTransform.setMetadata(metadatas);
    return toTransform;
}
Also used : Proxy(io.gravitee.definition.model.Proxy) HashMap(java.util.HashMap) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) UserEntity(io.gravitee.rest.api.model.UserEntity) Date(java.util.Date) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method getAUserEntity.

private UserEntity getAUserEntity() {
    UserEntity userEntity = new UserEntity();
    userEntity.setId("user#1");
    userEntity.setEmail("user@gv.io");
    userEntity.setPicture("http://image.png");
    userEntity.setSource("cockpit");
    userEntity.setSource("id");
    return userEntity;
}
Also used : UserEntity(io.gravitee.rest.api.model.UserEntity)

Example 20 with UserEntity

use of io.gravitee.rest.api.model.UserEntity 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

UserEntity (io.gravitee.rest.api.model.UserEntity)57 Test (org.junit.Test)36 User (io.gravitee.rest.api.portal.rest.model.User)14 Response (javax.ws.rs.core.Response)14 RoleEntity (io.gravitee.rest.api.model.RoleEntity)13 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)12 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)12 Date (java.util.Date)10 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)9 UserService (io.gravitee.rest.api.service.UserService)9 NewExternalUserEntity (io.gravitee.rest.api.model.NewExternalUserEntity)8 List (java.util.List)8 Instant (java.time.Instant)7 UserDetails (io.gravitee.rest.api.idp.api.authentication.UserDetails)6 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)6 MembershipService (io.gravitee.rest.api.service.MembershipService)6 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 MembershipPayload (io.gravitee.cockpit.api.command.membership.MembershipPayload)5 MembershipReply (io.gravitee.cockpit.api.command.membership.MembershipReply)5