Search in sources :

Example 1 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockEventDtoTest method shouldConvertFromDtoToJpaModel.

@Test
public void shouldConvertFromDtoToJpaModel() throws Exception {
    // given
    UUID userId = UUID.randomUUID();
    StockEventProcessContext context = new StockEventProcessContext();
    context.setCurrentUserId(new LazyResource<>(() -> userId));
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.setContext(context);
    // when
    StockEvent event = stockEventDto.toEvent();
    // then
    assertThat(event.getDocumentNumber(), is(stockEventDto.getDocumentNumber()));
    assertThat(event.getSignature(), is(stockEventDto.getSignature()));
    assertThat(event.getLineItems(), hasSize(stockEventDto.getLineItems().size()));
    assertThat(event.getProgramId(), is(stockEventDto.getProgramId()));
    assertThat(event.getFacilityId(), is(stockEventDto.getFacilityId()));
    assertThat(event.getUserId(), is(userId));
    ZonedDateTime processedDate = event.getProcessedDate();
    long between = SECONDS.between(processedDate, ZonedDateTime.now());
    assertThat(between, lessThan(2L));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 2 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardRepositoryIntegrationTest method generateInstance.

private StockCard generateInstance(UUID facility, UUID program, UUID product, UUID lot) {
    StockEvent event = new StockEventDataBuilder().withoutId().withFacility(facility).withProgram(program).build();
    event = stockEventsRepository.save(event);
    StockCardLineItem lineItem = new StockCardLineItemDataBuilder().withoutId().withOriginEvent(event).build();
    StockCard stockCard = new StockCardDataBuilder(event).withoutId().withOrderable(product).withLot(lot).withLineItem(lineItem).build();
    lineItem.setStockCard(stockCard);
    return stockCard;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockCardLineItemDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)

Example 3 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method save.

private StockEvent save(StockEventDto eventDto, UUID userId) {
    eventDto.setUserId(userId);
    setContext(eventDto);
    StockEvent event = eventDto.toEvent();
    StockEvent savedEvent = stockEventsRepository.save(event);
    stockCardService.saveFromEvent(eventDto, savedEvent.getId());
    return savedEvent;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent)

Example 4 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldGetStockCardWithCalculatedSohWhenFindStockCard.

@Test
public void shouldGetStockCardWithCalculatedSohWhenFindStockCard() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setSourceId(null);
    stockEventDto.getLineItems().get(0).setDestinationId(null);
    StockEvent savedEvent = save(stockEventDto, randomUUID());
    // when
    UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
    StockCardDto card = stockCardService.findStockCardById(cardId);
    // then
    assertThat(card.getStockOnHand(), is(stockEventDto.getLineItems().get(0).getQuantity()));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard.

@Test(expected = PermissionMessageException.class)
public void shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard() throws Exception {
    // given
    StockEvent savedEvent = save(createStockEventDto(), randomUUID());
    doThrow(new PermissionMessageException(new Message("some error"))).when(permissionService).canViewStockCard(savedEvent.getProgramId(), savedEvent.getFacilityId());
    // when
    UUID savedCardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
    stockCardService.findStockCardById(savedCardId);
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) Message(org.openlmis.stockmanagement.util.Message) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)18 UUID (java.util.UUID)10 Test (org.junit.Test)8 UUID.randomUUID (java.util.UUID.randomUUID)7 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)6 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)5 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)5 StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)4 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)4 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)3 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)3 Before (org.junit.Before)2 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)2 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)2 StockCardLineItemDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)2 Message (org.openlmis.stockmanagement.util.Message)2 ZonedDateTime (java.time.ZonedDateTime)1 Collections (java.util.Collections)1