Search in sources :

Example 1 with Project

use of io.imunity.furms.domain.projects.Project in project furms by unity-idm.

the class ProjectAuditLogServiceIntegrationTest method shouldDetectProjectCreation.

@Test
void shouldDetectProjectCreation() {
    // given
    String id = UUID.randomUUID().toString();
    PersistentId projectLeaderId = new PersistentId(UUID.randomUUID().toString());
    Project request = Project.builder().id(id).communityId("id").name("userFacingName").acronym("acronym").researchField("research field").utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now().plusWeeks(1)).leaderId(projectLeaderId).build();
    when(communityRepository.exists("id")).thenReturn(true);
    when(projectRepository.isNamePresent(request.getCommunityId(), request.getName())).thenReturn(true);
    when(projectRepository.findById(id)).thenReturn(Optional.of(request));
    when(projectRepository.create(request)).thenReturn(id);
    when(usersDAO.findById(projectLeaderId)).thenReturn(Optional.of(FURMSUser.builder().id(projectLeaderId).email("email").build()));
    // when
    service.create(request);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository, times(2)).create(argument.capture());
    assertEquals(Operation.PROJECTS_MANAGEMENT, argument.getAllValues().get(1).operationCategory);
    assertEquals(Action.CREATE, argument.getAllValues().get(1).action);
    assertEquals(Operation.ROLE_ASSIGNMENT, argument.getAllValues().get(0).operationCategory);
    assertEquals(Action.GRANT, argument.getAllValues().get(0).action);
}
Also used : Project(io.imunity.furms.domain.projects.Project) 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 2 with Project

use of io.imunity.furms.domain.projects.Project in project furms by unity-idm.

the class ProjectAuditLogServiceIntegrationTest method shouldDetectUserRemoval.

@Test
void shouldDetectUserRemoval() {
    UUID communityId = UUID.randomUUID();
    UUID projectId = UUID.randomUUID();
    PersistentId id = new PersistentId("id");
    Project project = Project.builder().name("userFacingName").build();
    when(projectRepository.findById(projectId.toString())).thenReturn(Optional.of(project));
    when(usersDAO.findById(id)).thenReturn(Optional.of(FURMSUser.builder().id(id).email("email").build()));
    service.removeUser(communityId.toString(), projectId.toString(), id);
    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 : Project(io.imunity.furms.domain.projects.Project) UUID(java.util.UUID) 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 3 with Project

use of io.imunity.furms.domain.projects.Project in project furms by unity-idm.

the class ProjectAuditLogServiceIntegrationTest method shouldDetectProjectDeletion.

@Test
void shouldDetectProjectDeletion() {
    // given
    String id = "id";
    String id2 = "id";
    when(projectRepository.exists(id)).thenReturn(true);
    List<FURMSUser> users = Collections.singletonList(FURMSUser.builder().id(new PersistentId("id")).email("email@test.com").build());
    when(projectGroupsDAO.getAllUsers("id", "id")).thenReturn(users);
    Project project = Project.builder().build();
    when(projectRepository.findById("id")).thenReturn(Optional.of(project));
    // when
    service.delete(id, id2);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.PROJECTS_MANAGEMENT, argument.getValue().operationCategory);
    assertEquals(Action.DELETE, argument.getValue().action);
}
Also used : Project(io.imunity.furms.domain.projects.Project) FURMSUser(io.imunity.furms.domain.users.FURMSUser) 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 Project

use of io.imunity.furms.domain.projects.Project in project furms by unity-idm.

the class ProjectAuditLogServiceIntegrationTest method shouldDetectUserAddition.

@Test
void shouldDetectUserAddition() {
    UUID communityId = UUID.randomUUID();
    UUID projectId = UUID.randomUUID();
    PersistentId id = new PersistentId("id");
    Project project = Project.builder().name("userFacingName").build();
    when(projectRepository.findById(projectId.toString())).thenReturn(Optional.of(project));
    when(usersDAO.findById(id)).thenReturn(Optional.of(FURMSUser.builder().id(id).email("email").build()));
    service.addUser(communityId.toString(), projectId.toString(), id);
    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 : Project(io.imunity.furms.domain.projects.Project) UUID(java.util.UUID) 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 Project

use of io.imunity.furms.domain.projects.Project in project furms by unity-idm.

the class ProjectServiceImplTest method shouldAllowToCreateProject.

@Test
void shouldAllowToCreateProject() {
    // given
    String id = UUID.randomUUID().toString();
    Project request = Project.builder().id(id).communityId("id").name("userFacingName").acronym("acronym").researchField("research field").utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now().plusWeeks(1)).leaderId(new PersistentId(UUID.randomUUID().toString())).build();
    ProjectGroup groupRequest = ProjectGroup.builder().id(id).communityId("id").name("userFacingName").build();
    when(communityRepository.exists("id")).thenReturn(true);
    when(projectRepository.isNamePresent(request.getCommunityId(), request.getName())).thenReturn(true);
    when(projectRepository.findById(id)).thenReturn(Optional.of(request));
    when(projectRepository.create(request)).thenReturn(id);
    // when
    service.create(request);
    orderVerifier.verify(projectRepository).create(eq(request));
    orderVerifier.verify(projectGroupsDAO).create(eq(groupRequest));
    orderVerifier.verify(publisher).publishEvent(eq(new ProjectCreatedEvent(request)));
}
Also used : Project(io.imunity.furms.domain.projects.Project) ProjectCreatedEvent(io.imunity.furms.domain.projects.ProjectCreatedEvent) PersistentId(io.imunity.furms.domain.users.PersistentId) ProjectGroup(io.imunity.furms.domain.projects.ProjectGroup) Test(org.junit.jupiter.api.Test)

Aggregations

Project (io.imunity.furms.domain.projects.Project)82 UUID (java.util.UUID)39 Test (org.junit.jupiter.api.Test)37 Community (io.imunity.furms.domain.communities.Community)33 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)32 BeforeEach (org.junit.jupiter.api.BeforeEach)30 Site (io.imunity.furms.domain.sites.Site)29 BigDecimal (java.math.BigDecimal)20 ResourceType (io.imunity.furms.domain.resource_types.ResourceType)19 InfraService (io.imunity.furms.domain.services.InfraService)19 PersistentId (io.imunity.furms.domain.users.PersistentId)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 FURMSUser (io.imunity.furms.domain.users.FURMSUser)10 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)7 RoleAssignmentAuditLogServiceTest (io.imunity.furms.core.users.audit_log.RoleAssignmentAuditLogServiceTest)7 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)7 ProjectGroup (io.imunity.furms.domain.projects.ProjectGroup)7 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)4 ResourceId (io.imunity.furms.domain.authz.roles.ResourceId)4 SiteId (io.imunity.furms.domain.sites.SiteId)4