use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.
the class PolicyDocumentAuditLogServiceIntegrationTest method shouldDetectPolicyDocumentAcceptation.
@Test
void shouldDetectPolicyDocumentAcceptation() {
FenixUserId userId = new FenixUserId("userId");
PolicyId policyId = new PolicyId(UUID.randomUUID());
PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).revision(1).siteId("siteId").build();
PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
FURMSUser user = FURMSUser.builder().id(new PersistentId("id")).email("email").fenixUserId(userId).build();
when(usersDAO.findById(userId)).thenReturn(Optional.of(user));
when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
Mockito.verify(auditLogRepository).create(argument.capture());
assertEquals(Operation.POLICY_ACCEPTANCE, argument.getValue().operationCategory);
assertEquals(Action.ACCEPT, argument.getValue().action);
}
use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.
the class PolicyDocumentServiceImplTest method shouldUpdateUsersPolicyAcceptances.
@Test
void shouldUpdateUsersPolicyAcceptances() {
FenixUserId userId = new FenixUserId("userId");
PolicyId policyId = new PolicyId(UUID.randomUUID());
PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
FURMSUser furmsUser = FURMSUser.builder().email("email").fenixUserId(userId).build();
PolicyDocument policyDocument = PolicyDocument.builder().id((policyId)).siteId("siteId").revision(1).build();
Site site = Site.builder().id("siteId").externalId(new SiteExternalId("id")).build();
AssignedPolicyDocument servicePolicyDocument = AssignedPolicyDocument.builder().build();
when(usersDAO.findById(userId)).thenReturn(Optional.of(furmsUser));
when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
when(repository.findAllAssignPoliciesBySiteId("siteId")).thenReturn(Set.of(servicePolicyDocument));
when(siteRepository.findById("siteId")).thenReturn(Optional.of(site));
when(userRepository.isUserInstalledOnSite(userId, "siteId")).thenReturn(true);
when(policyDocumentDAO.getPolicyAcceptances(userId)).thenReturn(Set.of(policyAcceptance));
service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
Mockito.verify(siteAgentPolicyDocumentService).updateUsersPolicyAcceptances(site.getExternalId(), new UserPolicyAcceptancesWithServicePolicies(furmsUser, Set.of(policyAcceptance), Optional.empty(), Set.of(servicePolicyDocument)));
}
use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.
the class PolicyDocumentServiceImplTest method shouldAddPolicyToUser.
@Test
void shouldAddPolicyToUser() {
FenixUserId userId = new FenixUserId("userId");
PolicyId policyId = new PolicyId(UUID.randomUUID());
PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
FURMSUser furmsUser = FURMSUser.builder().email("email").fenixUserId(userId).build();
PolicyDocument policyDocument = PolicyDocument.builder().id((policyId)).siteId("siteId").revision(1).build();
when(usersDAO.findById(userId)).thenReturn(Optional.of(furmsUser));
when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
orderVerifier.verify(policyDocumentDAO).addUserPolicyAcceptance(userId, policyAcceptance);
orderVerifier.verify(publisher).publishEvent(new UserAcceptedPolicyEvent(userId, policyAcceptance));
verify(repository, times(0)).findById(PolicyId.empty());
}
use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.
the class PolicyNotificationServiceTest method shouldNotNotifyAboutChangedPolicy.
@Test
void shouldNotNotifyAboutChangedPolicy() {
PersistentId id = new PersistentId(UUID.randomUUID().toString());
PolicyId policyId = new PolicyId(UUID.randomUUID());
String siteId = "siteId";
PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).siteId(siteId).name("policyName").build();
FURMSUser user = FURMSUser.builder().id(id).fenixUserId("fenixUserId").email("email").build();
PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(new PolicyId(UUID.randomUUID())).build();
UserPolicyAcceptances userPolicyAcceptances = new UserPolicyAcceptances(user, Set.of(policyAcceptance));
when(policyDocumentDAO.getUserPolicyAcceptances(siteId)).thenReturn(Set.of(userPolicyAcceptances));
policyNotificationService.notifyAboutChangedPolicy(policyDocument);
verify(emailNotificationSender, times(0)).notifyAboutChangedPolicy(id, "policyName");
}
use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.
the class PolicyNotificationServiceTest method shouldNotifyAboutChangedPolicy.
@Test
void shouldNotifyAboutChangedPolicy() {
PersistentId id = new PersistentId(UUID.randomUUID().toString());
PolicyId policyId = new PolicyId(UUID.randomUUID());
String siteId = "siteId";
PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).siteId(siteId).name("policyName").build();
FURMSUser user = FURMSUser.builder().id(id).fenixUserId("fenixUserId").email("email").build();
PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).build();
UserPolicyAcceptances userPolicyAcceptances = new UserPolicyAcceptances(user, Set.of(policyAcceptance));
when(policyDocumentDAO.getUserPolicyAcceptances(siteId)).thenReturn(Set.of(userPolicyAcceptances));
policyNotificationService.notifyAboutChangedPolicy(policyDocument);
verify(emailNotificationSender).notifyAboutChangedPolicy(id, "policyName");
}
Aggregations