WorldpayRiskScoreFraudSymptom extends AbstractWorldpayOrderFraudSymptomDetection { @Override public FraudServiceResponse recognizeSymptom(final FraudServiceResponse fraudServiceResponse, final AbstractOrderModel abstractOrderModel) { final List<PaymentTransactionModel> paymentTransactions = abstractOrderModel.getPaymentTransactions(); final double scoreLimit = getScoreLimit(); paymentTransactions.stream().filter(Objects::nonNull).forEach(paymentTransaction -> { final WorldpayRiskScoreModel riskScore = paymentTransaction.getRiskScore(); if (riskScore == null) { LOG.warn(format("We did not get a risk score back, skipping risk check for: {0}", paymentTransaction)); return; } final String riskScoreValue = riskScore.getValue(); try { if (riskScoreValue != null && Double.compare(Double.valueOf(riskScoreValue), scoreLimit) > 0) { setIncrement(Double.valueOf(riskScoreValue)); fraudServiceResponse.addSymptom(createSymptom("RiskValue", true)); } } catch (final NumberFormatException e) { LOG.error(format("riskScoreValue for order with code [{0}] was not a number: [{1}]. The RiskScore was not checked for fraud.", abstractOrderModel.getCode(), riskScoreValue)); } }); return fraudServiceResponse; }  @Override FraudServiceResponse recognizeSymptom(final FraudServiceResponse fraudServiceResponse, final AbstractOrderModel abstractOrderModel);  }
@Test public void recognizeSymptomShouldReturnAPositiveFraudServiceResponseWhenRiskScoreValueInPaymentTransactionHasScore() throws Exception { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); final double positiveRiskScoreValue = configuredLimitValue + 10; final String riskScoreValue = String.valueOf(positiveRiskScoreValue); when(worldpayRiskScoreModelMock.getValue()).thenReturn(riskScoreValue); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(positiveRiskScoreValue, fraudServiceResponse.getScore(), 0.0); assertEquals(positiveRiskScoreValue, fraudServiceResponse.getSymptoms().get(0).getScore(), 0.0); assertEquals(positiveRiskScoreValue, testObj.getIncrement(), 0.0); verify(worldpayRiskScoreModelMock).getValue(); }
@Test public void recognizeSymptomShouldReturnTheSameFraudServiceResponseWhenRiskScoreIsRiskGuardian() throws Exception { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); final double negativeRiskScoreValue = configuredLimitValue - 10; final String riskScoreValue = String.valueOf(negativeRiskScoreValue); when(worldpayRiskScoreModelMock.getValue()).thenReturn(riskScoreValue); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0D, fraudServiceResponse.getScore(), 0.0); assertEquals(Collections.emptyList(), fraudServiceResponse.getSymptoms()); verify(worldpayRiskScoreModelMock).getValue(); }
@Test public void recognizeSymptomShouldReturnTheSameFraudServiceResponseWhenRiskScoreIsNotConvertible() throws Exception { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); when(worldpayRiskScoreModelMock.getValue()).thenReturn("abd"); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0D, fraudServiceResponse.getScore(), 0.0); assertEquals(Collections.emptyList(), fraudServiceResponse.getSymptoms()); verify(worldpayRiskScoreModelMock).getValue(); }
@Test public void recognizeSymptomShouldReturnTheSameFraudServiceResponseWhenRiskScoreIsNull() throws Exception { when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(worldpayRiskScoreModelMock); when(worldpayRiskScoreModelMock.getValue()).thenReturn(null); final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0D, fraudServiceResponse.getScore(), 0.0); assertEquals(Collections.emptyList(), fraudServiceResponse.getSymptoms()); verify(worldpayRiskScoreModelMock).getValue(); }
@Test public void recognizeSymptomWithNullRiskScore() { final FraudServiceResponse fraudServiceResponse = new FraudServiceResponse(StringUtils.EMPTY); when(orderModelMock.getPaymentTransactions()).thenReturn(singletonList(worldpayPaymentAuthoriseTransactionModelMock)); when(worldpayPaymentAuthoriseTransactionModelMock.getRiskScore()).thenReturn(null); testObj.recognizeSymptom(fraudServiceResponse, orderModelMock); assertEquals(0d, fraudServiceResponse.getScore(), 0.0); }