tests for notifications

This commit is contained in:
akulikov 2022-12-29 17:09:41 +03:00
parent c7f6d097cc
commit 732ad424f4
15 changed files with 189 additions and 38 deletions

View file

@ -12,10 +12,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.LocalDate;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.*;
@Component
public class REXNotificationBuilder extends NotificationBuilder {
@ -70,7 +69,7 @@ public class REXNotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -80,8 +79,8 @@ public class REXNotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${validFromDate}", "%02d.%02d.%04d".formatted(day, month, year));
String outputFilename = "REX.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));

View file

@ -15,6 +15,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.*;
@Component
@ -71,7 +74,7 @@ public class ROOT_ACTV_NotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -81,13 +84,13 @@ public class ROOT_ACTV_NotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt));
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
String outputFilename = "ROOT.ACTV.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
outputFilename = normalizeFilenameForOS(outputFilename);

View file

@ -15,6 +15,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.*;
@Component
@ -71,7 +74,7 @@ public class ROOT_BLKD_NotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -81,13 +84,13 @@ public class ROOT_BLKD_NotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt));
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
String outputFilename = "ROOT.BLKD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
outputFilename = normalizeFilenameForOS(outputFilename);

View file

@ -13,10 +13,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.LocalDate;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.*;
@Component
public class ROOT_CLOS_NotificationBuilder extends NotificationBuilder {
@ -83,7 +82,7 @@ public class ROOT_CLOS_NotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -93,8 +92,8 @@ public class ROOT_CLOS_NotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);

View file

@ -13,10 +13,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.LocalDate;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.*;
@Component
public class ROOT_NEW_NotificationBuilder extends NotificationBuilder {
@ -83,7 +82,7 @@ public class ROOT_NEW_NotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -93,8 +92,8 @@ public class ROOT_NEW_NotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);

View file

@ -15,6 +15,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.*;
@Component
@ -71,7 +74,7 @@ public class ROOT_SSPD_NotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -81,13 +84,13 @@ public class ROOT_SSPD_NotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt));
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
String outputFilename = "ROOT.SSPD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
outputFilename = normalizeFilenameForOS(outputFilename);

View file

@ -14,7 +14,9 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.*;
@Component
@ -71,7 +73,7 @@ public class RRPCNotificationBuilder extends NotificationBuilder {
return null;
}
LocalDate notificationDate = LocalDate.now();
LocalDateTime notificationDate = LocalDateTime.now();
int day = notificationDate.getDayOfMonth();
int month = notificationDate.getMonthValue();
int year = notificationDate.getYear();
@ -81,10 +83,10 @@ public class RRPCNotificationBuilder extends NotificationBuilder {
valuesForTemplate.put("${dateStr}", dateStr);
valuesForTemplate.put("${count}", String.valueOf(notificationId));
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
valuesForTemplate.put("${currMonth}", "%02d".formatted(month));
valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100));
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt));
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
valuesForTemplate.put("${companyFullName}", company.getFullName());
valuesForTemplate.put("${companyShortName}", company.getShortName());
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());

View file

