Search in sources :

Example 1 with ResourceCredit

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)));
}
Also used : ResourceCreditCreatedEvent(io.imunity.furms.domain.resource_credits.ResourceCreditCreatedEvent) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) BigDecimal(java.math.BigDecimal) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceCredit

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)));
}
Also used : ResourceCreditCreatedEvent(io.imunity.furms.domain.resource_credits.ResourceCreditCreatedEvent) ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 3 with ResourceCredit

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));
}
Also used : ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) Test(org.junit.jupiter.api.Test)

Example 4 with ResourceCredit

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));
}
Also used : ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 5 with 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));
}
Also used : ResourceCredit(io.imunity.furms.domain.resource_credits.ResourceCredit) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceCredit (io.imunity.furms.domain.resource_credits.ResourceCredit)36 Test (org.junit.jupiter.api.Test)26 BigDecimal (java.math.BigDecimal)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)6 ResourceCreditCreatedEvent (io.imunity.furms.domain.resource_credits.ResourceCreditCreatedEvent)4 Site (io.imunity.furms.domain.sites.Site)4 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)4 PersistentId (io.imunity.furms.domain.users.PersistentId)4 Optional (java.util.Optional)4 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 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)3 ResourceType (io.imunity.furms.domain.resource_types.ResourceType)3 InfraService (io.imunity.furms.domain.services.InfraService)3 SiteRepository (io.imunity.furms.spi.sites.SiteRepository)3 Set (java.util.Set)3 UUID (java.util.UUID)3 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)2