Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 9a823d3

Browse files
wandi34atamanroman
authored andcommitted
Add dateTo and dateFrom transaction filter
1 parent 95a448f commit 9a823d3

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ database-migration.sql
44

55
### Services ###
66
target
7+
service/logs
78
.service
89

910
### UI ###

service/src/main/java/de/adorsys/psd2/sandbox/xs2a/service/ais/AccountSpiImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public SpiResponse<SpiTransactionReport> requestTransactionsForAccount(
105105
}
106106

107107
List<SpiTransaction> spiTransactions = transactions.get().stream()
108+
.filter(t -> this.dateIsInDateRange(t.getBookingDate(), dateFrom, dateTo))
108109
.map(testDataMapper::mapTransactionToSpiTransaction)
109110
.collect(Collectors.toList());
110111

@@ -261,4 +262,8 @@ private <T> Pair<List<SpiAccountBalance>, SpiResponse<T>> getBalancesForAccount(
261262
null
262263
);
263264
}
265+
266+
boolean dateIsInDateRange(LocalDate date, LocalDate from, LocalDate to) {
267+
return date.isAfter(from) && date.isBefore(to) || date.isEqual(from) || date.isEqual(to);
268+
}
264269
}

service/src/test/java/de/adorsys/psd2/sandbox/xs2a/ais/AisSteps.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import static org.hamcrest.CoreMatchers.containsString;
44
import static org.hamcrest.CoreMatchers.equalTo;
5-
import static org.hamcrest.CoreMatchers.nullValue;
65
import static org.hamcrest.MatcherAssert.assertThat;
76
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assert.assertFalse;
88
import static org.junit.Assert.assertNotNull;
99
import static org.junit.Assert.assertNull;
1010
import static org.junit.Assert.assertTrue;
@@ -18,6 +18,7 @@
1818
import de.adorsys.psd2.model.AccountAccess;
1919
import de.adorsys.psd2.model.AccountList;
2020
import de.adorsys.psd2.model.AccountReference;
21+
import de.adorsys.psd2.model.AccountReport;
2122
import de.adorsys.psd2.model.BalanceType;
2223
import de.adorsys.psd2.model.ConsentInformationResponse200Json;
2324
import de.adorsys.psd2.model.ConsentStatus;
@@ -407,14 +408,19 @@ public void receiveAccountData() {
407408
@Then("the transaction list data are received")
408409
public void receiveTransactionListData() {
409410
ResponseEntity<TransactionsResponse200Json> actualResponse = context.getActualResponse();
411+
AccountReport transactions = actualResponse.getBody().getTransactions();
410412

411-
assertThat(actualResponse.getBody().getTransactions().getBooked().size(), equalTo(5));
413+
assertThat(actualResponse.getBody().getTransactions().getBooked().size(), equalTo(4));
412414

413415
if (context.isWithBalance()) {
414416
assertThat(actualResponse.getBody().getBalances().size(), equalTo(2));
415417
} else {
416418
assertNull(actualResponse.getBody().getBalances());
417419
}
420+
assertThat(transactions.getBooked().size(), equalTo(4));
421+
boolean includesInvalidTransactions = transactions.getBooked().stream()
422+
.anyMatch(x -> x.getBookingDate().compareTo(LocalDate.now().minusYears(1)) < 0);
423+
assertFalse(includesInvalidTransactions);
418424
}
419425

420426
@Then("the transaction data are received")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package de.adorsys.psd2.sandbox.xs2a.service.ais;
2+
3+
import static junit.framework.TestCase.assertFalse;
4+
import static junit.framework.TestCase.assertTrue;
5+
6+
import de.adorsys.psd2.sandbox.xs2a.testdata.TestDataMapper;
7+
import de.adorsys.psd2.sandbox.xs2a.testdata.TestDataService;
8+
import java.time.LocalDate;
9+
import org.junit.Before;
10+
import org.junit.Test;
11+
import org.mockito.Mock;
12+
13+
public class AccountSpiImplTest {
14+
15+
private AccountSpiImpl accountSpi;
16+
17+
@Mock
18+
TestDataService testDataService;
19+
20+
@Mock
21+
TestDataMapper testDataMapper;
22+
23+
private LocalDate dateFrom = LocalDate.of(2019, 1, 17);
24+
private LocalDate dateTo = LocalDate.of(2019, 9, 28);
25+
26+
@Before
27+
public void setup() {
28+
accountSpi = new AccountSpiImpl(testDataService, testDataMapper);
29+
}
30+
31+
@Test
32+
public void dateIsInDateRange() {
33+
LocalDate date = LocalDate.of(2019, 4, 3);
34+
35+
assertTrue(accountSpi.dateIsInDateRange(date, dateFrom, dateTo));
36+
}
37+
38+
@Test
39+
public void dateFromIsInRange() {
40+
assertTrue(accountSpi.dateIsInDateRange(dateFrom, dateFrom, dateTo));
41+
}
42+
43+
@Test
44+
public void dateToIsInRange() {
45+
assertTrue(accountSpi.dateIsInDateRange(dateTo, dateFrom, dateTo));
46+
}
47+
48+
@Test
49+
public void dateIsNotInRange() {
50+
LocalDate date = LocalDate.of(2019, 1, 16);
51+
52+
assertFalse(accountSpi.dateIsInDateRange(date, dateFrom, dateTo));
53+
}
54+
}

0 commit comments

Comments
 (0)