WorldpayFraudCheckOrderInternalAction extends WorldpayAbstractFraudCheckAction<OrderProcessModel> { @Override public String executeAction(final OrderProcessModel process) { ServicesUtil.validateParameterNotNull(process, "Process can not be null"); ServicesUtil.validateParameterNotNull(process.getOrder(), "Order can not be null"); final OrderModel order = process.getOrder(); final FraudServiceResponse response = getFraudService().recognizeOrderSymptoms(getProviderName(), order); if (CollectionUtils.isEmpty(response.getSymptoms())) { final FraudReportModel fraudReport = createFraudReport(providerName, response, order, FraudStatus.OK); final OrderHistoryEntryModel historyEntry = createHistoryLog(providerName, order, FraudStatus.OK, null); order.setFraudulent(Boolean.FALSE); order.setPotentiallyFraudulent(Boolean.FALSE); order.setStatus(OrderStatus.FRAUD_CHECKED); modelService.save(fraudReport); modelService.save(historyEntry); modelService.save(order); return OK; } else { LOG.warn(MessageFormat.format("The order [{0}] is potentially fraudulent. Sent into Fraud Review state", order.getCode())); final FraudReportModel fraudReport = createFraudReport(providerName, response, order, CHECK); final OrderHistoryEntryModel historyEntry = createHistoryLog(providerName, order, CHECK, fraudReport.getCode()); order.setFraudulent(Boolean.FALSE); order.setPotentiallyFraudulent(Boolean.TRUE); order.setStatus(OrderStatus.FRAUD_CHECKED); modelService.save(fraudReport); modelService.save(historyEntry); modelService.save(order); return POTENTIAL; } }  @Override String executeAction(final OrderProcessModel process); FraudService getFraudService(); @Required void setFraudService(final FraudService fraudService); String getProviderName(); @Required void setProviderName(final String providerName);  }
@Test public void testExecuteActionShouldReturnTransactionOK() { when(orderProcessModelMock.getOrder()).thenReturn(orderModelMock); when(fraudServiceMock.recognizeOrderSymptoms(PROVIDER_NAME, orderModelMock)).thenReturn(fraudServiceResponseMock); when(fraudServiceResponseMock.getSymptoms()).thenReturn(Collections.emptyList()); final String result = testObj.executeAction(orderProcessModelMock); assertThat(result).isEqualTo("OK"); verify(orderModelMock).setFraudulent(FALSE); verify(orderModelMock).setPotentiallyFraudulent(FALSE); verify(orderModelMock).setStatus(OrderStatus.FRAUD_CHECKED); }
@Test public void testExecuteActionShouldReturnTransactionFraud() { when(orderProcessModelMock.getOrder()).thenReturn(orderModelMock); when(fraudServiceMock.recognizeOrderSymptoms(PROVIDER_NAME, orderModelMock)).thenReturn(fraudServiceResponseMock); when(fraudServiceResponseMock.getSymptoms()).thenReturn(Collections.singletonList(fraudSymptomMock)); final String result = testObj.executeAction(orderProcessModelMock); assertThat(result).isEqualTo("POTENTIAL"); verify(testObj).createFraudReport(PROVIDER_NAME, fraudServiceResponseMock, orderModelMock, CHECK); verify(orderModelMock).setFraudulent(FALSE); verify(orderModelMock).setPotentiallyFraudulent(TRUE); verify(orderModelMock).setStatus(OrderStatus.FRAUD_CHECKED); }