Search in sources :

Example 1 with ProjectAllocation

use of io.imunity.furms.domain.project_allocation.ProjectAllocation in project furms by unity-idm.

the class ProjectAllocationAuditLogServiceIntegrationTest method shouldDetectProjectAllocationCreation.

@Test
void shouldDetectProjectAllocationCreation() {
    // given
    ProjectAllocation request = ProjectAllocation.builder().id("id").projectId("id").communityAllocationId("id").name("name").amount(new BigDecimal(1)).build();
    // when
    when(projectInstallationService.findProjectInstallationOfProjectAllocation("projectAllocationId")).thenReturn(ProjectInstallation.builder().siteId("siteId").build());
    when(projectAllocationRepository.create(request)).thenReturn("projectAllocationId");
    when(projectAllocationRepository.findById("projectAllocationId")).thenReturn(Optional.of(request));
    service.create("communityId", request);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.PROJECT_ALLOCATION, argument.getValue().operationCategory);
    assertEquals(Action.CREATE, argument.getValue().action);
}
Also used : ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) BigDecimal(java.math.BigDecimal) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ProjectAllocation

use of io.imunity.furms.domain.project_allocation.ProjectAllocation in project furms by unity-idm.

the class ProjectAllocationAuditLogServiceIntegrationTest method shouldDetectProjectAllocationDeletion.

@Test
void shouldDetectProjectAllocationDeletion() {
    // given
    String id = "id";
    ProjectAllocationResolved projectAllocationResolved = ProjectAllocationResolved.builder().amount(BigDecimal.TEN).consumed(BigDecimal.ZERO).build();
    ProjectAllocation projectAllocation = ProjectAllocation.builder().build();
    when(projectAllocationRepository.findByIdWithRelatedObjects(id)).thenReturn(Optional.of(projectAllocationResolved));
    when(projectAllocationRepository.findById(id)).thenReturn(Optional.of(projectAllocation));
    // when
    service.delete("projectId", id);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.PROJECT_ALLOCATION, argument.getValue().operationCategory);
    assertEquals(Action.DELETE, argument.getValue().action);
}
Also used : ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ProjectAllocation

use of io.imunity.furms.domain.project_allocation.ProjectAllocation in project furms by unity-idm.

the class ProjectAllocationServiceImplValidatorTest method shouldNotPassUpdateWhenConsumptionIsBiggerThenAllocationAmount.

@Test
void shouldNotPassUpdateWhenConsumptionIsBiggerThenAllocationAmount() {
    // given
    ProjectAllocation projectAllocation = ProjectAllocation.builder().id("id").projectId("id").communityAllocationId("id").name("name").amount(new BigDecimal(5)).build();
    ProjectAllocation updatedProjectAllocation = ProjectAllocation.builder().id("id").projectId("id").communityAllocationId("id").name("name").amount(BigDecimal.valueOf(3)).build();
    when(projectRepository.exists(projectAllocation.projectId)).thenReturn(true);
    when(communityAllocationRepository.exists(projectAllocation.communityAllocationId)).thenReturn(true);
    when(projectAllocationRepository.exists(projectAllocation.id)).thenReturn(true);
    when(projectAllocationRepository.isNamePresent(any(), any())).thenReturn(true);
    when(projectAllocationRepository.findById(projectAllocation.id)).thenReturn(Optional.of(projectAllocation));
    when(projectAllocationRepository.getAvailableAmount(projectAllocation.id)).thenReturn(BigDecimal.TEN);
    when(communityAllocationRepository.findById(any())).thenReturn(Optional.of(CommunityAllocation.builder().id("id").build()));
    when(projectRepository.isProjectRelatedWithCommunity("communityId", projectAllocation.projectId)).thenReturn(true);
    when(resourceUsageRepository.findCurrentResourceUsage(projectAllocation.id)).thenReturn(Optional.of(ResourceUsage.builder().cumulativeConsumption(BigDecimal.valueOf(4)).build()));
    // when+then
    assertThrows(ProjectAllocationDecreaseBeyondUsageException.class, () -> validator.validateUpdate("communityId", updatedProjectAllocation));
}
Also used : ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectAllocation

