@Test public void shouldAddStockCardEntriesWithAdjustmentReasonToStockCard() throws Exception { setupStockData(); String stockAdjustmentReasonName = "Issue"; StockAdjustmentReason stockAdjustmentReason = new StockAdjustmentReason(); stockAdjustmentReason.setName(stockAdjustmentReasonName); stockAdjustmentReason.setAdditive(false); stockEvent1.setReasonName(stockAdjustmentReasonName); String stockAdjustmentReasonName2 = "Acquire"; StockAdjustmentReason stockAdjustmentReason2 = new StockAdjustmentReason(); stockAdjustmentReason2.setName(stockAdjustmentReasonName2); stockAdjustmentReason2.setAdditive(true); stockEvent2.setReasonName(stockAdjustmentReasonName2); when(facilityRepository.getById(facilityId)).thenReturn(defaultFacility); when(productService.getByCode(productCode)).thenReturn(defaultProduct); when(stockAdjustmentReasonRepository.getAdjustmentReasonByName(stockAdjustmentReasonName)).thenReturn(stockAdjustmentReason); when(stockAdjustmentReasonRepository.getAdjustmentReasonByName(stockAdjustmentReasonName2)).thenReturn(stockAdjustmentReason2); StockCard expectedStockCard = StockCard.createZeroedStockCard(defaultFacility, defaultProduct); when(stockCardService.getOrCreateStockCard(facilityId, productCode)).thenReturn(expectedStockCard); List<StockCardEntry> stockCardEntries = restStockCardService.adjustStock(facilityId, stockEventList, userId); verify(stockCardService).addStockCardEntries(anyList()); assertThat(stockCardEntries.get(0).getAdjustmentReason(), is(stockAdjustmentReason)); assertThat(stockCardEntries.get(1).getAdjustmentReason(), is(stockAdjustmentReason2)); }
public List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId) { if (!validFacility(facilityId)) { throw new DataException("error.facility.unknown"); } Map<String, StockCard> stockCardMap = new HashMap<>(); List<StockCardEntry> entries = new ArrayList<>(); for (StockEvent stockEvent : stockEventList) { String errorInStockEvent = validateStockEvent(stockEvent); if (errorInStockEvent != null) { throw new DataException(errorInStockEvent); } String productCode = stockEvent.getProductCode(); StockCard stockCard; if (stockCardMap.get(productCode) == null) { stockCard = stockCardService.getOrCreateStockCard(facilityId, productCode); stockCardMap.put(productCode, stockCard); } else { stockCard = stockCardMap.get(productCode); } StockCardEntry entry = createStockCardEntry(stockEvent, stockCard, userId); entries.add(entry); } stockCardService.addStockCardEntries(entries); return entries; }
RestStockCardService { public List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId) { if (!validFacility(facilityId)) { throw new DataException("error.facility.unknown"); } Map<String, StockCard> stockCardMap = new HashMap<>(); List<StockCardEntry> entries = new ArrayList<>(); for (StockEvent stockEvent : stockEventList) { String errorInStockEvent = validateStockEvent(stockEvent); if (errorInStockEvent != null) { throw new DataException(errorInStockEvent); } String productCode = stockEvent.getProductCode(); StockCard stockCard; if (stockCardMap.get(productCode) == null) { stockCard = stockCardService.getOrCreateStockCard(facilityId, productCode); stockCardMap.put(productCode, stockCard); } else { stockCard = stockCardMap.get(productCode); } StockCardEntry entry = createStockCardEntry(stockEvent, stockCard, userId); entries.add(entry); } stockCardService.addStockCardEntries(entries); return entries; } }
RestStockCardService { public List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId) { if (!validFacility(facilityId)) { throw new DataException("error.facility.unknown"); } Map<String, StockCard> stockCardMap = new HashMap<>(); List<StockCardEntry> entries = new ArrayList<>(); for (StockEvent stockEvent : stockEventList) { String errorInStockEvent = validateStockEvent(stockEvent); if (errorInStockEvent != null) { throw new DataException(errorInStockEvent); } String productCode = stockEvent.getProductCode(); StockCard stockCard; if (stockCardMap.get(productCode) == null) { stockCard = stockCardService.getOrCreateStockCard(facilityId, productCode); stockCardMap.put(productCode, stockCard); } else { stockCard = stockCardMap.get(productCode); } StockCardEntry entry = createStockCardEntry(stockEvent, stockCard, userId); entries.add(entry); } stockCardService.addStockCardEntries(entries); return entries; }  }
RestStockCardService { public List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId) { if (!validFacility(facilityId)) { throw new DataException("error.facility.unknown"); } Map<String, StockCard> stockCardMap = new HashMap<>(); List<StockCardEntry> entries = new ArrayList<>(); for (StockEvent stockEvent : stockEventList) { String errorInStockEvent = validateStockEvent(stockEvent); if (errorInStockEvent != null) { throw new DataException(errorInStockEvent); } String productCode = stockEvent.getProductCode(); StockCard stockCard; if (stockCardMap.get(productCode) == null) { stockCard = stockCardService.getOrCreateStockCard(facilityId, productCode); stockCardMap.put(productCode, stockCard); } else { stockCard = stockCardMap.get(productCode); } StockCardEntry entry = createStockCardEntry(stockEvent, stockCard, userId); entries.add(entry); } stockCardService.addStockCardEntries(entries); return entries; }  List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId); }
RestStockCardService { public List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId) { if (!validFacility(facilityId)) { throw new DataException("error.facility.unknown"); } Map<String, StockCard> stockCardMap = new HashMap<>(); List<StockCardEntry> entries = new ArrayList<>(); for (StockEvent stockEvent : stockEventList) { String errorInStockEvent = validateStockEvent(stockEvent); if (errorInStockEvent != null) { throw new DataException(errorInStockEvent); } String productCode = stockEvent.getProductCode(); StockCard stockCard; if (stockCardMap.get(productCode) == null) { stockCard = stockCardService.getOrCreateStockCard(facilityId, productCode); stockCardMap.put(productCode, stockCard); } else { stockCard = stockCardMap.get(productCode); } StockCardEntry entry = createStockCardEntry(stockEvent, stockCard, userId); entries.add(entry); } stockCardService.addStockCardEntries(entries); return entries; }  List<StockCardEntry> adjustStock(Long facilityId, List<StockEvent> stockEventList, Long userId);  }