Search in sources :

Example 1 with ProjectAllocationResolved

use of io.imunity.furms.domain.project_allocation.ProjectAllocationResolved 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 2 with ProjectAllocationResolved

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

the class ProjectAllocationInstallationServiceTest method shouldDeleteProjectAllocationIfFailed.

@Test
void shouldDeleteProjectAllocationIfFailed() {
    // given
    ProjectAllocationResolved projectAllocationInstallation = ProjectAllocationResolved.builder().id("id").site(Site.builder().id("id").build()).build();
    // when
    when(repository.findByProjectAllocationId("id")).thenReturn(ProjectAllocationInstallation.builder().id("id").projectAllocationId("id").status(ProjectAllocationInstallationStatus.PROJECT_INSTALLATION_FAILED).build());
    service.createDeallocation(projectAllocationInstallation);
    // then
    orderVerifier.verify(projectAllocationRepository).deleteById("id");
}
Also used : ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectAllocationResolved

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

the class ProjectAllocationInstallationServiceTest method shouldCreateProjectDeallocation.

@Test
void shouldCreateProjectDeallocation() {
    // given
    ProjectAllocationResolved projectAllocationInstallation = ProjectAllocationResolved.builder().id("id").site(Site.builder().id("id").build()).build();
    // when
    when(repository.findByProjectAllocationId("id")).thenReturn(ProjectAllocationInstallation.builder().status(ProjectAllocationInstallationStatus.ACKNOWLEDGED).build());
    service.createDeallocation(projectAllocationInstallation);
    for (TransactionSynchronization transactionSynchronization : TransactionSynchronizationManager.getSynchronizations()) {
        transactionSynchronization.afterCommit();
    }
    // then
    orderVerifier.verify(repository).create(any(ProjectDeallocation.class));
    orderVerifier.verify(siteAgentProjectAllocationInstallationService).deallocateProject(any(), any());
}
Also used : TransactionSynchronization(org.springframework.transaction.support.TransactionSynchronization) ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) ProjectDeallocation(io.imunity.furms.domain.project_allocation_installation.ProjectDeallocation) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectAllocationResolved

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

the class ResourceUsageUpdaterTest method shouldUpdateResourceUsage.

@Test
void shouldUpdateResourceUsage() {
    ResourceUsage resourceUsage = ResourceUsage.builder().projectId("id").projectAllocationId("id").cumulativeConsumption(BigDecimal.TEN).probedAt(LocalDateTime.now().minusMinutes(5)).build();
    ProjectAllocationResolved build = ProjectAllocationResolved.builder().build();
    when(projectAllocationRepository.findByIdWithRelatedObjects("id")).thenReturn(Optional.of(build));
    service.updateUsage(resourceUsage);
    verify(repository).create(resourceUsage, build);
}
Also used : ResourceUsage(io.imunity.furms.domain.resource_usage.ResourceUsage) UserResourceUsage(io.imunity.furms.domain.resource_usage.UserResourceUsage) ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectAllocationResolved

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

the class ProjectAllocationDatabaseRepositoryTest method shouldReturnAllocationsWithRelatedObjects.

@Test
void shouldReturnAllocationsWithRelatedObjects() {
    entityRepository.save(ProjectAllocationEntity.builder().projectId(projectId).communityAllocationId(communityAllocationId).name("anem").amount(new BigDecimal(10)).build());
    Set<ProjectAllocationResolved> entities = entityDatabaseRepository.findAllWithRelatedObjects(projectId.toString());
    assertThat(entities.size()).isEqualTo(1);
    ProjectAllocationResolved entity = entities.iterator().next();
    assertThat(entity.name).isEqualTo("anem");
    assertThat(entity.amount).isEqualTo(new BigDecimal(10));
    assertThat(entity.site.getName()).isEqualTo("name");
    assertThat(entity.resourceType.type).isEqualTo(ResourceMeasureType.FLOATING_POINT);
    assertThat(entity.resourceType.unit).isEqualTo(ResourceMeasureUnit.TERA);
    assertThat(entity.resourceCredit.name).isEqualTo("name");
    assertThat(entity.resourceCredit.splittable).isEqualTo(true);
    assertThat(entity.resourceCredit.amount).isEqualTo(new BigDecimal(100));
}
Also used : ProjectAllocationResolved(io.imunity.furms.domain.project_allocation.ProjectAllocationResolved) BigDecimal(java.math.BigDecimal) DBIntegrationTest(io.imunity.furms.db.DBIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProjectAllocationResolved (io.imunity.furms.domain.project_allocation.ProjectAllocationResolved)23 Test (org.junit.jupiter.api.Test)13 CorrelationId (io.imunity.furms.domain.site_agent.CorrelationId)6 ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)4 BigDecimal (java.math.BigDecimal)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)3 AlarmWithUserEmails (io.imunity.furms.domain.alarms.AlarmWithUserEmails)3 ProjectAllocationChunk (io.imunity.furms.domain.project_allocation_installation.ProjectAllocationChunk)3 ResourceUsage (io.imunity.furms.domain.resource_usage.ResourceUsage)3 UserResourceUsage (io.imunity.furms.domain.resource_usage.UserResourceUsage)3 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ProjectAllocationRemovedEvent (io.imunity.furms.domain.project_allocation.ProjectAllocationRemovedEvent)2 LocalDate (java.time.LocalDate)2 RemovalOfConsumedProjectAllocationIsFirbiddenException (io.imunity.furms.api.validation.exceptions.RemovalOfConsumedProjectAllocationIsFirbiddenException)1 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)1 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)1 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)1 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)1