Remove FlagsServiceTest; Added FlagsEnricherTest with mocked methods
This commit is contained in:
parent
8ddf3b6316
commit
bd30604225
2 changed files with 276 additions and 275 deletions
|
|
@ -1,275 +0,0 @@
|
||||||
package ru.nbch.credit_tracker.service;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FlagsServiceTest {
|
|
||||||
|
|
||||||
private static final LocalDate INITIAL_DATE = LocalDate.parse("2025-09-25");
|
|
||||||
|
|
||||||
private static final String RU_PASTDUEAREAR_CREATE = """
|
|
||||||
create table RU_PASTDUEARREAR
|
|
||||||
(
|
|
||||||
FID INTEGER not null,
|
|
||||||
SERIAL_NUM BIGINT not null primary key,
|
|
||||||
ACC_SERIAL_NUM BIGINT not null,
|
|
||||||
REPORTED_DT DATE not null,
|
|
||||||
AMT_PAST_DUE DECIMAL(17, 2),
|
|
||||||
DAYS_PAST_DUE BIGINT
|
|
||||||
);
|
|
||||||
""";
|
|
||||||
|
|
||||||
private static final String RU_PASTDUEAREAR_DROP = """
|
|
||||||
DROP TABLE IF EXISTS RU_PASTDUEARREAR;
|
|
||||||
""";
|
|
||||||
|
|
||||||
private static final String RU_PAYMT_DROP = """
|
|
||||||
DROP TABLE IF EXISTS RU_PAYMT;
|
|
||||||
""";
|
|
||||||
|
|
||||||
private static final String RU_PAYMT_CREATE = """
|
|
||||||
create table RU_PAYMT
|
|
||||||
(
|
|
||||||
FID INTEGER not null,
|
|
||||||
SERIAL_NUM BIGINT not null primary key,
|
|
||||||
DAYS_PAST_DUE INTEGER,
|
|
||||||
REPORTED_DT DATE not null
|
|
||||||
);
|
|
||||||
""";
|
|
||||||
|
|
||||||
private static final String FILL_RU_PASTDUEARREAR = String.format("""
|
|
||||||
INSERT INTO RU_PASTDUEARREAR VALUES
|
|
||||||
(1, 1, 1, '%s', 36000.00, 159), -- просрочка 5000 и 90_days по этой записи
|
|
||||||
(2, 2, 2, '%s', 3200.00, null), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(2, 3, 2, '%s', 6700.00, null), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(2, 4, 2, '%s', 5700.00, null), -- просрочка 5000 по этой записи
|
|
||||||
(3, 5, 3, '%s', 300000000000.00, null),
|
|
||||||
(2, 6, 2, '%s', 0.00, null), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(4, 7, 4, '%s', 4000.00, null), -- нет просрочек
|
|
||||||
(5, 8, 5, '%s', 2000.31, 182), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 9, 5, '%s', 2000.31, 212), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 10, 5, '%s', 2000.31, null), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 11, 5, '%s', 2000.31, 273), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 12, 5, '%s', 2000.31, null), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 13, 5, '%s', 7000.31, 307), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 14, 5, '%s', 2000.31, 338), -- не макс reported_date для того же acc_serial_num, просрочка 90_days будет взята у этой записи
|
|
||||||
(5, 15, 5, '%s', 7000.31, 368), -- Просрочка 5000 будет взята у этой записи. Уникальный acc_serial_num с макс reported_dt
|
|
||||||
(5, 16, 5, '%s', 2000.31, 399), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(5, 17, 5, '%s', 5000.31, 5), -- не макс reported_date для того же acc_serial_num
|
|
||||||
(6, 18, 6, '%s', 3000, null), -- Нет просрочки 5000, нет просрочки 90_days (90_days будет в RU_PAYMT)
|
|
||||||
(7, 19, 7, '%s', 5500, 90), -- не макс reported_date для того же acc_serial_num. 90_days будет взята отсюда
|
|
||||||
(7, 20, 7, '%s', 3000, null) -- Нет просрочки 5000. Уникальный acc_serial_num с макс reported_dt
|
|
||||||
""",
|
|
||||||
calcLocalDateFromInitialDate("2025-05-31"),
|
|
||||||
calcLocalDateFromInitialDate("2021-12-29"),
|
|
||||||
calcLocalDateFromInitialDate("2022-01-28"),
|
|
||||||
calcLocalDateFromInitialDate("2025-04-06"),
|
|
||||||
calcLocalDateFromInitialDate("2025-01-14"),
|
|
||||||
calcLocalDateFromInitialDate("2021-11-29"),
|
|
||||||
calcLocalDateFromInitialDate("2025-12-06"),
|
|
||||||
calcLocalDateFromInitialDate("2021-04-01"),
|
|
||||||
calcLocalDateFromInitialDate("2021-05-01"),
|
|
||||||
calcLocalDateFromInitialDate("2021-05-31"),
|
|
||||||
calcLocalDateFromInitialDate("2021-07-01"),
|
|
||||||
calcLocalDateFromInitialDate("2021-07-31"),
|
|
||||||
calcLocalDateFromInitialDate("2021-08-04"),
|
|
||||||
calcLocalDateFromInitialDate("2025-09-08"),
|
|
||||||
calcLocalDateFromInitialDate("2025-09-09"),
|
|
||||||
calcLocalDateFromInitialDate("2021-11-04"),
|
|
||||||
calcLocalDateFromInitialDate("2022-01-04"),
|
|
||||||
calcLocalDateFromInitialDate("2025-09-09"),
|
|
||||||
calcLocalDateFromInitialDate("2025-09-09"),
|
|
||||||
calcLocalDateFromInitialDate("2025-09-10"));
|
|
||||||
|
|
||||||
private static final String FILL_RU_PAYMT = String.format("""
|
|
||||||
INSERT INTO RU_PAYMT VALUES
|
|
||||||
(1, 1, null, '%s'),
|
|
||||||
(2, 2, 30, '%s'),
|
|
||||||
(3, 3, null, '%s'),
|
|
||||||
(3, 4, 100, '%s'),
|
|
||||||
(4, 5, 10, '%s'),
|
|
||||||
(5, 6, 10, '%s'),
|
|
||||||
(6, 7, 90, '%s'),
|
|
||||||
(6, 8, 80, '%s'),
|
|
||||||
(7, 9, null, '%s'),
|
|
||||||
(8, 10, null, '%s'),
|
|
||||||
(8, 11, 83, '%s'),
|
|
||||||
(8, 12, 91, '%s'),
|
|
||||||
(9, 13, 100, '%s')
|
|
||||||
""",
|
|
||||||
calcLocalDateFromInitialDate("2024-11-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-11-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-11-10"),
|
|
||||||
calcLocalDateFromInitialDate("2024-11-15"),
|
|
||||||
calcLocalDateFromInitialDate("2024-11-15"),
|
|
||||||
calcLocalDateFromInitialDate("2023-11-15"),
|
|
||||||
calcLocalDateFromInitialDate("2024-11-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"),
|
|
||||||
calcLocalDateFromInitialDate("2024-10-09"));
|
|
||||||
|
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private NamedParameterJdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
dataSource = DataSourceBuilder.create()
|
|
||||||
.url("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=DB2;DATABASE_TO_LOWER=TRUE")
|
|
||||||
.driverClassName("org.h2.Driver")
|
|
||||||
.username("sa")
|
|
||||||
.password("")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
|
||||||
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(RU_PASTDUEAREAR_DROP);
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(RU_PAYMT_DROP);
|
|
||||||
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(RU_PASTDUEAREAR_CREATE);
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(RU_PAYMT_CREATE);
|
|
||||||
|
|
||||||
// flagsService = new FlagsService(null, jdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testfindFlags() {
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(FILL_RU_PASTDUEARREAR);
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(FILL_RU_PAYMT);
|
|
||||||
|
|
||||||
List<Integer> fids = new ArrayList<>(List.of(
|
|
||||||
1, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
2, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Нет просрочки 90_days в RU_PAYMT
|
|
||||||
3, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
4, // нет никаких просрочек
|
|
||||||
7, // нет просрочки 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
5, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
6, // нет просрочки 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
8, // нету в RU_PASTDUEARREAR, есть в RU_PAYMT
|
|
||||||
9) // нету в RU_PASTDUEARREAR, нету в RU_PAYMT
|
|
||||||
);
|
|
||||||
|
|
||||||
// Map<Integer, FlagsService.FlagsData> resultMap = flagsService.findFlags(fids);
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(9, resultMap.size());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(1).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(2).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(3).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(5).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(6).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(7).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(8).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(9).getFlagDebt5000());
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(1).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(2).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(3).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(5).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(6).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(7).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(8).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(9).getFlag90days());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testfindFlagsWithoutRuPaymt() {
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(FILL_RU_PASTDUEARREAR);
|
|
||||||
|
|
||||||
List<Integer> fids = new ArrayList<>(List.of(
|
|
||||||
1, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
2, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Нет просрочки 90_days в RU_PAYMT
|
|
||||||
3, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
4, // нет никаких просрочек
|
|
||||||
7, // нет просрочки 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
5, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
6, // нет просрочки 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
8, // нету в RU_PASTDUEARREAR, есть в RU_PAYMT
|
|
||||||
9) // нету в RU_PASTDUEARREAR, нету в RU_PAYMT
|
|
||||||
);
|
|
||||||
|
|
||||||
// Map<Integer, FlagsService.FlagsData> resultMap = flagsService.findFlags(fids);
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(9, resultMap.size());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(1).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(2).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(3).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(5).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(6).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(7).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(8).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(9).getFlagDebt5000());
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(1).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(2).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(3).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(5).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(6).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(7).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(8).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(9).getFlag90days());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testfindFlagsWithoutRuPastduearreae() {
|
|
||||||
jdbcTemplate.getJdbcTemplate().execute(FILL_RU_PAYMT);
|
|
||||||
|
|
||||||
List<Integer> fids = new ArrayList<>(List.of(
|
|
||||||
1, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
2, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Нет просрочки 90_days в RU_PAYMT
|
|
||||||
3, // есть просрочка 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
4, // нет никаких просрочек
|
|
||||||
7, // нет просрочки 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
5, // есть просрочка 5000, есть просрочка 90_days в RU_PASTDUEARREAR
|
|
||||||
6, // нет просрочки 5000, нет просрочки 90_days в RU_PASTDUEARREAR. Есть просрочка 90_days в RU_PAYMT
|
|
||||||
8, // нету в RU_PASTDUEARREAR, есть в RU_PAYMT
|
|
||||||
9) // нету в RU_PASTDUEARREAR, нету в RU_PAYMT
|
|
||||||
);
|
|
||||||
|
|
||||||
// Map<Integer, FlagsService.FlagsData> resultMap = flagsService.findFlags(fids);
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(9, resultMap.size());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(1).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(2).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(3).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(5).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(6).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(7).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(8).getFlagDebt5000());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(9).getFlagDebt5000());
|
|
||||||
//
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(1).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(2).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(3).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(4).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(5).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(6).getFlag90days());
|
|
||||||
// Assertions.assertEquals(0, resultMap.get(7).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(8).getFlag90days());
|
|
||||||
// Assertions.assertEquals(1, resultMap.get(9).getFlag90days());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static LocalDate calcLocalDateFromInitialDate(String date) {
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
long daysPassed = ChronoUnit.DAYS.between(INITIAL_DATE, now);
|
|
||||||
return LocalDate.parse(date).plusDays(daysPassed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,276 @@
|
||||||
|
package ru.nbch.credit_tracker.service.task.impl;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import ru.nbch.credit_tracker.config.settings.CreditTrackerSettings;
|
||||||
|
import ru.nbch.credit_tracker.config.settings.FlagUpdaterSettings;
|
||||||
|
import ru.nbch.credit_tracker.entities.app.PhonesMap;
|
||||||
|
import ru.nbch.credit_tracker.model.FlagData;
|
||||||
|
import ru.nbch.credit_tracker.service.indic.FlagsService;
|
||||||
|
import ru.nbch.credit_tracker.service.signal.PackageRecordsService;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyList;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
public class FlagsEnricherTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private FlagsService flagsService;
|
||||||
|
@Mock
|
||||||
|
private PackageRecordsService packageRecordsService;
|
||||||
|
@Mock
|
||||||
|
private CreditTrackerSettings creditTrackerSettings;
|
||||||
|
@Mock
|
||||||
|
private FlagUpdaterSettings flagUpdater;
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<List<FlagData>> flagCacheCaptor;
|
||||||
|
|
||||||
|
private FlagsEnricher flagsEnricher;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
when(creditTrackerSettings.getFlagUpdater()).thenReturn(flagUpdater);
|
||||||
|
when(flagUpdater.concurrency()).thenReturn(1);
|
||||||
|
when(flagUpdater.queueCapacity()).thenReturn(1);
|
||||||
|
|
||||||
|
flagsEnricher = new FlagsEnricher(flagsService, packageRecordsService, creditTrackerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Тест основан на исходных тестовых данных
|
||||||
|
* <p>
|
||||||
|
* Ожидаемые результаты по fid
|
||||||
|
* <p>
|
||||||
|
* fid | flagDebt5000 | flag90days (итоговый: max из pastDueArrear, ruPaymt, ruAllArrears)
|
||||||
|
* ----|--------------|--------------------------------------------------------
|
||||||
|
* 1 | 1 | 1 (есть в pastDueArrear)
|
||||||
|
* 2 | 1 | 0 (нет в pastDueArrear, нет в ruPaymt)
|
||||||
|
* 3 | 1 | 1 (нет в pastDueArrear, есть в ruPaymt)
|
||||||
|
* 4 | 0 | 0 (нет никаких просрочек)
|
||||||
|
* 5 | 1 | 1 (есть в pastDueArrear)
|
||||||
|
* 6 | 0 | 1 (нет в pastDueArrear, есть в ruPaymt)
|
||||||
|
* 7 | 0 | 1 (есть в pastDueArrear)
|
||||||
|
* 8 | 0 | 1 (нет в pastDueArrear, есть в ruPaymt)
|
||||||
|
* 9 | 0 | 0 (нет нигде)
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void process_shouldBuildCorrectFlagCache() {
|
||||||
|
List<PhonesMap> phonesMaps = createPhonesMaps();
|
||||||
|
|
||||||
|
Map<Integer, Integer> flagsDebt5000 = Map.of(
|
||||||
|
1, 1,
|
||||||
|
2, 1,
|
||||||
|
3, 1,
|
||||||
|
4, 0,
|
||||||
|
5, 1,
|
||||||
|
6, 0,
|
||||||
|
7, 0,
|
||||||
|
8, 0,
|
||||||
|
9, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<Integer, Integer> flag90ByPastDueArrear = Map.of(
|
||||||
|
1, 1,
|
||||||
|
2, 0,
|
||||||
|
3, 0,
|
||||||
|
4, 0,
|
||||||
|
5, 1,
|
||||||
|
6, 0,
|
||||||
|
7, 1,
|
||||||
|
8, 0,
|
||||||
|
9, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<Integer, Integer> flag90ByRuPaymt = Map.of(
|
||||||
|
1, 0,
|
||||||
|
2, 0,
|
||||||
|
3, 1,
|
||||||
|
4, 0,
|
||||||
|
5, 0,
|
||||||
|
6, 1,
|
||||||
|
7, 0,
|
||||||
|
8, 1,
|
||||||
|
9, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<Integer, Integer> flag90ByRuAllArrears = Map.of(
|
||||||
|
1, 0,
|
||||||
|
2, 0,
|
||||||
|
3, 0,
|
||||||
|
4, 0,
|
||||||
|
5, 0,
|
||||||
|
6, 0,
|
||||||
|
7, 0,
|
||||||
|
8, 0,
|
||||||
|
9, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
when(flagsService.findFlagsDebt5000(anyList()))
|
||||||
|
.thenReturn(flagsDebt5000);
|
||||||
|
when(flagsService.findFlag90ByPastDueArrear(anyList(), any(LocalDate.class)))
|
||||||
|
.thenReturn(flag90ByPastDueArrear);
|
||||||
|
when(flagsService.findFlag90ByRuPaymt(anyList(), any(LocalDate.class)))
|
||||||
|
.thenReturn(flag90ByRuPaymt);
|
||||||
|
when(flagsService.findFlag90ByRuAllArrears(anyList(), any(LocalDate.class)))
|
||||||
|
.thenReturn(flag90ByRuAllArrears);
|
||||||
|
|
||||||
|
flagsEnricher.process(phonesMaps);
|
||||||
|
|
||||||
|
verify(packageRecordsService).updateFlagCache(flagCacheCaptor.capture());
|
||||||
|
List<FlagData> actualFlagCache = flagCacheCaptor.getValue();
|
||||||
|
|
||||||
|
assertNotNull(actualFlagCache);
|
||||||
|
assertEquals(9, actualFlagCache.size());
|
||||||
|
|
||||||
|
|
||||||
|
assertFlagData(actualFlagCache, 79123456781L, 1, 1); // fid 1: flag90days=1 (pastDueArrear)
|
||||||
|
assertFlagData(actualFlagCache, 79123456782L, 1, 0); // fid 2: flag90days=0
|
||||||
|
assertFlagData(actualFlagCache, 79123456783L, 1, 1); // fid 3: flag90days=1 (ruPaymt)
|
||||||
|
assertFlagData(actualFlagCache, 79123456784L, 0, 0); // fid 4: flag90days=0
|
||||||
|
assertFlagData(actualFlagCache, 79123456785L, 1, 1); // fid 5: flag90days=1 (pastDueArrear)
|
||||||
|
assertFlagData(actualFlagCache, 79123456786L, 0, 1); // fid 6: flag90days=1 (ruPaymt)
|
||||||
|
assertFlagData(actualFlagCache, 79123456787L, 0, 1); // fid 7: flag90days=1 (pastDueArrear)
|
||||||
|
assertFlagData(actualFlagCache, 79123456788L, 0, 1); // fid 8: flag90days=1 (ruPaymt)
|
||||||
|
assertFlagData(actualFlagCache, 79123456789L, 0, 0); // fid 9: flag90days=0
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void process_withEmptyList_shouldCallUpdateFlagCacheWithEmptyList() {
|
||||||
|
List<PhonesMap> emptyList = List.of();
|
||||||
|
|
||||||
|
when(flagsService.findFlagsDebt5000(anyList())).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByPastDueArrear(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByRuPaymt(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByRuAllArrears(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
|
||||||
|
flagsEnricher.process(emptyList);
|
||||||
|
|
||||||
|
verify(packageRecordsService).updateFlagCache(flagCacheCaptor.capture());
|
||||||
|
List<FlagData> actualFlagCache = flagCacheCaptor.getValue();
|
||||||
|
assertTrue(actualFlagCache.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void process_whenAllFlagsAreZero_shouldReturnZeroFlags() {
|
||||||
|
List<PhonesMap> phonesMaps = List.of(
|
||||||
|
createPhonesMap(1, 79123456781L),
|
||||||
|
createPhonesMap(2, 79123456782L)
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<Integer, Integer> zeroMap = Map.of(
|
||||||
|
1, 0,
|
||||||
|
2, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
when(flagsService.findFlagsDebt5000(anyList())).thenReturn(zeroMap);
|
||||||
|
when(flagsService.findFlag90ByPastDueArrear(anyList(), any(LocalDate.class))).thenReturn(zeroMap);
|
||||||
|
when(flagsService.findFlag90ByRuPaymt(anyList(), any(LocalDate.class))).thenReturn(zeroMap);
|
||||||
|
when(flagsService.findFlag90ByRuAllArrears(anyList(), any(LocalDate.class))).thenReturn(zeroMap);
|
||||||
|
|
||||||
|
flagsEnricher.process(phonesMaps);
|
||||||
|
|
||||||
|
verify(packageRecordsService).updateFlagCache(flagCacheCaptor.capture());
|
||||||
|
List<FlagData> actualFlagCache = flagCacheCaptor.getValue();
|
||||||
|
|
||||||
|
assertEquals(2, actualFlagCache.size());
|
||||||
|
assertFlagData(actualFlagCache, 79123456781L, 0, 0);
|
||||||
|
assertFlagData(actualFlagCache, 79123456782L, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void process_whenFlag90ExistsInMultipleSources_shouldTakeMaxValue() {
|
||||||
|
List<PhonesMap> phonesMaps = List.of(createPhonesMap(1, 79123456781L));
|
||||||
|
|
||||||
|
Map<Integer, Integer> flagsDebt5000 = Map.of(
|
||||||
|
1, 1
|
||||||
|
);
|
||||||
|
Map<Integer, Integer> flag90ByPastDueArrear = Map.of(
|
||||||
|
1, 1
|
||||||
|
);
|
||||||
|
Map<Integer, Integer> flag90ByRuPaymt = Map.of(
|
||||||
|
1, 1
|
||||||
|
);
|
||||||
|
Map<Integer, Integer> flag90ByRuAllArrears = Map.of(
|
||||||
|
1, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
when(flagsService.findFlagsDebt5000(anyList())).thenReturn(flagsDebt5000);
|
||||||
|
when(flagsService.findFlag90ByPastDueArrear(anyList(), any(LocalDate.class))).thenReturn(flag90ByPastDueArrear);
|
||||||
|
when(flagsService.findFlag90ByRuPaymt(anyList(), any(LocalDate.class))).thenReturn(flag90ByRuPaymt);
|
||||||
|
when(flagsService.findFlag90ByRuAllArrears(anyList(), any(LocalDate.class))).thenReturn(flag90ByRuAllArrears);
|
||||||
|
|
||||||
|
flagsEnricher.process(phonesMaps);
|
||||||
|
|
||||||
|
verify(packageRecordsService).updateFlagCache(flagCacheCaptor.capture());
|
||||||
|
List<FlagData> actualFlagCache = flagCacheCaptor.getValue();
|
||||||
|
|
||||||
|
assertFlagData(actualFlagCache, 79123456781L, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void process_shouldCallFlagsServiceWithCorrectArguments() {
|
||||||
|
List<PhonesMap> phonesMaps = createPhonesMaps();
|
||||||
|
List<Integer> expectedFids = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||||
|
|
||||||
|
when(flagsService.findFlagsDebt5000(anyList())).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByPastDueArrear(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByRuPaymt(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
when(flagsService.findFlag90ByRuAllArrears(anyList(), any(LocalDate.class))).thenReturn(Map.of());
|
||||||
|
|
||||||
|
flagsEnricher.process(phonesMaps);
|
||||||
|
|
||||||
|
verify(flagsService).findFlagsDebt5000(expectedFids);
|
||||||
|
verify(flagsService).findFlag90ByPastDueArrear(eq(expectedFids), any(LocalDate.class));
|
||||||
|
verify(flagsService).findFlag90ByRuPaymt(eq(expectedFids), any(LocalDate.class));
|
||||||
|
verify(flagsService).findFlag90ByRuAllArrears(eq(expectedFids), any(LocalDate.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<PhonesMap> createPhonesMaps() {
|
||||||
|
return List.of(
|
||||||
|
createPhonesMap(1, 79123456781L),
|
||||||
|
createPhonesMap(2, 79123456782L),
|
||||||
|
createPhonesMap(3, 79123456783L),
|
||||||
|
createPhonesMap(4, 79123456784L),
|
||||||
|
createPhonesMap(5, 79123456785L),
|
||||||
|
createPhonesMap(6, 79123456786L),
|
||||||
|
createPhonesMap(7, 79123456787L),
|
||||||
|
createPhonesMap(8, 79123456788L),
|
||||||
|
createPhonesMap(9, 79123456789L)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PhonesMap createPhonesMap(int fid, Long phone) {
|
||||||
|
PhonesMap phonesMap = new PhonesMap();
|
||||||
|
phonesMap.setFid(fid);
|
||||||
|
phonesMap.setPhone(phone);
|
||||||
|
return phonesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertFlagData(List<FlagData> flagCache, Long expectedPhone, int expectedDebt5000, int expectedDays90) {
|
||||||
|
FlagData flagData = flagCache.stream()
|
||||||
|
.filter(fd -> expectedPhone.equals(fd.getPhone()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
assertNotNull(flagData, "FlagData not found for phone: " + expectedPhone);
|
||||||
|
assertEquals(expectedDebt5000, flagData.getFlag_debt5000(),
|
||||||
|
"flag_debt5000 mismatch for phone: " + expectedPhone);
|
||||||
|
assertEquals(expectedDays90, flagData.getFlag_90_12(),
|
||||||
|
"flag_90_12 mismatch for phone: " + expectedPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue