Search in sources :

Example 1 with Site

use of io.imunity.furms.domain.sites.Site in project furms by unity-idm.

the class PolicyDocumentServiceImplTest method shouldSendUpdateSitePolicyDocument.

@Test
void shouldSendUpdateSitePolicyDocument() {
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    SiteExternalId externalId = new SiteExternalId("id");
    PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).siteId("siteId").build();
    Site site = Site.builder().policyId(policyId).externalId(externalId).build();
    when(repository.update(policyDocument, true)).thenReturn(policyId);
    when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
    when(siteRepository.findById("siteId")).thenReturn(Optional.of(site));
    service.updateWithRevision(policyDocument);
    Mockito.verify(siteAgentPolicyDocumentService).updatePolicyDocument(externalId, policyDocument);
}
Also used : Site(io.imunity.furms.domain.sites.Site) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) SiteExternalId(io.imunity.furms.domain.sites.SiteExternalId) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) Test(org.junit.jupiter.api.Test)

Example 2 with Site

use of io.imunity.furms.domain.sites.Site 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)));
}
Also used : Site(io.imunity.furms.domain.sites.Site) UserPolicyAcceptancesWithServicePolicies(io.imunity.furms.domain.policy_documents.UserPolicyAcceptancesWithServicePolicies) PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) FenixUserId(io.imunity.furms.domain.users.FenixUserId) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) SiteExternalId(io.imunity.furms.domain.sites.SiteExternalId) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) Test(org.junit.jupiter.api.Test)

Example 3 with Site

use of io.imunity.furms.domain.sites.Site in project furms by unity-idm.

the class SiteAuditLogServiceIntegrationTest method shouldDetectSupportAddition.

@Test
void shouldDetectSupportAddition() {
    // given
    String siteId = UUID.randomUUID().toString();
    PersistentId userId = new PersistentId("userId");
    Site site = Site.builder().name("name").build();
    when(repository.findById(siteId)).thenReturn(Optional.of(site));
    when(usersDAO.findById(userId)).thenReturn(Optional.of(FURMSUser.builder().id(userId).email("email").build()));
    // when
    service.addSupport(siteId, userId);
    // then
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.ROLE_ASSIGNMENT, argument.getValue().operationCategory);
    assertEquals(Action.GRANT, argument.getValue().action);
}
Also used : Site(io.imunity.furms.domain.sites.Site) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) PersistentId(io.imunity.furms.domain.users.PersistentId) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) RoleAssignmentAuditLogServiceTest(io.imunity.furms.core.users.audit_log.RoleAssignmentAuditLogServiceTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Site

use of io.imunity.furms.domain.sites.Site in project furms by unity-idm.

the class SiteAuditLogServiceIntegrationTest method shouldDetectUserRemoval.

@Test
void shouldDetectUserRemoval() {
    // given
    String siteId = UUID.randomUUID().toString();
    PersistentId userId = new PersistentId("userId");
    Site site = Site.builder().name("name").build();
    when(service.findById(siteId)).thenReturn(Optional.of(site));
    when(usersDAO.findById(userId)).thenReturn(Optional.of(FURMSUser.builder().id(userId).email("email").build()));
    // when
    service.removeSiteUser(siteId, userId);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.ROLE_ASSIGNMENT, argument.getValue().operationCategory);
    assertEquals(Action.REVOKE, argument.getValue().action);
}
Also used : Site(io.imunity.furms.domain.sites.Site) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) PersistentId(io.imunity.furms.domain.users.PersistentId) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) RoleAssignmentAuditLogServiceTest(io.imunity.furms.core.users.audit_log.RoleAssignmentAuditLogServiceTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Site

use of io.imunity.furms.domain.sites.Site in project furms by unity-idm.

the class SiteAuditLogServiceIntegrationTest method shouldDetectInfraServiceCreation.

@Test
void shouldDetectInfraServiceCreation() {
    // given
    Site request = Site.builder().id("id").name("name").build();
    when(repository.isNamePresent(request.getName())).thenReturn(false);
    when(repository.create(eq(request), any())).thenReturn(request.getId());
    when(repository.findById(request.getId())).thenReturn(Optional.of(request));
    // when
    service.create(request);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.SITES_MANAGEMENT, argument.getValue().operationCategory);
    assertEquals(Action.CREATE, argument.getValue().action);
}
Also used : Site(io.imunity.furms.domain.sites.Site) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) RoleAssignmentAuditLogServiceTest(io.imunity.furms.core.users.audit_log.RoleAssignmentAuditLogServiceTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Site (io.imunity.furms.domain.sites.Site)130 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)85 BeforeEach (org.junit.jupiter.api.BeforeEach)55 Test (org.junit.jupiter.api.Test)53 UUID (java.util.UUID)39 Community (io.imunity.furms.domain.communities.Community)32 Project (io.imunity.furms.domain.projects.Project)30 InfraService (io.imunity.furms.domain.services.InfraService)26 ResourceType (io.imunity.furms.domain.resource_types.ResourceType)23 PersistentId (io.imunity.furms.domain.users.PersistentId)23 PolicyId (io.imunity.furms.domain.policy_documents.PolicyId)21 FenixUserId (io.imunity.furms.domain.users.FenixUserId)21 BigDecimal (java.math.BigDecimal)21 PolicyDocument (io.imunity.furms.domain.policy_documents.PolicyDocument)18 DefaultDataBuilders.defaultSite (io.imunity.furms.integration.tests.tools.DefaultDataBuilders.defaultSite)17 SiteId (io.imunity.furms.domain.sites.SiteId)16 Optional (java.util.Optional)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 SiteRepository (io.imunity.furms.spi.sites.SiteRepository)12 Logger (org.slf4j.Logger)12