Сделат дополнительную настройку, поправил коды ошибок, добавил тестовый модуль(и удалил дублирующие их конфиги)
This commit is contained in:
parent
02c5b2a176
commit
5096a2eb73
5 changed files with 66 additions and 127 deletions
|
|
@ -36,6 +36,20 @@
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
<artifactId>classes</artifactId>
|
<artifactId>classes</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
|
<artifactId>clearing-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
|
<artifactId>security-util</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
|
<artifactId>cleaning-builders</artifactId>
|
||||||
|
<version>SPCEX-1.0.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
|
@ -51,6 +65,11 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
|
<artifactId>test-clearing</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
@ -78,6 +97,23 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.21.0</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||||
|
<version>1.2.0-M1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.2.0-M1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ package ru.spcex.clearing.scheduler.error;
|
||||||
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
||||||
|
|
||||||
public enum ValidationError implements IErrorEnumId {
|
public enum ValidationError implements IErrorEnumId {
|
||||||
WrongDictionaryValue(10003L),
|
UserVerifyDenial(18001L),
|
||||||
EmptyRequiredValue(10002L),
|
EmptyRequiredValue(18002L),
|
||||||
|
WrongDictionaryValue(18003L),
|
||||||
WrongEnumValue(777L), //todo set code
|
WrongEnumValue(777L), //todo set code
|
||||||
RecordNotFound(7006L),
|
RecordNotFound(7006L),
|
||||||
TaskForPastDate(7010L),
|
TaskForPastDate(7010L),
|
||||||
|
|
@ -12,8 +13,7 @@ public enum ValidationError implements IErrorEnumId {
|
||||||
CompanyNotFound(7014L),
|
CompanyNotFound(7014L),
|
||||||
SecurityNotFound(7012L),
|
SecurityNotFound(7012L),
|
||||||
CompanyNotActive(7015L),
|
CompanyNotActive(7015L),
|
||||||
SecurityNotActive(7013L)
|
SecurityNotActive(7013L);
|
||||||
;
|
|
||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,42 @@ import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Проверка поля с LocalTime. Условие проверки: проверяемое время >= текущее время
|
* Проверка поля с LocalTime. Условие проверки: проверяемое время >= текущее время
|
||||||
|
*
|
||||||
* @param <R> Класс проверяемого объекта
|
* @param <R> Класс проверяемого объекта
|
||||||
*/
|
*/
|
||||||
public record TimeNotBeforeRule<R>(String fieldName, Function<R, LocalTime> getter, boolean required) implements IValidationRule<ImdgValidationContext<R>> {
|
public record TimeNotBeforeRule<R>(String fieldName,
|
||||||
|
Function<R, LocalTime> getter,
|
||||||
|
boolean required,
|
||||||
|
boolean isToday) implements IValidationRule<ImdgValidationContext<R>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fieldName Название поля класса, используется для передачи ошибки
|
* @param fieldName Название поля класса, используется для передачи ошибки
|
||||||
* @param getter Метод получения проверяемого времени
|
* @param getter Метод получения проверяемого времени
|
||||||
* @param required Флаг обязательности поля
|
* @param required Флаг обязательности поля
|
||||||
* @param <R> Класс проверяемого объекта
|
* @param <R> Класс проверяемого объекта
|
||||||
|
* @param isToday Флаг что дата сегодняшняя
|
||||||
*/
|
*/
|
||||||
public static <R> TimeNotBeforeRule<R> instance(String fieldName, Function<R, LocalTime> getter, boolean required) {
|
public static <R> TimeNotBeforeRule<R> instance(String fieldName, Function<R, LocalTime> getter, boolean required, boolean isToday) {
|
||||||
return new TimeNotBeforeRule<>(fieldName, getter, required);
|
return new TimeNotBeforeRule<>(fieldName, getter, required, isToday);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fieldName Название поля класса, используется для передачи ошибки
|
* @param fieldName Название поля класса, используется для передачи ошибки
|
||||||
* @param getter Метод получения проверяемого времени
|
* @param getter Метод получения проверяемого времени
|
||||||
* @param <R> Класс проверяемого объекта
|
* @param required Флаг обязательности поля
|
||||||
|
* @param <R> Класс проверяемого объекта
|
||||||
|
*/
|
||||||
|
public static <R> TimeNotBeforeRule<R> instance(String fieldName, Function<R, LocalTime> getter, boolean required) {
|
||||||
|
return new TimeNotBeforeRule<>(fieldName, getter, required, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fieldName Название поля класса, используется для передачи ошибки
|
||||||
|
* @param getter Метод получения проверяемого времени
|
||||||
|
* @param <R> Класс проверяемого объекта
|
||||||
*/
|
*/
|
||||||
public static <R> TimeNotBeforeRule<R> instance(String fieldName, Function<R, LocalTime> getter) {
|
public static <R> TimeNotBeforeRule<R> instance(String fieldName, Function<R, LocalTime> getter) {
|
||||||
return new TimeNotBeforeRule<>(fieldName, getter, true);
|
return new TimeNotBeforeRule<>(fieldName, getter, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -39,7 +54,8 @@ public record TimeNotBeforeRule<R>(String fieldName, Function<R, LocalTime> gett
|
||||||
R validatedObject = context.getValidatedObject();
|
R validatedObject = context.getValidatedObject();
|
||||||
LocalTime date = getter.apply(validatedObject);
|
LocalTime date = getter.apply(validatedObject);
|
||||||
if (date == null) return required ? of(ValidationError.EmptyRequiredValue, fieldName) : Optional.empty();
|
if (date == null) return required ? of(ValidationError.EmptyRequiredValue, fieldName) : Optional.empty();
|
||||||
if (date.isBefore(LocalTime.now())) return of(ValidationError.TaskForPastTime, fieldName);
|
if (date.isBefore(LocalTime.now()))
|
||||||
|
return isToday ? of(ValidationError.TaskForPastTime, fieldName) : Optional.empty();
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
package ru.specx.clearing.scheduler.config;
|
|
||||||
|
|
||||||
import com.hazelcast.config.*;
|
|
||||||
import com.hazelcast.core.Hazelcast;
|
|
||||||
import com.hazelcast.core.HazelcastInstance;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
|
||||||
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class HazelcastServiceTestConfiguration {
|
|
||||||
private HazelcastInstance hazelcastInstance;
|
|
||||||
|
|
||||||
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
|
|
||||||
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
|
|
||||||
if (maxPoolSz > 2) {
|
|
||||||
pool.setKeepAliveSeconds(60);
|
|
||||||
pool.setAllowCoreThreadTimeOut(true);
|
|
||||||
}
|
|
||||||
pool.setCorePoolSize(maxPoolSz);
|
|
||||||
pool.setWaitForTasksToCompleteOnShutdown(waitForCompletion);
|
|
||||||
return pool;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "hazelcastServiceTest")
|
|
||||||
public HazelcastService hazelcastService(@Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer, @Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter, HazelcastClientParams params) {
|
|
||||||
Config cfg = new Config();
|
|
||||||
cfg.setInstanceName("localhost");
|
|
||||||
|
|
||||||
NetworkConfig networkConfig = new NetworkConfig();
|
|
||||||
JoinConfig joinConfig = new JoinConfig();
|
|
||||||
joinConfig.setMulticastConfig(new MulticastConfig().setEnabled(false));
|
|
||||||
joinConfig.setTcpIpConfig(new TcpIpConfig().setEnabled(true).setMembers(List.of("127.0.0.1")));
|
|
||||||
networkConfig.setJoin(joinConfig);
|
|
||||||
cfg.setNetworkConfig(networkConfig);
|
|
||||||
hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
|
|
||||||
HazelcastHelper.imdgSystem_setStorageState(true, hazelcastInstance);
|
|
||||||
return new HazelcastService(taskExecutorHazelcastClientInitializer, taskExecutorIdGeneratorAwaiter, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "taskExecutorHazelcastClientInitializer")
|
|
||||||
public ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer() {
|
|
||||||
return createThreadPoolTaskExecutor(1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "taskExecutorIdGeneratorAwaiter")
|
|
||||||
public ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter() {
|
|
||||||
return createThreadPoolTaskExecutor(1, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "hazelcastClientParams")
|
|
||||||
public HazelcastClientParams getHazelcastClientParams() {
|
|
||||||
HazelcastClientParams params = new HazelcastClientParams();
|
|
||||||
params.setLogin("dev");
|
|
||||||
params.setPassword("dev-pass");
|
|
||||||
params.setClusterMembers("127.0.0.1");
|
|
||||||
params.setInstanceName("hzTestClient" + new Random().nextInt());
|
|
||||||
params.setNearCacheConfig(new NearCacheConfig());
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public IMessageResolver messageResolver() {
|
|
||||||
return new SimpleMessageResolver();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package ru.specx.clearing.scheduler.utils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory for creating test matchers.
|
|
||||||
* <p>
|
|
||||||
* Comparing actual and expected objects via AssertJ
|
|
||||||
*/
|
|
||||||
public class MatcherFactory {
|
|
||||||
|
|
||||||
public static <T> Matcher<T> usingIgnoringFieldsComparator(String... fieldsToIgnore) {
|
|
||||||
return new Matcher<>(fieldsToIgnore);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Matcher<T> {
|
|
||||||
private final String[] fieldsToIgnore;
|
|
||||||
|
|
||||||
private Matcher(String... fieldsToIgnore) {
|
|
||||||
this.fieldsToIgnore = fieldsToIgnore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertMatch(T actual, T expected) {
|
|
||||||
assertThat(actual).usingRecursiveComparison().ignoringFields(fieldsToIgnore).isEqualTo(expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public final void assertMatch(Iterable<T> actual, T... expected) {
|
|
||||||
assertMatch(actual, Arrays.asList(expected));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertMatch(Iterable<T> actual, Iterable<T> expected) {
|
|
||||||
assertThat(actual).usingRecursiveFieldByFieldElementComparatorIgnoringFields(fieldsToIgnore).isEqualTo(expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue