OrderModificationProcessorJobPerformable extends AbstractJobPerformable<OrderModificationCronJobModel> { @Override public PerformResult perform(final OrderModificationCronJobModel cronJobModel) { final Set<PaymentTransactionType> typeOfPaymentTransactionToProcessSet = cronJobModel.getPaymentTransactionTypes(); LOG.info(MessageFormat.format("Executing cronjob for payment transaction types: {0}", typeOfPaymentTransactionToProcessSet)); boolean success = true; for (final PaymentTransactionType paymentTransactionType : typeOfPaymentTransactionToProcessSet) { if (!worldpayOrderModificationProcessStrategy.processOrderModificationMessages(paymentTransactionType)) { success = false; } } final CronJobResult result = success ? SUCCESS : ERROR; LOG.info(MessageFormat.format("Cronjob finished with result {0}", result)); return new PerformResult(result, FINISHED); }  @Override PerformResult perform(final OrderModificationCronJobModel cronJobModel); @Required void setWorldpayOrderModificationProcessStrategy(WorldpayOrderModificationProcessStrategy worldpayOrderModificationProcessStrategy);  }
@Test public void performShouldProcessAllProcessableModifications() { when(cronJobModelMock.getPaymentTransactionTypes()).thenReturn(paymentTransactionTypes); when(worldpayOrderModificationProcessStrategyMock.processOrderModificationMessages(any(PaymentTransactionType.class))).thenReturn(true); final PerformResult result = testObj.perform(cronJobModelMock); assertEquals(CronJobResult.SUCCESS, result.getResult()); assertEquals(CronJobStatus.FINISHED, result.getStatus()); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(AUTHORIZATION); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(CAPTURE); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(CANCEL); }
@Test public void performShouldMarkErrorWhenFalseReturnedFromStrategy() { when(cronJobModelMock.getPaymentTransactionTypes()).thenReturn(paymentTransactionTypes); when(worldpayOrderModificationProcessStrategyMock.processOrderModificationMessages(any(PaymentTransactionType.class))).thenReturn(false); final PerformResult result = testObj.perform(cronJobModelMock); assertEquals(CronJobResult.ERROR, result.getResult()); assertEquals(CronJobStatus.FINISHED, result.getStatus()); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(AUTHORIZATION); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(CAPTURE); verify(worldpayOrderModificationProcessStrategyMock).processOrderModificationMessages(CANCEL); }