Search in sources :

Example 1 with CommunityAllocation

use of io.imunity.furms.domain.community_allocation.CommunityAllocation in project furms by unity-idm.

the class ProjectAllocationServiceImplValidatorTest method shouldPassWhenCommunityIdAndCommunityAllocationIdAreRelated.

@Test
void shouldPassWhenCommunityIdAndCommunityAllocationIdAreRelated() {
    // given
    String id = "id";
    String communityId = "id";
    CommunityAllocation communityAllocation = CommunityAllocation.builder().communityId(communityId).build();
    // when
    when(communityAllocationRepository.findById(id)).thenReturn(Optional.of(communityAllocation));
    // then
    validator.validateCommunityIdAndCommunityAllocationId(communityId, id);
}
Also used : CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) Test(org.junit.jupiter.api.Test)

Example 2 with CommunityAllocation

use of io.imunity.furms.domain.community_allocation.CommunityAllocation in project furms by unity-idm.

the class CommunityAllocationAuditLogServiceIntegrationTest method shouldDetectCommunityAllocationDeletion.

@Test
void shouldDetectCommunityAllocationDeletion() {
    // given
    String id = "id";
    CommunityAllocation request = CommunityAllocation.builder().id("id").communityId("id").resourceCreditId("id").name("name").amount(new BigDecimal(1)).build();
    when(communityAllocationRepository.findById("id")).thenReturn(Optional.of(request));
    // when
    service.delete(id);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.COMMUNITY_ALLOCATION, argument.getValue().operationCategory);
    assertEquals(Action.DELETE, argument.getValue().action);
}
Also used : CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) 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 3 with CommunityAllocation

use of io.imunity.furms.domain.community_allocation.CommunityAllocation in project furms by unity-idm.

the class CommunityAllocationServiceImplTest method shouldAllowToDeleteCommunityAllocation.

@Test
void shouldAllowToDeleteCommunityAllocation() {
    // given
    String id = "id";
    CommunityAllocation request = CommunityAllocation.builder().id("id").communityId("id").resourceCreditId("id").name("name").amount(new BigDecimal(1)).build();
    when(communityAllocationRepository.findById("id")).thenReturn(Optional.of(request));
    // when
    service.delete(id);
    orderVerifier.verify(communityAllocationRepository).delete(eq(id));
    orderVerifier.verify(publisher).publishEvent(eq(new CommunityAllocationRemovedEvent(request)));
}
Also used : CommunityAllocationRemovedEvent(io.imunity.furms.domain.community_allocation.CommunityAllocationRemovedEvent) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with CommunityAllocation

use of io.imunity.furms.domain.community_allocation.CommunityAllocation in project furms by unity-idm.

the class CommunityAllocationServiceImplValidatorTest method shouldNotPassCreateForNonExistingResourceCreditId.

@Test
void shouldNotPassCreateForNonExistingResourceCreditId() {
    // given
    CommunityAllocation communityAllocation = CommunityAllocation.builder().communityId("id").resourceCreditId("id").name("name").build();
    when(communityRepository.exists(communityAllocation.communityId)).thenReturn(true);
    when(resourceCreditRepository.exists(communityAllocation.resourceCreditId)).thenReturn(false);
    // when+then
    assertThrows(IllegalArgumentException.class, () -> validator.validateCreate(communityAllocation));
}
Also used : CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) Test(org.junit.jupiter.api.Test)

Example 5 with CommunityAllocation

use of io.imunity.furms.domain.community_allocation.CommunityAllocation in project furms by unity-idm.

the class CommunityAllocationServiceImplValidatorTest method shouldPassUpdateForUniqueName.

@Test
void shouldPassUpdateForUniqueName() {
    // given
    CommunityAllocation communityAllocation = CommunityAllocation.builder().id("id").communityId("id").resourceCreditId("id").name("name").amount(new BigDecimal(1)).build();
    when(projectAllocationRepository.getAvailableAmount(communityAllocation.id)).thenReturn(BigDecimal.valueOf(1));
    when(communityAllocationRepository.getAvailableAmount(communityAllocation.resourceCreditId)).thenReturn(BigDecimal.valueOf(2));
    when(resourceCreditRepository.findById(communityAllocation.resourceCreditId)).thenReturn(Optional.of(CREDIT_OF_TEN));
    when(communityAllocationRepository.isUniqueName(any())).thenReturn(true);
    when(communityAllocationRepository.findById(any())).thenReturn(Optional.of(communityAllocation));
    // when+then
    assertDoesNotThrow(() -> validator.validateUpdate(communityAllocation));
}
Also used : CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)36 Test (org.junit.jupiter.api.Test)26 BigDecimal (java.math.BigDecimal)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)6 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)3 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)3 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)3 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)3 ResourceUsageByCommunityAllocation (io.imunity.furms.domain.resource_usage.ResourceUsageByCommunityAllocation)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IdNotFoundValidationError (io.imunity.furms.api.validation.exceptions.IdNotFoundValidationError)2 CommunityAllocationCreatedEvent (io.imunity.furms.domain.community_allocation.CommunityAllocationCreatedEvent)2 CommunityAllocationRemovedEvent (io.imunity.furms.domain.community_allocation.CommunityAllocationRemovedEvent)2 CommunityAllocationUpdatedEvent (io.imunity.furms.domain.community_allocation.CommunityAllocationUpdatedEvent)2 ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)2 ProjectAllocationInstallation (io.imunity.furms.domain.project_allocation_installation.ProjectAllocationInstallation)2 ResourceCredit (io.imunity.furms.domain.resource_credits.ResourceCredit)2 CommunityAllocationViewModel (io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel)2