Add full result visitor (#36)

This commit is contained in:
Kostya 2020-07-21 16:33:39 +03:00 committed by GitHub
parent c2a9e316af
commit 992b0a8586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 291 additions and 135 deletions

@ -1 +1 @@
Subproject commit 07039c262ceb8fe944e4dae3840278494049ca0f
Subproject commit 540183862bc9fd04682e226de2056a320fd44be9

View File

@ -11,7 +11,7 @@
</parent>
<artifactId>fraudo</artifactId>
<version>0.0.18</version>
<version>0.0.19</version>
<name>Fraudo</name>
<description>Language for describing antifraud patterns</description>
@ -110,7 +110,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<version>0.8.4</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>

View File

@ -1,6 +1,5 @@
package com.rbkmoney.fraudo.model;
import com.rbkmoney.fraudo.constant.ResultStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -12,12 +11,6 @@ import java.util.List;
@AllArgsConstructor
public class ResultModel {
private ResultStatus resultStatus;
private String ruleChecked;
private List<String> notificationsRule;
private List<RuleResult> ruleResults;
public ResultModel(ResultStatus resultStatus, List<String> notificationsRule) {
this.resultStatus = resultStatus;
this.notificationsRule = notificationsRule;
}
}

View File

@ -0,0 +1,16 @@
package com.rbkmoney.fraudo.model;
import com.rbkmoney.fraudo.constant.ResultStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RuleResult {
private ResultStatus resultStatus;
private String ruleChecked;
}

View File

@ -2,13 +2,13 @@ package com.rbkmoney.fraudo.p2p.visitor.impl;
import com.rbkmoney.fraudo.FraudoP2PBaseVisitor;
import com.rbkmoney.fraudo.FraudoP2PParser.*;
import com.rbkmoney.fraudo.FraudoPaymentParser;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.exception.NotImplementedOperatorException;
import com.rbkmoney.fraudo.exception.NotValidContextException;
import com.rbkmoney.fraudo.exception.UnknownResultException;
import com.rbkmoney.fraudo.model.BaseModel;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.model.RuleResult;
import com.rbkmoney.fraudo.p2p.generator.*;
import com.rbkmoney.fraudo.p2p.visitor.CountP2PVisitor;
import com.rbkmoney.fraudo.p2p.visitor.CustomP2PFuncVisitor;
@ -63,7 +63,7 @@ public class FirstFindP2PVisitorImpl<T extends BaseModel, U> extends FraudoP2PBa
@Override
public ResultModel visitParse(ParseContext ctx) {
List<String> notifications = new ArrayList<>();
List<RuleResult> results = new ArrayList<>();
for (int i = 0; i < ctx.fraud_rule().size(); i++) {
Fraud_ruleContext fraudRuleContext = ctx.fraud_rule().get(i);
ResultStatus result = (ResultStatus) visit(fraudRuleContext);
@ -71,12 +71,13 @@ public class FirstFindP2PVisitorImpl<T extends BaseModel, U> extends FraudoP2PBa
if (result == null) {
throw new UnknownResultException(fraudRuleContext.getText());
} else if (result == ResultStatus.NOTIFY) {
notifications.add(key);
results.add(new RuleResult(result, key));
} else if (result != ResultStatus.NORMAL) {
return new ResultModel(result, key, notifications);
results.add(new RuleResult(result, key));
return new ResultModel(results);
}
}
return new ResultModel(ResultStatus.NORMAL, notifications);
return new ResultModel(results);
}
@Override

View File

@ -0,0 +1,38 @@
package com.rbkmoney.fraudo.payment.factory;
import com.rbkmoney.fraudo.aggregator.UniqueValueAggregator;
import com.rbkmoney.fraudo.finder.InListFinder;
import com.rbkmoney.fraudo.model.BaseModel;
import com.rbkmoney.fraudo.payment.aggregator.CountPaymentAggregator;
import com.rbkmoney.fraudo.payment.aggregator.SumPaymentAggregator;
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
import com.rbkmoney.fraudo.payment.visitor.ListVisitor;
import com.rbkmoney.fraudo.payment.visitor.SumVisitor;
import com.rbkmoney.fraudo.payment.visitor.impl.*;
import com.rbkmoney.fraudo.resolver.CountryResolver;
import com.rbkmoney.fraudo.resolver.FieldResolver;
public class FullVisitorFactoryImpl implements FraudVisitorFactory {
@Override
public <T extends BaseModel, U> FirstFindVisitorImpl<T, U> createVisitor(
CountPaymentAggregator<T, U> countPaymentAggregator,
SumPaymentAggregator<T, U> sumPaymentAggregator,
UniqueValueAggregator<T, U> uniqueValueAggregator,
CountryResolver<U> countryResolver,
InListFinder<T, U> listFinder,
FieldResolver<T, U> fieldResolver,
PaymentGroupResolver<T, U> paymentGroupResolver,
PaymentTimeWindowResolver timeWindowResolver) {
CountVisitor<T> countVisitor = new CountVisitorImpl<>(countPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
SumVisitor<T> sumVisitor = new SumVisitorImpl<>(sumPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
ListVisitor<T> listVisitor = new ListVisitorImpl<>(listFinder, fieldResolver);
CustomFuncVisitor<T> customFuncVisitor = new CustomFuncVisitorImpl<>(
uniqueValueAggregator, countryResolver, fieldResolver, paymentGroupResolver, timeWindowResolver);
return new FullVisitorImpl<>(countVisitor, sumVisitor, listVisitor, customFuncVisitor, fieldResolver);
}
}

View File

@ -7,6 +7,7 @@ import com.rbkmoney.fraudo.exception.NotValidContextException;
import com.rbkmoney.fraudo.exception.UnknownResultException;
import com.rbkmoney.fraudo.model.BaseModel;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.model.RuleResult;
import com.rbkmoney.fraudo.payment.generator.RuleKeyGenerator;
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
@ -67,7 +68,7 @@ public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentB
@Override
public ResultModel visitParse(ParseContext ctx) {
List<String> notifications = new ArrayList<>();
List<RuleResult> results = new ArrayList<>();
for (int i = 0; i < ctx.fraud_rule().size(); i++) {
Fraud_ruleContext fraudRuleContext = ctx.fraud_rule().get(i);
ResultStatus result = (ResultStatus) visit(fraudRuleContext);
@ -75,15 +76,13 @@ public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentB
if (result == null) {
throw new UnknownResultException(fraudRuleContext.getText());
} else if (result == ResultStatus.NOTIFY) {
notifications.add(key);
results.add(new RuleResult(result, key));
} else if (result != ResultStatus.NORMAL) {
if (result == ResultStatus.DECLINE_AND_NOTIFY || result == ResultStatus.ACCEPT_AND_NOTIFY) {
notifications.add(key);
}
return new ResultModel(result, key, notifications);
results.add(new RuleResult(result, key));
return new ResultModel(results);
}
}
return new ResultModel(ResultStatus.NORMAL, notifications);
return new ResultModel(results);
}
@Override

View File

@ -0,0 +1,45 @@
package com.rbkmoney.fraudo.payment.visitor.impl;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.exception.UnknownResultException;
import com.rbkmoney.fraudo.model.BaseModel;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.model.RuleResult;
import com.rbkmoney.fraudo.payment.generator.RuleKeyGenerator;
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
import com.rbkmoney.fraudo.payment.visitor.ListVisitor;
import com.rbkmoney.fraudo.payment.visitor.SumVisitor;
import com.rbkmoney.fraudo.resolver.FieldResolver;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import static com.rbkmoney.fraudo.FraudoPaymentParser.Fraud_ruleContext;
import static com.rbkmoney.fraudo.FraudoPaymentParser.ParseContext;
@Slf4j
public class FullVisitorImpl<T extends BaseModel, U> extends FirstFindVisitorImpl<T, U> {
public FullVisitorImpl(CountVisitor<T> countVisitor, SumVisitor<T> sumVisitor, ListVisitor<T> listVisitor, CustomFuncVisitor<T> customFuncVisitor, FieldResolver<T, U> fieldResolver) {
super(countVisitor, sumVisitor, listVisitor, customFuncVisitor, fieldResolver);
}
@Override
public ResultModel visitParse(ParseContext ctx) {
List<RuleResult> results = new ArrayList<>();
for (int i = 0; i < ctx.fraud_rule().size(); i++) {
Fraud_ruleContext fraudRuleContext = ctx.fraud_rule().get(i);
ResultStatus result = (ResultStatus) visit(fraudRuleContext);
String key = RuleKeyGenerator.generateRuleKey(fraudRuleContext, i);
if (result == null) {
throw new UnknownResultException(fraudRuleContext.getText());
} else if (result != ResultStatus.NORMAL) {
results.add(new RuleResult(result, key));
}
}
return new ResultModel(results);
}
}

View File

@ -0,0 +1,28 @@
package com.rbkmoney.fraudo.utils;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.model.RuleResult;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class ResultUtils {
public static List<String> getNotifications(ResultModel result) {
return result.getRuleResults().stream()
.filter(ruleResult -> ResultStatus.NOTIFY.equals(ruleResult.getResultStatus())
|| ResultStatus.DECLINE_AND_NOTIFY.equals(ruleResult.getResultStatus())
|| ResultStatus.ACCEPT_AND_NOTIFY.equals(ruleResult.getResultStatus()))
.map(RuleResult::getRuleChecked)
.collect(Collectors.toList());
}
public static Optional<RuleResult> findFirstNotNotifyStatus(ResultModel result) {
return result.getRuleResults().stream()
.filter(ruleResult -> !ruleResult.getResultStatus().equals(ResultStatus.NOTIFY))
.findFirst();
}
}

View File

@ -7,6 +7,7 @@ import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.payment.aggregator.CountPaymentAggregator;
import com.rbkmoney.fraudo.payment.aggregator.SumPaymentAggregator;
import com.rbkmoney.fraudo.payment.factory.FraudVisitorFactoryImpl;
import com.rbkmoney.fraudo.payment.factory.FullVisitorFactoryImpl;
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
import com.rbkmoney.fraudo.resolver.CountryResolver;
@ -63,6 +64,20 @@ public class AbstractPaymentTest {
.visit(parse, model);
}
ResultModel invokeFullVisitor(ParseContext parse, PaymentModel model) {
return new FullVisitorFactoryImpl()
.createVisitor(
countPaymentAggregator,
sumPaymentAggregator,
uniqueValueAggregator,
countryResolver,
inListFinder,
fieldResolver,
paymentGroupResolver,
timeWindowResolver)
.visit(parse, model);
}
ParseContext getParseContext(InputStream resourceAsStream) throws IOException {
com.rbkmoney.fraudo.FraudoPaymentLexer lexer = new com.rbkmoney.fraudo.FraudoPaymentLexer(new ANTLRInputStream(resourceAsStream));
com.rbkmoney.fraudo.FraudoPaymentParser parser = new com.rbkmoney.fraudo.FraudoPaymentParser(new CommonTokenStream(lexer));

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo;
import com.rbkmoney.fraudo.FraudoPaymentParser.ParseContext;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@ -10,6 +11,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
@ -30,15 +32,15 @@ public class CountTest extends AbstractPaymentTest {
when(countPaymentAggregator.countRefund(anyObject(), any(), any(), any())).thenReturn(1);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("0", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("0", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(9);
when(countPaymentAggregator.countError(anyObject(), any(), any(), anyString(), any())).thenReturn(6);
when(countPaymentAggregator.countSuccess(anyObject(), any(), any(), any())).thenReturn(6);
result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -48,8 +50,8 @@ public class CountTest extends AbstractPaymentTest {
when(countPaymentAggregator.countRefund(anyObject(), any(), any(), any())).thenReturn(5);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("0", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("0", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
}
@Test
@ -58,12 +60,12 @@ public class CountTest extends AbstractPaymentTest {
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("0", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("0", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(1);
result = invokeParse(parseContext);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -72,19 +74,19 @@ public class CountTest extends AbstractPaymentTest {
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("0", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("0", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(1);
result = invokeParse(parseContext);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
resourceAsStream = CountTest.class.getResourceAsStream("/rules/countTimeWindowGroupBy_2.frd");
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
parseContext = getParseContext(resourceAsStream);
result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("0", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("0", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
}
@Test
@ -94,7 +96,7 @@ public class CountTest extends AbstractPaymentTest {
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
verify(countPaymentAggregator, times(1)).count(anyObject(), any(), any(), any());
}

View File

@ -5,7 +5,9 @@ import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.exception.UnknownResultException;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.test.model.PaymentModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@ -13,6 +15,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
@ -31,7 +34,7 @@ public class CustomTest extends AbstractPaymentTest {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/three_ds.frd");
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.THREE_DS, result.getResultStatus());
assertEquals(ResultStatus.THREE_DS, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -39,48 +42,46 @@ public class CustomTest extends AbstractPaymentTest {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/highRisk.frd");
when(countPaymentAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.HIGH_RISK, result.getResultStatus());
assertEquals(ResultStatus.HIGH_RISK, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
public void notifyTest() throws Exception {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/notify.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
assertEquals(1, ResultUtils.getNotifications(result).size());
}
@Test
public void declineTest() throws Exception {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/decline.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("test_11", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("test_11", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
}
@Test
public void declineAndNotifyTest() throws Exception {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/declineAndNotify.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.DECLINE_AND_NOTIFY, result.getResultStatus());
assertEquals("test_11", result.getRuleChecked());
assertEquals(1, result.getNotificationsRule().size());
System.out.println(result.getNotificationsRule());
assertEquals(ResultStatus.DECLINE_AND_NOTIFY, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("test_11", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
}
@Test
public void acceptTest() throws Exception {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/accept.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
public void ruleIsNotFireTest() throws Exception {
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/rule_is_not_fire.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test(expected = UnknownResultException.class)
@ -96,7 +97,7 @@ public class CustomTest extends AbstractPaymentTest {
PaymentModel model = new PaymentModel();
model.setEmail(TEST_GMAIL_RU);
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -108,7 +109,7 @@ public class CustomTest extends AbstractPaymentTest {
PaymentModel model = new PaymentModel();
model.setAmount(500L);
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -119,7 +120,7 @@ public class CustomTest extends AbstractPaymentTest {
PaymentModel model = new PaymentModel();
model.setCurrency("EUR");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -130,11 +131,11 @@ public class CustomTest extends AbstractPaymentTest {
model.setAmount(56L);
model.setCurrency("RUB");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
model.setCurrency("USD");
result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -143,7 +144,7 @@ public class CustomTest extends AbstractPaymentTest {
when(uniqueValueAggregator.countUniqueValue(any(), any(), any(), any(), any())).thenThrow(new UnknownResultException("as"));
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -155,11 +156,11 @@ public class CustomTest extends AbstractPaymentTest {
model.setBin("553619");
model.setPan("9137");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
model.setPan("9111");
result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -169,7 +170,7 @@ public class CustomTest extends AbstractPaymentTest {
PaymentModel model = new PaymentModel();
model.setEmail(TEST_GMAIL_RU);
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -178,7 +179,7 @@ public class CustomTest extends AbstractPaymentTest {
when(uniqueValueAggregator.countUniqueValue(any(), any(), any(), any(), any())).thenReturn(2);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -188,7 +189,7 @@ public class CustomTest extends AbstractPaymentTest {
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
verify(uniqueValueAggregator, times(1)).countUniqueValue(any(), any(), any(), any(), any());
}
@ -199,17 +200,17 @@ public class CustomTest extends AbstractPaymentTest {
when(countryResolver.resolveCountry(any(), anyString())).thenReturn("RU");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
assertEquals(1, ResultUtils.getNotifications(result).size());
when(countryResolver.resolveCountry(any(), anyString())).thenReturn("US");
resourceAsStream = CustomTest.class.getResourceAsStream("/rules/eq_country.frd");
result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
resourceAsStream = CustomTest.class.getResourceAsStream("/rules/accept_with_notify.frd");
result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(2, result.getNotificationsRule().size());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(2, ResultUtils.getNotifications(result).size());
}
}

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo;
import com.rbkmoney.fraudo.FraudoPaymentParser.ParseContext;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -11,6 +12,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.*;
public class ListTest extends AbstractPaymentTest {
@ -26,14 +28,15 @@ public class ListTest extends AbstractPaymentTest {
ParseContext parseContext = getParseContext(resourceAsStream);
Mockito.when(inListFinder.findInWhiteList(anyList(), anyObject())).thenReturn(true);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.DECLINE, result.getResultStatus());
Assert.assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
resourceAsStream = ListTest.class.getResourceAsStream("/rules/blacklist.frd");
parseContext = getParseContext(resourceAsStream);
Mockito.when(inListFinder.findInBlackList(anyList(), anyObject())).thenReturn(true);
result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
}
@Test
@ -42,7 +45,7 @@ public class ListTest extends AbstractPaymentTest {
ParseContext parseContext = getParseContext(resourceAsStream);
Mockito.when(inListFinder.findInGreyList(anyList(), anyObject())).thenReturn(true);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
Assert.assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -51,6 +54,6 @@ public class ListTest extends AbstractPaymentTest {
ParseContext parseContext = getParseContext(resourceAsStream);
Mockito.when(inListFinder.findInList(anyString(), anyList(), anyObject())).thenReturn(true);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
Assert.assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
}

View File

@ -4,6 +4,8 @@ import com.rbkmoney.fraudo.FraudoPaymentParser.ParseContext;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.test.model.PaymentModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@ -43,11 +45,15 @@ public class RealTimerTest extends AbstractPaymentTest {
long start = System.currentTimeMillis();
ResultModel result = invoke(parseContext, model);
long executionTime = System.currentTimeMillis() - start;
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
Assert.assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(0, countDownLatch.getCount());
assertTrue(executionTime < TIME_CALL_AGGR_FUNC + 1 + TIME_CALLING);
System.out.println("executionTime=" + executionTime);
result = invokeFullVisitor(parseContext, model);
assertEquals(2, result.getRuleResults().size());
}
@Test
@ -66,10 +72,7 @@ public class RealTimerTest extends AbstractPaymentTest {
ResultModel result = invoke(parseContext, model);
long executionTime = System.currentTimeMillis() - start;
System.out.println("executionTime=" + executionTime);
System.out.println("result=" + result.getRuleChecked());
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
Assert.assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertTrue(executionTime < TIME_CALL_AGGR_FUNC * 4 + TIME_CALLING);
}

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo;
import com.rbkmoney.fraudo.FraudoPaymentParser.ParseContext;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -28,16 +29,16 @@ public class SumTest extends AbstractPaymentTest {
Mockito.when(sumPaymentAggregator.sumSuccess(anyObject(), any(), any(), any())).thenReturn(4.0);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(1, result.getNotificationsRule().size());
Assert.assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
Mockito.when(sumPaymentAggregator.sum(anyObject(), any(), any(), any())).thenReturn(90.0);
Mockito.when(sumPaymentAggregator.sumError(anyObject(), any(), any(), anyString(), any())).thenReturn(504.0);
Mockito.when(sumPaymentAggregator.sumSuccess(anyObject(), any(), any(), any())).thenReturn(501.0);
result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(0, result.getNotificationsRule().size());
Assert.assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(0, ResultUtils.getNotifications(result).size());
}
@Test
@ -47,7 +48,7 @@ public class SumTest extends AbstractPaymentTest {
Mockito.when(sumPaymentAggregator.sumRefund(anyObject(), any(), any(), any())).thenReturn(10000.60);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
Assert.assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -58,16 +59,17 @@ public class SumTest extends AbstractPaymentTest {
Mockito.when(sumPaymentAggregator.sumSuccess(anyObject(), any(), any(), any())).thenReturn(4.0);
ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(1, result.getNotificationsRule().size());
Assert.assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
Mockito.when(sumPaymentAggregator.sum(anyObject(), any(), any(), any())).thenReturn(90.0);
Mockito.when(sumPaymentAggregator.sumError(anyObject(), any(), any(), anyString(), any())).thenReturn(504.0);
Mockito.when(sumPaymentAggregator.sumSuccess(anyObject(), any(), any(), any())).thenReturn(501.0);
result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(0, result.getNotificationsRule().size());
Assert.assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(0, ResultUtils.getNotifications(result).size());
}
}

View File

@ -3,6 +3,8 @@ package com.rbkmoney.fraudo.p2p;
import com.rbkmoney.fraudo.FraudoP2PParser;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@ -11,6 +13,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.*;
@ -33,13 +36,13 @@ public class CountP2PTest extends AbstractP2PTest {
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(FIRST_RULE_INDEX, result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(FIRST_RULE_INDEX, ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(14);
result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -48,12 +51,13 @@ public class CountP2PTest extends AbstractP2PTest {
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(FIRST_RULE_INDEX, result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(FIRST_RULE_INDEX, ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(1);
result = invokeParse(parseContext);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -62,19 +66,19 @@ public class CountP2PTest extends AbstractP2PTest {
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(FIRST_RULE_INDEX, result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(FIRST_RULE_INDEX, ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(1);
result = invokeParse(parseContext);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
resourceAsStream = CountP2PTest.class.getResourceAsStream("/rules/p2p/countTimeWindowGroupBy_2.frd");
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
parseContext = getParseContext(resourceAsStream);
result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(FIRST_RULE_INDEX, result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals(FIRST_RULE_INDEX, ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
}
@Test
@ -84,7 +88,7 @@ public class CountP2PTest extends AbstractP2PTest {
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
verify(countAggregator, times(1)).count(anyObject(), any(), any(), any());
}

View File

@ -8,6 +8,8 @@ import com.rbkmoney.fraudo.exception.UnknownResultException;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.test.model.P2PModel;
import com.rbkmoney.fraudo.test.model.PaymentModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@ -15,6 +17,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
@ -32,7 +35,7 @@ public class CustomP2PTest extends AbstractP2PTest {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/three_ds.frd");
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.THREE_DS, result.getResultStatus());
assertEquals(ResultStatus.THREE_DS, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -40,37 +43,37 @@ public class CustomP2PTest extends AbstractP2PTest {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/highRisk.frd");
when(countAggregator.count(anyObject(), any(), any(), any())).thenReturn(10);
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.HIGH_RISK, result.getResultStatus());
assertEquals(ResultStatus.HIGH_RISK, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
public void notifyTest() throws Exception {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/notify.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
assertEquals(1, ResultUtils.getNotifications(result).size());
}
@Test
public void declineTest() throws Exception {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/decline.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals("test_11", result.getRuleChecked());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
assertEquals("test_11", ResultUtils.findFirstNotNotifyStatus(result).get().getRuleChecked());
}
@Test
public void acceptTest() throws Exception {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/accept.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
public void ruleIsNotFireTest() throws Exception {
InputStream resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/rule_is_not_fire.frd");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test(expected = UnknownResultException.class)
@ -89,7 +92,7 @@ public class CustomP2PTest extends AbstractP2PTest {
model.setEmail(TEST_GMAIL_RU);
model.setBin("123213");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -100,7 +103,7 @@ public class CustomP2PTest extends AbstractP2PTest {
P2PModel model = new P2PModel();
model.setCurrency("EUR");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -112,7 +115,7 @@ public class CustomP2PTest extends AbstractP2PTest {
P2PModel model = new P2PModel();
model.setAmount(500L);
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -123,11 +126,11 @@ public class CustomP2PTest extends AbstractP2PTest {
model.setAmount(56L);
model.setCurrency("RUB");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
model.setCurrency("USD");
result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -136,7 +139,7 @@ public class CustomP2PTest extends AbstractP2PTest {
when(uniqueValueAggregator.countUniqueValue(any(), any(), any(), any(), any())).thenThrow(new UnknownResultException("as"));
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -148,11 +151,11 @@ public class CustomP2PTest extends AbstractP2PTest {
model.setBin("553619");
model.setPan("9137");
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
model.setPan("9111");
result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -162,7 +165,7 @@ public class CustomP2PTest extends AbstractP2PTest {
P2PModel model = new P2PModel();
model.setEmail(TEST_GMAIL_RU);
ResultModel result = invoke(parseContext, model);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
}
@Test
@ -171,7 +174,7 @@ public class CustomP2PTest extends AbstractP2PTest {
when(uniqueValueAggregator.countUniqueValue(any(), any(), any(), any(), any())).thenReturn(2);
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
}
@Test
@ -181,7 +184,7 @@ public class CustomP2PTest extends AbstractP2PTest {
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
verify(uniqueValueAggregator, times(1)).countUniqueValue(any(), any(), any(), any(), any());
}
@ -192,18 +195,18 @@ public class CustomP2PTest extends AbstractP2PTest {
when(countryResolver.resolveCountry(any(), anyString())).thenReturn("RU");
ResultModel result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
when(countryResolver.resolveCountry(any(), anyString())).thenReturn("US");
resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/eq_country.frd");
result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertEquals(0, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(0, ResultUtils.getNotifications(result).size());
resourceAsStream = CustomP2PTest.class.getResourceAsStream("/rules/p2p/accept_with_notify.frd");
result = parseAndVisit(resourceAsStream);
assertEquals(ResultStatus.ACCEPT, result.getResultStatus());
assertEquals(2, result.getNotificationsRule().size());
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
Assert.assertEquals(2, ResultUtils.getNotifications(result).size());
}
}

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo.p2p;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.test.model.P2PModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@ -11,8 +12,7 @@ import org.mockito.stubbing.Answer;
import java.io.InputStream;
import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.when;
@ -43,7 +43,7 @@ public class P2PTest extends AbstractP2PTest {
long start = System.currentTimeMillis();
ResultModel result = invoke(parseContext, model);
long executionTime = System.currentTimeMillis() - start;
assertEquals(ResultStatus.NORMAL, result.getResultStatus());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
assertEquals(0, countDownLatch.getCount());
assertTrue(executionTime < TIME_CALL_AGGR_FUNC + 1 + TIME_CALLING);

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo.p2p;
import com.rbkmoney.fraudo.FraudoP2PParser;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@ -31,7 +32,7 @@ public class ParenP2PTest extends AbstractP2PTest {
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
assertEquals(ResultStatus.DECLINE, result.getResultStatus());
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
verify(countAggregator, times(2)).count(anyObject(), any(), any(), any());
}

View File

@ -3,6 +3,7 @@ package com.rbkmoney.fraudo.p2p;
import com.rbkmoney.fraudo.FraudoP2PParser;
import com.rbkmoney.fraudo.constant.ResultStatus;
import com.rbkmoney.fraudo.model.ResultModel;
import com.rbkmoney.fraudo.utils.ResultUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -11,6 +12,7 @@ import org.mockito.MockitoAnnotations;
import java.io.InputStream;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
@ -27,14 +29,14 @@ public class SumP2PTest extends AbstractP2PTest {
Mockito.when(sumAggregator.sum(anyObject(), any(), any(), any())).thenReturn(10500.60);
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
Mockito.when(sumAggregator.sum(anyObject(), any(), any(), any())).thenReturn(90.0);
result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(0, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(0, ResultUtils.getNotifications(result).size());
}
@Test
@ -43,14 +45,14 @@ public class SumP2PTest extends AbstractP2PTest {
Mockito.when(sumAggregator.sum(anyObject(), any(), any(), any())).thenReturn(10500.60);
FraudoP2PParser.ParseContext parseContext = getParseContext(resourceAsStream);
ResultModel result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(1, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(1, ResultUtils.getNotifications(result).size());
Mockito.when(sumAggregator.sum(anyObject(), any(), any(), any())).thenReturn(90.0);
result = invokeParse(parseContext);
Assert.assertEquals(ResultStatus.NORMAL, result.getResultStatus());
Assert.assertEquals(0, result.getNotificationsRule().size());
assertFalse(ResultUtils.findFirstNotNotifyStatus(result).isPresent());
Assert.assertEquals(0, ResultUtils.getNotifications(result).size());
}
}

View File

@ -13,4 +13,4 @@ rule:cards_test_count_3:unique("fingerprint","card_token",1440)>3 AND not in(cou
rule:USSRcount:count("card_token",1440,"party_id")<11 AND in(countryBy("country_bank"),"UZB")->accept;
rule:count11tur:count("card_token",1440,"party_id")<12 AND in(countryBy("country_bank"),"TUR")->accept;
rule:count10:count("card_token",1440,"party_id")<11 AND not in(countryBy("country_bank"),"ARG")->accept;
rule:count5bra:count("card_token",1440,"party_id")>5->decline;
rule:count5bra:count("card_token",1440,"party_id")>0->decline;