DefaultOrderNotificationService implements OrderNotificationService { @Override public void processOrderNotificationMessage(final OrderNotificationMessage orderNotificationMessage) throws WorldpayConfigurationException { final AuthorisedStatus journalTypeCode = orderNotificationMessage.getJournalReply().getJournalType(); final OrderNotificationProcessorStrategy orderNotificationProcessorStrategy = journalTypeToNotificationProcessorStrategyMap.get(journalTypeCode); if (orderNotificationProcessorStrategy != null) { final PaymentTransactionModel paymentTransactionModel = worldpayPaymentTransactionDao.findPaymentTransactionByRequestIdFromOrdersOnly(orderNotificationMessage.getOrderCode()); orderNotificationProcessorStrategy.processNotificationMessage(paymentTransactionModel, orderNotificationMessage); } else { LOG.warn(format("Could not find notification processor for journal type code [{0}]. " + "It's either an unsupported journal type or there is a configuration problem.", journalTypeCode.name())); } }  @Override void processOrderNotificationMessage(final OrderNotificationMessage orderNotificationMessage); @Required void setWorldpayPaymentTransactionDao(final WorldpayPaymentTransactionDao worldpayPaymentTransactionDao); @Required void setJournalTypeToNotificationProcessorStrategyMap(final Map<AuthorisedStatus, OrderNotificationProcessorStrategy> journalTypeToNotificationProcessorStrategyMap);  }
@Test public void processOrderNotificationMessageDoesNothingIfNoProcessorFound() throws WorldpayConfigurationException { when(orderNotificationMessageMock.getJournalReply().getJournalType()).thenReturn(REFUSED); testObj.processOrderNotificationMessage(orderNotificationMessageMock); verify(worldpayPaymentTransactionDaoMock, never()).findPaymentTransactionByRequestIdFromOrdersOnly(anyString()); verify(orderNotificationProcessorStrategyMock, never()).processNotificationMessage(anyObject(), anyObject()); }
@Test public void processOrderNotificationMessageInvokesProcessorForJournalType() throws WorldpayConfigurationException { when(orderNotificationMessageMock.getOrderCode()).thenReturn(ORDER_CODE); when(orderNotificationMessageMock.getJournalReply().getJournalType()).thenReturn(AUTHORISED); when(worldpayPaymentTransactionDaoMock.findPaymentTransactionByRequestIdFromOrdersOnly(ORDER_CODE)).thenReturn(paymentTransactionModelMock); testObj.processOrderNotificationMessage(orderNotificationMessageMock); verify(worldpayPaymentTransactionDaoMock).findPaymentTransactionByRequestIdFromOrdersOnly(ORDER_CODE); verify(orderNotificationProcessorStrategyMock).processNotificationMessage(paymentTransactionModelMock, orderNotificationMessageMock); }