Merge pull request #8 from rbkmoney/ft/update

update java 15 + test
This commit is contained in:
Gregory 2021-12-13 18:23:11 +03:00 committed by GitHub
commit 2d0dd8325f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 470 additions and 399 deletions

5
Jenkinsfile vendored
View File

@ -5,12 +5,11 @@ build('deanonimus', 'java-maven') {
def javaServicePipeline
runStage('load JavaService pipeline') {
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaServiceInsideDocker.groovy")
}
def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"'
def useJava11 = true
javaServicePipeline(serviceName, useJava11, mvnArgs)
javaServicePipeline(serviceName, mvnArgs)
}

@ -1 +1 @@
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486
Subproject commit a87ebf3ae5e56910dc6a0edcac7f90565368a3d1

45
pom.xml
View File

@ -5,8 +5,8 @@
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<artifactId>service-parent-pom</artifactId>
<version>2.0.15</version>
</parent>
<artifactId>deanonimus</artifactId>
@ -19,13 +19,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<server.port>8022</server.port>
<exposed.ports>${server.port}</exposed.ports>
<dockerfile.base.service.tag>57e26d8ee999d7b0b50248c22afc63e6f926d276</dockerfile.base.service.tag>
<management.port>8023</management.port>
<exposed.ports>${server.port} ${management.port}</exposed.ports>
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
<shared.resources.version>0.3.8</shared.resources.version>
<damsel.version>1.446-38bdfd5</damsel.version>
<deanonimus.proto.version>1.18-b9fab4f</deanonimus.proto.version>
</properties>
<dependencies>
@ -38,17 +36,14 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>custom-actuator-endpoints</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>1.1.22</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>shared-resources</artifactId>
<version>${shared.resources.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
@ -58,7 +53,6 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>kafka-common-lib</artifactId>
<version>0.1.6</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
@ -68,17 +62,15 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
<version>${damsel.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>serializer</artifactId>
<version>0.6.11</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>deanonimus-proto</artifactId>
<version>1.16-c0bbabe</version>
<version>${deanonimus.proto.version}</version>
</dependency>
<!--spring-->
<dependency>
@ -117,7 +109,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@ -145,13 +136,13 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
<version>1.14.3</version>
<version>1.16.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.14.3</version>
<version>1.16.2</version>
</dependency>
</dependencies>
@ -181,7 +172,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -196,7 +186,7 @@
</dependencies>
<configuration>
<resourceBundles>
<resourceBundle>com.rbkmoney:shared-resources:${shared.resources.version}</resourceBundle>
<resourceBundle>com.rbkmoney:shared-resources:${shared-resources.version}</resourceBundle>
</resourceBundles>
<attachToMain>false</attachToMain>
<attachToTest>false</attachToTest>
@ -209,23 +199,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<destFile>${sonar.jacoco.reportPaths}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -75,11 +75,13 @@ public class KafkaConfig {
private void configureSsl(Map<String, Object> props, KafkaSslProperties kafkaSslProperties) {
if (kafkaSslProperties.isEnabled()) {
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, SecurityProtocol.SSL.name());
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, new File(kafkaSslProperties.getTrustStoreLocation()).getAbsolutePath());
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,
new File(kafkaSslProperties.getTrustStoreLocation()).getAbsolutePath());
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, kafkaSslProperties.getTrustStorePassword());
props.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, kafkaSslProperties.getKeyStoreType());
props.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, kafkaSslProperties.getTrustStoreType());
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, new File(kafkaSslProperties.getKeyStoreLocation()).getAbsolutePath());
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,
new File(kafkaSslProperties.getKeyStoreLocation()).getAbsolutePath());
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, kafkaSslProperties.getKeyStorePassword());
props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, kafkaSslProperties.getKeyPassword());
}
@ -91,7 +93,8 @@ public class KafkaConfig {
}
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> partyManagementContainerFactory(
public KafkaListenerContainerFactory
<ConcurrentMessageListenerContainer<String, MachineEvent>> partyManagementContainerFactory(
KafkaSslProperties kafkaSslProperties) {
Map<String, Object> configs = consumerConfigs(kafkaSslProperties);
configs.put(ConsumerConfig.GROUP_ID_CONFIG, partyConsumerGroup);
@ -99,14 +102,17 @@ public class KafkaConfig {
return createConcurrentFactory(consumerFactory, partyConcurrency);
}
private KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> createConcurrentFactory(
private KafkaListenerContainerFactory
<ConcurrentMessageListenerContainer<String, MachineEvent>> createConcurrentFactory(
ConsumerFactory<String, MachineEvent> consumerFactory, int threadsNumber) {
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory = new ConcurrentKafkaListenerContainerFactory<>();
ConcurrentKafkaListenerContainerFactory<String, MachineEvent> factory =
new ConcurrentKafkaListenerContainerFactory<>();
initFactory(consumerFactory, threadsNumber, factory);
return factory;
}
private <T> void initFactory(ConsumerFactory<String, T> consumerFactory, int threadsNumber, ConcurrentKafkaListenerContainerFactory<String, T> factory) {
private <T> void initFactory(ConsumerFactory<String, T> consumerFactory, int threadsNumber,
ConcurrentKafkaListenerContainerFactory<String, T> factory) {
factory.setConsumerFactory(consumerFactory);
factory.setBatchListener(true);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL);

View File

@ -17,7 +17,8 @@ public class SerializationConfig {
}
@Bean
public MachineEventParser<PartyEventData> partyEventDataMachineEventParser(BinaryDeserializer<PartyEventData> partyEventDataBinaryDeserializer) {
public MachineEventParser<PartyEventData> partyEventDataMachineEventParser(
BinaryDeserializer<PartyEventData> partyEventDataBinaryDeserializer) {
return new PartyEventDataMachineEventParser(partyEventDataBinaryDeserializer);
}
}

View File

@ -50,16 +50,12 @@ public class ContractConverter {
}
private ContractStatus convertStatus(com.rbkmoney.deanonimus.domain.ContractStatus status) {
switch (status) {
case active:
return ContractStatus.active(new ContractActive());
case expired:
return ContractStatus.expired(new ContractExpired());
case terminated:
return ContractStatus.terminated(new ContractTerminated());
default:
throw new IllegalArgumentException("No such contractStatus: " + status);
}
return switch (status) {
case active -> ContractStatus.active(new ContractActive());
case expired -> ContractStatus.expired(new ContractExpired());
case terminated -> ContractStatus.terminated(new ContractTerminated());
default -> throw new IllegalArgumentException("No such contractStatus: " + status);
};
}
}

View File

@ -2,6 +2,7 @@ package com.rbkmoney.deanonimus.converter;
import com.rbkmoney.damsel.deanonimus.*;
import com.rbkmoney.deanonimus.domain.Contractor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import java.util.Collections;
@ -10,6 +11,8 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.rbkmoney.damsel.deanonimus.Contractor.*;
@Component
public class ContractorConverter {
@ -28,44 +31,47 @@ public class ContractorConverter {
}
private com.rbkmoney.damsel.deanonimus.Contractor convertContractor(Contractor contractor) {
switch (contractor.getType()) {
case legal_entity:
return com.rbkmoney.damsel.deanonimus.Contractor.legal_entity(convertLegalEntity(contractor));
case private_entity:
return com.rbkmoney.damsel.deanonimus.Contractor.private_entity(new PrivateEntity());
case registered_user:
return com.rbkmoney.damsel.deanonimus.Contractor.registered_user(new RegisteredUser(contractor.getRegisteredUserEmail()));
default:
throw new IllegalArgumentException("No such contractorType: " + contractor.getType());
}
return switch (contractor.getType()) {
case legal_entity -> legal_entity(convertLegalEntity(contractor));
case private_entity -> private_entity(new PrivateEntity());
case registered_user -> registered_user(new RegisteredUser(contractor.getRegisteredUserEmail()));
default -> throw new IllegalArgumentException("No such contractorType: " + contractor.getType());
};
}
private LegalEntity convertLegalEntity(Contractor contractor) {
switch (contractor.getLegalEntity()) {
case international_legal_entity:
InternationalLegalEntity internationalLegalEntity = new InternationalLegalEntity()
.setLegalName(contractor.getInternationalLegalEntityLegalName())
.setTradingName(contractor.getInternationalLegalEntityTradingName())
.setRegisteredAddress(contractor.getInternationalLegalEntityRegisteredAddress())
.setActualAddress(contractor.getInternationalLegalEntityActualAddress())
.setRegisteredNumber(contractor.getInternationalLegalEntityRegisteredNumber());
return LegalEntity.international_legal_entity(internationalLegalEntity);
case russian_legal_entity:
RussianLegalEntity russianLegalEntity = new RussianLegalEntity()
.setRegisteredName(contractor.getRussianLegalEntityRegisteredName())
.setRegisteredNumber(contractor.getRussianLegalEntityRegisteredNumber())
.setInn(contractor.getRussianLegalEntityInn())
.setActualAddress(contractor.getRussianLegalEntityActualAddress())
.setPostAddress(contractor.getRussianLegalEntityPostAddress())
.setRussianBankAccount(new RussianBankAccount(
contractor.getRussianLegalEntityRussianBankAccount(),
contractor.getRussianLegalEntityRussianBankName(),
contractor.getRussianLegalEntityRussianBankPostAccount(),
contractor.getRussianLegalEntityRussianBankBik()
));
return LegalEntity.russian_legal_entity(russianLegalEntity);
default:
throw new IllegalArgumentException("No such legalEntity " + contractor.getLegalEntity());
}
return switch (contractor.getLegalEntity()) {
case international_legal_entity -> buildInternationalLegalEntity(contractor);
case russian_legal_entity -> buildRussianLegalEntity(contractor);
default -> throw new IllegalArgumentException("No such legalEntity " + contractor.getLegalEntity());
};
}
@NotNull
private LegalEntity buildInternationalLegalEntity(Contractor contractor) {
InternationalLegalEntity internationalLegalEntity = new InternationalLegalEntity()
.setLegalName(contractor.getInternationalLegalEntityLegalName())
.setTradingName(contractor.getInternationalLegalEntityTradingName())
.setRegisteredAddress(contractor.getInternationalLegalEntityRegisteredAddress())
.setActualAddress(contractor.getInternationalLegalEntityActualAddress())
.setRegisteredNumber(contractor.getInternationalLegalEntityRegisteredNumber());
return LegalEntity.international_legal_entity(internationalLegalEntity);
}
@NotNull
private LegalEntity buildRussianLegalEntity(Contractor contractor) {
RussianLegalEntity russianLegalEntity = new RussianLegalEntity()
.setRegisteredName(contractor.getRussianLegalEntityRegisteredName())
.setRegisteredNumber(contractor.getRussianLegalEntityRegisteredNumber())
.setInn(contractor.getRussianLegalEntityInn())
.setActualAddress(contractor.getRussianLegalEntityActualAddress())
.setPostAddress(contractor.getRussianLegalEntityPostAddress())
.setRussianBankAccount(new RussianBankAccount(
contractor.getRussianLegalEntityRussianBankAccount(),
contractor.getRussianLegalEntityRussianBankName(),
contractor.getRussianLegalEntityRussianBankPostAccount(),
contractor.getRussianLegalEntityRussianBankBik()
));
return LegalEntity.russian_legal_entity(russianLegalEntity);
}
}

View File

@ -27,15 +27,15 @@ public class ShopConverter {
private Shop convertShop(com.rbkmoney.deanonimus.domain.Shop shopDomain) {
Shop shop = new Shop()
.setId(shopDomain.getId())
.setBlocking(EnumUtils.convertBlocking(shopDomain.getBlocking()))
.setSuspension(EnumUtils.convertSuspension(shopDomain.getSuspension()))
.setCategory(new CategoryRef(shopDomain.getCategoryId()))
.setContractId(shopDomain.getContractId())
.setDetails(new ShopDetails()
.setName(shopDomain.getDetailsName())
.setDescription(shopDomain.getDetailsDescription())
)
.setPayoutToolId(shopDomain.getPayoutToolId());
.setBlocking(EnumUtils.convertBlocking(shopDomain.getBlocking()))
.setSuspension(EnumUtils.convertSuspension(shopDomain.getSuspension()))
.setCategory(new CategoryRef(shopDomain.getCategoryId()))
.setContractId(shopDomain.getContractId())
.setDetails(new ShopDetails()
.setName(shopDomain.getDetailsName())
.setDescription(shopDomain.getDetailsDescription())
)
.setPayoutToolId(shopDomain.getPayoutToolId());
setAccount(shopDomain, shop);

View File

@ -2,7 +2,7 @@ package com.rbkmoney.deanonimus.kafka.handler;
import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.damsel.payment_processing.PartyEventData;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import com.rbkmoney.sink.common.parser.impl.MachineEventParser;
import lombok.RequiredArgsConstructor;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management;
package com.rbkmoney.deanonimus.kafka.handler.party.management;
import com.rbkmoney.damsel.payment_processing.ClaimStatus;
import com.rbkmoney.damsel.payment_processing.PartyChange;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management;
package com.rbkmoney.deanonimus.kafka.handler.party.management;
import com.rbkmoney.geck.filter.Filter;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management;
package com.rbkmoney.deanonimus.kafka.handler.party.management;
import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.machinegun.eventsink.MachineEvent;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.contract;
package com.rbkmoney.deanonimus.kafka.handler.party.management.contract;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
import com.rbkmoney.damsel.payment_processing.ContractEffectUnit;
@ -8,7 +8,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Contract;
import com.rbkmoney.deanonimus.domain.ContractStatus;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.util.ContractUtil;
import com.rbkmoney.geck.common.util.TBaseUtil;
import com.rbkmoney.geck.common.util.TypeUtil;
@ -35,7 +35,8 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (ClaimEffect claimEffect : claimEffects) {
if (claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetCreated()) {
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetCreated()) {
handleEvent(event, changeId, sequenceId, claimEffect);
}
}
@ -43,16 +44,13 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e) {
ContractEffectUnit contractEffectUnit = e.getContractEffect();
com.rbkmoney.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
Contract contract = new Contract();
contract.setId(contractId);
com.rbkmoney.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated();
contract.setPartyId(partyId);
if (contractCreated.isSetPaymentInstitution()) {
contract.setPaymentInstitutionId(contractCreated.getPaymentInstitution().getId());
@ -68,17 +66,16 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler {
if (contractCreated.isSetLegalAgreement()) {
ContractUtil.fillContractLegalAgreementFields(contract, contractCreated.getLegalAgreement());
}
if (contractCreated.isSetReportPreferences() && contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
ContractUtil.fillReportPreferences(contract, contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
if (contractCreated.isSetReportPreferences()
&& contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
ContractUtil.fillReportPreferences(contract,
contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
}
String contractorId = initContractorId(contractCreated);
contract.setContractorId(contractorId);
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
party.addContract(contract);
partyRepository.save(party);
log.info("End contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
}

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.contract;
package com.rbkmoney.deanonimus.kafka.handler.party.management.contract;
import com.rbkmoney.damsel.domain.LegalAgreement;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.ContractNotFoundException;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Contract;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -32,7 +32,8 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (ClaimEffect claimEffect : claimEffects) {
if (claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetLegalAgreementBound()) {
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetLegalAgreementBound()) {
handleEvent(event, changeId, sequenceId, claimEffect);
}
}
@ -45,12 +46,11 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand
String partyId = event.getSourceId();
log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
Contract contract = party.getContractById(contractId).orElseThrow(() -> new ContractNotFoundException(contractId));
Party party = partyRepository.findById(partyId)
.orElseThrow(() -> new PartyNotFoundException(partyId));
Contract contract = party.getContractById(contractId)
.orElseThrow(() -> new ContractNotFoundException(contractId));
contract.setLegalAgreementId(legalAgreement.getLegalAgreementId());
partyRepository.save(party);
log.info("End contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}",

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.contract;
package com.rbkmoney.deanonimus.kafka.handler.party.management.contract;
import com.rbkmoney.damsel.domain.ReportPreferences;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.ContractNotFoundException;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Contract;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.util.ContractUtil;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
@ -33,7 +33,8 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (ClaimEffect claimEffect : claimEffects) {
if (claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetReportPreferencesChanged()) {
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetReportPreferencesChanged()) {
handleEvent(event, changeId, sequenceId, claimEffect);
}
}
@ -44,12 +45,17 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange
ReportPreferences reportPreferencesChanged = contractEffectUnit.getEffect().getReportPreferencesChanged();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract report preferences changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
log.info(
"""
Start contract report preferences changed handling,
sequenceId={}, partyId={}, contractId={}, changeId={}
""",
sequenceId, partyId, contractId, changeId);
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
Contract contract = party.getContractById(contractId).orElseThrow(() -> new ContractNotFoundException(contractId));
Contract contract =
party.getContractById(contractId).orElseThrow(() -> new ContractNotFoundException(contractId));
if (reportPreferencesChanged != null && reportPreferencesChanged.isSetServiceAcceptanceActPreferences()) {
ContractUtil.fillReportPreferences(contract, reportPreferencesChanged.getServiceAcceptanceActPreferences());
@ -59,7 +65,11 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange
partyRepository.save(party);
log.info("End contract report preferences changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
log.info(
"""
End contract report preferences changed handling,
sequenceId={}, partyId={}, contractId={}, changeId={}
""",
sequenceId, partyId, contractId, changeId);
}
}

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.contractor;
package com.rbkmoney.deanonimus.kafka.handler.party.management.contractor;
import com.rbkmoney.damsel.domain.PartyContractor;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -7,7 +7,7 @@ import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.util.ContractorUtil;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
@ -43,14 +43,17 @@ public class ContractorCreatedHandler extends AbstractClaimChangedHandler {
com.rbkmoney.damsel.domain.Contractor contractorCreated = partyContractor.getContractor();
String contractorId = contractorEffect.getId();
String partyId = event.getSourceId();
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId,
contractorId);
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
com.rbkmoney.deanonimus.domain.Contractor contractor = ContractorUtil.convertContractor(partyId, contractorCreated, contractorId);
com.rbkmoney.deanonimus.domain.Contractor contractor =
ContractorUtil.convertContractor(partyId, contractorCreated, contractorId);
party.addContractor(contractor);
partyRepository.save(party);
log.info("End contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId);
log.info("End contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId,
contractorId);
}

View File

@ -1,11 +1,11 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.party;
package com.rbkmoney.deanonimus.kafka.handler.party.management.party;
import com.rbkmoney.damsel.domain.Blocking;
import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;
@ -33,7 +33,8 @@ public class PartyBlockingHandler implements PartyManagementHandler {
long sequenceId = event.getEventId();
Blocking partyBlocking = change.getPartyBlocking();
String partyId = event.getSourceId();
log.info("Start party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
log.info("Start party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
changeId);
Party partySource = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
if (partyBlocking.isSetUnblocked()) {

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.party;
package com.rbkmoney.deanonimus.kafka.handler.party.management.party;
import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.damsel.payment_processing.PartyCreated;
@ -6,7 +6,7 @@ import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.domain.Blocking;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Suspension;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;

View File

@ -1,11 +1,11 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.party;
package com.rbkmoney.deanonimus.kafka.handler.party.management.party;
import com.rbkmoney.damsel.domain.Suspension;
import com.rbkmoney.damsel.payment_processing.PartyChange;
import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.domain.ShopAccount;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -8,7 +8,7 @@ import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.util.ShopUtil;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
@ -48,7 +48,8 @@ public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler {
Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId));
ShopUtil.fillShopAccount(party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)), accountCreated);
ShopUtil.fillShopAccount(party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)),
accountCreated);
partyRepository.save(party);

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.domain.Blocking;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -7,7 +7,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -8,7 +8,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -10,7 +10,7 @@ import com.rbkmoney.deanonimus.domain.Blocking;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.domain.Suspension;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.util.ShopUtil;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.domain.ShopDetails;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.domain.ShopLocation;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -9,7 +9,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.payment_processing.ClaimEffect;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -8,7 +8,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.AbstractClaimChangedHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler;
import com.rbkmoney.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.rbkmoney.deanonimus.kafka.handler.party_management.shop;
package com.rbkmoney.deanonimus.kafka.handler.party.management.shop;
import com.rbkmoney.damsel.domain.Suspension;
import com.rbkmoney.damsel.payment_processing.PartyChange;
@ -7,7 +7,7 @@ import com.rbkmoney.deanonimus.db.exception.PartyNotFoundException;
import com.rbkmoney.deanonimus.db.exception.ShopNotFoundException;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.domain.Shop;
import com.rbkmoney.deanonimus.kafka.handler.party_management.PartyManagementHandler;
import com.rbkmoney.deanonimus.kafka.handler.party.management.PartyManagementHandler;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;

View File

@ -29,6 +29,7 @@ public class PartyManagementListener {
.collect(Collectors.toList())
);
ack.acknowledge();
log.info("Batch partyManagement has been committed, size={}, {}", messages.size(), LogUtil.toSummaryStringWithSinkEventValues(messages));
log.info("Batch partyManagement has been committed, size={}, {}",
messages.size(), LogUtil.toSummaryStringWithSinkEventValues(messages));
}
}

View File

@ -12,10 +12,12 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ContractUtil {
public static void fillReportPreferences(Contract contract, ServiceAcceptanceActPreferences serviceAcceptanceActPreferences) {
public static void fillReportPreferences(Contract contract,
ServiceAcceptanceActPreferences serviceAcceptanceActPreferences) {
contract.setReportActSignerFullName(serviceAcceptanceActPreferences.getSigner().getFullName());
final com.rbkmoney.damsel.domain.RepresentativeDocument document = serviceAcceptanceActPreferences.getSigner().getDocument();
RepresentativeDocument reportActSignerDocument = TypeUtil.toEnumField(document.getSetField().getFieldName(), RepresentativeDocument.class);
var document = serviceAcceptanceActPreferences.getSigner().getDocument();
RepresentativeDocument reportActSignerDocument =
TypeUtil.toEnumField(document.getSetField().getFieldName(), RepresentativeDocument.class);
if (reportActSignerDocument == null) {
throw new IllegalArgumentException("Illegal representative document: " + document);
}

View File

@ -1,6 +1,7 @@
package com.rbkmoney.deanonimus.util;
import com.rbkmoney.damsel.domain.InternationalLegalEntity;
import com.rbkmoney.damsel.domain.RussianBankAccount;
import com.rbkmoney.damsel.domain.RussianLegalEntity;
import com.rbkmoney.deanonimus.domain.Contractor;
import com.rbkmoney.deanonimus.domain.ContractorType;
@ -12,7 +13,9 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ContractorUtil {
public static Contractor convertContractor(String partyId, com.rbkmoney.damsel.domain.Contractor contractorSource, String contractorId) {
public static Contractor convertContractor(String partyId,
com.rbkmoney.damsel.domain.Contractor contractorSource,
String contractorId) {
Contractor contractor = new Contractor();
contractor.setId(contractorId);
contractor.setPartyId(partyId);
@ -28,15 +31,18 @@ public class ContractorUtil {
contractor.setRussianLegalEntityInn(russianLegalEntity.getInn());
contractor.setRussianLegalEntityActualAddress(russianLegalEntity.getActualAddress());
contractor.setRussianLegalEntityPostAddress(russianLegalEntity.getPostAddress());
contractor.setRussianLegalEntityRussianBankAccount(russianLegalEntity.getRussianBankAccount().getAccount());
contractor.setRussianLegalEntityRussianBankName(russianLegalEntity.getRussianBankAccount().getBankName());
contractor.setRussianLegalEntityRussianBankPostAccount(russianLegalEntity.getRussianBankAccount().getBankPostAccount());
contractor.setRussianLegalEntityRussianBankBik(russianLegalEntity.getRussianBankAccount().getBankBik());
RussianBankAccount russianBankAccount = russianLegalEntity.getRussianBankAccount();
contractor.setRussianLegalEntityRussianBankAccount(russianBankAccount.getAccount());
contractor.setRussianLegalEntityRussianBankName(russianBankAccount.getBankName());
contractor.setRussianLegalEntityRussianBankPostAccount(russianBankAccount.getBankPostAccount());
contractor.setRussianLegalEntityRussianBankBik(russianBankAccount.getBankBik());
} else if (contractorSource.getLegalEntity().isSetInternationalLegalEntity()) {
InternationalLegalEntity internationalLegalEntity = contractorSource.getLegalEntity().getInternationalLegalEntity();
InternationalLegalEntity internationalLegalEntity =
contractorSource.getLegalEntity().getInternationalLegalEntity();
contractor.setInternationalLegalEntityLegalName(internationalLegalEntity.getLegalName());
contractor.setInternationalLegalEntityTradingName(internationalLegalEntity.getTradingName());
contractor.setInternationalLegalEntityRegisteredAddress(internationalLegalEntity.getRegisteredAddress());
contractor.setInternationalLegalEntityRegisteredAddress(
internationalLegalEntity.getRegisteredAddress());
contractor.setInternationalLegalEntityActualAddress(internationalLegalEntity.getActualAddress());
contractor.setInternationalLegalEntityRegisteredNumber(internationalLegalEntity.getRegisteredNumber());
}

View File

@ -5,24 +5,18 @@ import com.rbkmoney.damsel.deanonimus.*;
public class EnumUtils {
public static Blocking convertBlocking(com.rbkmoney.deanonimus.domain.Blocking blocking) {
switch (blocking) {
case blocked:
return Blocking.blocked(new Blocked());
case unblocked:
return Blocking.unblocked(new Unblocked());
default:
throw new IllegalArgumentException("No such blocking state " + blocking);
}
return switch (blocking) {
case blocked -> Blocking.blocked(new Blocked());
case unblocked -> Blocking.unblocked(new Unblocked());
default -> throw new IllegalArgumentException("No such blocking state " + blocking);
};
}
public static Suspension convertSuspension(com.rbkmoney.deanonimus.domain.Suspension suspension) {
switch (suspension) {
case active:
return Suspension.active(new Active());
case suspended:
return Suspension.suspended(new Suspended());
default:
throw new IllegalArgumentException("No such suspension state " + suspension);
}
return switch (suspension) {
case active -> Suspension.active(new Active());
case suspended -> Suspension.suspended(new Suspended());
default -> throw new IllegalArgumentException("No such suspension state " + suspension);
};
}
}

View File

@ -3,13 +3,27 @@ server:
management:
security:
flag: false
enabled: false
server:
port: '@management.port@'
metrics:
export:
statsd:
enabled: false
flavor: etsy
endpoint.health.show-details: always
enabled: false
prometheus:
enabled: false
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: health,info,prometheus
spring:
application:

View File

@ -0,0 +1,53 @@
package com.rbkmoney.deanonimus;
import com.rbkmoney.deanonimus.extension.ElasticsearchContainerExtension;
import com.rbkmoney.deanonimus.extension.KafkaContainerExtension;
import com.rbkmoney.kafka.common.serialization.ThriftSerializer;
import com.rbkmoney.machinegun.eventsink.SinkEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import java.util.List;
import java.util.Map;
@Slf4j
@ExtendWith({KafkaContainerExtension.class, ElasticsearchContainerExtension.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@SpringBootTest
public abstract class AbstractIntegrationTest {
private static final String TOPIC_NAME = "mg-events-party";
@DynamicPropertySource
static void containersProps(DynamicPropertyRegistry registry) {
registry.add("kafka.bootstrap-servers", KafkaContainerExtension.KAFKA::getBootstrapServers);
registry.add("spring.elasticsearch.rest.uris",
ElasticsearchContainerExtension.ELASTIC_SEARCH::getHttpHostAddress);
}
public static void sendMessages(List<SinkEvent> sinkEvents) {
final Producer<String, SinkEvent> producer = createProducer();
sinkEvents.forEach(sinkEvent ->
producer.send(new ProducerRecord<>(TOPIC_NAME, sinkEvent.getEvent().getSourceId(), sinkEvent)));
}
private static Producer<String, SinkEvent> createProducer() {
final Map<String, Object> configs =
KafkaTestUtils.producerProps(KafkaContainerExtension.KAFKA.getBootstrapServers());
configs.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configs.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ThriftSerializer.class);
return new KafkaProducer<>(configs);
}
}

View File

@ -1,16 +0,0 @@
package com.rbkmoney.deanonimus;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DeanonimusApplication.class)
public class DeanonimusApplicationTest {
@Test
public void contextLoads() {
}
}

View File

@ -1,75 +0,0 @@
package com.rbkmoney.deanonimus;
import com.rbkmoney.kafka.common.serialization.ThriftSerializer;
import com.rbkmoney.machinegun.eventsink.SinkEvent;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import java.util.List;
import java.util.Map;
@Slf4j
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@SpringBootTest(classes = DeanonimusApplication.class)
@ContextConfiguration(initializers = IntegrationTestBase.Initializer.class)
public abstract class IntegrationTestBase {
private static final String TOPIC_NAME = "mg-events-party";
private static final String CONFLUENT_PLATFORM_VERSION = "5.0.1";
@ClassRule
public static ElasticsearchContainer elastic = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.8.0");
@ClassRule
public static KafkaContainer kafka = new KafkaContainer(CONFLUENT_PLATFORM_VERSION).withEmbeddedZookeeper();
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@SneakyThrows
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("kafka.bootstrap-servers=" + kafka.getBootstrapServers(),
"spring.elasticsearch.rest.uris=" + elastic.getHttpHostAddress())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
public static void sendMessage(SinkEvent sinkEvent) {
createProducer().send(new ProducerRecord<>(TOPIC_NAME, sinkEvent.getEvent().getSourceId(), sinkEvent));
}
public static void sendMessages(List<SinkEvent> sinkEvents) {
final Producer<String, SinkEvent> producer = createProducer();
sinkEvents.forEach(sinkEvent ->
producer.send(new ProducerRecord<>(TOPIC_NAME, sinkEvent.getEvent().getSourceId(), sinkEvent)));
}
private static Producer<String, SinkEvent> createProducer() {
final Map<String, Object> configs = KafkaTestUtils.producerProps(kafka.getBootstrapServers());
configs.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configs.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ThriftSerializer.class);
return new KafkaProducer<>(configs);
}
}

View File

@ -71,7 +71,8 @@ public class PartyFlowGenerator {
sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(
buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId)));
return sinkEvents;
@ -92,12 +93,14 @@ public class PartyFlowGenerator {
sinkEvents.add(buildSinkEvent(buildMessageShopAccountCreated(sequenceId++, partyId, shopId)));
sinkEvents.add(buildSinkEvent(buildMessageShopSuspension(
sequenceId++, partyId, buildSuspendedShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId))));
sequenceId++, partyId,
buildSuspendedShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId))));
return sinkEvents;
}
public static List<SinkEvent> generatePartyFlowWithCount(int count, String lastPartyId, PartyContractor contractor) throws IOException {
public static List<SinkEvent> generatePartyFlowWithCount(int count, String lastPartyId, PartyContractor contractor)
throws IOException {
List<SinkEvent> sinkEvents = new ArrayList<>();
Long sequenceId = 0L;
for (int i = 0; i < count; i++) {
@ -109,7 +112,8 @@ public class PartyFlowGenerator {
} else {
String partyId = UUID.randomUUID().toString();
sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(
buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId)));
@ -122,7 +126,8 @@ public class PartyFlowGenerator {
public static List<SinkEvent> generatePartyFlowWithMultiplePartyChange(int count,
String lastPartyId,
PartyContractor partyContractor) throws IOException {
PartyContractor partyContractor)
throws IOException {
List<SinkEvent> sinkEvents = new ArrayList<>();
Long sequenceId = 0L;
for (int i = 0; i < count; i++) {
@ -141,12 +146,14 @@ public class PartyFlowGenerator {
public static List<SinkEvent> generatePartyFlowWithMultiplePartyShopChange(int count,
String lastPartyId,
String lastShopId,
PartyChange customPartyChange) throws IOException {
PartyChange customPartyChange)
throws IOException {
List<SinkEvent> sinkEvents = new ArrayList<>();
Long sequenceId = 0L;
for (int i = 0; i < count; i++) {
if (i == count - 1) {
sinkEvents.add(buildSinkEvent(buildMultiShopChange(sequenceId, lastPartyId, lastShopId, customPartyChange)));
sinkEvents.add(buildSinkEvent(
buildMultiShopChange(sequenceId, lastPartyId, lastShopId, customPartyChange)));
} else {
String partyId = UUID.randomUUID().toString();
String shopId = UUID.randomUUID().toString();
@ -159,30 +166,34 @@ public class PartyFlowGenerator {
public static List<SinkEvent> generatePartyFlowWithMultipleShopInOneChange(String lastPartyId,
String lastShopId,
PartyChange customPartyChange) throws IOException {
PartyChange customPartyChange)
throws IOException {
List<SinkEvent> sinkEvents = new ArrayList<>();
Long sequenceId = 0L;
sinkEvents.add(buildSinkEvent(buildMultiShopChangeDifferentShopId(sequenceId, lastPartyId, lastShopId, customPartyChange)));
sinkEvents.add(buildSinkEvent(
buildMultiShopChangeDifferentShopId(sequenceId, lastPartyId, lastShopId, customPartyChange)));
return sinkEvents;
}
public static List<SinkEvent> generatePartyFlowWithContract(String partyId, LegalEntity legalEntity) throws IOException {
public static List<SinkEvent> generatePartyFlowWithContract(String partyId, LegalEntity legalEntity)
throws IOException {
List<SinkEvent> sinkEvents = new ArrayList<>();
Long sequenceId = 0L;
sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(
buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId)));
sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId)));
sinkEvents.add(buildSinkEvent(buildContractContractorCreated(sequenceId++, partyId, legalEntity)));
return sinkEvents;
}
public static MachineEvent buildContractContractorCreated(Long sequenceId, String partyId, LegalEntity legalEntity) {
ContractEffect contractEffect = new ContractEffect();
public static MachineEvent buildContractContractorCreated(Long sequenceId, String partyId,
LegalEntity legalEntity) {
Contract contract = new Contract();
contract.setId("testContractId");
contract.setContractorId("testContractorId");
@ -196,6 +207,7 @@ public class PartyFlowGenerator {
Contractor contractor = new Contractor();
contractor.setLegalEntity(legalEntity);
contract.setContractor(contractor);
ContractEffect contractEffect = new ContractEffect();
contractEffect.setCreated(contract);
ContractEffectUnit contractEffectUnit = new ContractEffectUnit();
contractEffectUnit.setContractId("testContractId");
@ -210,7 +222,8 @@ public class PartyFlowGenerator {
public static RussianLegalEntity buildRussianLegalEntity() throws IOException {
RussianLegalEntity russianLegalEntity = new RussianLegalEntity();
russianLegalEntity = new MockTBaseProcessor(MockMode.ALL).process(russianLegalEntity, new TBaseHandler<>(RussianLegalEntity.class));
russianLegalEntity = new MockTBaseProcessor(MockMode.ALL)
.process(russianLegalEntity, new TBaseHandler<>(RussianLegalEntity.class));
russianLegalEntity.setInn(INN);
return russianLegalEntity;
}
@ -268,6 +281,18 @@ public class PartyFlowGenerator {
return buildMachineEvent(partyId, sequenceId, partyChange);
}
public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId, String shopId) {
PartyChange partyChange = buildShopSuspensionPartyChange(shopId);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId,
ShopSuspension shopSuspension) {
PartyChange partyChange = new PartyChange();
partyChange.setShopSuspension(shopSuspension);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
public static PartyChange buildShopBlockingPartyChange(String shopId) {
ShopBlocking shopBlocking = buildShopBlocking(shopId);
PartyChange partyChange = new PartyChange();
@ -275,25 +300,16 @@ public class PartyFlowGenerator {
return partyChange;
}
public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId, String shopId) {
PartyChange partyChange = buildShopSuspensionPartyChange(shopId);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
public static PartyChange buildShopSuspensionPartyChange(String shopId) {
ShopSuspension shopSuspension = buildActiveShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId);
ShopSuspension shopSuspension =
buildActiveShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId);
PartyChange partyChange = new PartyChange();
partyChange.setShopSuspension(shopSuspension);
return partyChange;
}
public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId, ShopSuspension shopSuspension) {
PartyChange partyChange = new PartyChange();
partyChange.setShopSuspension(shopSuspension);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
public static MachineEvent buildMessageShopCreated(Long sequenceId, String partyId, String shopId) throws IOException {
public static MachineEvent buildMessageShopCreated(Long sequenceId, String partyId, String shopId)
throws IOException {
PartyChange partyChange = buildShopCreatedPartyChange(shopId);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
@ -442,7 +458,8 @@ public class PartyFlowGenerator {
return partyChange;
}
public static MachineEvent buildContractorCreated(Long sequenceId, PartyContractor partyContractor, String partyId) throws IOException {
public static MachineEvent buildContractorCreated(Long sequenceId, PartyContractor partyContractor, String partyId)
throws IOException {
PartyChange partyChange = buildContractorCreatedPartyChange(partyContractor);
return buildMachineEvent(partyId, sequenceId, partyChange);
}
@ -480,7 +497,8 @@ public class PartyFlowGenerator {
return partyChange;
}
public static MachineEvent buildMultiPartyChange(Long sequenceId, String partyId, PartyChange customPartyChange) throws IOException {
public static MachineEvent buildMultiPartyChange(Long sequenceId, String partyId, PartyChange customPartyChange)
throws IOException {
PartyChange partyCreatedChange = buildPartyCreatedPartyChange(partyId);
PartyChange partyRevisionChange = buildPartyRevisionChangedPartyChange();
PartyChange partyBlockingChange = buildPartyBlockingPartyChange();
@ -491,11 +509,13 @@ public class PartyFlowGenerator {
partyBlockingChange, contractorCreatedPartyChange, identificationLevelChangedPartyChange);
} else {
return buildMachineEvent(partyId, sequenceId, partyCreatedChange, partyRevisionChange,
partyBlockingChange, contractorCreatedPartyChange, identificationLevelChangedPartyChange, customPartyChange);
partyBlockingChange, contractorCreatedPartyChange, identificationLevelChangedPartyChange,
customPartyChange);
}
}
public static MachineEvent buildMultiShopChange(Long sequenceId, String partyId, String shopId, PartyChange customPartyChange) throws IOException {
public static MachineEvent buildMultiShopChange(Long sequenceId, String partyId, String shopId,
PartyChange customPartyChange) throws IOException {
PartyChange shopCreatedPartyChange = buildShopCreatedPartyChange(shopId);
PartyChange shopBlockingPartyChange = buildShopBlockingPartyChange(shopId);
PartyChange shopCategoryPartyChange = buildShopCategoryPartyChange(shopId);
@ -508,15 +528,18 @@ public class PartyFlowGenerator {
if (customPartyChange == null) {
return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange,
shopCategoryPartyChange, shopContractPartyChange, shopDetailsPartyChange, shopSuspensionPartyChange,
shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange, shopPayouScheduleChangedPartyChange);
shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange,
shopPayouScheduleChangedPartyChange);
} else {
return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange,
shopCategoryPartyChange, shopContractPartyChange, shopDetailsPartyChange, shopSuspensionPartyChange,
shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange, shopPayouScheduleChangedPartyChange, customPartyChange);
shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange,
shopPayouScheduleChangedPartyChange, customPartyChange);
}
}
public static MachineEvent buildMultiShopChangeDifferentShopId(Long sequenceId, String partyId, String shopId, PartyChange customPartyChange) throws IOException {
public static MachineEvent buildMultiShopChangeDifferentShopId(Long sequenceId, String partyId, String shopId,
PartyChange customPartyChange) throws IOException {
String firstShopId = UUID.randomUUID().toString();
PartyChange shopCreatedPartyChange = buildShopCreatedPartyChange(firstShopId);
PartyChange shopBlockingPartyChange = buildShopBlockingPartyChange(firstShopId);
@ -531,18 +554,25 @@ public class PartyFlowGenerator {
String fourthShopId = shopId != null ? shopId : UUID.randomUUID().toString();
PartyChange shopCreatedPartyChangeFourth = buildShopCreatedPartyChange(fourthShopId);
PartyChange shopAccountCreatedPartyChangeFourth = buildShopAccountCreatedPartyChange(fourthShopId);
PartyChange shopPayoutToolChangedPartyChangeFourth = buildShopPayoutToolChangedPartyChange(fourthShopId, PAYOUT_TOOL_ID);
PartyChange shopPayoutToolChangedPartyChangeFourth =
buildShopPayoutToolChangedPartyChange(fourthShopId, PAYOUT_TOOL_ID);
PartyChange shopPayouScheduleChangedPartyChangeFourth = buildShopPayouScheduleChangedPartyChange(fourthShopId);
if (customPartyChange == null) {
return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange,
shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec, shopCreatedPartyChangeThird,
shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth, shopAccountCreatedPartyChangeFourth,
shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec,
shopCreatedPartyChangeThird,
shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth,
shopAccountCreatedPartyChangeFourth,
shopPayoutToolChangedPartyChangeFourth, shopPayouScheduleChangedPartyChangeFourth);
} else {
return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange,
shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec, shopCreatedPartyChangeThird,
shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth, shopAccountCreatedPartyChangeFourth,
shopPayoutToolChangedPartyChangeFourth, shopPayouScheduleChangedPartyChangeFourth, customPartyChange); }
shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec,
shopCreatedPartyChangeThird,
shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth,
shopAccountCreatedPartyChangeFourth,
shopPayoutToolChangedPartyChangeFourth, shopPayouScheduleChangedPartyChangeFourth,
customPartyChange);
}
}
public static PartyContractor buildPartyContractor(String partyId) throws IOException {
@ -560,12 +590,13 @@ public class PartyFlowGenerator {
PartyContractor partyContractor = new PartyContractor();
partyContractor.setId(partyId);
partyContractor.setStatus(ContractorIdentificationLevel.none);
Contractor contractor = new Contractor();
LegalEntity legalEntity = new LegalEntity();
RussianLegalEntity russianLegalEntity = new RussianLegalEntity();
russianLegalEntity = new MockTBaseProcessor(MockMode.ALL).process(russianLegalEntity, new TBaseHandler<>(RussianLegalEntity.class));
russianLegalEntity = new MockTBaseProcessor(MockMode.ALL)
.process(russianLegalEntity, new TBaseHandler<>(RussianLegalEntity.class));
russianLegalEntity.setInn(INN);
legalEntity.setRussianLegalEntity(russianLegalEntity);
Contractor contractor = new Contractor();
contractor.setLegalEntity(legalEntity);
partyContractor.setContractor(contractor);
partyContractor.setIdentityDocuments(Collections.emptyList());
@ -576,7 +607,8 @@ public class PartyFlowGenerator {
ClaimAccepted claimAccepted = new ClaimAccepted();
claimAccepted.setEffects(Collections.singletonList(claimEffect));
ClaimStatus claimStatus = ClaimStatus.accepted(claimAccepted);
return new Claim(CLAIM_ID, claimStatus, Collections.emptyList(), REVISION_ID, TypeUtil.temporalToString(LocalDateTime.now()));
return new Claim(CLAIM_ID, claimStatus, REVISION_ID,
TypeUtil.temporalToString(LocalDateTime.now()));
}
public static Shop buildShopCreated() throws IOException {
@ -613,7 +645,8 @@ public class PartyFlowGenerator {
}
public static PartyCreated buildPartyCreated(String partyId) {
return new PartyCreated(partyId, new PartyContactInfo(PARTY_EMAIL), TypeUtil.temporalToString(LocalDateTime.now()));
return new PartyCreated(partyId, new PartyContactInfo(PARTY_EMAIL),
TypeUtil.temporalToString(LocalDateTime.now()));
}
public static Suspension buildPartySuspension() {
@ -631,15 +664,13 @@ public class PartyFlowGenerator {
public static MachineEvent buildMachineEvent(String sourceId, Long sequenceId, PartyChange... partyChange) {
MachineEvent message = new MachineEvent();
ArrayList<PartyChange> partyChanges = new ArrayList<>(Arrays.asList(partyChange));
message.setCreatedAt(TypeUtil.temporalToString(Instant.now()));
message.setEventId(sequenceId);
message.setSourceNs(SOURCE_NS);
message.setSourceId(sourceId);
PartyEventDataSerializer partyEventDataSerializer = new PartyEventDataSerializer();
Value data = new Value();
ArrayList<PartyChange> partyChanges = new ArrayList<>(Arrays.asList(partyChange));
data.setBin(partyEventDataSerializer.serialize(new PartyEventData(partyChanges)));
message.setData(data);
return message;

View File

@ -5,15 +5,16 @@ import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.domain.Party;
import com.rbkmoney.deanonimus.handler.DeanonimusServiceHandler;
import org.apache.thrift.TException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.List;
public class ReadTest extends IntegrationTestBase {
import static org.junit.jupiter.api.Assertions.*;
public class ReadTest extends AbstractIntegrationTest {
@Value("${data.response.limit}")
Integer responseLimit;
@ -33,24 +34,24 @@ public class ReadTest extends IntegrationTestBase {
private static final String INN = "1234234123";
private static final String ACCOUNT = "9999999999";
@Before
public void cleanup() {
@BeforeEach
void setUp() {
partyRepository.deleteAll();
}
@Test
public void searchByPartyId() throws TException {
void searchByPartyId() throws TException {
givenParty(PARTY, EMAIL);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(PARTY);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getEmail().contains(EMAIL)));
}
@Test
public void searchByPartyIdWithoutTokens() throws TException {
void searchByPartyIdWithoutTokens() throws TException {
givenParty(PARTY + "-test-kek", EMAIL + "1");
givenParty(PARTY + "-test-lol", EMAIL + "2");
givenParty(PARTY + "-test-rofl", EMAIL + "3");
@ -59,149 +60,156 @@ public class ReadTest extends IntegrationTestBase {
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(PARTY + "-test-lol");
Assert.assertEquals(1, searchHits.size());
assertEquals(1, searchHits.size());
}
@Test
public void searchByPartyEmail() throws TException {
void searchByPartyEmail() throws TException {
givenParty(PARTY, EMAIL);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(EMAIL);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getEmail().contains(EMAIL)));
}
@Test
public void searchByShopUrl() throws TException {
void searchByShopUrl() throws TException {
Party party = givenParty(PARTY, EMAIL);
givenShop(party, SHOP, URL);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(URL);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getShops().values().stream()
.anyMatch(shop -> shop.getLocation().getUrl().contains(URL))));
}
@Test
public void searchByShopId() throws TException {
void searchByShopId() throws TException {
Party party = givenParty(PARTY, EMAIL);
givenShop(party, SHOP, URL);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(SHOP);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getShops().values().stream()
.anyMatch(shop -> shop.getId().equals(SHOP))));
}
@Test
public void searchByContractorEmail() throws TException {
void searchByContractorEmail() throws TException {
Party party = givenParty(PARTY, null);
givenRegisteredUserContractor(party, CONTRACTOR, EMAIL);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(EMAIL);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor().getRegisteredUser().getEmail().contains(EMAIL)));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor()
.getRegisteredUser().getEmail().contains(EMAIL)));
}
@Test
public void searchByContractorRussianLegalEntityRegisteredNameWithOneWord() throws TException {
void searchByContractorRussianLegalEntityRegisteredNameWithOneWord() throws TException {
Party party = givenParty(PARTY, null);
givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("ЧИ");
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor().getLegalEntity().getRussianLegalEntity().getRegisteredName().contains("ЧИ")));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor()
.getLegalEntity().getRussianLegalEntity().getRegisteredName().contains("ЧИ")));
}
@Test
public void searchByContractorRussianLegalEntityRegisteredNameWithOneMatchingAndOneNotMatchingWord() throws TException {
void searchByContractorRussianLegalEntityRegisteredNameWithOneMatchingAndOneNotMatchingWord()
throws TException {
Party party = givenParty(PARTY, null);
givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("ЧИ ДА");
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor().getLegalEntity().getRussianLegalEntity().getRegisteredName().contains("ЧИ")));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor()
.getLegalEntity().getRussianLegalEntity().getRegisteredName().contains("ЧИ")));
}
@Test
public void searchByContractorRussianLegalEntityRegisteredNameNoMatchingWords() throws TException {
void searchByContractorRussianLegalEntityRegisteredNameNoMatchingWords() throws TException {
Party party = givenParty(PARTY, null);
givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("ДА");
Assert.assertTrue(searchHits.isEmpty());
assertTrue(searchHits.isEmpty());
}
@Test
public void searchByContractorInnFullyEqual() throws TException {
void searchByContractorInnFullyEqual() throws TException {
Party party = givenParty(PARTY, null);
givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(INN);
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor().getLegalEntity().getRussianLegalEntity().getInn().equals(INN)));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor()
.getLegalEntity().getRussianLegalEntity().getInn().equals(INN)));
}
@Test
public void searchByContractorInnNotFullyEqual() throws TException {
void searchByContractorInnNotFullyEqual() throws TException {
Party party = givenParty(PARTY, null);
givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT);
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty(INN.substring(0, 6));
Assert.assertTrue(searchHits.isEmpty());
assertTrue(searchHits.isEmpty());
}
@Test
public void searchByContractorInternationalLegalEntityLegalName() throws TException {
void searchByContractorInternationalLegalEntityLegalName() throws TException {
Party party = givenParty(PARTY, null);
givenInternationalContractor(party, CONTRACTOR, "SoMe LeGaL NaMe","ANOTHER TRADING NAME");
givenInternationalContractor(party, CONTRACTOR, "SoMe LeGaL NaMe", "ANOTHER TRADING NAME");
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("legal");
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor().getLegalEntity().getInternationalLegalEntity().getLegalName().equals("SoMe LeGaL NaMe")));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContractors().get(CONTRACTOR).getContractor()
.getLegalEntity().getInternationalLegalEntity().getLegalName().equals("SoMe LeGaL NaMe")));
}
@Test
public void searchByContractLegalAgreementId() throws TException {
void searchByContractLegalAgreementId() throws TException {
Party party = givenParty(PARTY, null);
givenContract(party, CONTRACT, 123, "ДГ-123432", "Василий Пупкин");
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("ДГ");
Assert.assertFalse(searchHits.isEmpty());
Assert.assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContracts().get(CONTRACT).getLegalAgreement().getId().equals("ДГ-123432")));
assertFalse(searchHits.isEmpty());
assertTrue(searchHits.stream()
.anyMatch(partySearchHit -> partySearchHit.getParty().getContracts().get(CONTRACT).getLegalAgreement()
.getId().equals("ДГ-123432")));
}
@Test
public void searchForSeveralParties() throws TException {
void searchForSeveralParties() throws TException {
for (int i = 0; i < 10; i++) {
Party party = givenParty(i + "", i + EMAIL.substring(EMAIL.indexOf("@")));
givenShop(party, 9 - i + "", URL + i);
@ -209,13 +217,13 @@ public class ReadTest extends IntegrationTestBase {
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("1");
Assert.assertEquals(2, searchHits.size());
Assert.assertEquals("1", searchHits.get(0).getParty().getId());
Assert.assertNotNull(searchHits.get(1).getParty().getShops().get("1"));
assertEquals(2, searchHits.size());
assertEquals("1", searchHits.get(0).getParty().getId());
assertNotNull(searchHits.get(1).getParty().getShops().get("1"));
}
@Test
public void responseLimitApplied() throws TException {
void responseLimitApplied() throws TException {
for (int i = 0; i < 30; i++) {
Party party = givenParty(i + "", EMAIL);
givenShop(party, 29 - i + "", URL + i);
@ -223,12 +231,12 @@ public class ReadTest extends IntegrationTestBase {
List<SearchHit> searchHits = deanonimusServiceHandler.searchParty("email");
Assert.assertEquals((long) responseLimit, searchHits.size());
assertEquals((long) responseLimit, searchHits.size());
}
private void givenRegisteredUserContractor(Party party,
String id,
String registeredUserEmail) {
String id,
String registeredUserEmail) {
party.addContractor(TestData.contractor(id,
registeredUserEmail,
null,

View File

@ -11,11 +11,11 @@ import com.rbkmoney.geck.serializer.kit.mock.MockTBaseProcessor;
import java.time.Instant;
import java.util.Map;
public class TestData {
public abstract class TestData {
private static final Map.Entry<FieldHandler, String[]> timeFields = Map.entry(
structHandler -> structHandler.value(Instant.now().toString()),
new String[]{"created_at", "at", "due"}
new String[] {"created_at", "at", "due"}
);
private static final MockTBaseProcessor mockTBaseProcessor = new MockTBaseProcessor(MockMode.ALL, 15, 1);
@ -60,7 +60,8 @@ public class TestData {
String internationalLegalEntityTradingName) {
return com.rbkmoney.deanonimus.domain.Contractor.builder()
.id(id)
.type(getContractorType(registeredUserEmail, russianLegalEntityRegisteredInn, internationalLegalEntityLegalName))
.type(getContractorType(registeredUserEmail, russianLegalEntityRegisteredInn,
internationalLegalEntityLegalName))
.legalEntity(getLegalEntity(russianLegalEntityRegisteredInn, internationalLegalEntityLegalName))
.registeredUserEmail(registeredUserEmail)
.russianLegalEntityRegisteredName(russianLegalEntityRegisteredName)
@ -83,7 +84,8 @@ public class TestData {
return null;
}
private static LegalEntity getLegalEntity(String russianLegalEntityRegisteredInn, String internationalLegalEntityLegalName) {
private static LegalEntity getLegalEntity(String russianLegalEntityRegisteredInn,
String internationalLegalEntityLegalName) {
if (russianLegalEntityRegisteredInn != null) {
return LegalEntity.russian_legal_entity;
}

View File

@ -3,7 +3,7 @@ package com.rbkmoney.deanonimus;
import com.rbkmoney.deanonimus.db.PartyRepository;
import com.rbkmoney.deanonimus.domain.Blocking;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
@ -12,13 +12,13 @@ import java.util.List;
import static com.rbkmoney.deanonimus.PartyFlowGenerator.*;
import static org.awaitility.Awaitility.await;
public class WriteTest extends IntegrationTestBase {
public class WriteTest extends AbstractIntegrationTest {
@Autowired
private PartyRepository partyRepository;
@Test
public void onPartyCreatedElasticHaveIt() throws IOException {
void onPartyCreatedElasticHaveIt() throws IOException {
sendMessages(generatePartyContractorFlow(TestData.SOURCE_ID_ONE));
@ -29,7 +29,7 @@ public class WriteTest extends IntegrationTestBase {
}
@Test
public void onPartyBlockingPartyChanges() {
void onPartyBlockingPartyChanges() {
sendMessages(
List.of(
buildSinkEvent(buildMessagePartyCreated(0L, TestData.SOURCE_ID_ONE)),

View File

@ -0,0 +1,29 @@
package com.rbkmoney.deanonimus.extension;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.utility.DockerImageName;
public class ElasticsearchContainerExtension implements BeforeAllCallback, AfterAllCallback {
private static final String ELASTIC_SEARCH_IMAGE_NAME = "docker.elastic.co/elasticsearch/elasticsearch";
private static final String ELASTIC_SEARCH_VERSION = "7.8.0";
public static ElasticsearchContainer ELASTIC_SEARCH;
@Override
public void beforeAll(ExtensionContext extensionContext) throws Exception {
ELASTIC_SEARCH = new ElasticsearchContainer(DockerImageName
.parse(ELASTIC_SEARCH_IMAGE_NAME)
.withTag(ELASTIC_SEARCH_VERSION));
ELASTIC_SEARCH.addExposedPort(9200);
ELASTIC_SEARCH.start();
}
@Override
public void afterAll(ExtensionContext extensionContext) throws Exception {
ELASTIC_SEARCH.stop();
}
}

View File

@ -0,0 +1,29 @@
package com.rbkmoney.deanonimus.extension;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.utility.DockerImageName;
public class KafkaContainerExtension implements BeforeAllCallback, AfterAllCallback {
private static final String CONFLUENT_IMAGE_NAME = "confluentinc/cp-kafka";
private static final String CONFLUENT_PLATFORM_VERSION = "5.0.1";
public static KafkaContainer KAFKA;
@Override
public void beforeAll(ExtensionContext extensionContext) {
KAFKA = new org.testcontainers.containers.KafkaContainer(DockerImageName
.parse(CONFLUENT_IMAGE_NAME)
.withTag(CONFLUENT_PLATFORM_VERSION))
.withEmbeddedZookeeper();
KAFKA.start();
}
@Override
public void afterAll(ExtensionContext context) throws Exception {
KAFKA.stop();
}
}