diff --git a/.dx/group_vars/all.yml b/.dx/group_vars/all.yml index 83069f67..55e7fac3 100644 --- a/.dx/group_vars/all.yml +++ b/.dx/group_vars/all.yml @@ -8,7 +8,6 @@ prefs: turing lib_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}" lib_cids: signatures: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/signatures')[:7] }}" - construction: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/construction')[:7] }}" storage: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/storage')[:7] }}" essentials: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/essentials')[:7] }}" messaging: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/messaging')[:7] }}" @@ -52,4 +51,4 @@ stack_images: docker_entity: "{{ 'image' if image_repo == 'local' else 'manifest' }}" app_deps: - foo: [essentials, construction, signatures, messaging, storage] + foo: [essentials, signatures, messaging, storage] diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d719fdae..991e349a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,7 @@ updates: schedule: interval: "weekly" - package-ecosystem: "maven" - directory: "/libs" + directory: "/" open-pull-requests-limit: 10 schedule: interval: "daily" @@ -14,22 +14,6 @@ updates: spring-framework: patterns: - "org.springframework*" - - package-ecosystem: "maven" - directory: "/apps" - schedule: - interval: "weekly" - ignore: - - dependency-name: "smecalculus.bezmen:*" - - package-ecosystem: "maven" - directory: "/tests" - schedule: - interval: "weekly" - ignore: - - dependency-name: "smecalculus.bezmen:*" - - package-ecosystem: "maven" - directory: "/tools" - schedule: - interval: "weekly" - package-ecosystem: "docker" directory: "/schemas/postgres" schedule: diff --git a/README.adoc b/README.adoc index c6bc679f..ca298022 100644 --- a/README.adoc +++ b/README.adoc @@ -1,84 +1,3 @@ = bezmen Шаблон репозитория backend-проекта на Java. - -== Ключевые принципы - -Решение и конвейер как сущности первого класса:: -Решение (solution) - система, реализуемая для клиентов. Конвейер (pipeline) - система, реализуемая для разработчиков. - -Единый интерфейс для локальной разработки и непрерывной интеграции:: -Семантика интерфейса подразумевает набор предопределенных абстракций, артефакты которых последовательно конструируются в ходе сборки. Перед началом конструирования выполняются обязательные проверки. Примеры абстракций: исходники (sources), бинарники (binaries), образы (images), стеки (stacks) и другие. - -Контентная адресация (aka идентификация по содержимому):: -Контентная адресация (content addressability) делает конструирование *идемпотентным*. Для директорий с исходным кодом вычисляются их контентные идентификаторы (CID's). Затем вычисляются корневые идентификаторы решения и конвейера. Таким образом формируется 2 небольших дерева Меркла, хеши которых подставляются в качестве тегов/классификаторов артефактов соответствующих абстракций. Артефакт конструируется, только когда его контентный идентификатор меняется. - -Множественность окружений, назначений и настроек:: -Решение/конвейер используется клиентами/разработчиками в разных окружениях (environs) для разных назначений (usages) и с разными настройками (prefs). Ключевые окружения/назначения/настройки именуются и проверяются в рамках непрерывной интеграции. Устаревшие окружения/назначения/настройки снимаются с поддержки. - -Тесты! Тесты! Тесты!:: -Тестирование - один из самых важных (или даже самый важный) аспектов разработки! При тестировании проверяется поведение целевого объекта в различных ситуациях. В зависимости от подхода к подготовке зависимостей целевого объекта тесты можно разделить на 3 категории. -Модульные тесты (unit tests)::: -Все зависимости целевого объекта глушатся (stub) или мокируются (mock). -Интеграционные тесты (integration tests)::: -Все зависимости глушатся/мокируются кроме одной (иногда нескольких), которая честно конструируется. -Сквозные тесты (end-to-end tests)::: -Все зависимости честно конструируются. - -Роботизированная асинхронная заливка (merge):: -Позволяет избежать ошибок/конкуренции и, как следствие, неоправданных потерь на загруженных ветках (например, таких как main). - -== Непрерывная интеграция (CI) - -Планы делим на 2 категории: - -. Проверяющие решение (solution) -. Проверяющие конвейер (pipeline) - -=== Проверка решения - -Решение проверяем во всех окружениях, в которых его могут эксплуатировать клиенты. - -==== В пределах разумного (sanity) - -Запускаем анализ зависимостей, линтинг, статический анализ, компиляцию, модульные тесты и собираем/публикуем бинарники. - -==== Убедительная (convincing) - -Все перечисленное ранее. Плюс запускаем интеграционные тесты, анализируем покрытие и собираем/публикуем образы. - -==== За пределами сомнений (beyond doubt) - -Все перечисленное ранее. Плюс запускаем сквозные тесты, собираем/публикуем решения. - -=== Проверка конвейера - -Конвейер проверяем во всех окружениях, в которых его могут эксплуатировать разработчики. - -==== В пределах разумного (sanity) - -Запускаем линтинг исходного кода конвейера. - -==== За пределами сомнений (beyond doubt) - -Запускаем весь конвейер на минимальном наборе тестов. - -== Частые вопросы (FAQ) - -[qanda] -Почему обязательными статусными проверками назначены тестовые отчеты, а не тестовые джобы?:: -Это дает свободу выбора структуры джобов, т.к. в различных планах сборки она может быть разной. - -== Консольный интерфейс (CLI) - - ansible-playbook .yml [-l ] - -== Todo - -. Релизная сборка -. Параллелизация модульных тестов -. Построение дерева хешей (взглянуть критически) -. Версионирование библиотек и приложений (взглянуть критически) -. Локальные проверки в удаленном репозитории -. Чистка артефактов в удаленном репозитории -. Поддержка нескольких версий Java diff --git a/apps/foo/pom.xml b/apps/foo/pom.xml index fc985115..62fe4ea1 100644 --- a/apps/foo/pom.xml +++ b/apps/foo/pom.xml @@ -17,10 +17,6 @@ ${project.groupId} essentials - - ${project.groupId} - construction - ${project.groupId} messaging 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 c144464d..1175bb1f 100644 --- a/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java +++ b/apps/foo/src/main/java/smecalculus/bezmen/construction/App.java @@ -1,26 +1,18 @@ package smecalculus.bezmen.construction; -import static smecalculus.bezmen.configuration.OrmMode.MY_BATIS; -import static smecalculus.bezmen.configuration.OrmMode.SPRING_DATA; -import static smecalculus.bezmen.configuration.WebMode.SPRING_MVC; +import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_WEB_MVC; +import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS; +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; import org.springframework.boot.SpringApplication; -import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthContributorAutoConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; -import org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration; -import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration; -import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; -import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; -import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; -import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration; -import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; -import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -32,7 +24,7 @@ import smecalculus.bezmen.messaging.SepulkaMsgMapper; import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl; import smecalculus.bezmen.messaging.client.SepulkaClient; -import smecalculus.bezmen.messaging.springmvc.SepulkaController; +import smecalculus.bezmen.messaging.springwebmvc.SepulkaController; import smecalculus.bezmen.storage.SepulkaDao; import smecalculus.bezmen.storage.SepulkaDaoMyBatis; import smecalculus.bezmen.storage.SepulkaDaoSpringData; @@ -42,26 +34,17 @@ import smecalculus.bezmen.storage.springdata.SepulkaRepository; import smecalculus.bezmen.validation.EdgeValidator; -@Import({ConfigBeans.class, ValidationBeans.class, MessagingBeans.class, StorageBeans.class}) -@EnableAutoConfiguration( - exclude = { - LiquibaseAutoConfiguration.class, - AopAutoConfiguration.class, - DataSourceHealthContributorAutoConfiguration.class, - DiskSpaceHealthContributorAutoConfiguration.class, - EmbeddedWebServerFactoryCustomizerAutoConfiguration.class, - PersistenceExceptionTranslationAutoConfiguration.class, - SpringDataWebAutoConfiguration.class, - HealthContributorAutoConfiguration.class, - HttpMessageConvertersAutoConfiguration.class, - LifecycleAutoConfiguration.class, - MultipartAutoConfiguration.class, - PropertyPlaceholderAutoConfiguration.class, - RestTemplateAutoConfiguration.class, - TaskExecutionAutoConfiguration.class, - TaskSchedulingAutoConfiguration.class - }) @Configuration(proxyBeanMethods = false) +@Import({ConfigBeans.class, ValidationBeans.class, MessagingBeans.class, StorageBeans.class}) +@ImportAutoConfiguration({ + ManagementContextAutoConfiguration.class, + ServletManagementContextAutoConfiguration.class, + EndpointAutoConfiguration.class, + WebEndpointAutoConfiguration.class, + HealthEndpointAutoConfiguration.class, + ObservationAutoConfiguration.class, + WebMvcObservationAutoConfiguration.class +}) public class App { public static void main(String[] args) { @@ -69,8 +52,8 @@ public static void main(String[] args) { } @Bean - @ConditionalOnWebMode(SPRING_MVC) - SepulkaController sepulkaController(SepulkaClient client, SepulkaMsgMapper mapper) { + @ConditionalOnMessageMappingMode(SPRING_WEB_MVC) + SepulkaController sepulkaControllerSpringWeb(SepulkaClient client, SepulkaMsgMapper mapper) { return new SepulkaController(client, mapper); } @@ -95,13 +78,13 @@ SepulkaConverter sepulkaConverter() { } @Bean - @ConditionalOnOrmMode(SPRING_DATA) + @ConditionalOnStateMappingMode(SPRING_DATA) SepulkaDaoSpringData sepulkaDaoSpringData(SepulkaRecMapper mapper, SepulkaRepository repository) { return new SepulkaDaoSpringData(mapper, repository); } @Bean - @ConditionalOnOrmMode(MY_BATIS) + @ConditionalOnStateMappingMode(MY_BATIS) SepulkaDaoMyBatis sepulkaDaoMyBatis(SepulkaRecMapper recMapper, SepulkaSqlMapper sqlMapper) { return new SepulkaDaoMyBatis(recMapper, sqlMapper); } diff --git a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java similarity index 95% rename from apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java rename to apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java index 786a97f9..1902f008 100644 --- a/apps/foo/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java +++ b/apps/foo/src/main/java/smecalculus/bezmen/messaging/springwebmvc/SepulkaController.java @@ -1,4 +1,4 @@ -package smecalculus.bezmen.messaging.springmvc; +package smecalculus.bezmen.messaging.springwebmvc; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; 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..134b606a 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.springmvc.SepulkaController; +import smecalculus.bezmen.messaging.springwebmvc.SepulkaController; import smecalculus.bezmen.validation.EdgeValidator; @Import(ValidationBeans.class) diff --git a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java index 313ff598..23dfbee7 100644 --- a/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java +++ b/apps/foo/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java @@ -1,9 +1,9 @@ package smecalculus.bezmen.construction; import static java.util.stream.Collectors.joining; -import static smecalculus.bezmen.configuration.OrmMode.MY_BATIS; -import static smecalculus.bezmen.configuration.OrmMode.SPRING_DATA; -import static smecalculus.bezmen.configuration.VendorMode.POSTGRES; +import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS; +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; +import static smecalculus.bezmen.configuration.StorageProtocolMode.POSTGRES; import java.util.Collection; import java.util.List; @@ -13,9 +13,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import smecalculus.bezmen.configuration.OrmProps; +import smecalculus.bezmen.configuration.StateMappingProps; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.VendorProps; +import smecalculus.bezmen.configuration.StorageProtocolProps; import smecalculus.bezmen.storage.SepulkaDao; import smecalculus.bezmen.storage.SepulkaDaoMyBatis; import smecalculus.bezmen.storage.SepulkaDaoSpringData; @@ -33,7 +33,7 @@ public class SepulkaDaoBeans { public DataSource dataSource(StorageProps storageProps) { List common = List.of("DB_CLOSE_DELAY=-1"); List specific = - switch (storageProps.vendorProps().mode()) { + switch (storageProps.protocolProps().protocolMode()) { case H2 -> List.of("MODE=STRICT"); case POSTGRES -> List.of("MODE=PostgreSQL", "DATABASE_TO_LOWER=TRUE", "DEFAULT_NULL_ORDERING=HIGH"); }; @@ -64,8 +64,11 @@ public SepulkaDao underTest(SepulkaRecMapper recMapper, SepulkaRepository reposi @Bean public StorageProps storageProps() { return StorageProps.builder() - .ormProps(OrmProps.builder().mode(SPRING_DATA).build()) - .vendorProps(VendorProps.builder().mode(POSTGRES).build()) + .mappingProps( + StateMappingProps.builder().mappingMode(SPRING_DATA).build()) + .protocolProps(StorageProtocolProps.builder() + .protocolMode(POSTGRES) + .build()) .build(); } } @@ -81,8 +84,11 @@ public SepulkaDao underTest(SepulkaRecMapper recMapper, SepulkaSqlMapper sqlMapp @Bean public StorageProps storageProps() { return StorageProps.builder() - .ormProps(OrmProps.builder().mode(MY_BATIS).build()) - .vendorProps(VendorProps.builder().mode(POSTGRES).build()) + .mappingProps( + StateMappingProps.builder().mappingMode(MY_BATIS).build()) + .protocolProps(StorageProtocolProps.builder() + .protocolMode(POSTGRES) + .build()) .build(); } } diff --git a/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoMyBatisPostgresIT.java b/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoMyBatisPostgresIT.java index 02de52d7..31aac61e 100644 --- a/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoMyBatisPostgresIT.java +++ b/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoMyBatisPostgresIT.java @@ -1,8 +1,8 @@ package smecalculus.bezmen.storage; import org.springframework.test.context.ContextConfiguration; -import smecalculus.bezmen.construction.OrmMyBatisBeans; +import smecalculus.bezmen.construction.MappingMyBatisBeans; import smecalculus.bezmen.construction.SepulkaDaoBeans; -@ContextConfiguration(classes = {SepulkaDaoBeans.MyBatisPostgres.class, OrmMyBatisBeans.class}) +@ContextConfiguration(classes = {SepulkaDaoBeans.MyBatisPostgres.class, MappingMyBatisBeans.class}) public class SepulkaDaoMyBatisPostgresIT extends SepulkaDaoIT {} diff --git a/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoSpringDataPostgresIT.java b/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoSpringDataPostgresIT.java index d711c009..386a603a 100644 --- a/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoSpringDataPostgresIT.java +++ b/apps/foo/src/test/java/smecalculus/bezmen/storage/SepulkaDaoSpringDataPostgresIT.java @@ -1,8 +1,8 @@ package smecalculus.bezmen.storage; import org.springframework.test.context.ContextConfiguration; -import smecalculus.bezmen.construction.OrmSpringDataBeans; +import smecalculus.bezmen.construction.MappingSpringDataBeans; import smecalculus.bezmen.construction.SepulkaDaoBeans; -@ContextConfiguration(classes = {SepulkaDaoBeans.SpringDataPostgres.class, OrmSpringDataBeans.class}) +@ContextConfiguration(classes = {SepulkaDaoBeans.SpringDataPostgres.class, MappingSpringDataBeans.class}) public class SepulkaDaoSpringDataPostgresIT extends SepulkaDaoIT {} diff --git a/docs/pipeline.adoc b/docs/pipeline.adoc new file mode 100644 index 00000000..69aeb6c8 --- /dev/null +++ b/docs/pipeline.adoc @@ -0,0 +1,82 @@ += Конвейер + +== Ключевые принципы + +Решение и конвейер как сущности первого класса:: +Решение (solution) - система, реализуемая для клиентов. Конвейер (pipeline) - система, реализуемая для разработчиков. + +Единый интерфейс для локальной разработки и непрерывной интеграции:: +Семантика интерфейса подразумевает набор предопределенных абстракций, артефакты которых последовательно конструируются в ходе сборки. Перед началом конструирования выполняются обязательные проверки. Примеры абстракций: исходники (sources), бинарники (binaries), образы (images), стеки (stacks) и другие. + +Контентная адресация (aka идентификация по содержимому):: +Контентная адресация (content addressability) делает конструирование *идемпотентным*. Для директорий с исходным кодом вычисляются их контентные идентификаторы (CID's). Затем вычисляются корневые идентификаторы решения и конвейера. Таким образом формируется 2 небольших дерева Меркла, хеши которых подставляются в качестве тегов/классификаторов артефактов соответствующих абстракций. Артефакт конструируется, только когда его контентный идентификатор меняется. + +Множественность окружений, назначений и настроек:: +Решение/конвейер используется клиентами/разработчиками в разных окружениях (environs) для разных назначений (usages) и с разными настройками (prefs). Ключевые окружения/назначения/настройки именуются и проверяются в рамках непрерывной интеграции. Устаревшие окружения/назначения/настройки снимаются с поддержки. + +Тесты! Тесты! Тесты!:: +Тестирование - один из самых важных (или даже самый важный) аспектов разработки! При тестировании проверяется поведение целевого объекта в различных ситуациях. В зависимости от подхода к подготовке зависимостей целевого объекта тесты можно разделить на 3 категории. +Модульные тесты (unit tests)::: +Все зависимости целевого объекта глушатся (stub) или мокируются (mock). +Интеграционные тесты (integration tests)::: +Все зависимости глушатся/мокируются кроме одной (иногда нескольких), которая честно конструируется. +Сквозные тесты (end-to-end tests)::: +Все зависимости честно конструируются. + +Роботизированная асинхронная заливка (merge):: +Позволяет избежать ошибок/конкуренции и, как следствие, неоправданных потерь на загруженных ветках (например, main). + +== Непрерывная интеграция (CI) + +Планы делим на 2 категории: + +. Проверяющие решение (solution) +. Проверяющие конвейер (pipeline) + +=== Проверка решения + +Решение проверяем во всех окружениях, в которых его могут эксплуатировать клиенты. + +==== В пределах разумного (sanity) + +Запускаем анализ зависимостей, линтинг, статический анализ, компиляцию, модульные тесты и собираем/публикуем бинарники. + +==== Убедительная (convincing) + +Все перечисленное ранее. Плюс запускаем интеграционные тесты, анализируем покрытие и собираем/публикуем образы. + +==== За пределами сомнений (beyond doubt) + +Все перечисленное ранее. Плюс запускаем сквозные тесты, собираем и публикуем стеки. + +=== Проверка конвейера + +Конвейер проверяем во всех окружениях, в которых его могут эксплуатировать разработчики. + +==== В пределах разумного (sanity) + +Запускаем линтинг исходного кода конвейера. + +==== За пределами сомнений (beyond doubt) + +Запускаем весь конвейер на минимально необходимом наборе тестов. + +== Частые вопросы (FAQ) + +[qanda] +Почему обязательными статусными проверками назначены тестовые отчеты, а не тестовые джобы?:: +Это дает свободу выбора структуры джобов, т.к. в различных планах сборки она может быть разной. + +== Консольный интерфейс (CLI) + + ansible-playbook .yml + +== Todo + +. Релизная сборка +. Параллелизация модульных тестов +. Построение дерева хешей (взглянуть критически) +. Версионирование библиотек и приложений (взглянуть критически) +. Локальные проверки в удаленном репозитории +. Чистка артефактов в удаленном репозитории +. Поддержка нескольких версий Java diff --git a/docs/solution.adoc b/docs/solution.adoc new file mode 100644 index 00000000..79072dc5 --- /dev/null +++ b/docs/solution.adoc @@ -0,0 +1,47 @@ += Решение + +== Обмен сообщениями + +Принимаем/отправляем сообщения в рамках некоторого протокола, отображая их в доменные объекты. + +=== Протокол + +Wire protocol footnote:[Подробнее https://en.wikipedia.org/wiki/Wire_protocol] - протокол прикладного уровня, который используется для коммуникации между сервером и клиентом. + +NOTE: Обычно используются стандартные протоколы, реже - кастомные. + +==== HTTP + +Стандартный протокол HTTP + +=== Отображение + +NOTE: Шаблон проектирования `Message Mapping`. + +==== SpringMeb + +Отображение SpringMeb + +== Хранение состояния + +Запоминаем/вспоминаем состояние в рамках некоторого протокола, отображая его в доменные объекты. + +=== Отображение + +NOTE: Шаблон проектирования `Object-Relational Mapping`. + +==== MyBatis + +Отображение MyBatis + +==== SpringData + +Отображение SpringData + +=== Протокол + +NOTE: Обычно используются кастомные протоколы, реже - стандартные. + +==== PostgreSQL + +Кастомный протокол PostgreSQL diff --git a/libs/README.adoc b/libs/README.adoc deleted file mode 100644 index 89114f27..00000000 --- a/libs/README.adoc +++ /dev/null @@ -1,25 +0,0 @@ -Разделяемые модули с публичной или приватной обвязкой. - -=== Client - -include::client/README.adoc[] - -=== Core - -include::essentials/README.adoc[] - -=== Construction - -include::construction/README.adoc[] - -=== Messaging - -include::messaging/README.adoc[] - -=== Data - -include::storage/README.adoc[] - -=== Testing - -include::testing/README.adoc[] diff --git a/libs/construction/README.adoc b/libs/construction/README.adoc deleted file mode 100644 index e68abf87..00000000 --- a/libs/construction/README.adoc +++ /dev/null @@ -1 +0,0 @@ -Приватная обвязка по инициализации/деинициализации. diff --git a/libs/construction/pom.xml b/libs/construction/pom.xml deleted file mode 100644 index 70d329a1..00000000 --- a/libs/construction/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - 4.0.0 - - - smecalculus.bezmen - libs - ${revision} - - - construction - - - - org.springframework.boot - spring-boot-autoconfigure - - - diff --git a/libs/essentials/pom.xml b/libs/essentials/pom.xml index 7328c38d..82257c35 100644 --- a/libs/essentials/pom.xml +++ b/libs/essentials/pom.xml @@ -13,10 +13,25 @@ essentials + ${project.groupId} signatures + + org.jetbrains.kotlin + kotlin-stdlib + + + com.github.spotbugs + spotbugs-annotations + + + com.google.code.findbugs + jsr305 + + + org.hibernate.validator @@ -42,21 +57,7 @@ ch.qos.logback logback-classic - - - org.jetbrains.kotlin - kotlin-stdlib - - - com.github.spotbugs - spotbugs-annotations - - - com.google.code.findbugs - jsr305 - - - + org.mapstruct mapstruct diff --git a/libs/messaging/README.adoc b/libs/messaging/README.adoc index 66e2cdd3..a248c019 100644 --- a/libs/messaging/README.adoc +++ b/libs/messaging/README.adoc @@ -1,2 +1 @@ -Приватная обвязка обмена сообщениями по различным протоколам. -Каждый протокол может иметь несколько имплементаций. += Обмен сообщениями diff --git a/libs/messaging/pom.xml b/libs/messaging/pom.xml index 6d2ec08d..d04b4760 100644 --- a/libs/messaging/pom.xml +++ b/libs/messaging/pom.xml @@ -17,13 +17,15 @@ + ${project.groupId} essentials + - com.typesafe - config + org.springframework + spring-webmvc com.fasterxml.jackson.core @@ -33,15 +35,7 @@ com.fasterxml.jackson.core jackson-databind - - jakarta.servlet - jakarta.servlet-api - - - org.springframework - spring-webmvc - org.eclipse.jetty jetty-servlets @@ -50,6 +44,11 @@ org.eclipse.jetty jetty-webapp + + + org.springframework.boot + spring-boot-autoconfigure + org.springframework.boot spring-boot-actuator @@ -68,7 +67,7 @@ - + ${project.groupId} testing diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpProps.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpProps.java index e2d2ce5a..ff487b21 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpProps.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpProps.java @@ -4,4 +4,4 @@ import lombok.NonNull; @Builder -public record HttpProps(@NonNull WebProps webProps) {} +public record HttpProps(@NonNull MessageMappingProps mappingProps) {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsCfg.java index 4503363e..297f952a 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsCfg.java @@ -7,5 +7,5 @@ public class HttpPropsCfg { @NotNull - WebPropsCfg web; + MessageMappingPropsCfg mapping; } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsEg.java index a280e77f..8ce88f82 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsEg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/HttpPropsEg.java @@ -1,11 +1,11 @@ package smecalculus.bezmen.configuration; -import static smecalculus.bezmen.configuration.MvcPropsEg.Builders.mvcProps; +import static smecalculus.bezmen.configuration.MessageMappingPropsEg.Builders.messageMappingProps; public class HttpPropsEg { public static class Builders { public static HttpProps.Builder httpProps() { - return HttpProps.builder().webProps(mvcProps().build()); + return HttpProps.builder().mappingProps(messageMappingProps().build()); } } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingMode.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingMode.java new file mode 100644 index 00000000..b39cc35c --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingMode.java @@ -0,0 +1,5 @@ +package smecalculus.bezmen.configuration; + +public enum MessageMappingMode { + SPRING_WEB_MVC +} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebProps.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingProps.java similarity index 52% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebProps.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingProps.java index 1c69c120..bc52fd57 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebProps.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingProps.java @@ -3,4 +3,4 @@ import lombok.Builder; @Builder -public record WebProps(WebMode webMode) {} +public record MessageMappingProps(MessageMappingMode mappingMode) {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java similarity index 63% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebPropsCfg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java index b01f6041..ed5d343f 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java @@ -4,8 +4,8 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class WebPropsCfg { +public class MessageMappingPropsCfg { - @ValueOfEnum(WebMode.class) + @ValueOfEnum(MessageMappingMode.class) String mode; } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java new file mode 100644 index 00000000..462d5fe2 --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEg.java @@ -0,0 +1,11 @@ +package smecalculus.bezmen.configuration; + +import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_WEB_MVC; + +public class MessageMappingPropsEg { + public static class Builders { + public static MessageMappingProps.Builder messageMappingProps() { + return MessageMappingProps.builder().mappingMode(SPRING_WEB_MVC); + } + } +} 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 108347f8..0e88da47 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java @@ -9,20 +9,21 @@ public interface MessagingCfgMapper { @Mapping(source = "protocol", target = "protocolProps") MessagingProps toDomain(MessagingPropsCfg messagingPropsCfg); + @Mapping(source = "modes", target = "protocolModes") @Mapping(source = "http", target = "httpProps") - ProtocolProps toDomain(ProtocolPropsCfg protocolPropsCfg); + MessagingProtocolProps toDomain(MessagingProtocolPropsCfg protocolPropsCfg); - @Mapping(source = "web", target = "webProps") + @Mapping(source = "mapping", target = "mappingProps") HttpProps toDomain(HttpPropsCfg httpPropsCfg); - @Mapping(source = "mode", target = "webMode") - WebProps toDomain(WebPropsCfg webPropsCfg); + @Mapping(source = "mode", target = "mappingMode") + MessageMappingProps toDomain(MessageMappingPropsCfg mappingPropsCfg); - default MessagingProtocol toMessagingProtocol(String value) { - return MessagingProtocol.valueOf(value.toUpperCase()); + default MessagingProtocolMode toProtocolMode(String value) { + return MessagingProtocolMode.valueOf(value.toUpperCase()); } - default WebMode toWebMode(String value) { - return WebMode.valueOf(value.toUpperCase()); + default MessageMappingMode toMappingMode(String value) { + return MessageMappingMode.valueOf(value.toUpperCase()); } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProps.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProps.java index 38a6234e..3136bcc4 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProps.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProps.java @@ -4,4 +4,4 @@ import lombok.NonNull; @Builder -public record MessagingProps(@NonNull ProtocolProps protocolProps) {} +public record MessagingProps(@NonNull MessagingProtocolProps protocolProps) {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java index 298e7076..14754618 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java @@ -7,5 +7,5 @@ public class MessagingPropsCfg { @NotNull - ProtocolPropsCfg protocol; + MessagingProtocolPropsCfg protocol; } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEg.java index 18fc531b..604f41c5 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEg.java @@ -1,11 +1,12 @@ package smecalculus.bezmen.configuration; -import static smecalculus.bezmen.configuration.ProtocolPropsEg.Builders.protocolProps; +import static smecalculus.bezmen.configuration.MessagingProtocolPropsEg.Builders.messagingProtocolProps; public class MessagingPropsEg { public static class Builders { public static MessagingProps.Builder messagingProps() { - return MessagingProps.builder().protocolProps(protocolProps().build()); + return MessagingProps.builder() + .protocolProps(messagingProtocolProps().build()); } } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocol.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolMode.java similarity index 60% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocol.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolMode.java index 5a27373b..a8409efa 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocol.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolMode.java @@ -1,5 +1,5 @@ package smecalculus.bezmen.configuration; -public enum MessagingProtocol { +public enum MessagingProtocolMode { HTTP } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolProps.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolProps.java similarity index 51% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolProps.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolProps.java index c287920d..6320e45a 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolProps.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolProps.java @@ -5,4 +5,4 @@ import lombok.NonNull; @Builder -public record ProtocolProps(@NonNull Set types, HttpProps httpProps) {} +public record MessagingProtocolProps(@NonNull Set protocolModes, HttpProps httpProps) {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java similarity index 76% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsCfg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java index 9d0a6f51..551f257f 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java @@ -8,11 +8,11 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class ProtocolPropsCfg { +public class MessagingProtocolPropsCfg { @NotNull @Size(min = 1) - Set<@ValueOfEnum(MessagingProtocol.class) String> types; + Set<@ValueOfEnum(MessagingProtocolMode.class) String> modes; @Optional HttpPropsCfg http; diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEg.java similarity index 57% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsEg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEg.java index 220724cd..98f6d59c 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/ProtocolPropsEg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEg.java @@ -1,15 +1,15 @@ package smecalculus.bezmen.configuration; import static smecalculus.bezmen.configuration.HttpPropsEg.Builders.httpProps; -import static smecalculus.bezmen.configuration.MessagingProtocol.HTTP; +import static smecalculus.bezmen.configuration.MessagingProtocolMode.HTTP; import java.util.Set; -public class ProtocolPropsEg { +public class MessagingProtocolPropsEg { public static class Builders { - public static ProtocolProps.Builder protocolProps() { - return ProtocolProps.builder() - .types(Set.of(HTTP)) + public static MessagingProtocolProps.Builder messagingProtocolProps() { + return MessagingProtocolProps.builder() + .protocolModes(Set.of(HTTP)) .httpProps(httpProps().build()); } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MvcPropsEg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MvcPropsEg.java deleted file mode 100644 index e7f427c1..00000000 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MvcPropsEg.java +++ /dev/null @@ -1,11 +0,0 @@ -package smecalculus.bezmen.configuration; - -import static smecalculus.bezmen.configuration.WebMode.SPRING_MVC; - -public class MvcPropsEg { - public static class Builders { - public static WebProps.Builder mvcProps() { - return WebProps.builder().webMode(SPRING_MVC); - } - } -} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebMode.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebMode.java deleted file mode 100644 index 71a9df21..00000000 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/WebMode.java +++ /dev/null @@ -1,5 +0,0 @@ -package smecalculus.bezmen.configuration; - -public enum WebMode { - SPRING_MVC -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnOrmMode.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessageMappingMode.java similarity index 64% rename from libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnOrmMode.java rename to libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessageMappingMode.java index 05b00715..3ee0d722 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnOrmMode.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessageMappingMode.java @@ -5,11 +5,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Conditional; -import smecalculus.bezmen.configuration.OrmMode; +import smecalculus.bezmen.configuration.MessageMappingMode; @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) -@Conditional(OrmModeCondition.class) -public @interface ConditionalOnOrmMode { - OrmMode value(); +@Conditional(MessageMappingModeCondition.class) +public @interface ConditionalOnMessageMappingMode { + MessageMappingMode value(); } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessagingProtocolMode.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessagingProtocolMode.java new file mode 100644 index 00000000..fcc6cb56 --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnMessagingProtocolMode.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.MessagingProtocolMode; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Conditional(MessagingProtocolModeCondition.class) +public @interface ConditionalOnMessagingProtocolMode { + MessagingProtocolMode value(); +} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/WebSpringMvcBeans.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MappingSpringWebBeans.java similarity index 57% rename from libs/messaging/src/main/java/smecalculus/bezmen/construction/WebSpringMvcBeans.java rename to libs/messaging/src/main/java/smecalculus/bezmen/construction/MappingSpringWebBeans.java index fbd2c7e7..2aba7882 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/WebSpringMvcBeans.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MappingSpringWebBeans.java @@ -1,11 +1,11 @@ package smecalculus.bezmen.construction; -import static smecalculus.bezmen.configuration.WebMode.SPRING_MVC; +import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_WEB_MVC; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @Configuration(proxyBeanMethods = false) -@ConditionalOnWebMode(SPRING_MVC) +@ConditionalOnMessageMappingMode(SPRING_WEB_MVC) @EnableWebMvc -public class WebSpringMvcBeans {} +public class MappingSpringWebBeans {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/WebModeCondition.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java similarity index 65% rename from libs/messaging/src/main/java/smecalculus/bezmen/construction/WebModeCondition.java rename to libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java index 49e8b517..bee57697 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/WebModeCondition.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java @@ -2,28 +2,29 @@ import static java.util.Objects.nonNull; import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; -import static smecalculus.bezmen.configuration.MessagingProtocol.HTTP; +import static smecalculus.bezmen.configuration.MessagingProtocolMode.HTTP; 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.HttpProps; +import smecalculus.bezmen.configuration.MessageMappingMode; import smecalculus.bezmen.configuration.MessagingProps; -import smecalculus.bezmen.configuration.WebMode; -class WebModeCondition implements ConfigurationCondition { +class MessageMappingModeCondition implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - Map attributes = metadata.getAnnotationAttributes(ConditionalOnWebMode.class.getName()); - WebMode mode = (WebMode) attributes.get("value"); + Map attributes = + metadata.getAnnotationAttributes(ConditionalOnMessageMappingMode.class.getName()); + MessageMappingMode mode = (MessageMappingMode) attributes.get("value"); MessagingProps messagingProps = context.getBeanFactory().getBean(MessagingProps.class); - if (!messagingProps.protocolProps().types().contains(HTTP)) { + if (!messagingProps.protocolProps().protocolModes().contains(HTTP)) { return false; } HttpProps httpProps = messagingProps.protocolProps().httpProps(); - return nonNull(httpProps) && mode == httpProps.webProps().webMode(); + return nonNull(httpProps) && mode == httpProps.mappingProps().mappingMode(); } @Override diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingBeans.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingBeans.java index 7228a635..0876d98b 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingBeans.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingBeans.java @@ -4,5 +4,5 @@ import org.springframework.context.annotation.Import; @Configuration(proxyBeanMethods = false) -@Import({MessagingConfigBeans.class, WebSpringMvcBeans.class}) +@Import({MessagingConfigBeans.class, MappingSpringWebBeans.class, ProtocolHttpBeans.class}) public class MessagingBeans {} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java new file mode 100644 index 00000000..075e3fe2 --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java @@ -0,0 +1,27 @@ +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.MessagingProps; +import smecalculus.bezmen.configuration.MessagingProtocolMode; + +class MessagingProtocolModeCondition implements ConfigurationCondition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + Map attributes = + metadata.getAnnotationAttributes(ConditionalOnMessagingProtocolMode.class.getName()); + MessagingProtocolMode mode = (MessagingProtocolMode) attributes.get("value"); + MessagingProps messagingProps = context.getBeanFactory().getBean(MessagingProps.class); + return messagingProps.protocolProps().protocolModes().contains(mode); + } + + @Override + public ConfigurationPhase getConfigurationPhase() { + return REGISTER_BEAN; + } +} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/ProtocolHttpBeans.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ProtocolHttpBeans.java new file mode 100644 index 00000000..981a7853 --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/ProtocolHttpBeans.java @@ -0,0 +1,13 @@ +package smecalculus.bezmen.construction; + +import static smecalculus.bezmen.configuration.MessagingProtocolMode.HTTP; + +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnMessagingProtocolMode(HTTP) +@ImportAutoConfiguration({ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class}) +public class ProtocolHttpBeans {} diff --git a/libs/messaging/src/main/resources/reference.conf b/libs/messaging/src/main/resources/reference.conf index ad0b6630..21dcd2e1 100644 --- a/libs/messaging/src/main/resources/reference.conf +++ b/libs/messaging/src/main/resources/reference.conf @@ -1,12 +1,12 @@ bezmen { messaging { protocol { - types = [http] + modes = [http] http { - web { - mode = spring_mvc + mapping { + mode = spring_web_mvc } } } } -} \ No newline at end of file +} diff --git a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java b/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java index 12ae4ab2..c95a9493 100644 --- a/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java +++ b/libs/messaging/src/test/java/smecalculus/bezmen/configuration/MessagingConfigIT.java @@ -20,12 +20,12 @@ abstract class MessagingConfigIT { MessagingConfig messagingConfig; @Test - void defaultConfShouldBeBackwardCompatible() { + void defaultConfigShouldBeBackwardCompatible() { // given - MessagingProps expectedMessagingProps = messagingProps().build(); + MessagingProps expectedProps = messagingProps().build(); // when - MessagingProps actualMessagingProps = messagingConfig.getMessagingProps(); + MessagingProps actualProps = messagingConfig.getMessagingProps(); // then - assertThat(actualMessagingProps).isEqualTo(expectedMessagingProps); + assertThat(actualProps).isEqualTo(expectedProps); } } diff --git a/libs/pom.xml b/libs/pom.xml index e3f401ad..0eef1a44 100644 --- a/libs/pom.xml +++ b/libs/pom.xml @@ -13,7 +13,7 @@ signatures essentials - construction + messaging storage testing @@ -58,11 +58,6 @@ - - ${project.groupId} - construction - ${project.version} - ${project.groupId} signatures @@ -183,6 +178,11 @@ spring-boot-actuator-autoconfigure ${spring-boot.version} + + org.springframework + spring-web + ${spring.version} + org.springframework spring-webmvc diff --git a/libs/storage/pom.xml b/libs/storage/pom.xml index 5f92b998..9bd631c7 100644 --- a/libs/storage/pom.xml +++ b/libs/storage/pom.xml @@ -45,6 +45,7 @@ org.springframework spring-beans + ${project.groupId} testing diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsEg.java deleted file mode 100644 index ba39bb55..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsEg.java +++ /dev/null @@ -1,19 +0,0 @@ -package smecalculus.bezmen.configuration; - -import static smecalculus.bezmen.configuration.OrmMode.SPRING_DATA; - -public class OrmPropsEg { - public static class Pojos { - public static OrmPropsCfg ormPropsCfg() { - OrmPropsCfg ormPropsCfg = new OrmPropsCfg(); - ormPropsCfg.setMode(SPRING_DATA.name()); - return ormPropsCfg; - } - } - - public static class Builders { - public static OrmProps.Builder ormProps() { - return OrmProps.builder().mode(SPRING_DATA); - } - } -} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmMode.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingMode.java similarity index 70% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmMode.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingMode.java index 2004aee5..40335f1a 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmMode.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingMode.java @@ -1,6 +1,6 @@ package smecalculus.bezmen.configuration; -public enum OrmMode { +public enum StateMappingMode { SPRING_DATA, MY_BATIS } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java similarity index 53% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmProps.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java index 9d6b4c68..f8010d0c 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmProps.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java @@ -3,4 +3,4 @@ import lombok.Builder; @Builder -public record OrmProps(OrmMode mode) {} +public record StateMappingProps(StateMappingMode mappingMode) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java similarity index 65% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java index b878848a..dfd890f0 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/OrmPropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java @@ -4,8 +4,8 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class OrmPropsCfg { +public class StateMappingPropsCfg { - @ValueOfEnum(OrmMode.class) + @ValueOfEnum(StateMappingMode.class) private String mode; } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java new file mode 100644 index 00000000..c7bb4c25 --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java @@ -0,0 +1,19 @@ +package smecalculus.bezmen.configuration; + +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; + +public class StateMappingPropsEg { + public static class Pojos { + public static StateMappingPropsCfg stateMappingPropsCfg() { + StateMappingPropsCfg propsCfg = new StateMappingPropsCfg(); + propsCfg.setMode(SPRING_DATA.name()); + return propsCfg; + } + } + + public static class Builders { + public static StateMappingProps.Builder stateMappingProps() { + return StateMappingProps.builder().mappingMode(SPRING_DATA); + } + } +} 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 32eacb99..7c6c1e77 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java @@ -6,21 +6,23 @@ @Mapper public interface StorageCfgMapper { - @Mapping(source = "vendor", target = "vendorProps") - @Mapping(source = "orm", target = "ormProps") + @Mapping(source = "protocol", target = "protocolProps") + @Mapping(source = "mapping", target = "mappingProps") StorageProps toDomain(StoragePropsCfg storagePropsCfg); + @Mapping(source = "mode", target = "protocolMode") @Mapping(source = "h2", target = "h2Props") @Mapping(source = "postgres", target = "postgresProps") - VendorProps toDomain(VendorPropsCfg vendorPropsCfg); + StorageProtocolProps toDomain(StorageProtocolPropsCfg propsCfg); - OrmProps toDomain(OrmPropsCfg ormPropsCfg); + @Mapping(source = "mode", target = "mappingMode") + StateMappingProps toDomain(StateMappingPropsCfg propsCfg); - default VendorMode toVendorMode(String mode) { - return VendorMode.valueOf(mode.toUpperCase()); + default StorageProtocolMode toProtocolMode(String mode) { + return StorageProtocolMode.valueOf(mode.toUpperCase()); } - default OrmMode toOrmMode(String mode) { - return OrmMode.valueOf(mode.toUpperCase()); + default StateMappingMode toMappingMode(String mode) { + return StateMappingMode.valueOf(mode.toUpperCase()); } } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java index 4ad9d78e..d5b13b05 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProps.java @@ -4,4 +4,4 @@ import lombok.NonNull; @Builder -public record StorageProps(@NonNull VendorProps vendorProps, @NonNull OrmProps ormProps) {} +public record StorageProps(@NonNull StorageProtocolProps protocolProps, @NonNull StateMappingProps mappingProps) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java index e350d492..1e55f192 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java @@ -7,8 +7,8 @@ public class StoragePropsCfg { @NotNull - VendorPropsCfg vendor; + StorageProtocolPropsCfg protocol; @NotNull - OrmPropsCfg orm; + StateMappingPropsCfg mapping; } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java index 07904dfc..9f9fe983 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java @@ -1,16 +1,16 @@ package smecalculus.bezmen.configuration; -import static smecalculus.bezmen.configuration.OrmPropsEg.Builders.ormProps; -import static smecalculus.bezmen.configuration.OrmPropsEg.Pojos.ormPropsCfg; -import static smecalculus.bezmen.configuration.VendorPropsEg.Builders.vendorProps; -import static smecalculus.bezmen.configuration.VendorPropsEg.Pojos.vendorPropsCfg; +import static smecalculus.bezmen.configuration.StateMappingPropsEg.Builders.stateMappingProps; +import static smecalculus.bezmen.configuration.StateMappingPropsEg.Pojos.stateMappingPropsCfg; +import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Builders.storageProtocolProps; +import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Pojos.storageProtocolPropsCfg; public class StoragePropsEg { public static class Pojos { public static StoragePropsCfg storagePropsCfg() { StoragePropsCfg storagePropsCfg = new StoragePropsCfg(); - storagePropsCfg.setVendor(vendorPropsCfg()); - storagePropsCfg.setOrm(ormPropsCfg()); + storagePropsCfg.setProtocol(storageProtocolPropsCfg()); + storagePropsCfg.setMapping(stateMappingPropsCfg()); return storagePropsCfg; } } @@ -18,8 +18,8 @@ public static StoragePropsCfg storagePropsCfg() { public static class Builders { public static StorageProps.Builder storageProps() { return StorageProps.builder() - .vendorProps(vendorProps().build()) - .ormProps(ormProps().build()); + .protocolProps(storageProtocolProps().build()) + .mappingProps(stateMappingProps().build()); } } } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorMode.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolMode.java similarity index 66% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorMode.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolMode.java index 88e8f04b..6c0eb350 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorMode.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolMode.java @@ -1,6 +1,6 @@ package smecalculus.bezmen.configuration; -public enum VendorMode { +public enum StorageProtocolMode { H2, POSTGRES } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java new file mode 100644 index 00000000..c6226c6c --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolProps.java @@ -0,0 +1,9 @@ +package smecalculus.bezmen.configuration; + +import edu.umd.cs.findbugs.annotations.Nullable; +import lombok.Builder; +import lombok.NonNull; + +@Builder +public record StorageProtocolProps( + @NonNull StorageProtocolMode protocolMode, @Nullable H2Props h2Props, @Nullable PostgresProps postgresProps) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java similarity index 75% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java index a89299fa..82a23b70 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java @@ -5,9 +5,9 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class VendorPropsCfg { +public class StorageProtocolPropsCfg { - @ValueOfEnum(VendorMode.class) + @ValueOfEnum(StorageProtocolMode.class) String mode; @Optional diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java new file mode 100644 index 00000000..e4e89b39 --- /dev/null +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java @@ -0,0 +1,28 @@ +package smecalculus.bezmen.configuration; + +public class StorageProtocolPropsEg { + public static class Pojos { + public static StorageProtocolPropsCfg storageProtocolPropsCfg() { + StorageProtocolPropsCfg propsCfg = new StorageProtocolPropsCfg(); + propsCfg.setMode(StorageProtocolMode.H2.name()); + return propsCfg; + } + } + + public static class Builders { + public static StorageProtocolProps.Builder storageProtocolProps() { + return StorageProtocolProps.builder() + .protocolMode(StorageProtocolMode.H2) + .h2Props(H2Props.builder() + .url("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1") + .username("sa") + .password("sa") + .build()) + .postgresProps(PostgresProps.builder() + .url("jdbc:postgresql://localhost:5432/bezmen") + .username("bezmen") + .password("bezmen") + .build()); + } + } +} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorProps.java deleted file mode 100644 index 1f9d18bd..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorProps.java +++ /dev/null @@ -1,8 +0,0 @@ -package smecalculus.bezmen.configuration; - -import edu.umd.cs.findbugs.annotations.Nullable; -import lombok.Builder; -import lombok.NonNull; - -@Builder -public record VendorProps(@NonNull VendorMode mode, @Nullable H2Props h2Props, @Nullable PostgresProps postgresProps) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsEg.java deleted file mode 100644 index 63741585..00000000 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/VendorPropsEg.java +++ /dev/null @@ -1,24 +0,0 @@ -package smecalculus.bezmen.configuration; - -public class VendorPropsEg { - public static class Pojos { - public static VendorPropsCfg vendorPropsCfg() { - VendorPropsCfg vendorPropsCfg = new VendorPropsCfg(); - vendorPropsCfg.setMode(VendorMode.H2.name()); - return vendorPropsCfg; - } - } - - public static class Builders { - public static VendorProps.Builder vendorProps() { - return VendorProps.builder() - .mode(VendorMode.H2) - .h2Props(H2Props.builder() - .url("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1") - .username("sa") - .password("sa") - .build()) - .postgresProps(null); - } - } -} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnWebMode.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnStateMappingMode.java similarity index 65% rename from libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnWebMode.java rename to libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnStateMappingMode.java index a4544043..3b1eb03c 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/ConditionalOnWebMode.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/ConditionalOnStateMappingMode.java @@ -5,11 +5,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Conditional; -import smecalculus.bezmen.configuration.WebMode; +import smecalculus.bezmen.configuration.StateMappingMode; @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) -@Conditional(WebModeCondition.class) -public @interface ConditionalOnWebMode { - WebMode value(); +@Conditional(StateMappingModeCondition.class) +public @interface ConditionalOnStateMappingMode { + StateMappingMode value(); } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmMyBatisBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java similarity index 82% rename from libs/storage/src/main/java/smecalculus/bezmen/construction/OrmMyBatisBeans.java rename to libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java index 4b2516b5..8339f75c 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmMyBatisBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java @@ -1,6 +1,6 @@ package smecalculus.bezmen.construction; -import static smecalculus.bezmen.configuration.OrmMode.MY_BATIS; +import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS; import javax.sql.DataSource; import org.apache.ibatis.session.SqlSessionFactory; @@ -10,9 +10,9 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) -@ConditionalOnOrmMode(MY_BATIS) +@ConditionalOnStateMappingMode(MY_BATIS) @MapperScan(basePackages = "smecalculus.bezmen.storage.mybatis") -public class OrmMyBatisBeans { +public class MappingMyBatisBeans { @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmSpringDataBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java similarity index 78% rename from libs/storage/src/main/java/smecalculus/bezmen/construction/OrmSpringDataBeans.java rename to libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java index f6fb61ab..927dfc67 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmSpringDataBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java @@ -1,6 +1,6 @@ package smecalculus.bezmen.construction; -import static smecalculus.bezmen.configuration.OrmMode.SPRING_DATA; +import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA; import javax.sql.DataSource; import org.springframework.context.annotation.Bean; @@ -14,12 +14,12 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.VendorProps; +import smecalculus.bezmen.configuration.StorageProtocolProps; @Configuration(proxyBeanMethods = false) -@ConditionalOnOrmMode(SPRING_DATA) +@ConditionalOnStateMappingMode(SPRING_DATA) @EnableJdbcRepositories("smecalculus.bezmen.storage.springdata") -public class OrmSpringDataBeans extends AbstractJdbcConfiguration { +public class MappingSpringDataBeans extends AbstractJdbcConfiguration { @Bean public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) { @@ -33,8 +33,8 @@ public PlatformTransactionManager transactionManager(DataSource dataSource) { @Bean public Dialect dialect(StorageProps storageProps) { - VendorProps vendorProps = storageProps.vendorProps(); - return switch (vendorProps.mode()) { + StorageProtocolProps storageProtocolProps = storageProps.protocolProps(); + return switch (storageProtocolProps.protocolMode()) { case H2 -> H2Dialect.INSTANCE; case POSTGRES -> PostgresDialect.INSTANCE; }; diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmModeCondition.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java similarity index 64% rename from libs/storage/src/main/java/smecalculus/bezmen/construction/OrmModeCondition.java rename to libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java index 085303fe..ff5dd6ba 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/OrmModeCondition.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java @@ -6,17 +6,18 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; -import smecalculus.bezmen.configuration.OrmMode; +import smecalculus.bezmen.configuration.StateMappingMode; import smecalculus.bezmen.configuration.StorageProps; -class OrmModeCondition implements ConfigurationCondition { +class StateMappingModeCondition implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - Map attributes = metadata.getAnnotationAttributes(ConditionalOnOrmMode.class.getName()); - OrmMode mode = (OrmMode) attributes.get("value"); + Map attributes = + metadata.getAnnotationAttributes(ConditionalOnStateMappingMode.class.getName()); + StateMappingMode mode = (StateMappingMode) attributes.get("value"); StorageProps props = context.getBeanFactory().getBean(StorageProps.class); - return mode == props.ormProps().mode(); + return mode == props.mappingProps().mappingMode(); } @Override diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java index ec9e2d52..2ffa68f3 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java @@ -8,19 +8,19 @@ import smecalculus.bezmen.configuration.H2Props; import smecalculus.bezmen.configuration.PostgresProps; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.VendorProps; +import smecalculus.bezmen.configuration.StorageProtocolProps; @Configuration(proxyBeanMethods = false) -@Import({StorageConfigBeans.class, OrmMyBatisBeans.class, OrmSpringDataBeans.class}) +@Import({StorageConfigBeans.class, MappingMyBatisBeans.class, MappingSpringDataBeans.class}) public class StorageBeans { @Bean public DataSource dataSource(StorageProps storageProps) { DriverManagerDataSource dataSource = new DriverManagerDataSource(); - VendorProps vendorProps = storageProps.vendorProps(); - switch (vendorProps.mode()) { - case H2 -> configure(dataSource, vendorProps.h2Props()); - case POSTGRES -> configure(dataSource, vendorProps.postgresProps()); + StorageProtocolProps storageProtocolProps = storageProps.protocolProps(); + switch (storageProtocolProps.protocolMode()) { + case H2 -> configure(dataSource, storageProtocolProps.h2Props()); + case POSTGRES -> configure(dataSource, storageProtocolProps.postgresProps()); } return dataSource; } diff --git a/libs/storage/src/main/resources/reference.conf b/libs/storage/src/main/resources/reference.conf index f1764fd6..0289af7f 100644 --- a/libs/storage/src/main/resources/reference.conf +++ b/libs/storage/src/main/resources/reference.conf @@ -1,14 +1,19 @@ bezmen { storage { - vendor { + 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" + } } - orm { + mapping { mode = spring_data } } diff --git a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java b/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java index 56478a46..fc4abfa2 100644 --- a/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java +++ b/libs/storage/src/test/java/smecalculus/bezmen/configuration/StorageConfigIT.java @@ -20,12 +20,12 @@ abstract class StorageConfigIT { StorageConfig storageConfig; @Test - void defaultConfShouldBeBackwardCompatible() { + void defaultConfigShouldBeBackwardCompatible() { // given - StorageProps expectedStorageProps = storageProps().build(); + StorageProps expectedProps = storageProps().build(); // when - StorageProps actualStorageProps = storageConfig.getStorageProps(); + StorageProps actualProps = storageConfig.getStorageProps(); // then - assertThat(actualStorageProps).isEqualTo(expectedStorageProps); + assertThat(actualProps).isEqualTo(expectedProps); } } diff --git a/libs/testing/pom.xml b/libs/testing/pom.xml index f70a0076..82a65a80 100644 --- a/libs/testing/pom.xml +++ b/libs/testing/pom.xml @@ -45,6 +45,10 @@ org.springframework spring-webflux + + jakarta.servlet + jakarta.servlet-api + org.junit.jupiter diff --git a/solutions/basis/church.conf b/solutions/basis/church.conf index d2ac09c3..d30edf69 100644 --- a/solutions/basis/church.conf +++ b/solutions/basis/church.conf @@ -1,6 +1,6 @@ bezmen { storage { - vendor { + protocol { mode = postgres postgres { url = "jdbc:postgresql://db:5432/bezmen" @@ -8,7 +8,7 @@ bezmen { password = "bezmen" } } - orm { + mapping { mode = my_batis } } diff --git a/solutions/basis/turing.conf b/solutions/basis/turing.conf index a0a610d6..c2cddac4 100644 --- a/solutions/basis/turing.conf +++ b/solutions/basis/turing.conf @@ -1,6 +1,6 @@ bezmen { storage { - vendor { + protocol { mode = postgres postgres { url = "jdbc:postgresql://db:5432/bezmen" @@ -8,7 +8,7 @@ bezmen { password = "bezmen" } } - orm { + mapping { mode = spring_data } } diff --git a/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java b/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java index d1b3b79d..67a2a283 100644 --- a/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java +++ b/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java @@ -28,7 +28,7 @@ public class SepulkaTest { @BeforeAll void beforeAll() { - await().atMost(ofSeconds(5)).until(bezmenClient::isReady); + await("isReady").atMost(ofSeconds(5)).until(bezmenClient::isReady); } @Test @@ -48,13 +48,13 @@ void shouldRegisterSepulka() { } @Test - @EnabledIfSystemProperty(named = "storage.vendor.mode", matches = "postgres") + @EnabledIfSystemProperty(named = "storage.protocol.mode", matches = "postgres") void postgresSpecificTest() { // empty } @Test - @EnabledIfSystemProperty(named = "storage.vendor.mode", matches = "sqlite") + @EnabledIfSystemProperty(named = "storage.protocol.mode", matches = "sqlite") void sqliteSpecificTest() { // empty } diff --git a/tests/prefs/church.properties b/tests/prefs/church.properties index 20a59491..566aaaf4 100644 --- a/tests/prefs/church.properties +++ b/tests/prefs/church.properties @@ -1,2 +1,2 @@ -storage.vendor.mode=sqlite -storage.orm.mode=my_batis +storage.protocol.mode=sqlite +storage.mapping.mode=my_batis diff --git a/tests/prefs/turing.properties b/tests/prefs/turing.properties index 832b8695..75c97d25 100644 --- a/tests/prefs/turing.properties +++ b/tests/prefs/turing.properties @@ -1,2 +1,2 @@ -storage.vendor.mode=postgres -storage.orm.mode=spring_data +storage.protocol.mode=postgres +storage.mapping.mode=spring_data