use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class EmailNotifierServiceTest method shouldHaveATemplateForApplicationHooksWithFreemarker.
@Test
public void shouldHaveATemplateForApplicationHooksWithFreemarker() throws TemplateException {
GenericNotificationConfig cfg = new GenericNotificationConfig();
cfg.setConfig("test@mail.com, ${api.primaryOwner.email} ");
ApiEntity api = new ApiEntity();
api.setName("api-name");
UserEntity userEntity = new UserEntity();
userEntity.setEmail("primary@owner.com");
api.setPrimaryOwner(new PrimaryOwnerEntity(userEntity));
PlanEntity plan = new PlanEntity();
plan.setId("plan-id");
plan.setName("plan-name");
Map<String, Object> params = new HashMap<>();
params.put((NotificationParamsBuilder.PARAM_API), api);
params.put((NotificationParamsBuilder.PARAM_PLAN), plan);
when(notificationTemplateService.resolveInlineTemplateWithParam(anyString(), anyString(), any())).thenReturn("primary@owner.com");
for (ApplicationHook hook : ApplicationHook.values()) {
reset(mockEmailService);
service.trigger(hook, cfg, params);
verify(mockEmailService, times(1)).sendAsyncEmailNotification(argThat(notification -> notification.getTo() != null && notification.getTo().length == 2 && notification.getTo()[0].equals("test@mail.com") && notification.getTo()[1].equals("primary@owner.com")), any());
verify(mockEmailService, never()).sendEmailNotification(any());
}
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class MembershipService_GetMembersTest method shouldGetMembersWithoutMembership.
@Test
public void shouldGetMembersWithoutMembership() throws Exception {
Membership membership = new Membership();
membership.setReferenceId(API_ID);
membership.setCreatedAt(new Date());
membership.setUpdatedAt(membership.getCreatedAt());
membership.setReferenceType(MembershipReferenceType.API);
membership.setRoleId("API_PRIMARY_OWNER");
membership.setMemberId("user-id");
membership.setMemberType(MembershipMemberType.USER);
UserEntity userEntity = new UserEntity();
userEntity.setId(membership.getMemberId());
userEntity.setFirstname("John");
userEntity.setLastname("Doe");
RoleEntity po = mock(RoleEntity.class);
po.setName(SystemRole.PRIMARY_OWNER.name());
List<String> memberIds = Collections.singletonList(membership.getMemberId());
Set<UserEntity> userEntities = Collections.singleton(userEntity);
when(roleService.findById("API_PRIMARY_OWNER")).thenReturn(po);
when(membershipRepository.findByReferencesAndRoleId(MembershipReferenceType.API, Collections.singletonList(API_ID), null)).thenReturn(Collections.singleton(membership));
when(userService.findByIds(memberIds, false)).thenReturn(userEntities);
Set<MemberEntity> members = membershipService.getMembersByReferenceAndRole(io.gravitee.rest.api.model.MembershipReferenceType.API, API_ID, null);
Assert.assertNotNull(members);
Assert.assertFalse("members must not be empty", members.isEmpty());
verify(membershipRepository, times(1)).findByReferencesAndRoleId(MembershipReferenceType.API, Collections.singletonList(API_ID), null);
verify(userService, times(1)).findByIds(memberIds, false);
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceTest method checkMetadataFormat_userWithoutEmail.
@Test
public void checkMetadataFormat_userWithoutEmail() throws TemplateException {
when(this.notificationTemplateService.resolveInlineTemplateWithParam(anyString(), any(Reader.class), any())).thenReturn("");
UserEntity userEntity = new UserEntity();
PrimaryOwnerEntity primaryOwnerEntity = new PrimaryOwnerEntity(userEntity);
ApiEntity apiEntity = new ApiEntity();
apiEntity.setPrimaryOwner(primaryOwnerEntity);
metadataService.checkMetadataFormat(MetadataFormat.MAIL, "${(api.primaryOwner.email)!''}", API, apiEntity);
}
use of io.gravitee.rest.api.model.UserEntity 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;
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class CurrentUserResourceTest method setCurrentUserDetails.
private void setCurrentUserDetails(final UserDetails userDetails) {
final Authentication authentication = mock(Authentication.class);
final UserEntity userEntity = new UserEntity();
userEntity.setId(ID);
userEntity.setRoles(Collections.emptySet());
userEntity.setFirstConnectionAt(new Date());
userEntity.setCreatedAt(new Date());
userEntity.setUpdatedAt(new Date());
userEntity.setLastConnectionAt(new Date());
when(authentication.getPrincipal()).thenReturn(userDetails);
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(userEntity);
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
SecurityContextHolder.setContext(new SecurityContextImpl(authentication));
}
Aggregations