From 12e8960edf290a63da46ee36f68b7aee5b34575b Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Tue, 3 Oct 2023 22:34:30 +0300
Subject: [PATCH 1/7] Introduce spring config mapping mode
---
apps/README.adoc | 5 ----
.../smecalculus/bezmen/construction/App.java | 2 +-
.../SepulkaController.java | 2 +-
apps/foo/src/main/resources/application.yaml | 6 +++++
.../construction/SepulkaClientBeans.java | 2 +-
docs/pipeline.adoc | 3 ---
libs/essentials/pom.xml | 9 +++++++
.../ConfigKeeperSpringConfig.java | 13 ++++++++++
.../configuration/ConfigMappingMode.java | 6 +++++
...onfigMode.java => ConfigProtocolMode.java} | 2 +-
.../ConditionalOnConfigMappingMode.java | 15 +++++++++++
.../ConditionalOnConfigProtocolMode.java | 15 +++++++++++
.../bezmen/construction/ConfigBeans.java | 23 +++++++++++-----
.../ConfigMappingModeCondition.java | 26 +++++++++++++++++++
.../ConfigProtocolModeCondition.java | 26 +++++++++++++++++++
.../configuration/MessageMappingPropsEg.java | 5 ++--
.../bezmen/configuration/MessagingConfig.java | 5 ----
.../configuration/MessagingConfigImpl.java | 21 ---------------
.../construction/MessagingConfigBeans.java | 19 +++++++-------
.../src/main/resources/messaging.yaml | 6 +++++
.../configuration/MessagingConfigImplIT.java | 3 ---
.../MessagingConfigBeansIT.java} | 15 ++++-------
.../bezmen/configuration/StorageConfig.java | 5 ----
.../configuration/StorageConfigImpl.java | 21 ---------------
.../construction/StorageConfigBeans.java | 19 +++++++-------
libs/storage/src/main/resources/storage.yaml | 14 ++++++++++
.../configuration/StorageConfigImplIT.java | 3 ---
.../configuration/StorageConfigImplTest.java | 3 ---
.../StorageConfigBeansIT.java} | 15 ++++-------
.../StorageConfigBeansTest.java} | 16 ++++++++----
30 files changed, 201 insertions(+), 124 deletions(-)
delete mode 100644 apps/README.adoc
rename apps/foo/src/main/java/smecalculus/bezmen/messaging/{springwebmvc => springmvc}/SepulkaController.java (95%)
create mode 100644 apps/foo/src/main/resources/application.yaml
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMappingMode.java
rename libs/essentials/src/main/java/smecalculus/bezmen/configuration/{ConfigMode.java => ConfigProtocolMode.java} (64%)
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigMappingMode.java
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigProtocolMode.java
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
delete mode 100644 libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfig.java
delete mode 100644 libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfigImpl.java
create mode 100644 libs/messaging/src/main/resources/messaging.yaml
delete mode 100644 libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigImplIT.java
rename libs/messaging/src/test/java/smecalculus/bezmen/{configuration/MessagingConfigIT.java => construction/MessagingConfigBeansIT.java} (64%)
delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfig.java
delete mode 100644 libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfigImpl.java
create mode 100644 libs/storage/src/main/resources/storage.yaml
delete mode 100644 libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplIT.java
delete mode 100644 libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplTest.java
rename libs/storage/src/test/java/smecalculus/bezmen/{configuration/StorageConfigIT.java => construction/StorageConfigBeansIT.java} (64%)
rename libs/storage/src/test/java/smecalculus/bezmen/{configuration/StorageConfigTest.java => construction/StorageConfigBeansTest.java} (62%)
diff --git a/apps/README.adoc b/apps/README.adoc
deleted file mode 100644
index 9069af3f..00000000
--- a/apps/README.adoc
+++ /dev/null
@@ -1,5 +0,0 @@
-Приложения решения или инструменты времени эксплуатации
-
-=== Foo
-
-TBD
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
index 7c63c018..f6250dc9 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
@@ -16,7 +16,7 @@
import smecalculus.bezmen.messaging.SepulkaMsgMapper;
import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl;
import smecalculus.bezmen.messaging.client.SepulkaClient;
-import smecalculus.bezmen.messaging.springwebmvc.SepulkaController;
+import smecalculus.bezmen.messaging.springmvc.SepulkaController;
import smecalculus.bezmen.storage.SepulkaDao;
import smecalculus.bezmen.storage.SepulkaDaoMyBatis;
import smecalculus.bezmen.storage.SepulkaDaoSpringData;
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
similarity index 95%
rename from apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java
rename to apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
index 1902f008..786a97f9 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
@@ -1,4 +1,4 @@
-package smecalculus.bezmen.messaging.springwebmvc;
+package smecalculus.bezmen.messaging.springmvc;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
diff --git a/apps/foo/src/main/resources/application.yaml b/apps/foo/src/main/resources/application.yaml
new file mode 100644
index 00000000..dc5a7746
--- /dev/null
+++ b/apps/foo/src/main/resources/application.yaml
@@ -0,0 +1,6 @@
+---
+spring:
+ config:
+ import:
+ - classpath:messaging.yaml
+ - classpath:storage.yaml
diff --git a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
index 134b606a..55c4a9dc 100644
--- a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
+++ b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
@@ -15,7 +15,7 @@
import smecalculus.bezmen.messaging.SepulkaMsgMapper;
import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl;
import smecalculus.bezmen.messaging.client.SepulkaClient;
-import smecalculus.bezmen.messaging.springwebmvc.SepulkaController;
+import smecalculus.bezmen.messaging.springmvc.SepulkaController;
import smecalculus.bezmen.validation.EdgeValidator;
@Import(ValidationBeans.class)
diff --git a/docs/pipeline.adoc b/docs/pipeline.adoc
index 69aeb6c8..2286dec7 100644
--- a/docs/pipeline.adoc
+++ b/docs/pipeline.adoc
@@ -76,7 +76,4 @@
. Релизная сборка
. Параллелизация модульных тестов
. Построение дерева хешей (взглянуть критически)
-. Версионирование библиотек и приложений (взглянуть критически)
-. Локальные проверки в удаленном репозитории
-. Чистка артефактов в удаленном репозитории
. Поддержка нескольких версий Java
diff --git a/libs/essentials/pom.xml b/libs/essentials/pom.xml
index 82257c35..8faf818d 100644
--- a/libs/essentials/pom.xml
+++ b/libs/essentials/pom.xml
@@ -48,6 +48,15 @@
com.typesafe
config
+
+ org.yaml
+ snakeyaml
+
+
+ org.springframework.boot
+ spring-boot
+ true
+
org.slf4j
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java
new file mode 100644
index 00000000..7ec0f62b
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java
@@ -0,0 +1,13 @@
+package smecalculus.bezmen.configuration;
+
+import org.springframework.boot.context.properties.bind.Binder;
+import org.springframework.core.env.Environment;
+
+public record ConfigKeeperSpringConfig(Environment environment) implements ConfigKeeper {
+
+ @Override
+ public T read(String key, Class type) {
+ Binder binder = Binder.get(environment);
+ return binder.bind(key, type).get();
+ }
+}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMappingMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMappingMode.java
new file mode 100644
index 00000000..6b93eca4
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMappingMode.java
@@ -0,0 +1,6 @@
+package smecalculus.bezmen.configuration;
+
+public enum ConfigMappingMode {
+ LIGHTBEND_CONFIG,
+ SPRING_CONFIG
+}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigProtocolMode.java
similarity index 64%
rename from libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMode.java
rename to libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigProtocolMode.java
index 99106a20..086768aa 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigMode.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigProtocolMode.java
@@ -1,5 +1,5 @@
package smecalculus.bezmen.configuration;
-public enum ConfigMode {
+public enum ConfigProtocolMode {
FILE_SYSTEM
}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigMappingMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigMappingMode.java
new file mode 100644
index 00000000..d92a2be1
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigMappingMode.java
@@ -0,0 +1,15 @@
+package smecalculus.bezmen.construction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.springframework.context.annotation.Conditional;
+import smecalculus.bezmen.configuration.ConfigMappingMode;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Conditional(ConfigMappingModeCondition.class)
+public @interface ConditionalOnConfigMappingMode {
+ ConfigMappingMode value();
+}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigProtocolMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigProtocolMode.java
new file mode 100644
index 00000000..ef188f0a
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnConfigProtocolMode.java
@@ -0,0 +1,15 @@
+package smecalculus.bezmen.construction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.springframework.context.annotation.Conditional;
+import smecalculus.bezmen.configuration.ConfigProtocolMode;
+
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Conditional(ConfigProtocolModeCondition.class)
+public @interface ConditionalOnConfigProtocolMode {
+ ConfigProtocolMode value();
+}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java
index abec626a..85c837b9 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java
@@ -1,20 +1,31 @@
package smecalculus.bezmen.construction;
+import static smecalculus.bezmen.configuration.ConfigMappingMode.LIGHTBEND_CONFIG;
+import static smecalculus.bezmen.configuration.ConfigMappingMode.SPRING_CONFIG;
+import static smecalculus.bezmen.configuration.ConfigProtocolMode.FILE_SYSTEM;
+
import com.typesafe.config.ConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
import smecalculus.bezmen.configuration.ConfigKeeper;
import smecalculus.bezmen.configuration.ConfigKeeperLightbendConfig;
-import smecalculus.bezmen.configuration.ConfigMode;
+import smecalculus.bezmen.configuration.ConfigKeeperSpringConfig;
@Configuration(proxyBeanMethods = false)
public class ConfigBeans {
@Bean
- ConfigKeeper configKeeper() {
- String configMode = System.getProperty("bezmen.config.mode", ConfigMode.FILE_SYSTEM.name());
- return switch (ConfigMode.valueOf(configMode.toUpperCase())) {
- case FILE_SYSTEM -> new ConfigKeeperLightbendConfig(ConfigFactory.load());
- };
+ @ConditionalOnConfigProtocolMode(FILE_SYSTEM)
+ @ConditionalOnConfigMappingMode(LIGHTBEND_CONFIG)
+ ConfigKeeper configKeeperLightbendConfig() {
+ return new ConfigKeeperLightbendConfig(ConfigFactory.load());
+ }
+
+ @Bean
+ @ConditionalOnConfigProtocolMode(FILE_SYSTEM)
+ @ConditionalOnConfigMappingMode(SPRING_CONFIG)
+ ConfigKeeper configKeeperSpringConfig(Environment environment) {
+ return new ConfigKeeperSpringConfig(environment);
}
}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
new file mode 100644
index 00000000..1488ba13
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
@@ -0,0 +1,26 @@
+package smecalculus.bezmen.construction;
+
+import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN;
+
+import java.util.Map;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.ConfigurationCondition;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import smecalculus.bezmen.configuration.ConfigMappingMode;
+
+class ConfigMappingModeCondition implements ConfigurationCondition {
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ Map attributes =
+ metadata.getAnnotationAttributes(ConditionalOnConfigMappingMode.class.getName());
+ ConfigMappingMode expectedMode = (ConfigMappingMode) attributes.get("value");
+ String actualMode = System.getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name());
+ return expectedMode.name().equalsIgnoreCase(actualMode);
+ }
+
+ @Override
+ public ConfigurationPhase getConfigurationPhase() {
+ return REGISTER_BEAN;
+ }
+}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
new file mode 100644
index 00000000..4822f77f
--- /dev/null
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
@@ -0,0 +1,26 @@
+package smecalculus.bezmen.construction;
+
+import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN;
+
+import java.util.Map;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.ConfigurationCondition;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import smecalculus.bezmen.configuration.ConfigProtocolMode;
+
+class ConfigProtocolModeCondition implements ConfigurationCondition {
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ Map attributes =
+ metadata.getAnnotationAttributes(ConditionalOnConfigProtocolMode.class.getName());
+ ConfigProtocolMode expectedMode = (ConfigProtocolMode) attributes.get("value");
+ String actualMode = System.getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name());
+ return expectedMode.name().equalsIgnoreCase(actualMode);
+ }
+
+ @Override
+ public ConfigurationPhase getConfigurationPhase() {
+ return REGISTER_BEAN;
+ }
+}
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java
index b888625b..2827d7a0 100644
--- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java
+++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java
@@ -1,12 +1,13 @@
package smecalculus.bezmen.configuration;
-import static java.util.Collections.singleton;
import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_MVC;
+import java.util.Set;
+
public class MessageMappingPropsEg {
public static class Builders {
public static MessageMappingProps.Builder messageMappingProps() {
- return MessageMappingProps.builder().mappingModes(singleton(SPRING_MVC));
+ return MessageMappingProps.builder().mappingModes(Set.of(SPRING_MVC));
}
}
}
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfig.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfig.java
deleted file mode 100644
index 78354377..00000000
--- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfig.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-public interface MessagingConfig {
- MessagingProps getMessagingProps();
-}
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfigImpl.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfigImpl.java
deleted file mode 100644
index a806286c..00000000
--- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingConfigImpl.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-import lombok.NonNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import smecalculus.bezmen.validation.EdgeValidator;
-
-public record MessagingConfigImpl(
- @NonNull ConfigKeeper keeper, @NonNull EdgeValidator validator, @NonNull MessagingCfgMapper mapper)
- implements MessagingConfig {
-
- private static final Logger LOG = LoggerFactory.getLogger(MessagingConfigImpl.class);
-
- @Override
- public MessagingProps getMessagingProps() {
- MessagingPropsCfg propsCfg = keeper.read("bezmen.messaging", MessagingPropsCfg.class);
- validator.validate(propsCfg);
- LOG.info("Read {}", propsCfg);
- return mapper.toDomain(propsCfg);
- }
-}
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
index 520139c1..35265465 100644
--- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
+++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
@@ -1,30 +1,31 @@
package smecalculus.bezmen.construction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import smecalculus.bezmen.configuration.ConfigKeeper;
import smecalculus.bezmen.configuration.MessagingCfgMapper;
import smecalculus.bezmen.configuration.MessagingCfgMapperImpl;
-import smecalculus.bezmen.configuration.MessagingConfig;
-import smecalculus.bezmen.configuration.MessagingConfigImpl;
import smecalculus.bezmen.configuration.MessagingProps;
+import smecalculus.bezmen.configuration.MessagingPropsCfg;
import smecalculus.bezmen.validation.EdgeValidator;
@Configuration(proxyBeanMethods = false)
public class MessagingConfigBeans {
+ private static final Logger LOG = LoggerFactory.getLogger(MessagingConfigBeans.class);
+
@Bean
MessagingCfgMapper messagingCfgMapper() {
return new MessagingCfgMapperImpl();
}
@Bean
- MessagingConfig messagingConfig(ConfigKeeper keeper, EdgeValidator validator, MessagingCfgMapper mapper) {
- return new MessagingConfigImpl(keeper, validator, mapper);
- }
-
- @Bean
- MessagingProps messagingProps(MessagingConfig config) {
- return config.getMessagingProps();
+ MessagingProps messagingProps(ConfigKeeper keeper, EdgeValidator validator, MessagingCfgMapper mapper) {
+ MessagingPropsCfg propsCfg = keeper.read("bezmen.messaging", MessagingPropsCfg.class);
+ validator.validate(propsCfg);
+ LOG.info("Read {}", propsCfg);
+ return mapper.toDomain(propsCfg);
}
}
diff --git a/libs/messaging/src/main/resources/messaging.yaml b/libs/messaging/src/main/resources/messaging.yaml
new file mode 100644
index 00000000..2bdc7d5b
--- /dev/null
+++ b/libs/messaging/src/main/resources/messaging.yaml
@@ -0,0 +1,6 @@
+bezmen:
+ messaging:
+ protocol:
+ modes: [http]
+ mapping:
+ modes: [spring_mvc]
diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigImplIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigImplIT.java
deleted file mode 100644
index 159e3c5f..00000000
--- a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigImplIT.java
+++ /dev/null
@@ -1,3 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-class MessagingConfigImplIT extends MessagingConfigIT {}
diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
similarity index 64%
rename from libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java
rename to libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
index c95a9493..5a929f5d 100644
--- a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java
+++ b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
@@ -1,4 +1,4 @@
-package smecalculus.bezmen.configuration;
+package smecalculus.bezmen.construction;
import static org.assertj.core.api.Assertions.assertThat;
import static smecalculus.bezmen.configuration.MessagingPropsEg.Builders.messagingProps;
@@ -8,23 +8,18 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
-import smecalculus.bezmen.construction.ConfigBeans;
-import smecalculus.bezmen.construction.MessagingConfigBeans;
-import smecalculus.bezmen.construction.ValidationBeans;
+import smecalculus.bezmen.configuration.MessagingProps;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ConfigBeans.class, ValidationBeans.class, MessagingConfigBeans.class})
-abstract class MessagingConfigIT {
-
- @Autowired
- MessagingConfig messagingConfig;
+class MessagingConfigBeansIT {
@Test
- void defaultConfigShouldBeBackwardCompatible() {
+ void defaultConfigShouldBeBackwardCompatible(@Autowired MessagingProps actualProps) {
// given
MessagingProps expectedProps = messagingProps().build();
// when
- MessagingProps actualProps = messagingConfig.getMessagingProps();
+ // construction
// then
assertThat(actualProps).isEqualTo(expectedProps);
}
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfig.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfig.java
deleted file mode 100644
index 159b41fb..00000000
--- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfig.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-public interface StorageConfig {
- StorageProps getStorageProps();
-}
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfigImpl.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfigImpl.java
deleted file mode 100644
index 1ec3263b..00000000
--- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageConfigImpl.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-import lombok.NonNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import smecalculus.bezmen.validation.EdgeValidator;
-
-public record StorageConfigImpl(
- @NonNull ConfigKeeper configKeeper, @NonNull EdgeValidator validator, @NonNull StorageCfgMapper mapper)
- implements StorageConfig {
-
- private static final Logger LOG = LoggerFactory.getLogger(StorageConfigImpl.class);
-
- @Override
- public StorageProps getStorageProps() {
- StoragePropsCfg propsCfg = configKeeper.read("bezmen.storage", StoragePropsCfg.class);
- validator.validate(propsCfg);
- LOG.info("Read {}", propsCfg);
- return mapper.toDomain(propsCfg);
- }
-}
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
index 9c5ddde8..6958fe7b 100644
--- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
+++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
@@ -1,30 +1,31 @@
package smecalculus.bezmen.construction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import smecalculus.bezmen.configuration.ConfigKeeper;
import smecalculus.bezmen.configuration.StorageCfgMapper;
import smecalculus.bezmen.configuration.StorageCfgMapperImpl;
-import smecalculus.bezmen.configuration.StorageConfig;
-import smecalculus.bezmen.configuration.StorageConfigImpl;
import smecalculus.bezmen.configuration.StorageProps;
+import smecalculus.bezmen.configuration.StoragePropsCfg;
import smecalculus.bezmen.validation.EdgeValidator;
@Configuration(proxyBeanMethods = false)
public class StorageConfigBeans {
+ private static final Logger LOG = LoggerFactory.getLogger(StorageConfigBeans.class);
+
@Bean
StorageCfgMapper storageCfgMapper() {
return new StorageCfgMapperImpl();
}
@Bean
- StorageConfig storageConfig(ConfigKeeper keeper, EdgeValidator validator, StorageCfgMapper mapper) {
- return new StorageConfigImpl(keeper, validator, mapper);
- }
-
- @Bean
- StorageProps storageProps(StorageConfig config) {
- return config.getStorageProps();
+ StorageProps storageProps(ConfigKeeper keeper, EdgeValidator validator, StorageCfgMapper mapper) {
+ StoragePropsCfg propsCfg = keeper.read("bezmen.storage", StoragePropsCfg.class);
+ validator.validate(propsCfg);
+ LOG.info("Read {}", propsCfg);
+ return mapper.toDomain(propsCfg);
}
}
diff --git a/libs/storage/src/main/resources/storage.yaml b/libs/storage/src/main/resources/storage.yaml
new file mode 100644
index 00000000..434d015d
--- /dev/null
+++ b/libs/storage/src/main/resources/storage.yaml
@@ -0,0 +1,14 @@
+bezmen:
+ storage:
+ protocol:
+ mode: h2
+ h2:
+ url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
+ username: sa
+ password: sa
+ postgres:
+ url: jdbc:postgresql://localhost:5432/bezmen
+ username: bezmen
+ password: bezmen
+ mapping:
+ mode: spring_data
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplIT.java b/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplIT.java
deleted file mode 100644
index 89bd661d..00000000
--- a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplIT.java
+++ /dev/null
@@ -1,3 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-class StorageConfigImplIT extends StorageConfigIT {}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplTest.java b/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplTest.java
deleted file mode 100644
index ca8d40aa..00000000
--- a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigImplTest.java
+++ /dev/null
@@ -1,3 +0,0 @@
-package smecalculus.bezmen.configuration;
-
-class StorageConfigImplTest extends StorageConfigTest {}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
similarity index 64%
rename from libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java
rename to libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
index fc4abfa2..f0381447 100644
--- a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
@@ -1,4 +1,4 @@
-package smecalculus.bezmen.configuration;
+package smecalculus.bezmen.construction;
import static org.assertj.core.api.Assertions.assertThat;
import static smecalculus.bezmen.configuration.StoragePropsEg.Builders.storageProps;
@@ -8,23 +8,18 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
-import smecalculus.bezmen.construction.ConfigBeans;
-import smecalculus.bezmen.construction.StorageConfigBeans;
-import smecalculus.bezmen.construction.ValidationBeans;
+import smecalculus.bezmen.configuration.StorageProps;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ConfigBeans.class, ValidationBeans.class, StorageConfigBeans.class})
-abstract class StorageConfigIT {
-
- @Autowired
- StorageConfig storageConfig;
+class StorageConfigBeansIT {
@Test
- void defaultConfigShouldBeBackwardCompatible() {
+ void defaultConfigShouldBeBackwardCompatible(@Autowired StorageProps actualProps) {
// given
StorageProps expectedProps = storageProps().build();
// when
- StorageProps actualProps = storageConfig.getStorageProps();
+ // construction
// then
assertThat(actualProps).isEqualTo(expectedProps);
}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigTest.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
similarity index 62%
rename from libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigTest.java
rename to libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
index 5e2ac79d..b01f3867 100644
--- a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigTest.java
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
@@ -1,4 +1,4 @@
-package smecalculus.bezmen.configuration;
+package smecalculus.bezmen.construction;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -7,19 +7,25 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import smecalculus.bezmen.configuration.ConfigKeeper;
+import smecalculus.bezmen.configuration.StorageCfgMapper;
+import smecalculus.bezmen.configuration.StorageCfgMapperImpl;
+import smecalculus.bezmen.configuration.StoragePropsCfg;
import smecalculus.bezmen.validation.EdgeValidator;
-abstract class StorageConfigTest {
+class StorageConfigBeansTest {
- private StorageConfig storageConfig;
+ private StorageConfigBeans configBeans;
private EdgeValidator validatorMock;
private ConfigKeeper keeperMock;
+ private StorageCfgMapper mapper;
@BeforeEach
void setUp() {
+ configBeans = new StorageConfigBeans();
validatorMock = mock(EdgeValidator.class);
keeperMock = mock(ConfigKeeper.class);
- storageConfig = new StorageConfigImpl(keeperMock, validatorMock, new StorageCfgMapperImpl());
+ mapper = new StorageCfgMapperImpl();
}
@Test
@@ -29,7 +35,7 @@ void shouldValidateConf() {
// and
when(keeperMock.read("bezmen.storage", StoragePropsCfg.class)).thenReturn(expectedStorageProps);
// when
- storageConfig.getStorageProps();
+ configBeans.storageProps(keeperMock, validatorMock, mapper);
// then
verify(validatorMock).validate(expectedStorageProps);
}
From 88da27885b588abc5c045e8f6bc504000585101c Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 09:01:32 +0300
Subject: [PATCH 2/7] Spring config in turing prefs
---
.dx/tasks/solution/build.yml | 17 ++++++++++++++++-
apps/foo/Dockerfile | 8 ++++----
.../ConfigMappingModeCondition.java | 2 +-
.../ConfigProtocolModeCondition.java | 2 +-
.../src/main/resources/messaging.yaml | 1 +
libs/storage/src/main/resources/storage.yaml | 1 +
solutions/basis/compose.yml | 7 +++++--
solutions/basis/turing.conf | 18 ------------------
solutions/basis/turing.yaml | 12 ++++++++++++
9 files changed, 41 insertions(+), 27 deletions(-)
delete mode 100644 solutions/basis/turing.conf
create mode 100644 solutions/basis/turing.yaml
diff --git a/.dx/tasks/solution/build.yml b/.dx/tasks/solution/build.yml
index 899634d4..d257d1ef 100644
--- a/.dx/tasks/solution/build.yml
+++ b/.dx/tasks/solution/build.yml
@@ -11,6 +11,13 @@
recurse: true
- name: Build spec
+ vars:
+ config_files:
+ turing: application.yaml
+ church: application.conf
+ config_mapping_modes:
+ turing: spring_config
+ church: lightbend_config
ansible.builtin.command:
cmd: >
docker compose
@@ -27,10 +34,18 @@
SCHEMA_IMAGE: "{{ schema_images.postgres }}"
FOO_TAG: "{{ hostvars.app.image_cids.foo[:7] }}"
FOO_IMAGE: "{{ app_images.foo }}"
+ CONFIG_FILE_NAME: "{{ config_files[prefs] }}"
+ CONFIG_MAPPING_MODE: "{{ config_mapping_modes[prefs] }}"
changed_when: true
- name: Build conf
+ vars:
+ config_extensions:
+ turing: yaml
+ church: conf
ansible.builtin.command:
- cmd: cp basis/{{ prefs }}.conf target/context/bezmen.conf
+ cmd: >
+ cp basis/{{ prefs }}.{{ config_extensions[prefs] }}
+ target/context/application.{{ config_extensions[prefs] }}
chdir: "{{ playbook_dir }}/../solutions"
changed_when: true
diff --git a/apps/foo/Dockerfile b/apps/foo/Dockerfile
index 073dd855..d6b5f175 100644
--- a/apps/foo/Dockerfile
+++ b/apps/foo/Dockerfile
@@ -2,10 +2,10 @@ FROM eclipse-temurin:17-jdk-alpine
RUN addgroup -S bezmen && adduser -S bezmen -G bezmen
USER bezmen:bezmen
WORKDIR /home/bezmen
-COPY libs foo/libs
-COPY app-foo*.jar foo/app.jar
+COPY libs libs
+COPY app*.jar app.jar
ENTRYPOINT [ \
- "java", "-cp", "foo/app.jar:foo/libs/*", \
- "-Dconfig.file=foo/application.conf", \
+ "java", "-cp", "app.jar:libs/*", \
+ "-Dconfig.file=${CONFIG_FILE_NAME}", \
"smecalculus.bezmen.construction.App" \
]
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
index 1488ba13..8b415ecf 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
@@ -15,7 +15,7 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
Map attributes =
metadata.getAnnotationAttributes(ConditionalOnConfigMappingMode.class.getName());
ConfigMappingMode expectedMode = (ConfigMappingMode) attributes.get("value");
- String actualMode = System.getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name());
+ String actualMode = context.getEnvironment().getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name());
return expectedMode.name().equalsIgnoreCase(actualMode);
}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
index 4822f77f..f454a06e 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
@@ -15,7 +15,7 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
Map attributes =
metadata.getAnnotationAttributes(ConditionalOnConfigProtocolMode.class.getName());
ConfigProtocolMode expectedMode = (ConfigProtocolMode) attributes.get("value");
- String actualMode = System.getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name());
+ String actualMode = context.getEnvironment().getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name());
return expectedMode.name().equalsIgnoreCase(actualMode);
}
diff --git a/libs/messaging/src/main/resources/messaging.yaml b/libs/messaging/src/main/resources/messaging.yaml
index 2bdc7d5b..aa960877 100644
--- a/libs/messaging/src/main/resources/messaging.yaml
+++ b/libs/messaging/src/main/resources/messaging.yaml
@@ -1,3 +1,4 @@
+---
bezmen:
messaging:
protocol:
diff --git a/libs/storage/src/main/resources/storage.yaml b/libs/storage/src/main/resources/storage.yaml
index 434d015d..0c2d3567 100644
--- a/libs/storage/src/main/resources/storage.yaml
+++ b/libs/storage/src/main/resources/storage.yaml
@@ -1,3 +1,4 @@
+---
bezmen:
storage:
protocol:
diff --git a/solutions/basis/compose.yml b/solutions/basis/compose.yml
index d45dc5b6..2237356f 100644
--- a/solutions/basis/compose.yml
+++ b/solutions/basis/compose.yml
@@ -7,7 +7,7 @@ networks:
configs:
bezmen:
name: bezmen
- file: ./bezmen.conf
+ file: ./${CONFIG_FILE_NAME}
services:
db:
@@ -85,7 +85,10 @@ services:
- 8080:8080
configs:
- source: bezmen
- target: /home/bezmen/foo/application.conf
+ target: /home/bezmen/${CONFIG_FILE_NAME}
+ command: >
+ --bezmen.config.mapping.mode=${CONFIG_MAPPING_MODE}
+ --spring.config.location=classpath:application.yaml,optional:file:${CONFIG_FILE_NAME}
depends_on:
schema-owner:
condition: service_completed_successfully
diff --git a/solutions/basis/turing.conf b/solutions/basis/turing.conf
deleted file mode 100644
index ed869071..00000000
--- a/solutions/basis/turing.conf
+++ /dev/null
@@ -1,18 +0,0 @@
-bezmen {
- messaging {
- mapping {
- modes = [spring_mvc, spring_management]
- }
- }
- storage {
- protocol {
- mode = postgres
- postgres {
- url = "jdbc:postgresql://db:5432/bezmen"
- }
- }
- mapping {
- mode = spring_data
- }
- }
-}
diff --git a/solutions/basis/turing.yaml b/solutions/basis/turing.yaml
new file mode 100644
index 00000000..b8d07045
--- /dev/null
+++ b/solutions/basis/turing.yaml
@@ -0,0 +1,12 @@
+---
+bezmen:
+ messaging:
+ mapping:
+ modes: [spring_mvc, spring_management]
+ storage:
+ protocol:
+ mode: postgres
+ postgres:
+ url: jdbc:postgresql://db:5432/bezmen
+ mapping:
+ mode: spring_data
From 28956cd47fac5f5c3435c879f2194cc916b0bb11 Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 19:37:14 +0300
Subject: [PATCH 3/7] Fix formatting
---
libs/essentials/pom.xml | 10 ----------
.../construction/ConfigMappingModeCondition.java | 3 ++-
.../construction/ConfigProtocolModeCondition.java | 3 ++-
libs/pom.xml | 6 ------
.../bezmen/configuration/StorageProtocolProps.java | 2 +-
5 files changed, 5 insertions(+), 19 deletions(-)
diff --git a/libs/essentials/pom.xml b/libs/essentials/pom.xml
index 8faf818d..24ef9ed8 100644
--- a/libs/essentials/pom.xml
+++ b/libs/essentials/pom.xml
@@ -22,16 +22,6 @@
org.jetbrains.kotlin
kotlin-stdlib
-
- com.github.spotbugs
- spotbugs-annotations
-
-
- com.google.code.findbugs
- jsr305
-
-
-
org.hibernate.validator
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
index 8b415ecf..a205f333 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java
@@ -15,7 +15,8 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
Map attributes =
metadata.getAnnotationAttributes(ConditionalOnConfigMappingMode.class.getName());
ConfigMappingMode expectedMode = (ConfigMappingMode) attributes.get("value");
- String actualMode = context.getEnvironment().getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name());
+ String actualMode = context.getEnvironment()
+ .getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name());
return expectedMode.name().equalsIgnoreCase(actualMode);
}
diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
index f454a06e..0d8f0a8a 100644
--- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
+++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java
@@ -15,7 +15,8 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
Map attributes =
metadata.getAnnotationAttributes(ConditionalOnConfigProtocolMode.class.getName());
ConfigProtocolMode expectedMode = (ConfigProtocolMode) attributes.get("value");
- String actualMode = context.getEnvironment().getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name());
+ String actualMode = context.getEnvironment()
+ .getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name());
return expectedMode.name().equalsIgnoreCase(actualMode);
}
diff --git a/libs/pom.xml b/libs/pom.xml
index 857cd66a..acc68287 100644
--- a/libs/pom.xml
+++ b/libs/pom.xml
@@ -208,12 +208,6 @@
6.0.0
-
- com.github.spotbugs
- spotbugs-annotations
- 4.7.3
-
-
jakarta.validation
jakarta.validation-api
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java
index c6226c6c..81c566fc 100644
--- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java
+++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java
@@ -1,8 +1,8 @@
package smecalculus.bezmen.configuration;
-import edu.umd.cs.findbugs.annotations.Nullable;
import lombok.Builder;
import lombok.NonNull;
+import org.springframework.lang.Nullable;
@Builder
public record StorageProtocolProps(
From a511af6ffc16fde0f211884745ed3ae887527dc5 Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 21:35:41 +0300
Subject: [PATCH 4/7] Decompose properties files
---
.../java/smecalculus/bezmen/construction/App.java | 2 ++
.../foo/src/main/resources/application.properties | 0
apps/foo/src/main/resources/application.yaml | 6 ------
apps/foo/src/main/resources/reference.conf | 0
.../bezmen/configuration/MessagingCfgMapper.java | 6 +++---
.../bezmen/construction/MessagingConfigBeans.java | 2 ++
.../src/main/resources/messaging.properties | 2 ++
libs/messaging/src/main/resources/messaging.yaml | 7 -------
.../construction/MessagingConfigBeansIT.java | 6 +++---
.../MessagingConfigBeansLightbendConfigIT.java | 6 ++++++
.../MessagingConfigBeansSpringConfigIT.java | 6 ++++++
.../bezmen/configuration/StorageCfgMapper.java | 2 +-
.../bezmen/construction/StorageConfigBeans.java | 2 ++
.../storage/src/main/resources/storage.properties | 8 ++++++++
libs/storage/src/main/resources/storage.yaml | 15 ---------------
.../bezmen/construction/StorageConfigBeansIT.java | 6 +++---
.../StorageConfigBeansLightbendConfigIT.java | 6 ++++++
.../StorageConfigBeansSpringConfigIT.java | 6 ++++++
.../construction/StorageConfigBeansTest.java | 14 ++++++--------
solutions/basis/compose.yml | 2 +-
20 files changed, 57 insertions(+), 47 deletions(-)
create mode 100644 apps/foo/src/main/resources/application.properties
delete mode 100644 apps/foo/src/main/resources/application.yaml
create mode 100644 apps/foo/src/main/resources/reference.conf
create mode 100644 libs/messaging/src/main/resources/messaging.properties
delete mode 100644 libs/messaging/src/main/resources/messaging.yaml
create mode 100644 libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansLightbendConfigIT.java
create mode 100644 libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansSpringConfigIT.java
create mode 100644 libs/storage/src/main/resources/storage.properties
delete mode 100644 libs/storage/src/main/resources/storage.yaml
create mode 100644 libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansLightbendConfigIT.java
create mode 100644 libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansSpringConfigIT.java
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
index f6250dc9..3a08cfff 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
@@ -8,6 +8,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.PropertySource;
import smecalculus.bezmen.core.SepulkaConverter;
import smecalculus.bezmen.core.SepulkaConverterImpl;
import smecalculus.bezmen.core.SepulkaService;
@@ -27,6 +28,7 @@
import smecalculus.bezmen.validation.EdgeValidator;
@Import({ConfigBeans.class, ValidationBeans.class, MessagingBeans.class, StorageBeans.class})
+@PropertySource("classpath:application.properties")
@Configuration(proxyBeanMethods = false)
public class App {
diff --git a/apps/foo/src/main/resources/application.properties b/apps/foo/src/main/resources/application.properties
new file mode 100644
index 00000000..e69de29b
diff --git a/apps/foo/src/main/resources/application.yaml b/apps/foo/src/main/resources/application.yaml
deleted file mode 100644
index dc5a7746..00000000
--- a/apps/foo/src/main/resources/application.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
----
-spring:
- config:
- import:
- - classpath:messaging.yaml
- - classpath:storage.yaml
diff --git a/apps/foo/src/main/resources/reference.conf b/apps/foo/src/main/resources/reference.conf
new file mode 100644
index 00000000..e69de29b
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java
index f04a1c62..2cd35b05 100644
--- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java
+++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java
@@ -8,13 +8,13 @@ public interface MessagingCfgMapper {
@Mapping(source = "protocol", target = "protocolProps")
@Mapping(source = "mapping", target = "mappingProps")
- MessagingProps toDomain(MessagingPropsCfg messagingPropsCfg);
+ MessagingProps toDomain(MessagingPropsCfg propsCfg);
@Mapping(source = "modes", target = "protocolModes")
- MessagingProtocolProps toDomain(MessagingProtocolPropsCfg protocolPropsCfg);
+ MessagingProtocolProps toDomain(MessagingProtocolPropsCfg propsCfg);
@Mapping(source = "modes", target = "mappingModes")
- MessageMappingProps toDomain(MessageMappingPropsCfg mappingPropsCfg);
+ MessageMappingProps toDomain(MessageMappingPropsCfg propsCfg);
default MessagingProtocolMode toProtocolMode(String value) {
return MessagingProtocolMode.valueOf(value.toUpperCase());
diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
index 35265465..cd190ca5 100644
--- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
+++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java
@@ -4,6 +4,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
import smecalculus.bezmen.configuration.ConfigKeeper;
import smecalculus.bezmen.configuration.MessagingCfgMapper;
import smecalculus.bezmen.configuration.MessagingCfgMapperImpl;
@@ -11,6 +12,7 @@
import smecalculus.bezmen.configuration.MessagingPropsCfg;
import smecalculus.bezmen.validation.EdgeValidator;
+@PropertySource("classpath:messaging.properties")
@Configuration(proxyBeanMethods = false)
public class MessagingConfigBeans {
diff --git a/libs/messaging/src/main/resources/messaging.properties b/libs/messaging/src/main/resources/messaging.properties
new file mode 100644
index 00000000..4cec1140
--- /dev/null
+++ b/libs/messaging/src/main/resources/messaging.properties
@@ -0,0 +1,2 @@
+bezmen.messaging.protocol.modes[0]=http
+bezmen.messaging.mapping.modes[0]=spring_mvc
diff --git a/libs/messaging/src/main/resources/messaging.yaml b/libs/messaging/src/main/resources/messaging.yaml
deleted file mode 100644
index aa960877..00000000
--- a/libs/messaging/src/main/resources/messaging.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-bezmen:
- messaging:
- protocol:
- modes: [http]
- mapping:
- modes: [spring_mvc]
diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
index 5a929f5d..19dbbb29 100644
--- a/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
+++ b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java
@@ -11,15 +11,15 @@
import smecalculus.bezmen.configuration.MessagingProps;
@ExtendWith(SpringExtension.class)
-@ContextConfiguration(classes = {ConfigBeans.class, ValidationBeans.class, MessagingConfigBeans.class})
-class MessagingConfigBeansIT {
+@ContextConfiguration(classes = {MessagingConfigBeans.class, ConfigBeans.class, ValidationBeans.class})
+abstract class MessagingConfigBeansIT {
@Test
void defaultConfigShouldBeBackwardCompatible(@Autowired MessagingProps actualProps) {
// given
MessagingProps expectedProps = messagingProps().build();
// when
- // construction
+ // default construction
// then
assertThat(actualProps).isEqualTo(expectedProps);
}
diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansLightbendConfigIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansLightbendConfigIT.java
new file mode 100644
index 00000000..5e8b69f1
--- /dev/null
+++ b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansLightbendConfigIT.java
@@ -0,0 +1,6 @@
+package smecalculus.bezmen.construction;
+
+import org.springframework.test.context.TestPropertySource;
+
+@TestPropertySource(properties = {"bezmen.config.mapping.mode=lightbend_config"})
+class MessagingConfigBeansLightbendConfigIT extends MessagingConfigBeansIT {}
diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansSpringConfigIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansSpringConfigIT.java
new file mode 100644
index 00000000..668b3e3f
--- /dev/null
+++ b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansSpringConfigIT.java
@@ -0,0 +1,6 @@
+package smecalculus.bezmen.construction;
+
+import org.springframework.test.context.TestPropertySource;
+
+@TestPropertySource(properties = {"bezmen.config.mapping.mode=spring_config"})
+class MessagingConfigBeansSpringConfigIT extends MessagingConfigBeansIT {}
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java
index 7c6c1e77..02ca7a8b 100644
--- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java
+++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java
@@ -8,7 +8,7 @@ public interface StorageCfgMapper {
@Mapping(source = "protocol", target = "protocolProps")
@Mapping(source = "mapping", target = "mappingProps")
- StorageProps toDomain(StoragePropsCfg storagePropsCfg);
+ StorageProps toDomain(StoragePropsCfg propsCfg);
@Mapping(source = "mode", target = "protocolMode")
@Mapping(source = "h2", target = "h2Props")
diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
index 6958fe7b..061cf4d7 100644
--- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
+++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java
@@ -4,6 +4,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
import smecalculus.bezmen.configuration.ConfigKeeper;
import smecalculus.bezmen.configuration.StorageCfgMapper;
import smecalculus.bezmen.configuration.StorageCfgMapperImpl;
@@ -11,6 +12,7 @@
import smecalculus.bezmen.configuration.StoragePropsCfg;
import smecalculus.bezmen.validation.EdgeValidator;
+@PropertySource("classpath:storage.properties")
@Configuration(proxyBeanMethods = false)
public class StorageConfigBeans {
diff --git a/libs/storage/src/main/resources/storage.properties b/libs/storage/src/main/resources/storage.properties
new file mode 100644
index 00000000..b3056b72
--- /dev/null
+++ b/libs/storage/src/main/resources/storage.properties
@@ -0,0 +1,8 @@
+bezmen.storage.protocol.mode=h2
+bezmen.storage.protocol.h2.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
+bezmen.storage.protocol.h2.username=sa
+bezmen.storage.protocol.h2.password=sa
+bezmen.storage.protocol.postgres.url=jdbc:postgresql://localhost:5432/bezmen
+bezmen.storage.protocol.postgres.username=bezmen
+bezmen.storage.protocol.postgres.password=bezmen
+bezmen.storage.mapping.mode=spring_data
diff --git a/libs/storage/src/main/resources/storage.yaml b/libs/storage/src/main/resources/storage.yaml
deleted file mode 100644
index 0c2d3567..00000000
--- a/libs/storage/src/main/resources/storage.yaml
+++ /dev/null
@@ -1,15 +0,0 @@
----
-bezmen:
- storage:
- protocol:
- mode: h2
- h2:
- url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
- username: sa
- password: sa
- postgres:
- url: jdbc:postgresql://localhost:5432/bezmen
- username: bezmen
- password: bezmen
- mapping:
- mode: spring_data
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
index f0381447..62de9f65 100644
--- a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansIT.java
@@ -11,15 +11,15 @@
import smecalculus.bezmen.configuration.StorageProps;
@ExtendWith(SpringExtension.class)
-@ContextConfiguration(classes = {ConfigBeans.class, ValidationBeans.class, StorageConfigBeans.class})
-class StorageConfigBeansIT {
+@ContextConfiguration(classes = {StorageConfigBeans.class, ConfigBeans.class, ValidationBeans.class})
+abstract class StorageConfigBeansIT {
@Test
void defaultConfigShouldBeBackwardCompatible(@Autowired StorageProps actualProps) {
// given
StorageProps expectedProps = storageProps().build();
// when
- // construction
+ // default construction
// then
assertThat(actualProps).isEqualTo(expectedProps);
}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansLightbendConfigIT.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansLightbendConfigIT.java
new file mode 100644
index 00000000..4631e191
--- /dev/null
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansLightbendConfigIT.java
@@ -0,0 +1,6 @@
+package smecalculus.bezmen.construction;
+
+import org.springframework.test.context.TestPropertySource;
+
+@TestPropertySource(properties = {"bezmen.config.mapping.mode=lightbend_config"})
+class StorageConfigBeansLightbendConfigIT extends StorageConfigBeansIT {}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansSpringConfigIT.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansSpringConfigIT.java
new file mode 100644
index 00000000..3fe90f67
--- /dev/null
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansSpringConfigIT.java
@@ -0,0 +1,6 @@
+package smecalculus.bezmen.construction;
+
+import org.springframework.test.context.TestPropertySource;
+
+@TestPropertySource(properties = {"bezmen.config.mapping.mode=spring_config"})
+class StorageConfigBeansSpringConfigIT extends StorageConfigBeansIT {}
diff --git a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
index b01f3867..79bf441f 100644
--- a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
+++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java
@@ -15,28 +15,26 @@
class StorageConfigBeansTest {
- private StorageConfigBeans configBeans;
+ private final StorageConfigBeans config = new StorageConfigBeans();
+ private final StorageCfgMapper mapper = new StorageCfgMapperImpl();
private EdgeValidator validatorMock;
private ConfigKeeper keeperMock;
- private StorageCfgMapper mapper;
@BeforeEach
void setUp() {
- configBeans = new StorageConfigBeans();
validatorMock = mock(EdgeValidator.class);
keeperMock = mock(ConfigKeeper.class);
- mapper = new StorageCfgMapperImpl();
}
@Test
void shouldValidateConf() {
// given
- StoragePropsCfg expectedStorageProps = storagePropsCfg();
+ StoragePropsCfg expectedProps = storagePropsCfg();
// and
- when(keeperMock.read("bezmen.storage", StoragePropsCfg.class)).thenReturn(expectedStorageProps);
+ when(keeperMock.read("bezmen.storage", StoragePropsCfg.class)).thenReturn(expectedProps);
// when
- configBeans.storageProps(keeperMock, validatorMock, mapper);
+ config.storageProps(keeperMock, validatorMock, mapper);
// then
- verify(validatorMock).validate(expectedStorageProps);
+ verify(validatorMock).validate(expectedProps);
}
}
diff --git a/solutions/basis/compose.yml b/solutions/basis/compose.yml
index 2237356f..e3695f7c 100644
--- a/solutions/basis/compose.yml
+++ b/solutions/basis/compose.yml
@@ -88,7 +88,7 @@ services:
target: /home/bezmen/${CONFIG_FILE_NAME}
command: >
--bezmen.config.mapping.mode=${CONFIG_MAPPING_MODE}
- --spring.config.location=classpath:application.yaml,optional:file:${CONFIG_FILE_NAME}
+ --spring.config.location=optional:file:${CONFIG_FILE_NAME}
depends_on:
schema-owner:
condition: service_completed_successfully
From dcb09658005a71d69c25a84a42ef3ef78ce23d5e Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 21:46:09 +0300
Subject: [PATCH 5/7] Spring Boot in testing deps
---
libs/testing/pom.xml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libs/testing/pom.xml b/libs/testing/pom.xml
index 82a65a80..76063572 100644
--- a/libs/testing/pom.xml
+++ b/libs/testing/pom.xml
@@ -33,6 +33,10 @@
spring-jdbc
+
+ jakarta.servlet
+ jakarta.servlet-api
+
org.reactivestreams
reactive-streams
@@ -46,8 +50,8 @@
spring-webflux
- jakarta.servlet
- jakarta.servlet-api
+ org.springframework.boot
+ spring-boot
From 5375e85aae68e8fcc9d4eb823dab3f9d7a6cdea9 Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 22:07:17 +0300
Subject: [PATCH 6/7] Fix config names
---
apps/foo/Dockerfile | 2 +-
.../main/java/smecalculus/bezmen/construction/App.java | 8 ++++----
.../smecalculus/bezmen/messaging/SepulkaClientImpl.java | 5 +----
.../bezmen/messaging/springmvc/SepulkaController.java | 7 ++++++-
.../bezmen/construction/SepulkaClientBeans.java | 8 ++++----
solutions/basis/compose.yml | 2 +-
6 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/apps/foo/Dockerfile b/apps/foo/Dockerfile
index d6b5f175..dd8c1887 100644
--- a/apps/foo/Dockerfile
+++ b/apps/foo/Dockerfile
@@ -6,6 +6,6 @@ COPY libs libs
COPY app*.jar app.jar
ENTRYPOINT [ \
"java", "-cp", "app.jar:libs/*", \
- "-Dconfig.file=${CONFIG_FILE_NAME}", \
+ "-Dconfig.file=application.conf", \
"smecalculus.bezmen.construction.App" \
]
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
index 3a08cfff..1ab95177 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
@@ -38,8 +38,8 @@ public static void main(String[] args) {
@Bean
@ConditionalOnMessageMappingModes(SPRING_MVC)
- SepulkaController sepulkaControllerSpringWeb(SepulkaClient client, SepulkaMsgMapper mapper) {
- return new SepulkaController(client, mapper);
+ SepulkaController sepulkaControllerSpringMvc(EdgeValidator validator, SepulkaClient client, SepulkaMsgMapper mapper) {
+ return new SepulkaController(validator, client, mapper);
}
@Bean
@@ -48,8 +48,8 @@ SepulkaMsgMapper sepulkaMsgMapper() {
}
@Bean
- SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaService service, SepulkaConverter converter) {
- return new SepulkaClientImpl(validator, service, converter);
+ SepulkaClient sepulkaClient(SepulkaService service, SepulkaConverter converter) {
+ return new SepulkaClientImpl(service, converter);
}
@Bean
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java b/apps/foo/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java
index 78d51b9e..ff21f451 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java
@@ -7,15 +7,12 @@
import smecalculus.bezmen.messaging.client.SepulkaClient;
import smecalculus.bezmen.messaging.client.SepulkaRegReq;
import smecalculus.bezmen.messaging.client.SepulkaRegRes;
-import smecalculus.bezmen.validation.EdgeValidator;
-public record SepulkaClientImpl(
- @NonNull EdgeValidator validator, @NonNull SepulkaService service, @NonNull SepulkaConverter converter)
+public record SepulkaClientImpl(@NonNull SepulkaService service, @NonNull SepulkaConverter converter)
implements SepulkaClient {
@Override
public SepulkaRegRes register(SepulkaRegReq request) {
- validator.validate(request);
Sepulka sepulka = service.register(request);
return converter.toRegRes(sepulka);
}
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
index 786a97f9..44cef518 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java
@@ -1,5 +1,6 @@
package smecalculus.bezmen.messaging.springmvc;
+import lombok.NonNull;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
@@ -12,12 +13,16 @@
import smecalculus.bezmen.messaging.client.SepulkaClient;
import smecalculus.bezmen.messaging.client.SepulkaRegReq;
import smecalculus.bezmen.messaging.client.SepulkaRegRes;
+import smecalculus.bezmen.validation.EdgeValidator;
@RestController
@RequestMapping("sepulkas")
-public record SepulkaController(SepulkaClient client, SepulkaMsgMapper mapper) {
+public record SepulkaController(
+ @NonNull EdgeValidator validator, @NonNull SepulkaClient client, @NonNull SepulkaMsgMapper mapper) {
+
@PostMapping
ResponseEntity register(@RequestBody SepulkaRegReqMsg sepulkaRegReqMsg) {
+ validator.validate(sepulkaRegReqMsg);
SepulkaRegReq sepulkaRegReq = mapper.toDomain(sepulkaRegReqMsg);
SepulkaRegRes sepulkaRegRes = client.register(sepulkaRegReq);
return ResponseEntity.status(HttpStatus.CREATED).body(mapper.toMsg(sepulkaRegRes));
diff --git a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
index 55c4a9dc..d9963976 100644
--- a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
+++ b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
@@ -33,14 +33,14 @@ SepulkaConverter sepulkaConverter() {
}
@Bean
- SepulkaClient internalClient(EdgeValidator validator, SepulkaService service, SepulkaConverterImpl converter) {
- return new SepulkaClientImpl(validator, service, converter);
+ SepulkaClient internalClient(SepulkaService service, SepulkaConverterImpl converter) {
+ return new SepulkaClientImpl(service, converter);
}
@Bean
- SepulkaClient externalClient(SepulkaClient internalClient) {
+ SepulkaClient externalClient(EdgeValidator validator, SepulkaClient internalClient) {
SepulkaMsgMapper mapper = new SepulkaMsgMapperImpl();
- WebTestClient client = MockMvcWebTestClient.bindToController(new SepulkaController(internalClient, mapper))
+ WebTestClient client = MockMvcWebTestClient.bindToController(new SepulkaController(validator, internalClient, mapper))
.build();
return new SepulkaClientSpringWeb(client, mapper);
}
diff --git a/solutions/basis/compose.yml b/solutions/basis/compose.yml
index e3695f7c..c42bae8a 100644
--- a/solutions/basis/compose.yml
+++ b/solutions/basis/compose.yml
@@ -88,7 +88,7 @@ services:
target: /home/bezmen/${CONFIG_FILE_NAME}
command: >
--bezmen.config.mapping.mode=${CONFIG_MAPPING_MODE}
- --spring.config.location=optional:file:${CONFIG_FILE_NAME}
+ --spring.config.location=optional:file:application.yaml
depends_on:
schema-owner:
condition: service_completed_successfully
From eaa4dc70a9d00133f82761c245e7de7dc84d33e2 Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Thu, 5 Oct 2023 22:19:23 +0300
Subject: [PATCH 7/7] Fix formatting
---
.../foo/src/main/java/smecalculus/bezmen/construction/App.java | 3 ++-
.../smecalculus/bezmen/construction/SepulkaClientBeans.java | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
index 1ab95177..c54d424c 100644
--- a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
+++ b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java
@@ -38,7 +38,8 @@ public static void main(String[] args) {
@Bean
@ConditionalOnMessageMappingModes(SPRING_MVC)
- SepulkaController sepulkaControllerSpringMvc(EdgeValidator validator, SepulkaClient client, SepulkaMsgMapper mapper) {
+ SepulkaController sepulkaControllerSpringMvc(
+ EdgeValidator validator, SepulkaClient client, SepulkaMsgMapper mapper) {
return new SepulkaController(validator, client, mapper);
}
diff --git a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
index d9963976..bb1af9fc 100644
--- a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
+++ b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java
@@ -40,7 +40,8 @@ SepulkaClient internalClient(SepulkaService service, SepulkaConverterImpl conver
@Bean
SepulkaClient externalClient(EdgeValidator validator, SepulkaClient internalClient) {
SepulkaMsgMapper mapper = new SepulkaMsgMapperImpl();
- WebTestClient client = MockMvcWebTestClient.bindToController(new SepulkaController(validator, internalClient, mapper))
+ WebTestClient client = MockMvcWebTestClient.bindToController(
+ new SepulkaController(validator, internalClient, mapper))
.build();
return new SepulkaClientSpringWeb(client, mapper);
}