APMOrderTimeoutJobPerformable extends AbstractJobPerformable { @Override public PerformResult perform(final CronJobModel cronJobModel) { LOG.debug("Executing Order Timeout cronjob for timed out pending payment transactions"); final List<PaymentTransactionModel> cancellablePendingAPMPaymentTransactions = worldpayPaymentTransactionDao.findCancellablePendingAPMPaymentTransactions(); CronJobResult cronJobResult = CronJobResult.SUCCESS; for (final PaymentTransactionModel paymentTransactionModel : cancellablePendingAPMPaymentTransactions) { transactionTemplate.execute(transactionStatus -> { worldpayPaymentTransactionService.updateEntriesStatus(paymentTransactionModel.getEntries(), REVIEW.name()); modelService.save(paymentTransactionModel); return null; }); final OrderModel orderModel = (OrderModel) paymentTransactionModel.getOrder(); final Collection<OrderProcessModel> orderProcesses = orderModel.getOrderProcess(); for (final OrderProcessModel orderProcess : orderProcesses) { final String eventName = orderProcess.getCode() + "_" + PaymentTransactionType.AUTHORIZATION; LOG.info(MessageFormat.format("Order with code [{0}] timed out. Attempting to trigger an event with code [{1}]", orderModel.getCode(), eventName)); businessProcessService.triggerEvent(eventName); } } return new PerformResult(cronJobResult, CronJobStatus.FINISHED); }  @Override PerformResult perform(final CronJobModel cronJobModel); @Required void setWorldpayPaymentTransactionDao(WorldpayPaymentTransactionDao worldpayPaymentTransactionDao); @Required void setBusinessProcessService(final BusinessProcessService businessProcessService); @Required void setWorldpayPaymentTransactionService(final WorldpayPaymentTransactionService worldpayPaymentTransactionService); @Required void setTransactionTemplate(final TransactionOperations transactionTemplate);  }
@Test public void testPerformShouldReturnSuccess() throws Exception { final PerformResult result = testObj.perform(cronJobModelMock); assertEquals(SUCCESS, result.getResult()); assertEquals(FINISHED, result.getStatus()); verify(worldpayPaymentTransactionServiceMock).updateEntriesStatus(Collections.singletonList(paymentTransactionEntryModelMock), REVIEW.name()); verify(modelServiceMock).save(paymentTransactionModelMock); verify(worldpayPaymentTransactionDaoMock).findCancellablePendingAPMPaymentTransactions(); verify(businessProcessServiceMock).triggerEvent(ORDER_PROCESS_CODE + "_" + PaymentTransactionType.AUTHORIZATION); }