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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations