@Test public void shouldProcessOrders() throws Exception { SupplyLine supplyLine = mock(SupplyLine.class); when(configurationSettingService.getBoolValue("USE_FTP_TO_SEND_ORDERS")).thenReturn(true); when(configurationSettingService.getConfigurationStringValue("LOCAL_ORDER_EXPORT_DIRECTORY")).thenReturn("./local-order-ftp-data"); when(orderService.getOrder(order.getId())).thenReturn(fullOrder); when(fullOrder.getId()).thenReturn(1l); when(fullOrder.getSupplyLine()).thenReturn(supplyLine); Long supplyLineId = 1l; when(supplyLine.getId()).thenReturn(supplyLineId); when(supplyLineService.getById(supplyLineId)).thenReturn(supplyLine); Facility facility = new Facility(); when(supplyLine.getSupplyingFacility()).thenReturn(facility); FacilityFtpDetails facilityFtpDetails = mock(FacilityFtpDetails.class); when(facilityFtpDetailsService.getByFacilityId(facility)).thenReturn(facilityFtpDetails); OrderFileTemplateDTO orderFileTemplateDTO = new OrderFileTemplateDTO(); OrderConfiguration orderConfiguration = new OrderConfiguration(); orderFileTemplateDTO.setOrderConfiguration(orderConfiguration); orderConfiguration.setFilePrefix("Order"); when(orderService.getOrderFileTemplateDTO()).thenReturn(orderFileTemplateDTO); File file = mock(File.class); whenNew(File.class).withArguments(localFileDirectory).thenReturn(file); whenNew(File.class).withArguments(localFileDirectory + System.getProperty("file.separator") + "Order1.csv").thenReturn(file); FileWriter fileWriter = mock(FileWriter.class); whenNew(FileWriter.class).withArguments(file).thenReturn(fileWriter); orderFtpTask.processOrder(orderList); verify(orderCsvHelper).writeCsvFile(fullOrder, orderFileTemplateDTO, fileWriter); verify(fileWriter).flush(); verify(ftpSender).sendFile(facilityFtpDetails, file); }
public void processOrder(@Payload List<Order> orders) { initiateSettings(); for (Order order : orders) { order = orderService.getOrder(order.getId()); SupplyLine supplyLine = order.getSupplyLine(); supplyLine = supplyLineService.getById(supplyLine.getId()); FacilityFtpDetails supplyingFacilityFtpDetails = facilityFtpDetailsService.getByFacilityId(supplyLine.getSupplyingFacility()); if (sendFtp && supplyingFacilityFtpDetails == null) { updateOrder(order, TRANSFER_FAILED, FTP_CREDENTIAL_MISSING_COMMENT); continue; } OrderFileTemplateDTO orderFileTemplateDTO = orderService.getOrderFileTemplateDTO(); String fileName = orderFileTemplateDTO.getOrderConfiguration().getFilePrefix() + order.getId() + ".csv"; File localDirectory = new File(localFileDirectory); if (!localDirectory.exists()) { localDirectory.mkdir(); } File file = new File(localFileDirectory + System.getProperty("file.separator") + fileName); try (FileWriter fileWriter = new FileWriter(file)) { orderCsvHelper.writeCsvFile(order, orderFileTemplateDTO, fileWriter); fileWriter.flush(); if(sendFtp) { ftpSender.sendFile(supplyingFacilityFtpDetails, file); } updateOrder(order, RELEASED, null); } catch (FailedToCreateProducerException producerException) { updateOrder(order, TRANSFER_FAILED, CONNECTION_REFUSED_COMMENT); } catch (CamelExecutionException camelException) { handleException(camelException, order); } catch (Exception e) { logger.error("Error in ftp of order file", e); updateOrder(order, TRANSFER_FAILED, null); } finally { if(sendFtp) { file.delete(); } } } }
OrderFtpTask { public void processOrder(@Payload List<Order> orders) { initiateSettings(); for (Order order : orders) { order = orderService.getOrder(order.getId()); SupplyLine supplyLine = order.getSupplyLine(); supplyLine = supplyLineService.getById(supplyLine.getId()); FacilityFtpDetails supplyingFacilityFtpDetails = facilityFtpDetailsService.getByFacilityId(supplyLine.getSupplyingFacility()); if (sendFtp && supplyingFacilityFtpDetails == null) { updateOrder(order, TRANSFER_FAILED, FTP_CREDENTIAL_MISSING_COMMENT); continue; } OrderFileTemplateDTO orderFileTemplateDTO = orderService.getOrderFileTemplateDTO(); String fileName = orderFileTemplateDTO.getOrderConfiguration().getFilePrefix() + order.getId() + ".csv"; File localDirectory = new File(localFileDirectory); if (!localDirectory.exists()) { localDirectory.mkdir(); } File file = new File(localFileDirectory + System.getProperty("file.separator") + fileName); try (FileWriter fileWriter = new FileWriter(file)) { orderCsvHelper.writeCsvFile(order, orderFileTemplateDTO, fileWriter); fileWriter.flush(); if(sendFtp) { ftpSender.sendFile(supplyingFacilityFtpDetails, file); } updateOrder(order, RELEASED, null); } catch (FailedToCreateProducerException producerException) { updateOrder(order, TRANSFER_FAILED, CONNECTION_REFUSED_COMMENT); } catch (CamelExecutionException camelException) { handleException(camelException, order); } catch (Exception e) { logger.error("Error in ftp of order file", e); updateOrder(order, TRANSFER_FAILED, null); } finally { if(sendFtp) { file.delete(); } } } } }
OrderFtpTask { public void processOrder(@Payload List<Order> orders) { initiateSettings(); for (Order order : orders) { order = orderService.getOrder(order.getId()); SupplyLine supplyLine = order.getSupplyLine(); supplyLine = supplyLineService.getById(supplyLine.getId()); FacilityFtpDetails supplyingFacilityFtpDetails = facilityFtpDetailsService.getByFacilityId(supplyLine.getSupplyingFacility()); if (sendFtp && supplyingFacilityFtpDetails == null) { updateOrder(order, TRANSFER_FAILED, FTP_CREDENTIAL_MISSING_COMMENT); continue; } OrderFileTemplateDTO orderFileTemplateDTO = orderService.getOrderFileTemplateDTO(); String fileName = orderFileTemplateDTO.getOrderConfiguration().getFilePrefix() + order.getId() + ".csv"; File localDirectory = new File(localFileDirectory); if (!localDirectory.exists()) { localDirectory.mkdir(); } File file = new File(localFileDirectory + System.getProperty("file.separator") + fileName); try (FileWriter fileWriter = new FileWriter(file)) { orderCsvHelper.writeCsvFile(order, orderFileTemplateDTO, fileWriter); fileWriter.flush(); if(sendFtp) { ftpSender.sendFile(supplyingFacilityFtpDetails, file); } updateOrder(order, RELEASED, null); } catch (FailedToCreateProducerException producerException) { updateOrder(order, TRANSFER_FAILED, CONNECTION_REFUSED_COMMENT); } catch (CamelExecutionException camelException) { handleException(camelException, order); } catch (Exception e) { logger.error("Error in ftp of order file", e); updateOrder(order, TRANSFER_FAILED, null); } finally { if(sendFtp) { file.delete(); } } } }  }
OrderFtpTask { public void processOrder(@Payload List<Order> orders) { initiateSettings(); for (Order order : orders) { order = orderService.getOrder(order.getId()); SupplyLine supplyLine = order.getSupplyLine(); supplyLine = supplyLineService.getById(supplyLine.getId()); FacilityFtpDetails supplyingFacilityFtpDetails = facilityFtpDetailsService.getByFacilityId(supplyLine.getSupplyingFacility()); if (sendFtp && supplyingFacilityFtpDetails == null) { updateOrder(order, TRANSFER_FAILED, FTP_CREDENTIAL_MISSING_COMMENT); continue; } OrderFileTemplateDTO orderFileTemplateDTO = orderService.getOrderFileTemplateDTO(); String fileName = orderFileTemplateDTO.getOrderConfiguration().getFilePrefix() + order.getId() + ".csv"; File localDirectory = new File(localFileDirectory); if (!localDirectory.exists()) { localDirectory.mkdir(); } File file = new File(localFileDirectory + System.getProperty("file.separator") + fileName); try (FileWriter fileWriter = new FileWriter(file)) { orderCsvHelper.writeCsvFile(order, orderFileTemplateDTO, fileWriter); fileWriter.flush(); if(sendFtp) { ftpSender.sendFile(supplyingFacilityFtpDetails, file); } updateOrder(order, RELEASED, null); } catch (FailedToCreateProducerException producerException) { updateOrder(order, TRANSFER_FAILED, CONNECTION_REFUSED_COMMENT); } catch (CamelExecutionException camelException) { handleException(camelException, order); } catch (Exception e) { logger.error("Error in ftp of order file", e); updateOrder(order, TRANSFER_FAILED, null); } finally { if(sendFtp) { file.delete(); } } } }  void processOrder(@Payload List<Order> orders); }
OrderFtpTask { public void processOrder(@Payload List<Order> orders) { initiateSettings(); for (Order order : orders) { order = orderService.getOrder(order.getId()); SupplyLine supplyLine = order.getSupplyLine(); supplyLine = supplyLineService.getById(supplyLine.getId()); FacilityFtpDetails supplyingFacilityFtpDetails = facilityFtpDetailsService.getByFacilityId(supplyLine.getSupplyingFacility()); if (sendFtp && supplyingFacilityFtpDetails == null) { updateOrder(order, TRANSFER_FAILED, FTP_CREDENTIAL_MISSING_COMMENT); continue; } OrderFileTemplateDTO orderFileTemplateDTO = orderService.getOrderFileTemplateDTO(); String fileName = orderFileTemplateDTO.getOrderConfiguration().getFilePrefix() + order.getId() + ".csv"; File localDirectory = new File(localFileDirectory); if (!localDirectory.exists()) { localDirectory.mkdir(); } File file = new File(localFileDirectory + System.getProperty("file.separator") + fileName); try (FileWriter fileWriter = new FileWriter(file)) { orderCsvHelper.writeCsvFile(order, orderFileTemplateDTO, fileWriter); fileWriter.flush(); if(sendFtp) { ftpSender.sendFile(supplyingFacilityFtpDetails, file); } updateOrder(order, RELEASED, null); } catch (FailedToCreateProducerException producerException) { updateOrder(order, TRANSFER_FAILED, CONNECTION_REFUSED_COMMENT); } catch (CamelExecutionException camelException) { handleException(camelException, order); } catch (Exception e) { logger.error("Error in ftp of order file", e); updateOrder(order, TRANSFER_FAILED, null); } finally { if(sendFtp) { file.delete(); } } } }  void processOrder(@Payload List<Order> orders); static String FTP_CREDENTIAL_MISSING_COMMENT; }