http://jira.mfd.msk:8088/browse/CLS-806 NullSerializer added, tests updated

This commit is contained in:
Ivan Nikolaev-Axenov 2024-12-18 13:07:07 +03:00
parent 9a0aebfee4
commit f59537b0bd
20 changed files with 1415 additions and 671 deletions

View file

@ -1,52 +1,66 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import ru.clearing.classes.statics.data.sdf.SDf02;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF02ObjectTag extends ObjectTag<SDf02> {
@JacksonXmlProperty(isAttribute = true, localName = "CURR_CODE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String currCode;
@JacksonXmlProperty(isAttribute = true, localName = "ACCOUNT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String account;
@JacksonXmlProperty(isAttribute = true, localName = "REMAINDER")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String remainder;
@JacksonXmlProperty(isAttribute = true, localName = "DEAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String deal;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_CODE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accCode;
@JacksonXmlProperty(isAttribute = true, localName = "DAT")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dat;
@JacksonXmlProperty(isAttribute = true, localName = "MARKET")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String market;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_NAME")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accName;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accType;
@JacksonXmlProperty(isAttribute = true, localName = "SUMENGAGE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sumengage;
@JacksonXmlProperty(isAttribute = true, localName = "SUMUNBLOK")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sumunblock;
@JacksonXmlProperty(isAttribute = true, localName = "FILE_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String fileType;
@JacksonXmlProperty(isAttribute = true, localName = "RESULT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String result;
public DF02ObjectTag() {
@ -56,19 +70,19 @@ public class DF02ObjectTag extends ObjectTag<SDf02> {
@Override
public void setData(SDf02 entity) {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yy");
this.currCode = Optional.ofNullable(entity.getCurr_code()).orElse("");
this.account = Optional.ofNullable(entity.getAccount()).orElse("");
this.remainder = Optional.ofNullable(entity.getRemainder()).orElse("");
this.deal = Optional.ofNullable(entity.getDeal()).orElse("");
this.accCode = Optional.ofNullable(entity.getAcc_code()).orElse("");
this.dat = LocalDate.parse(entity.getDat(), dtf);
this.market = Optional.ofNullable(entity.getMarket()).orElse("");
this.accName = Optional.ofNullable(entity.getAcc_name()).orElse("");
this.accType = Optional.ofNullable(entity.getAcc_type()).orElse("");
this.sumengage = Optional.ofNullable(entity.getSumengage()).orElse("");
this.sumunblock = Optional.ofNullable(entity.getSumunblock()).orElse("");
this.fileType = Optional.ofNullable(entity.getFile_type()).orElse("");
this.result = Optional.ofNullable(entity.getResult()).orElse("");
this.currCode = entity.getCurr_code();
this.account = entity.getAccount();
this.remainder = entity.getRemainder();
this.deal = entity.getDeal();
this.accCode = entity.getAcc_code();
this.dat = entity.getDat() == null ? null : LocalDate.parse(entity.getDat(), dtf);
this.market = entity.getMarket();
this.accName = entity.getAcc_name();
this.accType = entity.getAcc_type();
this.sumengage = entity.getSumengage();
this.sumunblock = entity.getSumunblock();
this.fileType = entity.getFile_type();
this.result = entity.getResult();
}
@Override

View file

@ -2,30 +2,37 @@ package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import ru.clearing.classes.statics.data.sdf.SDf03;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF03ObjectTag extends ObjectTag<SDf03> {
@JacksonXmlProperty(isAttribute = true, localName = "SEG_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String segType;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docType;
@JacksonXmlProperty(isAttribute = true, localName = "DOCNM_REF")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docnmRef;
@JacksonXmlProperty(isAttribute = true, localName = "DOCNMPREV")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docnmprev;
@JacksonXmlProperty(isAttribute = true, localName = "C_ACC_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String cAccDeb;
@JacksonXmlProperty(isAttribute = true, localName = "SBANKNAM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sbanknam1;
@JsonIgnore
private String sbanknam2;
@ -37,9 +44,11 @@ public class DF03ObjectTag extends ObjectTag<SDf03> {
private String sbanknam5;
@JacksonXmlProperty(isAttribute = true, localName = "C_ACC_CRED")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String cAccCred;
@JacksonXmlProperty(isAttribute = true, localName = "RBANKNAM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String rbanknam1;
@JsonIgnore
private String rbanknam2;
@ -51,19 +60,24 @@ public class DF03ObjectTag extends ObjectTag<SDf03> {
private String rbanknam5;
@JacksonXmlProperty(isAttribute = true, localName = "PAY_DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate payDate;
@JacksonXmlProperty(isAttribute = true, localName = "PAY_VAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String payVal;
@JacksonXmlProperty(isAttribute = true, localName = "SUM_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sumDeb;
@JacksonXmlProperty(isAttribute = true, localName = "SPECIF_1")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String specif1;
@JacksonXmlProperty(isAttribute = true, localName = "IMP_RESULT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String impResult;
@ -74,27 +88,27 @@ public class DF03ObjectTag extends ObjectTag<SDf03> {
@Override
public void setData(SDf03 entity) {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yy");
this.segType = Optional.ofNullable(entity.getSeg_type()).orElse("");
this.docType = Optional.ofNullable(entity.getDoc_type()).orElse("");
this.docnmRef = Optional.ofNullable(entity.getDocnm_ref()).orElse("");
this.docnmprev = Optional.ofNullable(entity.getDocnmprev()).orElse("");
this.cAccDeb = Optional.ofNullable(entity.getC_acc_deb()).orElse("");
this.sbanknam1 = Optional.ofNullable(entity.getSbanknam1()).orElse("");
this.sbanknam2 = Optional.ofNullable(entity.getSbanknam2()).orElse("");
this.sbanknam3 = Optional.ofNullable(entity.getSbanknam3()).orElse("");
this.sbanknam4 = Optional.ofNullable(entity.getSbanknam4()).orElse("");
this.sbanknam5 = Optional.ofNullable(entity.getSbanknam5()).orElse("");
this.cAccCred = Optional.ofNullable(entity.getC_acc_cred()).orElse("");
this.rbanknam1 = Optional.ofNullable(entity.getRbanknam1()).orElse("");
this.rbanknam2 = Optional.ofNullable(entity.getRbanknam2()).orElse("");
this.rbanknam3 = Optional.ofNullable(entity.getRbanknam3()).orElse("");
this.rbanknam4 = Optional.ofNullable(entity.getRbanknam4()).orElse("");
this.rbanknam5 = Optional.ofNullable(entity.getRbanknam5()).orElse("");
this.payDate = LocalDate.parse(entity.getPay_date(), dtf);
this.payVal = Optional.ofNullable(entity.getPay_val()).orElse("");
this.sumDeb = Optional.ofNullable(entity.getSum_deb()).orElse("");
this.specif1 = Optional.ofNullable(entity.getSpecif_1()).orElse("");
this.impResult = Optional.ofNullable(entity.getImp_result()).orElse("");
this.segType = entity.getSeg_type();
this.docType = entity.getDoc_type();
this.docnmRef = entity.getDocnm_ref();
this.docnmprev = entity.getDocnmprev();
this.cAccDeb = entity.getC_acc_deb();
this.sbanknam1 = entity.getSbanknam1();
this.sbanknam2 = entity.getSbanknam2();
this.sbanknam3 = entity.getSbanknam3();
this.sbanknam4 = entity.getSbanknam4();
this.sbanknam5 = entity.getSbanknam5();
this.cAccCred = entity.getC_acc_cred();
this.rbanknam1 = entity.getRbanknam1();
this.rbanknam2 = entity.getRbanknam2();
this.rbanknam3 = entity.getRbanknam3();
this.rbanknam4 = entity.getRbanknam4();
this.rbanknam5 = entity.getRbanknam5();
this.payDate = entity.getPay_date() != null ? LocalDate.parse(entity.getPay_date(), dtf) : null;
this.payVal = entity.getPay_val();
this.sumDeb = entity.getSum_deb();
this.specif1 = entity.getSpecif_1();
this.impResult = entity.getImp_result();
}
@Override

View file

@ -1,6 +1,7 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -8,20 +9,25 @@ import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import ru.clearing.classes.statics.data.sdf.SDf05;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF05ObjectTag extends ObjectTag<SDf05> {
@JacksonXmlProperty(isAttribute = true, localName = "TP")
@JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal tp;
@JacksonXmlProperty(isAttribute = true, localName = "DT")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dt;
@JacksonXmlProperty(isAttribute = true, localName = "TM")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "hh:mm:ss")
private LocalTime tm;
@JacksonXmlProperty(isAttribute = true, localName = "PR")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String pr;
public DF05ObjectTag() {
@ -33,7 +39,7 @@ public class DF05ObjectTag extends ObjectTag<SDf05> {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
this.tp = entity.getTp();
this.dt = entity.getDt();
this.tm = LocalTime.parse(entity.getTm(), dtf);
this.tm = entity.getTm() != null ? LocalTime.parse(entity.getTm(), dtf) : null;
this.pr = entity.getPr();
}

View file

@ -1,56 +1,71 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import ru.clearing.classes.statics.data.sdf.SDf07;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF07ObjectTag extends ObjectTag<SDf07> {
@JacksonXmlProperty(isAttribute = true, localName = "ACCOUNT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String account;
@JacksonXmlProperty(isAttribute = true, localName = "SUM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal sum;
@JacksonXmlProperty(isAttribute = true, localName = "MARKET")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String market;
@JacksonXmlProperty(isAttribute = true, localName = "TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String type;
@JacksonXmlProperty(isAttribute = true, localName = "DEAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String deal;
@JacksonXmlProperty(isAttribute = true, localName = "CLIENTN")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String clientN;
@JacksonXmlProperty(isAttribute = true, localName = "INN")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String inn;
@JacksonXmlProperty(isAttribute = true, localName = "BIC")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String bic;
@JacksonXmlProperty(isAttribute = true, localName = "SPEC")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String spec;
@JacksonXmlProperty(isAttribute = true, localName = "NUMBER")
@JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal number;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_NUM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docNum;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate docDate;
@JacksonXmlProperty(isAttribute = true, localName = "PAY_VAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String payVal;
@JacksonXmlProperty(isAttribute = true, localName = "RESULT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private BigDecimal result;
@ -61,20 +76,20 @@ public class DF07ObjectTag extends ObjectTag<SDf07> {
@Override
public void setData(SDf07 entity) {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yy");
this.account = Optional.ofNullable(entity.getAccount()).orElse("");
this.account = entity.getAccount();
this.sum = entity.getSum();
this.market = Optional.ofNullable(entity.getMarket()).orElse("");
this.type = Optional.ofNullable(entity.getType()).orElse("");
this.deal = Optional.ofNullable(entity.getDeal()).orElse("");
this.clientN = Optional.ofNullable(entity.getClientN()).orElse("");
this.inn = Optional.ofNullable(entity.getInn()).orElse("");
this.bic = Optional.ofNullable(entity.getBic()).orElse("");
this.spec = Optional.ofNullable(entity.getSpec()).orElse("");
this.market = entity.getMarket();
this.type = entity.getType();
this.deal = entity.getDeal();
this.clientN = entity.getClientN();
this.inn = entity.getInn();
this.bic = entity.getBic();
this.spec = entity.getSpec();
this.number = entity.getNumber();
this.result = entity.getResult();
this.docNum = Optional.ofNullable(entity.getDoc_num()).orElse("");
this.docDate = LocalDate.parse(entity.getDoc_date(), dtf);
this.payVal = Optional.ofNullable(entity.getPay_val()).orElse("");
this.docNum = entity.getDoc_num();
this.docDate = entity.getDoc_date() != null ? LocalDate.parse(entity.getDoc_date(), dtf) : null;
this.payVal = entity.getPay_val();
}
@Override

View file

@ -2,6 +2,7 @@ package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.Instant;
import java.time.LocalDateTime;
@ -9,15 +10,19 @@ import java.time.ZoneId;
import java.util.Objects;
import org.springframework.format.annotation.DateTimeFormat;
import ru.clearing.classes.statics.data.sdf.SDf51;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF51ObjectTag extends ObjectTag<SDf51> {
@JacksonXmlProperty(isAttribute = true, localName = "NUMBER")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String number;
@JacksonXmlProperty(isAttribute = true, localName = "UNIXTIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long unixtime;
@JacksonXmlProperty(isAttribute = true, localName = "DATETIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime datetime;
@ -29,8 +34,8 @@ public class DF51ObjectTag extends ObjectTag<SDf51> {
@Override
public void setData(SDf51 entity) {
this.number = entity.getNumber();
this.unixtime = Long.valueOf(entity.getDatetime());
this.datetime = Instant.ofEpochMilli(this.unixtime).atZone(ZoneId.systemDefault()).toLocalDateTime();
this.unixtime = entity.getDatetime() != null ? Long.valueOf(entity.getDatetime()) : null;
this.datetime = this.unixtime != null ? Instant.ofEpochMilli(this.unixtime).atZone(ZoneId.systemDefault()).toLocalDateTime() : null;
}
@Override

View file

@ -1,34 +1,42 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import ru.clearing.classes.statics.data.sdf.SDf53;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF53ObjectTag extends ObjectTag<SDf53> {
@JacksonXmlProperty(isAttribute = true, localName = "ACCOUNT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String account;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_NAME")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accName;
@JacksonXmlProperty(isAttribute = true, localName = "DEAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String deal;
@JacksonXmlProperty(isAttribute = true, localName = "DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate date;
@JacksonXmlProperty(isAttribute = true, localName = "STATUS")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long status;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accType;
@JacksonXmlProperty(isAttribute = true, localName = "RESULT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String result;
public DF53ObjectTag() {
@ -38,13 +46,13 @@ public class DF53ObjectTag extends ObjectTag<SDf53> {
@Override
public void setData(SDf53 entity) {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yy");
this.account = Optional.ofNullable(entity.getAccount()).orElse("");
this.accName = Optional.ofNullable(entity.getAccName()).orElse("");
this.deal = Optional.ofNullable(entity.getDeal()).orElse("");
this.date = LocalDate.parse(entity.getDate(), dtf);
this.account = entity.getAccount();
this.accName = entity.getAccName();
this.deal = entity.getDeal();
this.date = entity.getDate() != null ? LocalDate.parse(entity.getDate(), dtf) : null;
this.status = entity.getStatus();
this.accType = Optional.ofNullable(entity.getAccType()).orElse("");
this.result = Optional.ofNullable(entity.getResult()).orElse("");
this.accType = entity.getAccType();
this.result = entity.getResult();
}
@Override

View file

@ -2,33 +2,41 @@ package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import ru.clearing.classes.statics.data.sdf.SDf54;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF54ObjectTag extends ObjectTag<SDf54> {
@JacksonXmlProperty(isAttribute = true, localName = "SEG_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String segType;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docType;
@JacksonXmlProperty(isAttribute = true, localName = "DOCNM_REF")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docnmRef;
@JacksonXmlProperty(isAttribute = true, localName = "DOCNMPREV")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docnmprev;
@JacksonXmlProperty(isAttribute = true, localName = "SBANKCODE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sbankcode;
@JacksonXmlProperty(isAttribute = true, localName = "C_ACC_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String cAccDeb;
@JacksonXmlProperty(isAttribute = true, localName = "SBANKNAM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sbanknam1;
@JsonIgnore
private String sbanknam2;
@ -40,12 +48,15 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
private String sbanknam5;
@JacksonXmlProperty(isAttribute = true, localName = "RBANKCODE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String rbankcode;
@JacksonXmlProperty(isAttribute = true, localName = "C_ACC_CRED")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String cAccCred;
@JacksonXmlProperty(isAttribute = true, localName = "RBANKNAM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String rbanknam1;
@JsonIgnore
private String rbanknam2;
@ -57,22 +68,28 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
private String rbanknam5;
@JacksonXmlProperty(isAttribute = true, localName = "OP_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String opType;
@JacksonXmlProperty(isAttribute = true, localName = "OP_ORDER")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String opOrder;
@JacksonXmlProperty(isAttribute = true, localName = "PAY_DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate payDate;
@JacksonXmlProperty(isAttribute = true, localName = "PAY_VAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String payVal;
@JacksonXmlProperty(isAttribute = true, localName = "SUM_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sumDeb;
@JacksonXmlProperty(isAttribute = true, localName = "SCLIENTN")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sclientn1;
@JsonIgnore
private String sclientn2;
@ -82,15 +99,19 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
private String sclientn4;
@JacksonXmlProperty(isAttribute = true, localName = "INN_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String innDeb;
@JacksonXmlProperty(isAttribute = true, localName = "KPP_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String kppDeb;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_DEB")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accDeb;
@JacksonXmlProperty(isAttribute = true, localName = "RCLIENTN")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String rclientn1;
@JsonIgnore
private String rclientn2;
@ -100,38 +121,49 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
private String rclientn4;
@JacksonXmlProperty(isAttribute = true, localName = "INN_CRED")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String innCred;
@JacksonXmlProperty(isAttribute = true, localName = "KPP_CRED")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String kppCred;
@JacksonXmlProperty(isAttribute = true, localName = "ACC_KR_1")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String accKr1;
@JacksonXmlProperty(isAttribute = true, localName = "SPECIF_1")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String specif1;
@JacksonXmlProperty(isAttribute = true, localName = "SEND_TYPE")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String sendType;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_RESULT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docResult;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_NUM")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String docNum;
@JacksonXmlProperty(isAttribute = true, localName = "DOC_DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate docDate;
@JacksonXmlProperty(isAttribute = true, localName = "VALUE_DATE")
@JsonSerialize(nullsUsing = NullSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate valueDate;
@JacksonXmlProperty(isAttribute = true, localName = "SWIFT_BEN")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String swiftBen;
@JacksonXmlProperty(isAttribute = true, localName = "SWIFT_INT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String swiftInt;
public DF54ObjectTag() {
@ -141,51 +173,51 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
@Override
public void setData(SDf54 entity) {
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yy");
this.segType = Optional.ofNullable(entity.getSeg_type()).orElse("");
this.docType = Optional.ofNullable(entity.getDoc_type()).orElse("");
this.docnmRef = Optional.ofNullable(entity.getDocnm_ref()).orElse("");
this.docnmprev = Optional.ofNullable(entity.getDocnmprev()).orElse("");
this.sbankcode = Optional.ofNullable(entity.getSbankcode()).orElse("");
this.cAccDeb = Optional.ofNullable(entity.getC_acc_deb()).orElse("");
this.sbanknam1 = Optional.ofNullable(entity.getSbanknam1()).orElse("");
this.sbanknam2 = Optional.ofNullable(entity.getSbanknam2()).orElse("");
this.sbanknam3 = Optional.ofNullable(entity.getSbanknam3()).orElse("");
this.sbanknam4 = Optional.ofNullable(entity.getSbanknam4()).orElse("");
this.sbanknam5 = Optional.ofNullable(entity.getSbanknam5()).orElse("");
this.rbankcode = Optional.ofNullable(entity.getRbankcode()).orElse("");
this.cAccCred = Optional.ofNullable(entity.getC_acc_cred()).orElse("");
this.rbanknam1 = Optional.ofNullable(entity.getRbanknam1()).orElse("");
this.rbanknam2 = Optional.ofNullable(entity.getRbanknam2()).orElse("");
this.rbanknam3 = Optional.ofNullable(entity.getRbanknam3()).orElse("");
this.rbanknam4 = Optional.ofNullable(entity.getRbanknam4()).orElse("");
this.rbanknam5 = Optional.ofNullable(entity.getRbanknam5()).orElse("");
this.opType = Optional.ofNullable(entity.getOp_type()).orElse("");
this.opOrder = Optional.ofNullable(entity.getOp_order()).orElse("");
this.payDate = LocalDate.parse(entity.getPay_date(), dtf);
this.payVal = Optional.ofNullable(entity.getPay_val()).orElse("");
this.sumDeb = Optional.ofNullable(entity.getSum_deb()).orElse("");
this.sclientn1 = Optional.ofNullable(entity.getSclientn1()).orElse("");
this.sclientn2 = Optional.ofNullable(entity.getSclientn2()).orElse("");
this.sclientn3 = Optional.ofNullable(entity.getSclientn3()).orElse("");
this.sclientn4 = Optional.ofNullable(entity.getSclientn4()).orElse("");
this.innDeb = Optional.ofNullable(entity.getInn_deb()).orElse("");
this.kppDeb = Optional.ofNullable(entity.getKpp_deb()).orElse("");
this.accDeb = Optional.ofNullable(entity.getAcc_deb()).orElse("");
this.rclientn1 = Optional.ofNullable(entity.getRclientn1()).orElse("");
this.rclientn2 = Optional.ofNullable(entity.getRclientn2()).orElse("");
this.rclientn3 = Optional.ofNullable(entity.getRclientn3()).orElse("");
this.rclientn4 = Optional.ofNullable(entity.getRclientn4()).orElse("");
this.innCred = Optional.ofNullable(entity.getInn_cred()).orElse("");
this.kppCred = Optional.ofNullable(entity.getKpp_cred()).orElse("");
this.accKr1 = Optional.ofNullable(entity.getAcc_kr_1()).orElse("");
this.specif1 = Optional.ofNullable(entity.getSpecif_1()).orElse("");
this.sendType = Optional.ofNullable(entity.getSend_type()).orElse("");
this.docResult = Optional.ofNullable(entity.getDoc_result()).orElse("");
this.docNum = Optional.ofNullable(entity.getDoc_num()).orElse("");
this.docDate = LocalDate.parse(entity.getDoc_date(), dtf);
this.valueDate = LocalDate.parse(entity.getValue_date(), dtf);
this.swiftBen = Optional.ofNullable(entity.getSwift_ben()).orElse("");
this.swiftInt = Optional.ofNullable(entity.getSwift_int()).orElse("");
this.segType = entity.getSeg_type();
this.docType = entity.getDoc_type();
this.docnmRef = entity.getDocnm_ref();
this.docnmprev = entity.getDocnmprev();
this.sbankcode = entity.getSbankcode();
this.cAccDeb = entity.getC_acc_deb();
this.sbanknam1 = entity.getSbanknam1();
this.sbanknam2 = entity.getSbanknam2();
this.sbanknam3 = entity.getSbanknam3();
this.sbanknam4 = entity.getSbanknam4();
this.sbanknam5 = entity.getSbanknam5();
this.rbankcode = entity.getRbankcode();
this.cAccCred = entity.getC_acc_cred();
this.rbanknam1 = entity.getRbanknam1();
this.rbanknam2 = entity.getRbanknam2();
this.rbanknam3 = entity.getRbanknam3();
this.rbanknam4 = entity.getRbanknam4();
this.rbanknam5 = entity.getRbanknam5();
this.opType = entity.getOp_type();
this.opOrder = entity.getOp_order();
this.payDate = entity.getPay_date() != null ? LocalDate.parse(entity.getPay_date(), dtf) : null;
this.payVal = entity.getPay_val();
this.sumDeb = entity.getSum_deb();
this.sclientn1 = entity.getSclientn1();
this.sclientn2 = entity.getSclientn2();
this.sclientn3 = entity.getSclientn3();
this.sclientn4 = entity.getSclientn4();
this.innDeb = entity.getInn_deb();
this.kppDeb = entity.getKpp_deb();
this.accDeb = entity.getAcc_deb();
this.rclientn1 = entity.getRclientn1();
this.rclientn2 = entity.getRclientn2();
this.rclientn3 = entity.getRclientn3();
this.rclientn4 = entity.getRclientn4();
this.innCred = entity.getInn_cred();
this.kppCred = entity.getKpp_cred();
this.accKr1 = entity.getAcc_kr_1();
this.specif1 = entity.getSpecif_1();
this.sendType = entity.getSend_type();
this.docResult = entity.getDoc_result();
this.docNum = entity.getDoc_num();
this.docDate = entity.getDoc_date() != null ? LocalDate.parse(entity.getDoc_date(), dtf) : null;
this.valueDate = entity.getValue_date() != null ? LocalDate.parse(entity.getValue_date(), dtf) : null;
this.swiftBen = entity.getSwift_ben();
this.swiftInt = entity.getSwift_int();
}
@Override

View file

@ -1,39 +1,47 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Objects;
import java.util.Optional;
import org.springframework.format.annotation.DateTimeFormat;
import ru.clearing.classes.statics.data.sdf.SDf56;
import ru.spcex.clearing.xml.exporter.serializers.NullSerializer;
public class DF56ObjectTag extends ObjectTag<SDf56> {
@JacksonXmlProperty(isAttribute = true, localName = "NUMBER")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String number;
@JacksonXmlProperty(isAttribute = true, localName = "SUNIXTIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long startUnixtime;
@JacksonXmlProperty(isAttribute = true, localName = "SDATETIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime startDatetime;
@JacksonXmlProperty(isAttribute = true, localName = "EUNIXTIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long endUnixtime;
@JacksonXmlProperty(isAttribute = true, localName = "EDATETIME")
@JsonSerialize(nullsUsing = NullSerializer.class)
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime endDatetime;
@JacksonXmlProperty(isAttribute = true, localName = "ACCOUNT")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String account;
@JacksonXmlProperty(isAttribute = true, localName = "DEAL")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String deal;
public DF56ObjectTag() {
@ -43,12 +51,12 @@ public class DF56ObjectTag extends ObjectTag<SDf56> {
@Override
public void setData(SDf56 entity) {
this.number = entity.getNumber();
this.startUnixtime = Long.valueOf(entity.getStart_datetime());
this.startDatetime = Instant.ofEpochMilli(this.startUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime();
this.endUnixtime = Long.valueOf(entity.getEnd_datetime());
this.endDatetime = Instant.ofEpochMilli(this.endUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime();
this.account = Optional.ofNullable(entity.getAccount()).orElse("");
this.deal = Optional.ofNullable(entity.getDeal()).orElse("");
this.startUnixtime = entity.getStart_datetime() != null ? Long.valueOf(entity.getStart_datetime()) : null;
this.startDatetime = this.startUnixtime != null ? Instant.ofEpochMilli(this.startUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime() : null;
this.endUnixtime = entity.getEnd_datetime() != null ? Long.valueOf(entity.getEnd_datetime()) : null;
this.endDatetime = this.endUnixtime != null ? Instant.ofEpochMilli(this.endUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime() : null;
this.account = entity.getAccount();
this.deal = entity.getDeal();
}
@Override

View file

@ -0,0 +1,13 @@
package ru.spcex.clearing.xml.exporter.serializers;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
public class NullSerializer extends JsonSerializer<Object> {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeString("");
}
}

View file

@ -0,0 +1,10 @@
package ru.spcex.clearing.xml.exporter;
public class TestUtils {
public static String removeAttributes(String src, String ... args) {
for (String arg : args) {
src = src.replaceAll("%s\\s*=\\s*\".*?\"".formatted(arg), "");
}
return src;
}
}

View file

@ -1,559 +0,0 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf02;
import ru.clearing.classes.statics.data.sdf.SDf03;
import ru.clearing.classes.statics.data.sdf.SDf05;
import ru.clearing.classes.statics.data.sdf.SDf07;
import ru.clearing.classes.statics.data.sdf.SDf51;
import ru.clearing.classes.statics.data.sdf.SDf53;
import ru.clearing.classes.statics.data.sdf.SDf54;
import ru.clearing.classes.statics.data.sdf.SDf56;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF02ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF03ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF05ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF07ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF51ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF53ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF54ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF56ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
class ExportFromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf02ToObjectTag() {
SDf02 expectedSDf02 = new SDf02();
expectedSDf02.setGenerationId(1777L);
expectedSDf02.setCurr_code("test1");
expectedSDf02.setAccount("test2");
expectedSDf02.setRemainder("test3");
expectedSDf02.setDeal("test4");
expectedSDf02.setAcc_code("test5");
expectedSDf02.setDat("14.03.24");
expectedSDf02.setMarket("test6");
expectedSDf02.setAcc_name("test7");
expectedSDf02.setAcc_type("test8");
expectedSDf02.setSumengage("test9");
expectedSDf02.setSumunblock("test10");
expectedSDf02.setFile_type("test11");
expectedSDf02.setResult("test12");
expectedSDf02.setInSDfId((long) "inSDf02Id".hashCode());
expectedSDf02.setParentId("007");
Imdg<SDf02> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf02, SDf02.class);
imdg.insert(expectedSDf02);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setGroupId(1777L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF02ObjectTag actualObjectTag = (DF02ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat("007").isEqualTo(actualResultContainer.getDocumentTag().getParentDoc().getParentId());
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF02");
Assertions.assertThat(actualObjectTag.getCurrCode()).isEqualTo(expectedSDf02.getCurr_code());
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf02.getAccount());
Assertions.assertThat(actualObjectTag.getRemainder()).isEqualTo(expectedSDf02.getRemainder());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf02.getDeal());
Assertions.assertThat(actualObjectTag.getAccCode()).isEqualTo(expectedSDf02.getAcc_code());
Assertions.assertThat(actualObjectTag.getDat().format(formatter)).isEqualTo(expectedSDf02.getDat());
Assertions.assertThat(actualObjectTag.getMarket()).isEqualTo(expectedSDf02.getMarket());
Assertions.assertThat(actualObjectTag.getAccName()).isEqualTo(expectedSDf02.getAcc_name());
Assertions.assertThat(actualObjectTag.getAccType()).isEqualTo(expectedSDf02.getAcc_type());
Assertions.assertThat(actualObjectTag.getSumengage()).isEqualTo(expectedSDf02.getSumengage());
Assertions.assertThat(actualObjectTag.getSumunblock()).isEqualTo(expectedSDf02.getSumunblock());
Assertions.assertThat(actualObjectTag.getFileType()).isEqualTo(expectedSDf02.getFile_type());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportEmptySDf02ToObjectTag() {
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
Object actualObjectTag = actualResultContainer.getDocumentTag().getObjects();
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF02");
Assertions.assertThat(((Collection<?>) actualObjectTag).isEmpty()).isTrue();
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1_empty.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf03ToObjectTag() {
SDf03 expectedSDf03 = new SDf03();
expectedSDf03.setSeg_type("test1");
expectedSDf03.setDoc_type("test2");
expectedSDf03.setDocnm_ref("test3");
expectedSDf03.setDocnmprev("test4");
expectedSDf03.setC_acc_deb("test5");
expectedSDf03.setSbanknam1("test6");
expectedSDf03.setC_acc_cred("test7");
expectedSDf03.setRbanknam1("test8");
expectedSDf03.setPay_date("14.03.24");
expectedSDf03.setPay_val("test9");
expectedSDf03.setSum_deb("test10");
expectedSDf03.setSpecif_1("test11");
expectedSDf03.setImp_result("test12");
Imdg<SDf03> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
imdg.insert(expectedSDf03);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF03, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF03ObjectTag actualObjectTag = (DF03ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF03");
Assertions.assertThat(actualObjectTag.getSegType()).isEqualTo(expectedSDf03.getSeg_type());
Assertions.assertThat(actualObjectTag.getDocType()).isEqualTo(expectedSDf03.getDoc_type());
Assertions.assertThat(actualObjectTag.getDocnmRef()).isEqualTo(expectedSDf03.getDocnm_ref());
Assertions.assertThat(actualObjectTag.getDocnmprev()).isEqualTo(expectedSDf03.getDocnmprev());
Assertions.assertThat(actualObjectTag.getcAccDeb()).isEqualTo(expectedSDf03.getC_acc_deb());
Assertions.assertThat(actualObjectTag.getSbanknam1()).isEqualTo(expectedSDf03.getSbanknam1());
Assertions.assertThat(actualObjectTag.getcAccCred()).isEqualTo(expectedSDf03.getC_acc_cred());
Assertions.assertThat(actualObjectTag.getRbanknam1()).isEqualTo(expectedSDf03.getRbanknam1());
Assertions.assertThat(actualObjectTag.getPayDate().format(formatter)).isEqualTo(expectedSDf03.getPay_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf03.getPay_val());
Assertions.assertThat(actualObjectTag.getSumDeb()).isEqualTo(expectedSDf03.getSum_deb());
Assertions.assertThat(actualObjectTag.getSpecif1()).isEqualTo(expectedSDf03.getSpecif_1());
Assertions.assertThat(actualObjectTag.getImpResult()).isEqualTo(expectedSDf03.getImp_result());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-03_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf05ToObjectTag() {
SDf05 expectedSDf05 = new SDf05();
expectedSDf05.setTp(BigDecimal.TEN);
expectedSDf05.setDt(LocalDate.parse("2024-03-14"));
expectedSDf05.setTm("09:22:12");
expectedSDf05.setPr("test2");
Imdg<SDf05> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf05, SDf05.class);
imdg.insert(expectedSDf05);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF05, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF05ObjectTag actualObjectTag = (DF05ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF05");
Assertions.assertThat(actualObjectTag.getTp()).isEqualTo(expectedSDf05.getTp());
Assertions.assertThat(actualObjectTag.getDt()).isEqualTo(expectedSDf05.getDt());
Assertions.assertThat(actualObjectTag.getTm()).isEqualTo(expectedSDf05.getTm());
Assertions.assertThat(actualObjectTag.getPr()).isEqualTo(expectedSDf05.getPr());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-05_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf07ToObjectTag() {
SDf07 expectedSDf07 = new SDf07();
expectedSDf07.setGenerationId(Long.valueOf(3775));
expectedSDf07.setInSDfId((long) "inSDf07Id".hashCode());
expectedSDf07.setAccount("test1");
expectedSDf07.setSum(new BigDecimal(BigInteger.TEN));
expectedSDf07.setMarket("test3");
expectedSDf07.setType("test4");
expectedSDf07.setDeal("test5");
expectedSDf07.setClientN("test6");
expectedSDf07.setInn("test7");
expectedSDf07.setBic("test8");
expectedSDf07.setSpec("test9");
expectedSDf07.setNumber(new BigDecimal(BigInteger.TWO));
expectedSDf07.setDoc_num("test11");
expectedSDf07.setDoc_date("14.03.24");
expectedSDf07.setPay_val("test12");
expectedSDf07.setParentId("005");
Imdg<SDf07> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf07, SDf07.class);
imdg.insert(expectedSDf07);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF07, "S");
actualResultContainer.setGroupId(3775L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF07ObjectTag actualObjectTag = (DF07ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF07");
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf07.getAccount());
Assertions.assertThat(actualObjectTag.getSum()).isEqualTo(expectedSDf07.getSum());
Assertions.assertThat(actualObjectTag.getMarket()).isEqualTo(expectedSDf07.getMarket());
Assertions.assertThat(actualObjectTag.getType()).isEqualTo(expectedSDf07.getType());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf07.getDeal());
Assertions.assertThat(actualObjectTag.getClientN()).isEqualTo(expectedSDf07.getClientN());
Assertions.assertThat(actualObjectTag.getInn()).isEqualTo(expectedSDf07.getInn());
Assertions.assertThat(actualObjectTag.getBic()).isEqualTo(expectedSDf07.getBic());
Assertions.assertThat(actualObjectTag.getSpec()).isEqualTo(expectedSDf07.getSpec());
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf07.getNumber());
Assertions.assertThat(actualObjectTag.getDocNum()).isEqualTo(expectedSDf07.getDoc_num());
Assertions.assertThat(actualObjectTag.getDocDate().format(formatter)).isEqualTo(expectedSDf07.getDoc_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf07.getPay_val());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-07_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf51ToObjectTag() {
SDf51 expectedSDf51 = new SDf51();
expectedSDf51.setNumber("1234");
expectedSDf51.setDatetime("1718785193000");
Imdg<SDf51> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf51, SDf51.class);
imdg.insert(expectedSDf51);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF51, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF51ObjectTag actualObjectTag = (DF51ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF51");
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf51.getNumber());
Assertions.assertThat(actualObjectTag.getUnixtime()).isEqualTo(Long.parseLong(expectedSDf51.getDatetime()));
Assertions.assertThat(actualObjectTag.getDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf51.getDatetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-51_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "UNIXTIME", "DATETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "UNIXTIME", "DATETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf53ToObjectTag() {
SDf53 expectedSDf53 = new SDf53();
expectedSDf53.setGenerationId(2776L);
expectedSDf53.setInSDfId((long) "inSDf53Id".hashCode());
expectedSDf53.setAccount("test1");
expectedSDf53.setAccName("test2");
expectedSDf53.setDeal("test3");
expectedSDf53.setDate("14.03.24");
expectedSDf53.setStatus(1L);
expectedSDf53.setAccType("test4");
expectedSDf53.setResult("test5");
expectedSDf53.setParentId("006");
Imdg<SDf53> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf53, SDf53.class);
imdg.insert(expectedSDf53);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF53, "S");
actualResultContainer.setGroupId(2776L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF53ObjectTag actualObjectTag = (DF53ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF53");
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf53.getAccount());
Assertions.assertThat(actualObjectTag.getAccName()).isEqualTo(expectedSDf53.getAccName());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf53.getDeal());
Assertions.assertThat(actualObjectTag.getDate().format(formatter)).isEqualTo(expectedSDf53.getDate());
Assertions.assertThat(actualObjectTag.getStatus()).isEqualTo(expectedSDf53.getStatus());
Assertions.assertThat(actualObjectTag.getAccType()).isEqualTo(expectedSDf53.getAccType());
Assertions.assertThat(actualObjectTag.getResult()).isEqualTo(expectedSDf53.getResult());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-53_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf54ToObjectTag() {
SDf54 expectedSDf54 = new SDf54();
expectedSDf54.setSeg_type("test1");
expectedSDf54.setDoc_type("test2");
expectedSDf54.setDocnm_ref("test3");
expectedSDf54.setDocnmprev("test4");
expectedSDf54.setSbankcode("test5");
expectedSDf54.setC_acc_deb("test6");
expectedSDf54.setSbanknam1("test7");
expectedSDf54.setRbankcode("test8");
expectedSDf54.setC_acc_cred("test9");
expectedSDf54.setRbanknam1("test10");
expectedSDf54.setOp_type("test11");
expectedSDf54.setOp_order("test12");
expectedSDf54.setPay_date("14.03.24");
expectedSDf54.setPay_val("test13");
expectedSDf54.setSum_deb("test14");
expectedSDf54.setSclientn1("test15");
expectedSDf54.setInn_deb("test16");
expectedSDf54.setKpp_deb("test17");
expectedSDf54.setAcc_deb("test18");
expectedSDf54.setRclientn1("test19");
expectedSDf54.setInn_cred("test20");
expectedSDf54.setKpp_cred("test21");
expectedSDf54.setAcc_kr_1("test22");
expectedSDf54.setSpecif_1("test23");
expectedSDf54.setSend_type("test24");
expectedSDf54.setDoc_result("test25");
expectedSDf54.setDoc_num("test26");
expectedSDf54.setDoc_date("14.03.24");
expectedSDf54.setValue_date("14.03.24");
expectedSDf54.setSwift_ben("test27");
expectedSDf54.setSwift_int("test28");
Imdg<SDf54> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf54, SDf54.class);
imdg.insert(expectedSDf54);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF54, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF54ObjectTag actualObjectTag = (DF54ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF54");
Assertions.assertThat(actualObjectTag.getSegType()).isEqualTo(expectedSDf54.getSeg_type());
Assertions.assertThat(actualObjectTag.getDocType()).isEqualTo(expectedSDf54.getDoc_type());
Assertions.assertThat(actualObjectTag.getDocnmRef()).isEqualTo(expectedSDf54.getDocnm_ref());
Assertions.assertThat(actualObjectTag.getDocnmprev()).isEqualTo(expectedSDf54.getDocnmprev());
Assertions.assertThat(actualObjectTag.getSbankcode()).isEqualTo(expectedSDf54.getSbankcode());
Assertions.assertThat(actualObjectTag.getcAccDeb()).isEqualTo(expectedSDf54.getC_acc_deb());
Assertions.assertThat(actualObjectTag.getSbanknam1()).isEqualTo(expectedSDf54.getSbanknam1());
Assertions.assertThat(actualObjectTag.getRbankcode()).isEqualTo(expectedSDf54.getRbankcode());
Assertions.assertThat(actualObjectTag.getcAccCred()).isEqualTo(expectedSDf54.getC_acc_cred());
Assertions.assertThat(actualObjectTag.getRbanknam1()).isEqualTo(expectedSDf54.getRbanknam1());
Assertions.assertThat(actualObjectTag.getOpType()).isEqualTo(expectedSDf54.getOp_type());
Assertions.assertThat(actualObjectTag.getOpOrder()).isEqualTo(expectedSDf54.getOp_order());
Assertions.assertThat(actualObjectTag.getPayDate().format(formatter)).isEqualTo(expectedSDf54.getPay_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf54.getPay_val());
Assertions.assertThat(actualObjectTag.getSumDeb()).isEqualTo(expectedSDf54.getSum_deb());
Assertions.assertThat(actualObjectTag.getSclientn1()).isEqualTo(expectedSDf54.getSclientn1());
Assertions.assertThat(actualObjectTag.getInnDeb()).isEqualTo(expectedSDf54.getInn_deb());
Assertions.assertThat(actualObjectTag.getKppDeb()).isEqualTo(expectedSDf54.getKpp_deb());
Assertions.assertThat(actualObjectTag.getAccDeb()).isEqualTo(expectedSDf54.getAcc_deb());
Assertions.assertThat(actualObjectTag.getRclientn1()).isEqualTo(expectedSDf54.getRclientn1());
Assertions.assertThat(actualObjectTag.getInnCred()).isEqualTo(expectedSDf54.getInn_cred());
Assertions.assertThat(actualObjectTag.getKppCred()).isEqualTo(expectedSDf54.getKpp_cred());
Assertions.assertThat(actualObjectTag.getAccKr1()).isEqualTo(expectedSDf54.getAcc_kr_1());
Assertions.assertThat(actualObjectTag.getSpecif1()).isEqualTo(expectedSDf54.getSpecif_1());
Assertions.assertThat(actualObjectTag.getSendType()).isEqualTo(expectedSDf54.getSend_type());
Assertions.assertThat(actualObjectTag.getDocResult()).isEqualTo(expectedSDf54.getDoc_result());
Assertions.assertThat(actualObjectTag.getDocNum()).isEqualTo(expectedSDf54.getDoc_num());
Assertions.assertThat(actualObjectTag.getDocDate().format(formatter)).isEqualTo(expectedSDf54.getDoc_date());
Assertions.assertThat(actualObjectTag.getValueDate().format(formatter)).isEqualTo(expectedSDf54.getValue_date());
Assertions.assertThat(actualObjectTag.getSwiftBen()).isEqualTo(expectedSDf54.getSwift_ben());
Assertions.assertThat(actualObjectTag.getSwiftInt()).isEqualTo(expectedSDf54.getSwift_int());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-54_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE", "DOC_DATE", "VALUE_DATE");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE", "DOC_DATE", "VALUE_DATE");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportSDf56ToObjectTag() {
SDf56 expectedSDf56 = new SDf56();
expectedSDf56.setNumber("test1");
expectedSDf56.setStart_datetime("1718785193000");
expectedSDf56.setEnd_datetime("1718875193000");
expectedSDf56.setAccount("test4");
expectedSDf56.setDeal("test5");
Imdg<SDf56> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf56, SDf56.class);
imdg.insert(expectedSDf56);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF56, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF56ObjectTag actualObjectTag = (DF56ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF56");
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf56.getNumber());
Assertions.assertThat(actualObjectTag.getStartUnixtime()).isEqualTo(Long.valueOf(expectedSDf56.getStart_datetime()));
Assertions.assertThat(actualObjectTag.getEndUnixtime()).isEqualTo(Long.valueOf(expectedSDf56.getEnd_datetime()));
Assertions.assertThat(actualObjectTag.getStartDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf56.getStart_datetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
Assertions.assertThat(actualObjectTag.getEndDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf56.getEnd_datetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf56.getAccount());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf56.getDeal());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-56_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "SUNIXTIME", "SDATETIME", "EUNIXTIME", "EDATETIME");
expected = removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "SUNIXTIME", "SDATETIME", "EUNIXTIME", "EDATETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
private String removeAttributes(String src, String ... args) {
for (String arg : args) {
src = src.replaceAll("%s\\s*=\\s*\".*?\"".formatted(arg), "");
}
return src;
}
}

View file

@ -0,0 +1,173 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf02;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF02ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf02FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf02ToObjectTag() {
SDf02 expectedSDf02 = new SDf02();
expectedSDf02.setGenerationId(1777L);
expectedSDf02.setCurr_code("test1");
expectedSDf02.setAccount("test2");
expectedSDf02.setRemainder("test3");
expectedSDf02.setDeal("test4");
expectedSDf02.setAcc_code("test5");
expectedSDf02.setDat("14.03.24");
expectedSDf02.setMarket("test6");
expectedSDf02.setAcc_name("test7");
expectedSDf02.setAcc_type("test8");
expectedSDf02.setSumengage("test9");
expectedSDf02.setSumunblock("test10");
expectedSDf02.setFile_type("test11");
expectedSDf02.setResult("test12");
expectedSDf02.setInSDfId((long) "inSDf02Id".hashCode());
expectedSDf02.setParentId("007");
Imdg<SDf02> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf02, SDf02.class);
imdg.insert(expectedSDf02);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setGroupId(1777L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF02ObjectTag actualObjectTag = (DF02ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat("007").isEqualTo(actualResultContainer.getDocumentTag().getParentDoc().getParentId());
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF02");
Assertions.assertThat(actualObjectTag.getCurrCode()).isEqualTo(expectedSDf02.getCurr_code());
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf02.getAccount());
Assertions.assertThat(actualObjectTag.getRemainder()).isEqualTo(expectedSDf02.getRemainder());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf02.getDeal());
Assertions.assertThat(actualObjectTag.getAccCode()).isEqualTo(expectedSDf02.getAcc_code());
Assertions.assertThat(actualObjectTag.getDat().format(formatter)).isEqualTo(expectedSDf02.getDat());
Assertions.assertThat(actualObjectTag.getMarket()).isEqualTo(expectedSDf02.getMarket());
Assertions.assertThat(actualObjectTag.getAccName()).isEqualTo(expectedSDf02.getAcc_name());
Assertions.assertThat(actualObjectTag.getAccType()).isEqualTo(expectedSDf02.getAcc_type());
Assertions.assertThat(actualObjectTag.getSumengage()).isEqualTo(expectedSDf02.getSumengage());
Assertions.assertThat(actualObjectTag.getSumunblock()).isEqualTo(expectedSDf02.getSumunblock());
Assertions.assertThat(actualObjectTag.getFileType()).isEqualTo(expectedSDf02.getFile_type());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportEmptySDf02ToObjectTag() {
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
Object actualObjectTag = actualResultContainer.getDocumentTag().getObjects();
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF02");
Assertions.assertThat(((Collection<?>) actualObjectTag).isEmpty()).isTrue();
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1_empty.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,146 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf03;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF03ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf03FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf03ToObjectTag() {
SDf03 expectedSDf03 = new SDf03();
expectedSDf03.setSeg_type("test1");
expectedSDf03.setDoc_type("test2");
expectedSDf03.setDocnm_ref("test3");
expectedSDf03.setDocnmprev("test4");
expectedSDf03.setC_acc_deb("test5");
expectedSDf03.setSbanknam1("test6");
expectedSDf03.setC_acc_cred("test7");
expectedSDf03.setRbanknam1("test8");
expectedSDf03.setPay_date("14.03.24");
expectedSDf03.setPay_val("test9");
expectedSDf03.setSum_deb("test10");
expectedSDf03.setSpecif_1("test11");
expectedSDf03.setImp_result("test12");
Imdg<SDf03> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
imdg.insert(expectedSDf03);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF03, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF03ObjectTag actualObjectTag = (DF03ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF03");
Assertions.assertThat(actualObjectTag.getSegType()).isEqualTo(expectedSDf03.getSeg_type());
Assertions.assertThat(actualObjectTag.getDocType()).isEqualTo(expectedSDf03.getDoc_type());
Assertions.assertThat(actualObjectTag.getDocnmRef()).isEqualTo(expectedSDf03.getDocnm_ref());
Assertions.assertThat(actualObjectTag.getDocnmprev()).isEqualTo(expectedSDf03.getDocnmprev());
Assertions.assertThat(actualObjectTag.getcAccDeb()).isEqualTo(expectedSDf03.getC_acc_deb());
Assertions.assertThat(actualObjectTag.getSbanknam1()).isEqualTo(expectedSDf03.getSbanknam1());
Assertions.assertThat(actualObjectTag.getcAccCred()).isEqualTo(expectedSDf03.getC_acc_cred());
Assertions.assertThat(actualObjectTag.getRbanknam1()).isEqualTo(expectedSDf03.getRbanknam1());
Assertions.assertThat(actualObjectTag.getPayDate().format(formatter)).isEqualTo(expectedSDf03.getPay_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf03.getPay_val());
Assertions.assertThat(actualObjectTag.getSumDeb()).isEqualTo(expectedSDf03.getSum_deb());
Assertions.assertThat(actualObjectTag.getSpecif1()).isEqualTo(expectedSDf03.getSpecif_1());
Assertions.assertThat(actualObjectTag.getImpResult()).isEqualTo(expectedSDf03.getImp_result());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-03_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,129 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf05;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF05ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf05FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf05ToObjectTag() {
SDf05 expectedSDf05 = new SDf05();
expectedSDf05.setTp(BigDecimal.TEN);
expectedSDf05.setDt(LocalDate.parse("2024-03-14"));
expectedSDf05.setTm("09:22:12");
expectedSDf05.setPr("test2");
Imdg<SDf05> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf05, SDf05.class);
imdg.insert(expectedSDf05);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF05, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF05ObjectTag actualObjectTag = (DF05ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF05");
Assertions.assertThat(actualObjectTag.getTp()).isEqualTo(expectedSDf05.getTp());
Assertions.assertThat(actualObjectTag.getDt()).isEqualTo(expectedSDf05.getDt());
Assertions.assertThat(actualObjectTag.getTm()).isEqualTo(expectedSDf05.getTm());
Assertions.assertThat(actualObjectTag.getPr()).isEqualTo(expectedSDf05.getPr());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-05_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,151 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf07;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF07ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf07FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf07ToObjectTag() {
SDf07 expectedSDf07 = new SDf07();
expectedSDf07.setGenerationId(Long.valueOf(3775));
expectedSDf07.setInSDfId((long) "inSDf07Id".hashCode());
expectedSDf07.setAccount("test1");
expectedSDf07.setSum(new BigDecimal(BigInteger.TEN));
expectedSDf07.setMarket("test3");
expectedSDf07.setType("test4");
expectedSDf07.setDeal("test5");
expectedSDf07.setClientN("test6");
expectedSDf07.setInn("test7");
expectedSDf07.setBic("test8");
expectedSDf07.setSpec("test9");
expectedSDf07.setNumber(new BigDecimal(BigInteger.TWO));
expectedSDf07.setDoc_num("test11");
expectedSDf07.setDoc_date("14.03.24");
expectedSDf07.setPay_val("test12");
expectedSDf07.setParentId("005");
Imdg<SDf07> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf07, SDf07.class);
imdg.insert(expectedSDf07);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF07, "S");
actualResultContainer.setGroupId(3775L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF07ObjectTag actualObjectTag = (DF07ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF07");
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf07.getAccount());
Assertions.assertThat(actualObjectTag.getSum()).isEqualTo(expectedSDf07.getSum());
Assertions.assertThat(actualObjectTag.getMarket()).isEqualTo(expectedSDf07.getMarket());
Assertions.assertThat(actualObjectTag.getType()).isEqualTo(expectedSDf07.getType());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf07.getDeal());
Assertions.assertThat(actualObjectTag.getClientN()).isEqualTo(expectedSDf07.getClientN());
Assertions.assertThat(actualObjectTag.getInn()).isEqualTo(expectedSDf07.getInn());
Assertions.assertThat(actualObjectTag.getBic()).isEqualTo(expectedSDf07.getBic());
Assertions.assertThat(actualObjectTag.getSpec()).isEqualTo(expectedSDf07.getSpec());
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf07.getNumber());
Assertions.assertThat(actualObjectTag.getDocNum()).isEqualTo(expectedSDf07.getDoc_num());
Assertions.assertThat(actualObjectTag.getDocDate().format(formatter)).isEqualTo(expectedSDf07.getDoc_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf07.getPay_val());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-07_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,126 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf51;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF51ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf51FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf51ToObjectTag() {
SDf51 expectedSDf51 = new SDf51();
expectedSDf51.setNumber("1234");
expectedSDf51.setDatetime("1718785193000");
Imdg<SDf51> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf51, SDf51.class);
imdg.insert(expectedSDf51);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF51, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF51ObjectTag actualObjectTag = (DF51ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF51");
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf51.getNumber());
Assertions.assertThat(actualObjectTag.getUnixtime()).isEqualTo(Long.parseLong(expectedSDf51.getDatetime()));
Assertions.assertThat(actualObjectTag.getDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf51.getDatetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-51_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "UNIXTIME", "DATETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "UNIXTIME", "DATETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,138 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf53;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF53ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf53FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf53ToObjectTag() {
SDf53 expectedSDf53 = new SDf53();
expectedSDf53.setGenerationId(2776L);
expectedSDf53.setInSDfId((long) "inSDf53Id".hashCode());
expectedSDf53.setAccount("test1");
expectedSDf53.setAccName("test2");
expectedSDf53.setDeal("test3");
expectedSDf53.setDate("14.03.24");
expectedSDf53.setStatus(1L);
expectedSDf53.setAccType("test4");
expectedSDf53.setResult("test5");
expectedSDf53.setParentId("006");
Imdg<SDf53> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf53, SDf53.class);
imdg.insert(expectedSDf53);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF53, "S");
actualResultContainer.setGroupId(2776L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF53ObjectTag actualObjectTag = (DF53ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF53");
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf53.getAccount());
Assertions.assertThat(actualObjectTag.getAccName()).isEqualTo(expectedSDf53.getAccName());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf53.getDeal());
Assertions.assertThat(actualObjectTag.getDate().format(formatter)).isEqualTo(expectedSDf53.getDate());
Assertions.assertThat(actualObjectTag.getStatus()).isEqualTo(expectedSDf53.getStatus());
Assertions.assertThat(actualObjectTag.getAccType()).isEqualTo(expectedSDf53.getAccType());
Assertions.assertThat(actualObjectTag.getResult()).isEqualTo(expectedSDf53.getResult());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-53_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,181 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf54;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF54ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf54FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf54ToObjectTag() {
SDf54 expectedSDf54 = new SDf54();
expectedSDf54.setSeg_type("test1");
expectedSDf54.setDoc_type("test2");
expectedSDf54.setDocnm_ref("test3");
expectedSDf54.setDocnmprev("test4");
expectedSDf54.setSbankcode("test5");
expectedSDf54.setC_acc_deb("test6");
expectedSDf54.setSbanknam1("test7");
expectedSDf54.setRbankcode("test8");
expectedSDf54.setC_acc_cred("test9");
expectedSDf54.setRbanknam1("test10");
expectedSDf54.setOp_type("test11");
expectedSDf54.setOp_order("test12");
expectedSDf54.setPay_date("14.03.24");
expectedSDf54.setPay_val("test13");
expectedSDf54.setSum_deb("test14");
expectedSDf54.setSclientn1("test15");
expectedSDf54.setInn_deb("test16");
expectedSDf54.setKpp_deb("test17");
expectedSDf54.setAcc_deb("test18");
expectedSDf54.setRclientn1("test19");
expectedSDf54.setInn_cred("test20");
expectedSDf54.setKpp_cred("test21");
expectedSDf54.setAcc_kr_1("test22");
expectedSDf54.setSpecif_1("test23");
expectedSDf54.setSend_type("test24");
expectedSDf54.setDoc_result("test25");
expectedSDf54.setDoc_num("test26");
expectedSDf54.setDoc_date("14.03.24");
expectedSDf54.setValue_date("14.03.24");
expectedSDf54.setSwift_ben("test27");
expectedSDf54.setSwift_int("test28");
Imdg<SDf54> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf54, SDf54.class);
imdg.insert(expectedSDf54);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF54, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF54ObjectTag actualObjectTag = (DF54ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF54");
Assertions.assertThat(actualObjectTag.getSegType()).isEqualTo(expectedSDf54.getSeg_type());
Assertions.assertThat(actualObjectTag.getDocType()).isEqualTo(expectedSDf54.getDoc_type());
Assertions.assertThat(actualObjectTag.getDocnmRef()).isEqualTo(expectedSDf54.getDocnm_ref());
Assertions.assertThat(actualObjectTag.getDocnmprev()).isEqualTo(expectedSDf54.getDocnmprev());
Assertions.assertThat(actualObjectTag.getSbankcode()).isEqualTo(expectedSDf54.getSbankcode());
Assertions.assertThat(actualObjectTag.getcAccDeb()).isEqualTo(expectedSDf54.getC_acc_deb());
Assertions.assertThat(actualObjectTag.getSbanknam1()).isEqualTo(expectedSDf54.getSbanknam1());
Assertions.assertThat(actualObjectTag.getRbankcode()).isEqualTo(expectedSDf54.getRbankcode());
Assertions.assertThat(actualObjectTag.getcAccCred()).isEqualTo(expectedSDf54.getC_acc_cred());
Assertions.assertThat(actualObjectTag.getRbanknam1()).isEqualTo(expectedSDf54.getRbanknam1());
Assertions.assertThat(actualObjectTag.getOpType()).isEqualTo(expectedSDf54.getOp_type());
Assertions.assertThat(actualObjectTag.getOpOrder()).isEqualTo(expectedSDf54.getOp_order());
Assertions.assertThat(actualObjectTag.getPayDate().format(formatter)).isEqualTo(expectedSDf54.getPay_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf54.getPay_val());
Assertions.assertThat(actualObjectTag.getSumDeb()).isEqualTo(expectedSDf54.getSum_deb());
Assertions.assertThat(actualObjectTag.getSclientn1()).isEqualTo(expectedSDf54.getSclientn1());
Assertions.assertThat(actualObjectTag.getInnDeb()).isEqualTo(expectedSDf54.getInn_deb());
Assertions.assertThat(actualObjectTag.getKppDeb()).isEqualTo(expectedSDf54.getKpp_deb());
Assertions.assertThat(actualObjectTag.getAccDeb()).isEqualTo(expectedSDf54.getAcc_deb());
Assertions.assertThat(actualObjectTag.getRclientn1()).isEqualTo(expectedSDf54.getRclientn1());
Assertions.assertThat(actualObjectTag.getInnCred()).isEqualTo(expectedSDf54.getInn_cred());
Assertions.assertThat(actualObjectTag.getKppCred()).isEqualTo(expectedSDf54.getKpp_cred());
Assertions.assertThat(actualObjectTag.getAccKr1()).isEqualTo(expectedSDf54.getAcc_kr_1());
Assertions.assertThat(actualObjectTag.getSpecif1()).isEqualTo(expectedSDf54.getSpecif_1());
Assertions.assertThat(actualObjectTag.getSendType()).isEqualTo(expectedSDf54.getSend_type());
Assertions.assertThat(actualObjectTag.getDocResult()).isEqualTo(expectedSDf54.getDoc_result());
Assertions.assertThat(actualObjectTag.getDocNum()).isEqualTo(expectedSDf54.getDoc_num());
Assertions.assertThat(actualObjectTag.getDocDate().format(formatter)).isEqualTo(expectedSDf54.getDoc_date());
Assertions.assertThat(actualObjectTag.getValueDate().format(formatter)).isEqualTo(expectedSDf54.getValue_date());
Assertions.assertThat(actualObjectTag.getSwiftBen()).isEqualTo(expectedSDf54.getSwift_ben());
Assertions.assertThat(actualObjectTag.getSwiftInt()).isEqualTo(expectedSDf54.getSwift_int());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-54_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE", "DOC_DATE", "VALUE_DATE");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "PAY_DATE", "DOC_DATE", "VALUE_DATE");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -0,0 +1,134 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import ru.clearing.classes.statics.data.sdf.SDf56;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.test.TestObjectCreator;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.test.config.KafkaTestConfig;
import ru.spcex.clearing.xml.exporter.TestUtils;
import ru.spcex.clearing.xml.exporter.config.SFTPMockConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF56ObjectTag;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@SpringBootTest(classes = {
ExportFromHazelcast.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
SFTPMockConfig.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public class ExportSf56FromHazelcastTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yy");
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastService;
@Captor
private ArgumentCaptor<ProducerRecord> producerRecord;
@SpyBean
private MockProducer<String, Object> producer;
@Autowired
@Qualifier("mockProducer")
protected Producer<String, Object> mockProducer;
@Autowired
private ExportFromHazelcast exportFromHazelcast;
@PostConstruct
private void init() {
hazelcastService.waitAvailable();
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf56ToObjectTag() {
SDf56 expectedSDf56 = new SDf56();
expectedSDf56.setNumber("test1");
expectedSDf56.setStart_datetime("1718785193000");
expectedSDf56.setEnd_datetime("1718875193000");
expectedSDf56.setAccount("test4");
expectedSDf56.setDeal("test5");
Imdg<SDf56> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf56, SDf56.class);
imdg.insert(expectedSDf56);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF56, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF56ObjectTag actualObjectTag = (DF56ObjectTag) actualResultContainer.getDocumentTag().getObjects().get(0);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF56");
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf56.getNumber());
Assertions.assertThat(actualObjectTag.getStartUnixtime()).isEqualTo(Long.valueOf(expectedSDf56.getStart_datetime()));
Assertions.assertThat(actualObjectTag.getEndUnixtime()).isEqualTo(Long.valueOf(expectedSDf56.getEnd_datetime()));
Assertions.assertThat(actualObjectTag.getStartDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf56.getStart_datetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
Assertions.assertThat(actualObjectTag.getEndDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf56.getEnd_datetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf56.getAccount());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf56.getDeal());
try {
String actual = FileUtils.readFileToString(actualResultContainer.getFileForExport(), StandardCharsets.UTF_8);
String expected = FileUtils.readFileToString(new File("./src/test/resources/xml-original/DF-56_S_PRC1604240915_1.xml"), StandardCharsets.UTF_8);
actual = TestUtils.removeAttributes(actual, "MESSAGEDATE", "MESSAGETIME", "SUNIXTIME", "SDATETIME", "EUNIXTIME", "EDATETIME");
expected = TestUtils.removeAttributes(expected, "MESSAGEDATE", "MESSAGETIME", "SUNIXTIME", "SDATETIME", "EUNIXTIME", "EDATETIME");
assertEquals(expected, actual);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -2,6 +2,6 @@
<DOCUMENT MESSAGETYPE="DF07" MESSAGENAME="Квитанция на запрос неторгового поручения" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID="005"/>
<OBJECTS>
<OBJECT ACCOUNT="test1" SUM="10" MARKET="test3" TYPE="test4" DEAL="test5" CLIENTN="test6" INN="test7" BIC="test8" SPEC="test9" NUMBER="2" DOC_NUM="test11" DOC_DATE="2024-03-14" PAY_VAL="test12"/>
<OBJECT ACCOUNT="test1" SUM="10" MARKET="test3" TYPE="test4" DEAL="test5" CLIENTN="test6" INN="test7" BIC="test8" SPEC="test9" NUMBER="2" DOC_NUM="test11" DOC_DATE="2024-03-14" PAY_VAL="test12" RESULT=""/>
</OBJECTS>
</DOCUMENT>