use of io.imunity.furms.domain.resource_credits.ResourceCredit in project furms by unity-idm.
the class ResourceCreditServiceImplTest method shouldAllowToCreateResourceCredit.
@Test
void shouldAllowToCreateResourceCredit() {
// given
ResourceCredit request = ResourceCredit.builder().id("id").siteId("id").resourceTypeId("id").name("name").amount(new BigDecimal(1)).utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now()).build();
when(siteRepository.exists(request.siteId)).thenReturn(true);
when(resourceTypeRepository.exists(request.resourceTypeId)).thenReturn(true);
when(resourceCreditRepository.isNamePresent(request.name, request.siteId)).thenReturn(false);
when(resourceCreditRepository.create(request)).thenReturn("id");
when(resourceCreditRepository.findById("id")).thenReturn(Optional.of(request));
// when
service.create(request);
orderVerifier.verify(resourceCreditRepository).create(eq(request));
orderVerifier.verify(publisher).publishEvent(eq(new ResourceCreditCreatedEvent(new PersistentId("userId"), request)));
}
use of io.imunity.furms.domain.resource_credits.ResourceCredit in project furms by unity-idm.
the class ResourceCreditServiceImplTest method shouldNotAllowToCreateResourceCreditDueToNonUniqueName.
@Test
void shouldNotAllowToCreateResourceCreditDueToNonUniqueName() {
// given
ResourceCredit request = ResourceCredit.builder().id("id").siteId("siteId").resourceTypeId("typeId").name("name").build();
when(siteRepository.exists("siteId")).thenReturn(true);
when(resourceTypeRepository.exists("typeId")).thenReturn(true);
when(resourceCreditRepository.isNamePresent(request.name, request.siteId)).thenReturn(true);
// when
assertThrows(IllegalArgumentException.class, () -> service.create(request));
orderVerifier.verify(resourceCreditRepository, times(0)).create(eq(request));
orderVerifier.verify(publisher, times(0)).publishEvent(eq(new ResourceCreditCreatedEvent(new PersistentId("use"), request)));
}
use of io.imunity.furms.domain.resource_credits.ResourceCredit in project furms by unity-idm.
the class ResourceCreditServiceValidatorTest method shouldNotPassCreateForWrongDates.
@Test
void shouldNotPassCreateForWrongDates() {
// given
ResourceCredit service = ResourceCredit.builder().siteId("id").resourceTypeId("id").name("name").utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now().minusDays(10)).build();
when(siteRepository.exists(service.siteId)).thenReturn(true);
when(resourceTypeRepository.exists(service.resourceTypeId)).thenReturn(true);
when(resourceCreditRepository.isNamePresent(any(), any())).thenReturn(false);
// when+then
assertThrows(IllegalArgumentException.class, () -> validator.validateCreate(service));
}
use of io.imunity.furms.domain.resource_credits.ResourceCredit in project furms by unity-idm.
the class ResourceCreditServiceValidatorTest method shouldNotPassUpdateForNonUniqueName.
@Test
void shouldNotPassUpdateForNonUniqueName() {
// given
ResourceCredit resourceCredit = ResourceCredit.builder().id("id").siteId("id").resourceTypeId("id").name("name").amount(new BigDecimal(1)).utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now()).build();
ResourceCredit resourceCredit2 = ResourceCredit.builder().id("id").siteId("id").resourceTypeId("id").name("name2").amount(new BigDecimal(2)).utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now()).build();
when(siteRepository.exists(any())).thenReturn(true);
when(resourceCreditRepository.findById(any())).thenReturn(Optional.of(resourceCredit2));
when(resourceTypeRepository.exists(any())).thenReturn(true);
when(resourceCreditRepository.isNamePresent(any(), any())).thenReturn(true);
// when+then
assertThrows(IllegalArgumentException.class, () -> validator.validateUpdate(resourceCredit));
}
use of io.imunity.furms.domain.resource_credits.ResourceCredit in project furms by unity-idm.
the class ResourceCreditServiceValidatorTest method shouldPassCreateForUniqueName.
@Test
void shouldPassCreateForUniqueName() {
// given
ResourceCredit service = ResourceCredit.builder().siteId("id").resourceTypeId("id").name("name").amount(new BigDecimal(1)).utcStartTime(LocalDateTime.now()).utcEndTime(LocalDateTime.now()).build();
when(siteRepository.exists(service.siteId)).thenReturn(true);
when(resourceTypeRepository.exists(service.resourceTypeId)).thenReturn(true);
when(resourceCreditRepository.isNamePresent(any(), any())).thenReturn(false);
// when+then
assertDoesNotThrow(() -> validator.validateCreate(service));
}
Aggregations