@ -0,0 +1,143 @@
package ru.spcex.clearing.reports.notifications;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.classes.statics.data.company.CompanySymbols;
import ru.clearing.classes.statics.data.company.relation.Relation;
import ru.clearing.classes.statics.data.profile.ProfileDocument;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
import static org.mockito.Mockito.*;
class NotificationBuilderTest {
static ImdgProvider imdgProviderMock;
static Imdg<Company> companyImdgMock;
static Company testCompany;
static Imdg<ProfileDocument> profileDocumentImdgMock;
static ProfileDocument testProfileDocument_1;
static ProfileDocument testProfileDocument_2;
static Imdg<Relation> relationImdgMock;
static Relation testRelation_1;
static Relation testRelation_2;
static Imdg<CompanySymbols> companySymbolsImdgMock;
static CompanySymbols testCompanySymbols_1;
static CompanySymbols testCompanySymbols_2;
@BeforeAll
public static void initMocks() {
imdgProviderMock = mock(ImdgProvider.class);
testCompany = new Company();
testCompany.setFullName("== TEST FULL NAME ==");
testCompany.setShortName("== TEST SHORT NAME ==");
testCompany.setClearingCode("TEST_CLEARING_CODE");
companyImdgMock = mock(Imdg.class);
when(companyImdgMock.getSingleObjectByID(any())).thenReturn(testCompany);
when(imdgProviderMock.getImdg(eq(IMDGDistributedNames.Map_Company), eq(Company.class))).thenReturn(companyImdgMock);
testProfileDocument_1 = new ProfileDocument();
testProfileDocument_1.setId(777L);
testProfileDocument_1.setCompanyId(777L);
testProfileDocument_1.setValidFromDate(LocalDate.of(2020, 1, 1));
testProfileDocument_1.setNumber("TEST_NUMBER_1");
testProfileDocument_2 = new ProfileDocument();
testProfileDocument_2.setId(777L);
testProfileDocument_2.setCompanyId(777L);
testProfileDocument_2.setValidFromDate(LocalDate.of(2019, 1, 1));
testProfileDocument_2.setNumber("TEST_NUMBER_2");
profileDocumentImdgMock = mock(Imdg.class);
when(profileDocumentImdgMock.getCollectionObjectsBySQL(any())).thenReturn(Arrays.asList(testProfileDocument_1, testProfileDocument_2));
when(imdgProviderMock.getImdg(eq(IMDGDistributedNames.Map_ProfileDocument), eq(ProfileDocument.class))).thenReturn(profileDocumentImdgMock);
testRelation_1 = new Relation();
testRelation_1.setId(777L);
testRelation_1.setConsumerId(777L);
testRelation_1.setUpdated(LocalDate.of(2020, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant());
testRelation_2 = new Relation();
testRelation_2.setId(777L);
testRelation_2.setConsumerId(777L);
testRelation_2.setUpdated(LocalDate.of(2019, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant());
relationImdgMock = mock(Imdg.class);
when(relationImdgMock.getCollectionObjectsBySQL(any())).thenReturn(Arrays.asList(testRelation_1, testRelation_2));
when(imdgProviderMock.getImdg(eq(IMDGDistributedNames.Map_Relation), eq(Relation.class))).thenReturn(relationImdgMock);
testCompanySymbols_1 = new CompanySymbols();
testCompanySymbols_1.setId(777L);
testCompanySymbols_1.setCompanyId(777L);
testCompanySymbols_1.setCompanySymbol("TEST_COMPANY_SYMBOL_1");
testCompanySymbols_1.setCompanySymbolValue("TEST_COMPANY_SYMBOL_VALUE_1");
testCompanySymbols_2 = new CompanySymbols();
testCompanySymbols_2.setId(777L);
testCompanySymbols_2.setCompanyId(777L);
testCompanySymbols_2.setCompanySymbol("TEST_COMPANY_SYMBOL_2");
testCompanySymbols_2.setCompanySymbolValue("TEST_COMPANY_SYMBOL_VALUE_2");
companySymbolsImdgMock = mock(Imdg.class);
when(companySymbolsImdgMock.getCollectionObjectsBySQL(any())).thenReturn(Arrays.asList(testCompanySymbols_1, testCompanySymbols_2));
when(imdgProviderMock.getImdg(eq(IMDGDistributedNames.Map_CompanySymbols), eq(CompanySymbols.class))).thenReturn(companySymbolsImdgMock);
}
@Test
public void testREX() {
REXNotificationBuilder rexNotificationBuilder = new REXNotificationBuilder(imdgProviderMock);
File outputFile = rexNotificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testRRPC() {
RRPCNotificationBuilder rrpcNotificationBuilder = new RRPCNotificationBuilder(imdgProviderMock);
File outputFile = rrpcNotificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testROOT_ACTV() {
ROOT_ACTV_NotificationBuilder root_actv_notificationBuilder = new ROOT_ACTV_NotificationBuilder(imdgProviderMock);
File outputFile = root_actv_notificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testROOT_BLKD() {
ROOT_BLKD_NotificationBuilder root_actv_notificationBuilder = new ROOT_BLKD_NotificationBuilder(imdgProviderMock);
File outputFile = root_actv_notificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testROOT_CLOS() {
ROOT_CLOS_NotificationBuilder root_actv_notificationBuilder = new ROOT_CLOS_NotificationBuilder(imdgProviderMock);
File outputFile = root_actv_notificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testROOT_NEW() {
ROOT_NEW_NotificationBuilder root_actv_notificationBuilder = new ROOT_NEW_NotificationBuilder(imdgProviderMock);
File outputFile = root_actv_notificationBuilder.buildNotification(777L);
outputFile.delete();
}
@Test
public void testROOT_SSPD() {
ROOT_SSPD_NotificationBuilder root_actv_notificationBuilder = new ROOT_SSPD_NotificationBuilder(imdgProviderMock);
File outputFile = root_actv_notificationBuilder.buildNotification(777L);
outputFile.delete();
}
}