use of io.imunity.furms.domain.project_allocation.ProjectAllocation in project furms by unity-idm.

the class ProjectAllocationServiceImplValidatorTest method shouldNotPassCreateDueToExpiredResourceCredit.

@Test
void shouldNotPassCreateDueToExpiredResourceCredit() {
    // given
    final String communityId = "communityId";
    final ProjectAllocation projectAllocation = ProjectAllocation.builder().projectId("id").communityAllocationId("id").name("name").amount(new BigDecimal(1)).build();
    when(projectRepository.exists(projectAllocation.projectId)).thenReturn(true);
    when(communityAllocationRepository.exists(projectAllocation.communityAllocationId)).thenReturn(true);
    when(projectRepository.isProjectRelatedWithCommunity(communityId, projectAllocation.projectId)).thenReturn(true);
    when(projectRepository.findById(projectAllocation.projectId)).thenReturn(Optional.of(Project.builder().utcEndTime(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC).plusMinutes(1L)).build()));
    when(communityAllocationRepository.findByIdWithRelatedObjects(projectAllocation.communityAllocationId)).thenReturn(Optional.of(CommunityAllocationResolved.builder().resourceCredit(ResourceCredit.builder().utcEndTime(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC).minusMinutes(1L)).build()).build()));
    when(communityAllocationRepository.findById(projectAllocation.communityAllocationId)).thenReturn(Optional.of(CommunityAllocation.builder().resourceCreditId("id").build()));
    when(resourceCreditRepository.findById("id")).thenReturn(Optional.of(ResourceCredit.builder().resourceTypeId("id").build()));
    // when+then
    assertThrows(ResourceCreditExpiredException.class, () -> validator.validateCreate(communityId, projectAllocation));
}
Also used : ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectAllocation

use of io.imunity.furms.domain.project_allocation.ProjectAllocation in project furms by unity-idm.

the class ProjectAllocationServiceImplValidatorTest method shouldNotPassDeleteWhenCommunityAndProjectAreNotRelated.

@Test
void shouldNotPassDeleteWhenCommunityAndProjectAreNotRelated() {
    // given
    String communityId = "communityId";
    ProjectAllocation projectAllocation = ProjectAllocation.builder().id("id").projectId("id").communityAllocationId("id").name("name").amount(new BigDecimal(1)).build();
    when(projectAllocationRepository.findById(projectAllocation.id)).thenReturn(Optional.of(projectAllocation));
    when(projectRepository.isProjectRelatedWithCommunity(communityId, projectAllocation.projectId)).thenReturn(false);
    // when+then
    assertThrows(ProjectIsNotRelatedWithCommunity.class, () -> validator.validateDelete("communityId", projectAllocation.id));
}
Also used : ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)42 Test (org.junit.jupiter.api.Test)30 BigDecimal (java.math.BigDecimal)26 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)5 Optional (java.util.Optional)5 ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException (io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException)4 ProjectAllocationResolved (io.imunity.furms.domain.project_allocation.ProjectAllocationResolved)4 BeforeEvent (com.vaadin.flow.router.BeforeEvent)3 OptionalParameter (com.vaadin.flow.router.OptionalParameter)3 Route (com.vaadin.flow.router.Route)3 ResourceUsageCSVExporter (io.imunity.furms.api.export.ResourceUsageCSVExporter)3 ResourceUsageJSONExporter (io.imunity.furms.api.export.ResourceUsageJSONExporter)3 ProjectAllocationService (io.imunity.furms.api.project_allocation.ProjectAllocationService)3 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)3 ProjectAllocationDecreaseBeyondUsageException (io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException)3 ProjectAllocationIncreaseInExpiredProjectException (io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException)3 ProjectAllocationIsNotInTerminalStateException (io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException)3 ProjectAllocationWrongAmountException (io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException)3 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)3