Search in sources :

Example 1 with StockCardDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardDataBuilder 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 2 with StockCardDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandFromMiddleIsLessThanStockAdjustment.

@Test
public void shouldNotRejectWhenStockOnHandFromMiddleIsLessThanStockAdjustment() {
    // given
    StockCard card = new StockCardDataBuilder(new StockEventDataBuilder().build()).withLineItem(buildPhysicalInventoryLineItem(100, Month.JANUARY)).withLineItem(buildPhysicalInventoryLineItem(80, Month.MARCH)).build();
    StockEventDto event = createPhysicalInventoryEventDto(LocalDate.of(2017, Month.FEBRUARY, 28), 15, null);
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 3 with StockCardDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesV2DtoBuilderTest method before.

@Before
public void before() {
    ReflectionTestUtils.setField(builder, "serviceUrl", "https://openlmis/");
    orderable1 = new OrderableDtoDataBuilder().build();
    orderable2 = new OrderableDtoDataBuilder().build();
    orderable3 = new OrderableDtoDataBuilder().build();
    StockEvent event = new StockEventDataBuilder().withFacility(facilityId).withProgram(programId).build();
    stockCard = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(12, new StockCardLineItemDataBuilder().buildWithStockOnHand(16), orderable1.getId());
    stockCard1 = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(26, new StockCardLineItemDataBuilder().buildWithStockOnHand(30), orderable3.getId());
    stockCard2 = new StockCardDataBuilder(event).withLot(UUID.randomUUID()).buildWithStockOnHandAndLineItemAndOrderableId(22, new StockCardLineItemDataBuilder().buildWithStockOnHand(10), orderable3.getId());
    fulfillMap = new HashMap<>();
    fulfillMap.put(orderable1.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
    fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(Collections.singletonList(orderable1.getId())).build());
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) OrderableFulfillDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder) StockCardLineItemDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder) Before(org.junit.Before)

Example 4 with StockCardDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceTest method setUp.

@Before
public void setUp() {
    when(user.getId()).thenReturn(userId);
    when(authenticationHelper.getCurrentUser()).thenReturn(user);
    when(permissionStringsHandler.get()).thenReturn(Collections.singleton(PermissionStringDto.create(STOCK_CARDS_VIEW, facilityId, programId)));
    when(permissionService.getPermissionStrings(userId)).thenReturn(permissionStringsHandler);
    when(facilityRefDataService.findOne(facilityId)).thenReturn(FacilityDto.builder().id(facilityId).build());
    when(programRefDataService.findOne(programId)).thenReturn(ProgramDto.builder().id(programId).build());
    StockEvent originalEvent = new StockEventDataBuilder().withFacility(facilityId).withProgram(programId).build();
    stockCard = new StockCardDataBuilder(originalEvent).build();
    SecurityContextHolder.setContext(securityContext);
    when(securityContext.getAuthentication()).thenReturn(authentication);
    when(authentication.isClientOnly()).thenReturn(false);
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) Before(org.junit.Before)

Example 5 with StockCardDataBuilder

use of org.openlmis.stockmanagement.testutils.StockCardDataBuilder in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesServiceTest method shouldFindStockCards.

@Test
public void shouldFindStockCards() throws Exception {
    OrderableDto orderable = new OrderableDtoDataBuilder().build();
    OrderableDto orderable2 = new OrderableDtoDataBuilder().build();
    OrderableDto orderable3 = new OrderableDtoDataBuilder().build();
    StockCardSummariesV2SearchParams params = new StockCardSummariesV2SearchParamsDataBuilder().withOrderableIds(asList(orderable.getId(), orderable2.getId())).build();
    when(approvedProductReferenceDataService.getApprovedProducts(eq(params.getFacilityId()), eq(params.getProgramId()), eq(params.getOrderableIds()))).thenReturn(new PageImpl<>(asList(orderable, orderable2, orderable3), new PageRequest(0, Integer.MAX_VALUE), 3));
    Map<UUID, OrderableFulfillDto> fulfillMap = new HashMap<>();
    fulfillMap.put(orderable.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
    fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable.getId(), orderable3.getId())).build());
    when(orderableFulfillReferenceDataService.findByIds(asList(orderable.getId(), orderable2.getId(), orderable3.getId()))).thenReturn(fulfillMap);
    StockEvent event = new StockEventDataBuilder().withFacility(params.getFacilityId()).withProgram(params.getProgramId()).build();
    StockCard stockCard = new StockCardDataBuilder(event).withOrderable(orderable.getId()).withStockOnHand(12).build();
    StockCard stockCard1 = new StockCardDataBuilder(event).withOrderable(orderable3.getId()).withStockOnHand(26).build();
    List<StockCard> stockCards = asList(stockCard, stockCard1);
    when(cardRepository.findByProgramIdAndFacilityId(params.getProgramId(), params.getFacilityId())).thenReturn(stockCards);
    StockCardSummaries result = stockCardSummariesService.findStockCards(params);
    assertEquals(3, result.getPageOfApprovedProducts().size());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) HashMap(java.util.HashMap) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) OrderableFulfillDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder) OrderableFulfillDto(org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto) PageRequest(org.springframework.data.domain.PageRequest) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCardSummariesV2SearchParamsDataBuilder(org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)5 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)5 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)4 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)3 Before (org.junit.Before)2 Test (org.junit.Test)2 OrderableDtoDataBuilder (org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder)2 OrderableFulfillDtoDataBuilder (org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder)2 StockCardLineItemDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 UUID.randomUUID (java.util.UUID.randomUUID)1 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)1 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)1 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)1 OrderableFulfillDto (org.openlmis.stockmanagement.dto.referencedata.OrderableFulfillDto)1 StockCardSummariesV2SearchParamsDataBuilder (org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder)1 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)1 PageRequest (org.springframework.data.domain.PageRequest)1