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