Adding test VerificationResultComponentTest for clearing-service.
This commit is contained in:
parent
729280e629
commit
e24cece994
3 changed files with 115 additions and 1 deletions
|
|
@ -52,6 +52,9 @@ public abstract class AbstractClearingTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
protected PaymentUpdateBySdf04 paymentUpdateBySdf04;
|
protected PaymentUpdateBySdf04 paymentUpdateBySdf04;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected VerificationResultComponent verificationResultComponent;
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
hazelcastServiceTest.waitAvailable();
|
hazelcastServiceTest.waitAvailable();
|
||||||
TestUtils.FutureRecordMetadata future = spy(TestUtils.FutureRecordMetadata.class);
|
TestUtils.FutureRecordMetadata future = spy(TestUtils.FutureRecordMetadata.class);
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ class PaymentUpdateBySdf04Test extends AbstractClearingTest {
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final AtomicInteger currentInteger = new AtomicInteger(1);
|
private static final AtomicInteger currentInteger = new AtomicInteger(1);
|
||||||
private static final String TOPIC_SDF04_PROCESS = Consts.SDF04_PROCESS;
|
private static final String TOPIC_SDF04_PROCESS = Consts.SDF04_PROCESS;
|
||||||
ArgumentCaptor<PaymentInstruction> settingResult;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EventsReceiver eventsReceiver;
|
EventsReceiver eventsReceiver;
|
||||||
ImdgHazelcast<PaymentInstruction> paymentImdgsMock;
|
ImdgHazelcast<PaymentInstruction> paymentImdgsMock;
|
||||||
|
private ArgumentCaptor<PaymentInstruction> settingResult;
|
||||||
private Imdg<PaymentInstruction> paymentImdgs;
|
private Imdg<PaymentInstruction> paymentImdgs;
|
||||||
private Imdg<SDf04> sdf04Imdg;
|
private Imdg<SDf04> sdf04Imdg;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
package ru.spcex.clearing.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
|
import ru.clearing.classes.statics.data.account.AccountBalance;
|
||||||
|
import ru.clearing.classes.statics.data.clearing.VerificationResult;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.sdf.SDf01;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
|
||||||
|
import ru.spcex.platform.enumeration.AccountType;
|
||||||
|
import ru.spcex.platform.enumeration.Task;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static ru.spcex.clearing.utils.TestUtils.addRecordToKafka;
|
||||||
|
import static ru.spcex.clearing.utils.TestUtils.getJsonStringForUPDATE;
|
||||||
|
|
||||||
|
class VerificationResultComponentTest extends AbstractClearingTest {
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final AtomicInteger currentInteger = new AtomicInteger(1);
|
||||||
|
private static final String TOPIC_VERIFICATION = Task.getVerification.topic();
|
||||||
|
private final ArgumentCaptor<VerificationResult> settingResult = ArgumentCaptor.forClass(VerificationResult.class);
|
||||||
|
@Autowired
|
||||||
|
EventsReceiver eventsReceiver;
|
||||||
|
private Imdg<SDf01> sdf01Imdg;
|
||||||
|
private Imdg<AccountBalance> accountBalanceImdg;
|
||||||
|
private Imdg<Account> accountImdg;
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<VerificationResult> verificationResultImdg;
|
||||||
|
private Imdg<VerificationResult> verificationResultImdgMock;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.sdf01Imdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class);
|
||||||
|
this.accountBalanceImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_AccountBalance, AccountBalance.class);
|
||||||
|
this.accountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
|
this.companyImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
this.verificationResultImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_VerificationResult, VerificationResult.class);
|
||||||
|
this.verificationResultImdgMock = Mockito.mock(ImdgHazelcast.class, withSettings()
|
||||||
|
.serializable()
|
||||||
|
.spiedInstance(verificationResultImdg)
|
||||||
|
.defaultAnswer(CALLS_REAL_METHODS));
|
||||||
|
|
||||||
|
//setting imdg for been VerificationResultComponent
|
||||||
|
Field dbServiceField = null;
|
||||||
|
try {
|
||||||
|
dbServiceField = VerificationResultComponent.class.getDeclaredField("verificationResultImdg");
|
||||||
|
dbServiceField.setAccessible(true);
|
||||||
|
dbServiceField.set(verificationResultComponent, verificationResultImdgMock);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void executeRevision() {
|
||||||
|
//ARRANGE
|
||||||
|
int times = currentInteger.getAndIncrement();
|
||||||
|
Long companyId = 10L;
|
||||||
|
String acc = "15444876546";
|
||||||
|
String remainder = "15";
|
||||||
|
BigDecimal closeBalanceAmount = new BigDecimal(remainder);
|
||||||
|
SDf01 sDf01 = new SDf01();
|
||||||
|
sDf01.setAccount(acc);
|
||||||
|
sDf01.setRemainder(remainder);
|
||||||
|
sDf01.setDeal(acc);
|
||||||
|
sdf01Imdg.insert(sDf01);
|
||||||
|
AccountBalance accountBalance = new AccountBalance();
|
||||||
|
accountBalance.setCompanyId(companyId);
|
||||||
|
accountBalance.setAccount(acc);
|
||||||
|
accountBalance.setCloseBalanceAmount(closeBalanceAmount);
|
||||||
|
accountBalanceImdg.insert(accountBalance);
|
||||||
|
Account account = new Account();
|
||||||
|
account.setAccount(acc);
|
||||||
|
account.setAccountType(AccountType.Clrn.getKey());
|
||||||
|
account.setAccountStatus("UNBL");
|
||||||
|
account.setCompanyId(companyId);
|
||||||
|
account.setCompanyId(companyId);
|
||||||
|
accountImdg.insert(account);
|
||||||
|
Company company = new Company();
|
||||||
|
company.setId(companyId);
|
||||||
|
company.setClearingCode("codeTest");
|
||||||
|
companyImdg.insert(company);
|
||||||
|
|
||||||
|
//ACT
|
||||||
|
addRecordToKafka((MockConsumer) eventsReceiver.getConsumer(), TOPIC_VERIFICATION,
|
||||||
|
PARTITION, times, getJsonStringForUPDATE(new LauncherCommandRequest(), 1L));
|
||||||
|
|
||||||
|
//waiting for kafka producer send message
|
||||||
|
verify(verificationResultImdgMock, timeout(30_000L).times(4))
|
||||||
|
.insert(settingResult.capture());
|
||||||
|
settingResult.getValue();
|
||||||
|
Collection<VerificationResult> result = verificationResultImdg.getAllValues();
|
||||||
|
result.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue