Search in sources :

Example 1 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceTest method verifyPage.

private void verifyPage(Page<StockCardDto> search) {
    assertEquals(10, search.getTotalElements());
    assertEquals(1, search.getNumberOfElements());
    StockCardDto stockCardDto = search.getContent().get(0);
    assertEquals(stockCard.getId(), stockCardDto.getId());
    assertEquals(facilityId, stockCardDto.getFacility().getId());
    assertEquals(programId, stockCardDto.getProgram().getId());
    assertEquals(stockCard.getOrderableId(), stockCardDto.getOrderableId());
    assertEquals(stockCard.getLotId(), stockCardDto.getLotId());
}
Also used : StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto)

Example 2 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesServiceTest method shouldFindExistingStockCards.

@Test
public void shouldFindExistingStockCards() throws Exception {
    // given
    UUID orderable1Id = randomUUID();
    UUID orderable2Id = randomUUID();
    UUID orderable3Id = randomUUID();
    UUID orderable4Id = randomUUID();
    OrderableDto orderable1 = createOrderableDto(orderable1Id, "");
    OrderableDto orderable2 = createOrderableDto(orderable2Id, "");
    OrderableDto orderable3 = createOrderableDto(orderable3Id, "");
    OrderableDto orderable4 = createOrderableDto(orderable4Id, "");
    UUID programId = randomUUID();
    UUID facilityId = randomUUID();
    when(orderableReferenceDataService.findAll()).thenReturn(asList(orderable1, orderable2, orderable3, orderable4));
    when(cardRepository.findByProgramIdAndFacilityId(programId, facilityId)).thenReturn(asList(createStockCard(orderable1Id, randomUUID()), createStockCard(orderable3Id, randomUUID())));
    when(lotReferenceDataService.getAllLotsOf(any(UUID.class))).thenReturn(emptyList());
    // when
    List<StockCardDto> cardDtos = stockCardSummariesService.findStockCards(programId, facilityId);
    // then
    assertThat(cardDtos.size(), is(2));
    String orderablePropertyName = "orderable";
    String idPropertyName = "id";
    String lineItemsPropertyName = "lineItems";
    String stockOnHandPropertyName = "stockOnHand";
    String lastUpdatePropertyName = "lastUpdate";
    assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable1)), hasProperty(idPropertyName, notNullValue()), hasProperty(stockOnHandPropertyName, notNullValue()), hasProperty(lastUpdatePropertyName, is(LocalDate.of(2017, 3, 18))), hasProperty(lineItemsPropertyName, nullValue()))));
    assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable3)), hasProperty(idPropertyName, notNullValue()), hasProperty(stockOnHandPropertyName, notNullValue()), hasProperty(lastUpdatePropertyName, is(LocalDate.of(2017, 3, 18))), hasProperty(lineItemsPropertyName, nullValue()))));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID.fromString(java.util.UUID.fromString) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesServiceTest method shouldCreateDummyCards.

@Test
public void shouldCreateDummyCards() throws Exception {
    // given
    UUID orderable1Id = randomUUID();
    UUID orderable2Id = randomUUID();
    UUID orderable3Id = randomUUID();
    UUID orderable4Id = randomUUID();
    OrderableDto orderable1 = createOrderableDto(orderable1Id, "1");
    OrderableDto orderable2 = createOrderableDto(orderable2Id, "2");
    orderable2.getIdentifiers().put("tradeItem", randomUUID().toString());
    OrderableDto orderable3 = createOrderableDto(orderable3Id, "3");
    OrderableDto orderable4 = createOrderableDto(orderable4Id, "4");
    UUID programId = randomUUID();
    UUID facilityId = randomUUID();
    // 1,2,3,4 all approved
    when(orderableReferenceDataService.findAll()).thenReturn(asList(orderable1, orderable2, orderable3, orderable4));
    // but only 1, 3 have cards. 2, 4 don't have cards.
    when(cardRepository.getIdentitiesBy(programId, facilityId)).thenReturn(asList(new OrderableLotIdentity(orderable1Id, null), new OrderableLotIdentity(orderable3Id, null)));
    LotDto lotDto = new LotDto();
    lotDto.setId(randomUUID());
    // 2 has a lot
    when(lotReferenceDataService.getAllLotsOf(fromString(orderable2.getIdentifiers().get("tradeItem")))).thenReturn(singletonList(lotDto));
    // when
    List<StockCardDto> cardDtos = stockCardSummariesService.createDummyStockCards(programId, facilityId);
    // then
    assertThat(cardDtos.size(), is(3));
    String orderablePropertyName = "orderable";
    String lotPropertyName = "lot";
    String idPropertyName = "id";
    String lineItemsPropertyName = "lineItems";
    String stockOnHandPropertyName = "stockOnHand";
    String lastUpdatePropertyName = "lastUpdate";
    // 2 and lot
    assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(lotDto)), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
    // 2 and no lot
    assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
    // 4 and no lot
    assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable4)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID.fromString(java.util.UUID.fromString) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) Test(org.junit.Test)

Example 4 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardControllerIntegrationTest method shouldGetStockCardById.

@Test
public void shouldGetStockCardById() throws Exception {
    // given
    UUID stockCardId = UUID.randomUUID();
    StockCardDto stockCardDto = createStockCardDto();
    when(stockCardService.findStockCardById(stockCardId)).thenReturn(stockCardDto);
    // when
    ResultActions resultActions = mvc.perform(get(API_STOCK_CARDS + stockCardId.toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
    // then
    resultActions.andDo(print()).andExpect(status().isOk()).andExpect(content().json("{" + "'stockOnHand':1," + "'facility':{'name':'HC01'}," + "'program':{'name':'HIV'}," + "'orderable':{'productCode':'ABC01'}," + "'lineItems':[" + "{'occurredDate':'2017-02-13'," + "'source':{'name':'HF1'}," + "'destination':null," + "'reason':{'name':'Transfer In','reasonCategory':'ADJUSTMENT'," + "'reasonType':'CREDIT'}," + "'quantity':1, 'stockOnHand':1}]}"));
}
Also used : StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) StockCardDtoDataBuilder.createStockCardDto(org.openlmis.stockmanagement.testutils.StockCardDtoDataBuilder.createStockCardDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with StockCardDto

use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldReturnNullWhenCanNotFindStockCardById.

@Test
public void shouldReturnNullWhenCanNotFindStockCardById() throws Exception {
    // when
    UUID nonExistingCardId = randomUUID();
    StockCardDto cardDto = stockCardService.findStockCardById(nonExistingCardId);
    // then
    assertNull(cardDto);
}
Also used : 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)

Aggregations

StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)16 UUID (java.util.UUID)10 Test (org.junit.Test)8 UUID.randomUUID (java.util.UUID.randomUUID)7 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)5 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)5 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)4 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)4 List (java.util.List)3 UUID.fromString (java.util.UUID.fromString)3 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)3 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)3 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)2 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)2