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());
}
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()))));
}
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()))));
}
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}]}"));
}
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);
}
Aggregations