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