From 22e164dc2210b19c24c311bc3e18c50ca74840c0 Mon Sep 17 00:00:00 2001 From: Pavel Vetokhin Date: Sat, 14 Oct 2023 14:01:23 +0300 Subject: [PATCH] Refine props reading (#165) --- .../smecalculus/bezmen/construction/App.java | 22 ++++++------ .../bezmen/core/SepulkaServiceImpl.java | 2 +- .../bezmen/messaging/SepulkaClientImpl.java | 10 +++--- .../springmvc/SepulkaController.java | 10 +++--- .../bezmen/storage/SepulkaDao.java | 3 ++ .../bezmen/storage/SepulkaDaoMyBatis.java | 10 +++--- .../bezmen/storage/SepulkaDaoSpringData.java | 8 ++--- .../{SepulkaRec.java => SepulkaEdge.java} | 2 +- .../bezmen/storage/SepulkaRecMapper.java | 11 ------ .../bezmen/storage/SepulkaStateMapper.java | 11 ++++++ .../storage/mybatis/SepulkaSqlMapper.java | 8 ++--- .../storage/springdata/SepulkaRepository.java | 4 +-- .../construction/SepulkaClientBeans.java | 10 +++--- .../bezmen/construction/SepulkaDaoBeans.java | 22 ++++++------ .../bezmen/messaging/SepulkaClientIT.java | 8 ++--- .../messaging/SepulkaClientSpringWebIT.java | 3 -- .../SepulkaClientSpringWebTestIT.java | 3 ++ .../bezmen/storage/SepulkaDaoIT.java | 7 ++-- .../bezmen/messaging/SepulkaClient.java | 2 +- ...estMsg.java => SepulkaNewRequestEdge.java} | 2 +- .../bezmen/messaging/SepulkaNewRequestEg.java | 8 ++--- ...seMsg.java => SepulkaNewResponseEdge.java} | 2 +- .../messaging/SepulkaNewResponseEg.java | 16 ++++----- .../{ConfigKeeper.java => PropsKeeper.java} | 2 +- .../bezmen/core/SepulkaSliceMapper.java | 2 +- ...g.java => PropsKeeperLightbendConfig.java} | 2 +- ...nfig.java => PropsKeeperSpringConfig.java} | 2 +- .../bezmen/configuration/ValidationMode.java | 5 +++ .../bezmen/configuration/ValidationProps.java | 7 ++++ .../configuration/ValidationPropsEdge.java | 8 +++++ .../ConditionalOnValidationMode.java | 15 ++++++++ .../bezmen/construction/ConfigBeans.java | 14 ++++---- .../ConfigMappingModeCondition.java | 9 +++-- .../ConfigProtocolModeCondition.java | 5 +-- .../bezmen/construction/ValidationBeans.java | 34 +++++++++++++++++-- .../construction/ValidationModeCondition.java | 26 ++++++++++++++ .../EdgeValidatorHibernateValidator.java | 4 +-- .../validation/ValidationPropsMapper.java | 17 ++++++++++ .../src/main/resources/reference.conf | 5 +++ .../src/main/resources/validation.properties | 1 + .../messaging/BezmenClientJavaHttp.java | 4 +-- ...sCfg.java => MessageMappingPropsEdge.java} | 2 +- ...gPropsCfg.java => MessagingPropsEdge.java} | 6 ++-- ...gMapper.java => MessagingPropsMapper.java} | 8 ++--- ...g.java => MessagingProtocolPropsEdge.java} | 2 +- .../MessageMappingModeCondition.java | 14 ++++---- .../construction/MessagingConfigBeans.java | 22 ++++++------ .../MessagingProtocolModeCondition.java | 14 ++++---- .../messaging/SepulkaMessageMapper.java | 12 +++++++ .../bezmen/messaging/SepulkaMsgMapper.java | 14 -------- .../construction/MessagingConfigBeansIT.java | 2 +- .../{H2PropsCfg.java => H2PropsEdge.java} | 2 +- ...esPropsCfg.java => PostgresPropsEdge.java} | 2 +- .../configuration/StateMappingProps.java | 3 +- ...opsCfg.java => StateMappingPropsEdge.java} | 2 +- .../configuration/StateMappingPropsEg.java | 8 ++--- ...agePropsCfg.java => StoragePropsEdge.java} | 6 ++-- .../bezmen/configuration/StoragePropsEg.java | 14 ++++---- ...CfgMapper.java => StoragePropsMapper.java} | 8 ++--- ...Cfg.java => StorageProtocolPropsEdge.java} | 6 ++-- .../configuration/StorageProtocolPropsEg.java | 8 ++--- .../construction/MappingMyBatisBeans.java | 2 +- .../construction/MappingSpringDataBeans.java | 3 +- .../StateMappingModeCondition.java | 11 +++--- .../bezmen/construction/StorageBeans.java | 5 ++- .../construction/StorageConfigBeans.java | 22 ++++++------ .../construction/StorageConfigBeansTest.java | 20 +++++------ .../bezmen/construction/TestingBeans.java | 22 ------------ ...b.java => SepulkaClientSpringWebTest.java} | 6 ++-- .../java/smecalculus/bezmen/StandBeans.java | 4 +-- .../bezmen/registration/SepulkaTest.java | 8 ++--- 71 files changed, 343 insertions(+), 261 deletions(-) rename apps/sepuling/src/main/java/smecalculus/bezmen/storage/{SepulkaRec.java => SepulkaEdge.java} (92%) delete mode 100644 apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRecMapper.java create mode 100644 apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaStateMapper.java delete mode 100644 apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebIT.java create mode 100644 apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTestIT.java rename libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/{SepulkaNewRequestMsg.java => SepulkaNewRequestEdge.java} (83%) rename libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/{SepulkaNewResponseMsg.java => SepulkaNewResponseEdge.java} (82%) rename libs/abstraction/src/main/java/smecalculus/bezmen/configuration/{ConfigKeeper.java => PropsKeeper.java} (73%) rename libs/essentials/src/main/java/smecalculus/bezmen/configuration/{ConfigKeeperLightbendConfig.java => PropsKeeperLightbendConfig.java} (85%) rename libs/essentials/src/main/java/smecalculus/bezmen/configuration/{ConfigKeeperSpringConfig.java => PropsKeeperSpringConfig.java} (87%) create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationMode.java create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationProps.java create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationPropsEdge.java create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnValidationMode.java create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationModeCondition.java create mode 100644 libs/essentials/src/main/java/smecalculus/bezmen/validation/ValidationPropsMapper.java create mode 100644 libs/essentials/src/main/resources/reference.conf create mode 100644 libs/essentials/src/main/resources/validation.properties rename libs/messaging/src/main/java/smecalculus/bezmen/configuration/{MessageMappingPropsCfg.java => MessageMappingPropsEdge.java} (89%) rename libs/messaging/src/main/java/smecalculus/bezmen/configuration/{MessagingPropsCfg.java => MessagingPropsEdge.java} (56%) rename libs/messaging/src/main/java/smecalculus/bezmen/configuration/{MessagingCfgMapper.java => MessagingPropsMapper.java} (71%) rename libs/messaging/src/main/java/smecalculus/bezmen/configuration/{MessagingProtocolPropsCfg.java => MessagingProtocolPropsEdge.java} (88%) create mode 100644 libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMessageMapper.java delete mode 100644 libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMsgMapper.java rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{H2PropsCfg.java => H2PropsEdge.java} (89%) rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{PostgresPropsCfg.java => PostgresPropsEdge.java} (89%) rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{StateMappingPropsCfg.java => StateMappingPropsEdge.java} (83%) rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{StoragePropsCfg.java => StoragePropsEdge.java} (58%) rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{StorageCfgMapper.java => StoragePropsMapper.java} (75%) rename libs/storage/src/main/java/smecalculus/bezmen/configuration/{StorageProtocolPropsCfg.java => StorageProtocolPropsEdge.java} (73%) delete mode 100644 libs/testing/src/main/java/smecalculus/bezmen/construction/TestingBeans.java rename libs/testing/src/main/java/smecalculus/bezmen/messaging/{SepulkaClientSpringWeb.java => SepulkaClientSpringWebTest.java} (75%) diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java b/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java index 9aa3c617..9bd509a2 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/construction/App.java @@ -15,14 +15,14 @@ import smecalculus.bezmen.core.SepulkaSliceMapperImpl; import smecalculus.bezmen.messaging.SepulkaClient; import smecalculus.bezmen.messaging.SepulkaClientImpl; -import smecalculus.bezmen.messaging.SepulkaMsgMapper; -import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl; +import smecalculus.bezmen.messaging.SepulkaMessageMapper; +import smecalculus.bezmen.messaging.SepulkaMessageMapperImpl; import smecalculus.bezmen.messaging.springmvc.SepulkaController; import smecalculus.bezmen.storage.SepulkaDao; import smecalculus.bezmen.storage.SepulkaDaoMyBatis; import smecalculus.bezmen.storage.SepulkaDaoSpringData; -import smecalculus.bezmen.storage.SepulkaRecMapper; -import smecalculus.bezmen.storage.SepulkaRecMapperImpl; +import smecalculus.bezmen.storage.SepulkaStateMapper; +import smecalculus.bezmen.storage.SepulkaStateMapperImpl; import smecalculus.bezmen.storage.mybatis.SepulkaSqlMapper; import smecalculus.bezmen.storage.springdata.SepulkaRepository; import smecalculus.bezmen.validation.EdgeValidator; @@ -43,12 +43,12 @@ SepulkaController sepulkaControllerSpringMvc(SepulkaClient client) { } @Bean - SepulkaMsgMapper sepulkaMsgMapper() { - return new SepulkaMsgMapperImpl(); + SepulkaMessageMapper sepulkaMessageMapper() { + return new SepulkaMessageMapperImpl(); } @Bean - SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaMsgMapper mapper, SepulkaService service) { + SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaMessageMapper mapper, SepulkaService service) { return new SepulkaClientImpl(validator, mapper, service); } @@ -63,19 +63,19 @@ SepulkaService sepulkaService(SepulkaSliceMapper mapper, SepulkaDao dao) { } @Bean - SepulkaRecMapper sepulkaRecMapper() { - return new SepulkaRecMapperImpl(); + SepulkaStateMapper sepulkaStateMapper() { + return new SepulkaStateMapperImpl(); } @Bean @ConditionalOnStateMappingMode(SPRING_DATA) - SepulkaDaoSpringData sepulkaDaoSpringData(SepulkaRecMapper mapper, SepulkaRepository repository) { + SepulkaDaoSpringData sepulkaDaoSpringData(SepulkaStateMapper mapper, SepulkaRepository repository) { return new SepulkaDaoSpringData(mapper, repository); } @Bean @ConditionalOnStateMappingMode(MY_BATIS) - SepulkaDaoMyBatis sepulkaDaoMyBatis(SepulkaRecMapper recMapper, SepulkaSqlMapper sqlMapper) { + SepulkaDaoMyBatis sepulkaDaoMyBatis(SepulkaStateMapper recMapper, SepulkaSqlMapper sqlMapper) { return new SepulkaDaoMyBatis(recMapper, sqlMapper); } } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java b/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java index 3b31ceb0..aecda976 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/core/SepulkaServiceImpl.java @@ -18,7 +18,7 @@ public class SepulkaServiceImpl implements SepulkaService { @Override public SepulkaNewResponse register(SepulkaNewRequest request) { - var sepulkaCreated = mapper.toDomain(request).id(randomUUID()).build(); + var sepulkaCreated = mapper.toEntity(request).id(randomUUID()).build(); var sepulkaSaved = dao.save(sepulkaCreated); return mapper.toSlice(sepulkaSaved); } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java b/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java index bd2ae3c8..9f1a47ce 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/SepulkaClientImpl.java @@ -12,16 +12,16 @@ public class SepulkaClientImpl implements SepulkaClient { private EdgeValidator validator; @NonNull - private SepulkaMsgMapper mapper; + private SepulkaMessageMapper mapper; @NonNull private SepulkaService service; @Override - public SepulkaNewResponseMsg register(SepulkaNewRequestMsg requestMsg) { - validator.validate(requestMsg); - var request = mapper.toDomain(requestMsg); + public SepulkaNewResponseEdge register(SepulkaNewRequestEdge requestEdge) { + validator.validate(requestEdge); + var request = mapper.toDomain(requestEdge); var response = service.register(request); - return mapper.toMsg(response); + return mapper.toEdge(response); } } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java b/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java index edfb6da3..c9b877ff 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/messaging/springmvc/SepulkaController.java @@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import smecalculus.bezmen.messaging.SepulkaClient; -import smecalculus.bezmen.messaging.SepulkaNewRequestMsg; -import smecalculus.bezmen.messaging.SepulkaNewResponseMsg; +import smecalculus.bezmen.messaging.SepulkaNewRequestEdge; +import smecalculus.bezmen.messaging.SepulkaNewResponseEdge; @RestController @RequestMapping("sepulkas") @@ -21,8 +21,8 @@ public class SepulkaController { private SepulkaClient client; @PostMapping - ResponseEntity register(@RequestBody SepulkaNewRequestMsg requestMsg) { - var responseMsg = client.register(requestMsg); - return ResponseEntity.status(HttpStatus.CREATED).body(responseMsg); + ResponseEntity register(@RequestBody SepulkaNewRequestEdge requestEdge) { + var responseEdge = client.register(requestEdge); + return ResponseEntity.status(HttpStatus.CREATED).body(responseEdge); } } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDao.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDao.java index 32a13ccb..3cea0706 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDao.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDao.java @@ -4,6 +4,9 @@ import java.util.UUID; import smecalculus.bezmen.core.Sepulka; +/** + * Server side interface + */ public interface SepulkaDao { Sepulka getById(UUID id); diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoMyBatis.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoMyBatis.java index d4b47889..90e025df 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoMyBatis.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoMyBatis.java @@ -13,25 +13,25 @@ public class SepulkaDaoMyBatis implements SepulkaDao { @NonNull - private SepulkaRecMapper recMapper; + private SepulkaStateMapper stateMapper; @NonNull private SepulkaSqlMapper sqlMapper; @Override public Sepulka getById(@NonNull UUID id) { - return sqlMapper.findById(id.toString()).map(recMapper::toDomain).orElse(null); + return sqlMapper.findById(id.toString()).map(stateMapper::toDomain).orElse(null); } @Override public Sepulka save(@NonNull Sepulka sepulka) { - SepulkaRec sepulkaRec = recMapper.toRec(sepulka); - sqlMapper.insert(sepulkaRec); + var sepulkaEdge = stateMapper.toEdge(sepulka); + sqlMapper.insert(sepulkaEdge); return sepulka; } @Override public List getSepulkas() { - return sqlMapper.selectAll().stream().map(recMapper::toDomain).collect(toList()); + return sqlMapper.selectAll().stream().map(stateMapper::toDomain).collect(toList()); } } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoSpringData.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoSpringData.java index fef83ba2..b5fce727 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoSpringData.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaDaoSpringData.java @@ -14,7 +14,7 @@ public class SepulkaDaoSpringData implements SepulkaDao { @NonNull - private SepulkaRecMapper mapper; + private SepulkaStateMapper mapper; @NonNull private SepulkaRepository repository; @@ -26,9 +26,9 @@ public Sepulka getById(@NonNull UUID id) { @Override public Sepulka save(@NonNull Sepulka sepulka) { - SepulkaRec newSepulkaRec = mapper.toRec(sepulka); - SepulkaRec savedSepulkaRec = repository.save(newSepulkaRec); - return mapper.toDomain(savedSepulkaRec); + var newSepulkaEdge = mapper.toEdge(sepulka); + var savedSepulkaEdge = repository.save(newSepulkaEdge); + return mapper.toDomain(savedSepulkaEdge); } @Override diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRec.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaEdge.java similarity index 92% rename from apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRec.java rename to apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaEdge.java index dc6bcda9..775949be 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRec.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaEdge.java @@ -10,7 +10,7 @@ */ @Data @Table("sepulkas") -public class SepulkaRec { +public class SepulkaEdge { @Id String id; diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRecMapper.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRecMapper.java deleted file mode 100644 index 3bc8ccf1..00000000 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaRecMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package smecalculus.bezmen.storage; - -import org.mapstruct.Mapper; -import smecalculus.bezmen.core.Sepulka; - -@Mapper -public interface SepulkaRecMapper { - SepulkaRec toRec(Sepulka sepulka); - - Sepulka toDomain(SepulkaRec sepulkaRec); -} diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaStateMapper.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaStateMapper.java new file mode 100644 index 00000000..4a8c2788 --- /dev/null +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/SepulkaStateMapper.java @@ -0,0 +1,11 @@ +package smecalculus.bezmen.storage; + +import org.mapstruct.Mapper; +import smecalculus.bezmen.core.Sepulka; + +@Mapper +public interface SepulkaStateMapper { + SepulkaEdge toEdge(Sepulka sepulka); + + Sepulka toDomain(SepulkaEdge sepulkaEdge); +} diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/mybatis/SepulkaSqlMapper.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/mybatis/SepulkaSqlMapper.java index d617ecc4..f85a3af2 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/mybatis/SepulkaSqlMapper.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/mybatis/SepulkaSqlMapper.java @@ -5,16 +5,16 @@ import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; -import smecalculus.bezmen.storage.SepulkaRec; +import smecalculus.bezmen.storage.SepulkaEdge; public interface SepulkaSqlMapper { @Insert("INSERT INTO sepulkas (id, version, name) VALUES (#{id}, #{version}, #{name})") - void insert(SepulkaRec sepulkaRec); + void insert(SepulkaEdge sepulkaEdge); @Select("SELECT id, version, name FROM sepulkas WHERE id = #{id}") - Optional findById(@Param("id") String id); + Optional findById(@Param("id") String id); @Select("SELECT * FROM sepulkas") - List selectAll(); + List selectAll(); } diff --git a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/springdata/SepulkaRepository.java b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/springdata/SepulkaRepository.java index 947734b8..04e5bfc6 100644 --- a/apps/sepuling/src/main/java/smecalculus/bezmen/storage/springdata/SepulkaRepository.java +++ b/apps/sepuling/src/main/java/smecalculus/bezmen/storage/springdata/SepulkaRepository.java @@ -1,6 +1,6 @@ package smecalculus.bezmen.storage.springdata; import org.springframework.data.repository.CrudRepository; -import smecalculus.bezmen.storage.SepulkaRec; +import smecalculus.bezmen.storage.SepulkaEdge; -public interface SepulkaRepository extends CrudRepository {} +public interface SepulkaRepository extends CrudRepository {} diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java index b19ba583..9e745d65 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaClientBeans.java @@ -9,12 +9,12 @@ import smecalculus.bezmen.core.SepulkaService; import smecalculus.bezmen.messaging.SepulkaClient; import smecalculus.bezmen.messaging.SepulkaClientImpl; -import smecalculus.bezmen.messaging.SepulkaClientSpringWeb; -import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl; +import smecalculus.bezmen.messaging.SepulkaClientSpringWebTest; +import smecalculus.bezmen.messaging.SepulkaMessageMapperImpl; import smecalculus.bezmen.messaging.springmvc.SepulkaController; import smecalculus.bezmen.validation.EdgeValidator; -@Import(ValidationBeans.class) +@Import({ConfigBeans.class, ValidationBeans.class}) @Configuration(proxyBeanMethods = false) public class SepulkaClientBeans { @@ -25,7 +25,7 @@ public SepulkaService sepulkaService() { @Bean SepulkaClient internalClient(EdgeValidator validator, SepulkaService service) { - var mapper = new SepulkaMsgMapperImpl(); + var mapper = new SepulkaMessageMapperImpl(); return new SepulkaClientImpl(validator, mapper, service); } @@ -33,6 +33,6 @@ SepulkaClient internalClient(EdgeValidator validator, SepulkaService service) { SepulkaClient externalClient(SepulkaClient internalClient) { var client = MockMvcWebTestClient.bindToController(new SepulkaController(internalClient)) .build(); - return new SepulkaClientSpringWeb(client); + return new SepulkaClientSpringWebTest(client); } } diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java index 74305fd5..fe3fe17c 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/construction/SepulkaDaoBeans.java @@ -19,8 +19,8 @@ import smecalculus.bezmen.storage.SepulkaDao; import smecalculus.bezmen.storage.SepulkaDaoMyBatis; import smecalculus.bezmen.storage.SepulkaDaoSpringData; -import smecalculus.bezmen.storage.SepulkaRecMapper; -import smecalculus.bezmen.storage.SepulkaRecMapperImpl; +import smecalculus.bezmen.storage.SepulkaStateMapper; +import smecalculus.bezmen.storage.SepulkaStateMapperImpl; import smecalculus.bezmen.storage.mybatis.SepulkaSqlMapper; import smecalculus.bezmen.storage.springdata.SepulkaRepository; @@ -31,13 +31,13 @@ public class SepulkaDaoBeans { @Bean public DataSource dataSource(StorageProps storageProps) { - List common = List.of("DB_CLOSE_DELAY=-1"); - List specific = + var common = List.of("DB_CLOSE_DELAY=-1"); + var specific = switch (storageProps.protocolProps().protocolMode()) { case H2 -> List.of("MODE=STRICT"); case POSTGRES -> List.of("MODE=PostgreSQL", "DATABASE_TO_LOWER=TRUE", "DEFAULT_NULL_ORDERING=HIGH"); }; - String nameWithSettings = Stream.of(List.of(DB), common, specific) + var nameWithSettings = Stream.of(List.of(DB), common, specific) .flatMap(Collection::stream) .collect(joining(";")); return new EmbeddedDatabaseBuilder() @@ -49,16 +49,16 @@ public DataSource dataSource(StorageProps storageProps) { } @Bean - public SepulkaRecMapper sepulkaRecMapper() { - return new SepulkaRecMapperImpl(); + public SepulkaStateMapper sepulkaStateMapper() { + return new SepulkaStateMapperImpl(); } @Configuration(proxyBeanMethods = false) public static class SpringDataPostgres { @Bean - public SepulkaDao underTest(SepulkaRecMapper recMapper, SepulkaRepository repository) { - return new SepulkaDaoSpringData(recMapper, repository); + public SepulkaDao underTest(SepulkaStateMapper mapper, SepulkaRepository repository) { + return new SepulkaDaoSpringData(mapper, repository); } @Bean @@ -77,8 +77,8 @@ public StorageProps storageProps() { public static class MyBatisPostgres { @Bean - public SepulkaDao underTest(SepulkaRecMapper recMapper, SepulkaSqlMapper sqlMapper) { - return new SepulkaDaoMyBatis(recMapper, sqlMapper); + public SepulkaDao underTest(SepulkaStateMapper stateMapper, SepulkaSqlMapper sqlMapper) { + return new SepulkaDaoMyBatis(stateMapper, sqlMapper); } @Bean diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientIT.java b/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientIT.java index 3b96ad32..5b44655c 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientIT.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientIT.java @@ -4,8 +4,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static smecalculus.bezmen.core.SepulkaNewResponseEg.Pojos.sepulkaNewResponse; -import static smecalculus.bezmen.messaging.SepulkaNewRequestEg.Pojos.sepulkaNewRequestMsg; -import static smecalculus.bezmen.messaging.SepulkaNewResponseEg.Pojos.sepulkaNewResponseMsg; +import static smecalculus.bezmen.messaging.SepulkaNewRequestEg.Pojos.sepulkaNewRequestEdge; +import static smecalculus.bezmen.messaging.SepulkaNewResponseEg.Pojos.sepulkaNewResponseEdge; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -32,11 +32,11 @@ void shouldRegisterSepulka() { // given var id = UUID.randomUUID(); // and - var request = sepulkaNewRequestMsg(); + var request = sepulkaNewRequestEdge(); // and when(serviceMock.register(any(SepulkaNewRequest.class))).thenReturn(sepulkaNewResponse(id)); // and - var expectedResponse = sepulkaNewResponseMsg(id); + var expectedResponse = sepulkaNewResponseEdge(id); // when var actualResponse = externalClient.register(request); // then diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebIT.java b/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebIT.java deleted file mode 100644 index 0859ae5b..00000000 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebIT.java +++ /dev/null @@ -1,3 +0,0 @@ -package smecalculus.bezmen.messaging; - -public class SepulkaClientSpringWebIT extends SepulkaClientIT {} diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTestIT.java b/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTestIT.java new file mode 100644 index 00000000..cf1220b1 --- /dev/null +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTestIT.java @@ -0,0 +1,3 @@ +package smecalculus.bezmen.messaging; + +public class SepulkaClientSpringWebTestIT extends SepulkaClientIT {} diff --git a/apps/sepuling/src/test/java/smecalculus/bezmen/storage/SepulkaDaoIT.java b/apps/sepuling/src/test/java/smecalculus/bezmen/storage/SepulkaDaoIT.java index 607d1cda..f99f620f 100644 --- a/apps/sepuling/src/test/java/smecalculus/bezmen/storage/SepulkaDaoIT.java +++ b/apps/sepuling/src/test/java/smecalculus/bezmen/storage/SepulkaDaoIT.java @@ -10,7 +10,6 @@ import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit.jupiter.SpringExtension; import smecalculus.bezmen.construction.SepulkaDaoBeans; -import smecalculus.bezmen.core.Sepulka; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = SepulkaDaoBeans.class) @@ -23,11 +22,11 @@ abstract class SepulkaDaoIT { @Test void shouldSaveOneSepulka() { // given - Sepulka expectedSepulka = sepulka(); + var expectedSepulka = sepulka(); // when - Sepulka actualSepulka1 = sepulkaDao.save(expectedSepulka); + var actualSepulka1 = sepulkaDao.save(expectedSepulka); // and - Sepulka actualSepulka2 = sepulkaDao.getById(expectedSepulka.id()); + var actualSepulka2 = sepulkaDao.getById(expectedSepulka.id()); // then assertThat(actualSepulka1).isEqualTo(expectedSepulka); // and diff --git a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaClient.java b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaClient.java index ba4d002e..b0dfb11c 100644 --- a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaClient.java +++ b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaClient.java @@ -1,5 +1,5 @@ package smecalculus.bezmen.messaging; public interface SepulkaClient { - SepulkaNewResponseMsg register(SepulkaNewRequestMsg request); + SepulkaNewResponseEdge register(SepulkaNewRequestEdge request); } diff --git a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestMsg.java b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEdge.java similarity index 83% rename from libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestMsg.java rename to libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEdge.java index 5b9190d3..9cc5c1ab 100644 --- a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestMsg.java +++ b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEdge.java @@ -7,7 +7,7 @@ * Model: edge slice */ @Data -public class SepulkaNewRequestMsg { +public class SepulkaNewRequestEdge { @NotNull private String name; } diff --git a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEg.java b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEg.java index a16727c2..1e5e5d7c 100644 --- a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEg.java +++ b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewRequestEg.java @@ -5,10 +5,10 @@ public class SepulkaNewRequestEg { public static class Pojos { - public static SepulkaNewRequestMsg sepulkaNewRequestMsg() { - var requestMsg = new SepulkaNewRequestMsg(); - requestMsg.setName(NAME); - return requestMsg; + public static SepulkaNewRequestEdge sepulkaNewRequestEdge() { + var requestEdge = new SepulkaNewRequestEdge(); + requestEdge.setName(NAME); + return requestEdge; } } } diff --git a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseMsg.java b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEdge.java similarity index 82% rename from libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseMsg.java rename to libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEdge.java index fb3f0c3a..22f6ad95 100644 --- a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseMsg.java +++ b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEdge.java @@ -7,7 +7,7 @@ * Model: edge slice */ @Data -public class SepulkaNewResponseMsg { +public class SepulkaNewResponseEdge { @NotNull private String id; } diff --git a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEg.java b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEg.java index 9b7d7a19..3d5e898e 100644 --- a/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEg.java +++ b/libs/abstraction-client/src/main/java/smecalculus/bezmen/messaging/SepulkaNewResponseEg.java @@ -6,16 +6,16 @@ public class SepulkaNewResponseEg { public static class Pojos { - public static SepulkaNewResponseMsg sepulkaNewResponseMsg() { - var responseMsg = new SepulkaNewResponseMsg(); - responseMsg.setId(UUID.randomUUID().toString()); - return responseMsg; + public static SepulkaNewResponseEdge sepulkaNewResponseEdge() { + var responseEdge = new SepulkaNewResponseEdge(); + responseEdge.setId(UUID.randomUUID().toString()); + return responseEdge; } - public static SepulkaNewResponseMsg sepulkaNewResponseMsg(UUID id) { - var responseMsg = sepulkaNewResponseMsg(); - responseMsg.setId(id.toString()); - return responseMsg; + public static SepulkaNewResponseEdge sepulkaNewResponseEdge(UUID id) { + var responseEdge = sepulkaNewResponseEdge(); + responseEdge.setId(id.toString()); + return responseEdge; } } } diff --git a/libs/abstraction/src/main/java/smecalculus/bezmen/configuration/ConfigKeeper.java b/libs/abstraction/src/main/java/smecalculus/bezmen/configuration/PropsKeeper.java similarity index 73% rename from libs/abstraction/src/main/java/smecalculus/bezmen/configuration/ConfigKeeper.java rename to libs/abstraction/src/main/java/smecalculus/bezmen/configuration/PropsKeeper.java index cdb202e1..0dabf618 100644 --- a/libs/abstraction/src/main/java/smecalculus/bezmen/configuration/ConfigKeeper.java +++ b/libs/abstraction/src/main/java/smecalculus/bezmen/configuration/PropsKeeper.java @@ -1,5 +1,5 @@ package smecalculus.bezmen.configuration; -public interface ConfigKeeper { +public interface PropsKeeper { T read(String key, Class type); } diff --git a/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java b/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java index 278f2dd4..970d9cd9 100644 --- a/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java +++ b/libs/abstraction/src/main/java/smecalculus/bezmen/core/SepulkaSliceMapper.java @@ -4,7 +4,7 @@ @Mapper public interface SepulkaSliceMapper { - Sepulka.Builder toDomain(SepulkaNewRequest request); + Sepulka.Builder toEntity(SepulkaNewRequest request); SepulkaNewResponse toSlice(Sepulka sepulka); } diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperLightbendConfig.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperLightbendConfig.java similarity index 85% rename from libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperLightbendConfig.java rename to libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperLightbendConfig.java index 3a69e722..d8a0eaad 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperLightbendConfig.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperLightbendConfig.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor -public class ConfigKeeperLightbendConfig implements ConfigKeeper { +public class PropsKeeperLightbendConfig implements PropsKeeper { @NonNull private Config config; diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperSpringConfig.java similarity index 87% rename from libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java rename to libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperSpringConfig.java index 1c3feed6..606c021a 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ConfigKeeperSpringConfig.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/PropsKeeperSpringConfig.java @@ -6,7 +6,7 @@ import org.springframework.core.env.Environment; @RequiredArgsConstructor -public class ConfigKeeperSpringConfig implements ConfigKeeper { +public class PropsKeeperSpringConfig implements PropsKeeper { @NonNull private Environment environment; diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationMode.java new file mode 100644 index 00000000..13531983 --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationMode.java @@ -0,0 +1,5 @@ +package smecalculus.bezmen.configuration; + +public enum ValidationMode { + HIBERNATE_VALIDATOR +} diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationProps.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationProps.java new file mode 100644 index 00000000..9783efe0 --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationProps.java @@ -0,0 +1,7 @@ +package smecalculus.bezmen.configuration; + +import lombok.Builder; +import lombok.NonNull; + +@Builder +public record ValidationProps(@NonNull ValidationMode validationMode) {} diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationPropsEdge.java b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationPropsEdge.java new file mode 100644 index 00000000..42be4ffc --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationPropsEdge.java @@ -0,0 +1,8 @@ +package smecalculus.bezmen.configuration; + +import lombok.Data; + +@Data +public class ValidationPropsEdge { + private String mode; +} diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnValidationMode.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnValidationMode.java new file mode 100644 index 00000000..d0e4ee0a --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnValidationMode.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.ValidationMode; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Conditional(ValidationModeCondition.class) +public @interface ConditionalOnValidationMode { + ValidationMode 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 8e90b345..2bded066 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigBeans.java @@ -4,11 +4,11 @@ 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.ConfigKeeperSpringConfig; import smecalculus.bezmen.configuration.ConfigMappingMode; import smecalculus.bezmen.configuration.ConfigProtocolMode; +import smecalculus.bezmen.configuration.PropsKeeper; +import smecalculus.bezmen.configuration.PropsKeeperLightbendConfig; +import smecalculus.bezmen.configuration.PropsKeeperSpringConfig; @Configuration(proxyBeanMethods = false) public class ConfigBeans { @@ -16,14 +16,14 @@ public class ConfigBeans { @Bean @ConditionalOnConfigProtocolMode(ConfigProtocolMode.FILE_SYSTEM) @ConditionalOnConfigMappingMode(ConfigMappingMode.LIGHTBEND_CONFIG) - ConfigKeeper configKeeperLightbendConfig() { - return new ConfigKeeperLightbendConfig(ConfigFactory.load()); + PropsKeeper configKeeperLightbendConfig() { + return new PropsKeeperLightbendConfig(ConfigFactory.load()); } @Bean @ConditionalOnConfigProtocolMode(ConfigProtocolMode.FILE_SYSTEM) @ConditionalOnConfigMappingMode(ConfigMappingMode.SPRING_CONFIG) - ConfigKeeper configKeeperSpringConfig(Environment environment) { - return new ConfigKeeperSpringConfig(environment); + PropsKeeper configKeeperSpringConfig(Environment environment) { + return new PropsKeeperSpringConfig(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 index a205f333..acf631c9 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigMappingModeCondition.java @@ -2,7 +2,7 @@ import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; -import java.util.Map; +import lombok.NonNull; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -12,16 +12,15 @@ 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"); + var attributes = metadata.getAnnotationAttributes(ConditionalOnConfigMappingMode.class.getName()); + var expectedMode = (ConfigMappingMode) attributes.get("value"); String actualMode = context.getEnvironment() .getProperty("bezmen.config.mapping.mode", ConfigMappingMode.LIGHTBEND_CONFIG.name()); return expectedMode.name().equalsIgnoreCase(actualMode); } @Override - public ConfigurationPhase getConfigurationPhase() { + public @NonNull 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 index 0d8f0a8a..9ccccda0 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ConfigProtocolModeCondition.java @@ -3,6 +3,7 @@ import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; import java.util.Map; +import lombok.NonNull; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -14,14 +15,14 @@ class ConfigProtocolModeCondition implements ConfigurationCondition { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Map attributes = metadata.getAnnotationAttributes(ConditionalOnConfigProtocolMode.class.getName()); - ConfigProtocolMode expectedMode = (ConfigProtocolMode) attributes.get("value"); + var expectedMode = (ConfigProtocolMode) attributes.get("value"); String actualMode = context.getEnvironment() .getProperty("bezmen.config.protocol.mode", ConfigProtocolMode.FILE_SYSTEM.name()); return expectedMode.name().equalsIgnoreCase(actualMode); } @Override - public ConfigurationPhase getConfigurationPhase() { + public @NonNull ConfigurationPhase getConfigurationPhase() { return REGISTER_BEAN; } } diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationBeans.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationBeans.java index baf32469..7ec0dd19 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationBeans.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationBeans.java @@ -1,18 +1,46 @@ package smecalculus.bezmen.construction; +import static java.util.Objects.requireNonNull; +import static smecalculus.bezmen.configuration.ValidationMode.HIBERNATE_VALIDATOR; + import jakarta.validation.Validation; -import jakarta.validation.ValidatorFactory; +import org.slf4j.Logger; +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.PropsKeeper; +import smecalculus.bezmen.configuration.ValidationProps; +import smecalculus.bezmen.configuration.ValidationPropsEdge; import smecalculus.bezmen.validation.EdgeValidator; import smecalculus.bezmen.validation.EdgeValidatorHibernateValidator; +import smecalculus.bezmen.validation.ValidationPropsMapper; +import smecalculus.bezmen.validation.ValidationPropsMapperImpl; +@PropertySource("classpath:validation.properties") @Configuration(proxyBeanMethods = false) public class ValidationBeans { + private static final Logger LOG = LoggerFactory.getLogger(ValidationBeans.class); + + @Bean + ValidationPropsMapper validationPropsMapper() { + return new ValidationPropsMapperImpl(); + } + + @Bean + ValidationProps validationProps(PropsKeeper keeper, ValidationPropsMapper mapper) { + var propsEdge = keeper.read("bezmen.validation", ValidationPropsEdge.class); + requireNonNull(propsEdge.getMode(), "validation mode must not be null"); + LOG.info("Read {}", propsEdge); + return mapper.toDomain(propsEdge); + } + @Bean + @ConditionalOnValidationMode(HIBERNATE_VALIDATOR) EdgeValidator edgeValidatorHibernateValidator() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - return new EdgeValidatorHibernateValidator(factory.getValidator()); + try (var factory = Validation.buildDefaultValidatorFactory()) { + return new EdgeValidatorHibernateValidator(factory.getValidator()); + } } } diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationModeCondition.java b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationModeCondition.java new file mode 100644 index 00000000..94cf8adc --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationModeCondition.java @@ -0,0 +1,26 @@ +package smecalculus.bezmen.construction; + +import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; + +import lombok.NonNull; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.context.annotation.ConfigurationCondition; +import org.springframework.core.type.AnnotatedTypeMetadata; +import smecalculus.bezmen.configuration.ValidationMode; +import smecalculus.bezmen.configuration.ValidationProps; + +class ValidationModeCondition implements ConfigurationCondition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + var attributes = metadata.getAnnotationAttributes(ConditionalOnValidationMode.class.getName()); + var mode = (ValidationMode) attributes.get("value"); + var props = context.getBeanFactory().getBean(ValidationProps.class); + return mode == props.validationMode(); + } + + @Override + public @NonNull ConfigurationPhase getConfigurationPhase() { + return REGISTER_BEAN; + } +} diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/validation/EdgeValidatorHibernateValidator.java b/libs/essentials/src/main/java/smecalculus/bezmen/validation/EdgeValidatorHibernateValidator.java index 9749f8fa..ac22df5c 100644 --- a/libs/essentials/src/main/java/smecalculus/bezmen/validation/EdgeValidatorHibernateValidator.java +++ b/libs/essentials/src/main/java/smecalculus/bezmen/validation/EdgeValidatorHibernateValidator.java @@ -1,9 +1,7 @@ package smecalculus.bezmen.validation; -import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolationException; import jakarta.validation.Validator; -import java.util.Set; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -15,7 +13,7 @@ public class EdgeValidatorHibernateValidator implements EdgeValidator { @Override public void validate(T object, Class... groups) { - Set> violations = validator.validate(object, groups); + var violations = validator.validate(object, groups); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } diff --git a/libs/essentials/src/main/java/smecalculus/bezmen/validation/ValidationPropsMapper.java b/libs/essentials/src/main/java/smecalculus/bezmen/validation/ValidationPropsMapper.java new file mode 100644 index 00000000..24735a74 --- /dev/null +++ b/libs/essentials/src/main/java/smecalculus/bezmen/validation/ValidationPropsMapper.java @@ -0,0 +1,17 @@ +package smecalculus.bezmen.validation; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import smecalculus.bezmen.configuration.ValidationMode; +import smecalculus.bezmen.configuration.ValidationProps; +import smecalculus.bezmen.configuration.ValidationPropsEdge; + +@Mapper +public interface ValidationPropsMapper { + @Mapping(source = "mode", target = "validationMode") + ValidationProps toDomain(ValidationPropsEdge propsEdge); + + default ValidationMode toValidationMode(String value) { + return ValidationMode.valueOf(value.toUpperCase()); + } +} diff --git a/libs/essentials/src/main/resources/reference.conf b/libs/essentials/src/main/resources/reference.conf new file mode 100644 index 00000000..80842253 --- /dev/null +++ b/libs/essentials/src/main/resources/reference.conf @@ -0,0 +1,5 @@ +bezmen { + validation { + mode = hibernate_validator + } +} diff --git a/libs/essentials/src/main/resources/validation.properties b/libs/essentials/src/main/resources/validation.properties new file mode 100644 index 00000000..a9e5bd52 --- /dev/null +++ b/libs/essentials/src/main/resources/validation.properties @@ -0,0 +1 @@ +bezmen.validation.mode=hibernate_validator diff --git a/libs/messaging-client/src/main/java/smecalculus/bezmen/messaging/BezmenClientJavaHttp.java b/libs/messaging-client/src/main/java/smecalculus/bezmen/messaging/BezmenClientJavaHttp.java index 9cbfed2d..c8a20c01 100644 --- a/libs/messaging-client/src/main/java/smecalculus/bezmen/messaging/BezmenClientJavaHttp.java +++ b/libs/messaging-client/src/main/java/smecalculus/bezmen/messaging/BezmenClientJavaHttp.java @@ -21,7 +21,7 @@ public class BezmenClientJavaHttp implements BezmenClient { private HttpClient client; @Override - public SepulkaNewResponseMsg register(SepulkaNewRequestMsg request) { + public SepulkaNewResponseEdge register(SepulkaNewRequestEdge request) { try { var requestJson = mapper.writeValueAsString(request); var httpRequest = HttpRequest.newBuilder() @@ -31,7 +31,7 @@ public SepulkaNewResponseMsg register(SepulkaNewRequestMsg request) { .header("Accept", "application/json") .build(); var httpResponse = client.send(httpRequest, BodyHandlers.ofString()); - return mapper.readValue(httpResponse.body(), SepulkaNewResponseMsg.class); + return mapper.readValue(httpResponse.body(), SepulkaNewResponseEdge.class); } catch (JsonProcessingException e) { throw new RuntimeException(e); } catch (IOException | InterruptedException e) { diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEdge.java similarity index 89% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEdge.java index b2045650..e1d97504 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessageMappingPropsEdge.java @@ -7,7 +7,7 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class MessageMappingPropsCfg { +public class MessageMappingPropsEdge { @NotNull @Size(min = 1) diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEdge.java similarity index 56% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEdge.java index 917e19c3..e6ebbe90 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsEdge.java @@ -4,11 +4,11 @@ import lombok.Data; @Data -public class MessagingPropsCfg { +public class MessagingPropsEdge { @NotNull - MessagingProtocolPropsCfg protocol; + MessagingProtocolPropsEdge protocol; @NotNull - MessageMappingPropsCfg mapping; + MessageMappingPropsEdge mapping; } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsMapper.java similarity index 71% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsMapper.java index 2cd35b05..83e1aecd 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingCfgMapper.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingPropsMapper.java @@ -4,17 +4,17 @@ import org.mapstruct.Mapping; @Mapper -public interface MessagingCfgMapper { +public interface MessagingPropsMapper { @Mapping(source = "protocol", target = "protocolProps") @Mapping(source = "mapping", target = "mappingProps") - MessagingProps toDomain(MessagingPropsCfg propsCfg); + MessagingProps toDomain(MessagingPropsEdge propsEdge); @Mapping(source = "modes", target = "protocolModes") - MessagingProtocolProps toDomain(MessagingProtocolPropsCfg propsCfg); + MessagingProtocolProps toDomain(MessagingProtocolPropsEdge propsEdge); @Mapping(source = "modes", target = "mappingModes") - MessageMappingProps toDomain(MessageMappingPropsCfg propsCfg); + MessageMappingProps toDomain(MessageMappingPropsEdge propsEdge); default MessagingProtocolMode toProtocolMode(String value) { return MessagingProtocolMode.valueOf(value.toUpperCase()); diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEdge.java similarity index 88% rename from libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java rename to libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEdge.java index 522501b3..045ace11 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsCfg.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/configuration/MessagingProtocolPropsEdge.java @@ -7,7 +7,7 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class MessagingProtocolPropsCfg { +public class MessagingProtocolPropsEdge { @NotNull @Size(min = 1) diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java index 0722e131..4cf01edb 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessageMappingModeCondition.java @@ -2,9 +2,8 @@ import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; -import java.util.Map; -import java.util.Set; import java.util.stream.Stream; +import lombok.NonNull; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -15,16 +14,15 @@ class MessageMappingModeCondition implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - Map attributes = - metadata.getAnnotationAttributes(ConditionalOnMessageMappingModes.class.getName()); - MessageMappingMode[] expectedModes = (MessageMappingMode[]) attributes.get("value"); - MessagingProps messagingProps = context.getBeanFactory().getBean(MessagingProps.class); - Set actualModes = messagingProps.mappingProps().mappingModes(); + var attributes = metadata.getAnnotationAttributes(ConditionalOnMessageMappingModes.class.getName()); + var expectedModes = (MessageMappingMode[]) attributes.get("value"); + var props = context.getBeanFactory().getBean(MessagingProps.class); + var actualModes = props.mappingProps().mappingModes(); return Stream.of(expectedModes).anyMatch(actualModes::contains); } @Override - public ConfigurationPhase getConfigurationPhase() { + public @NonNull ConfigurationPhase getConfigurationPhase() { return REGISTER_BEAN; } } 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 cd190ca5..589bac7a 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingConfigBeans.java @@ -5,11 +5,11 @@ 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; import smecalculus.bezmen.configuration.MessagingProps; -import smecalculus.bezmen.configuration.MessagingPropsCfg; +import smecalculus.bezmen.configuration.MessagingPropsEdge; +import smecalculus.bezmen.configuration.MessagingPropsMapper; +import smecalculus.bezmen.configuration.MessagingPropsMapperImpl; +import smecalculus.bezmen.configuration.PropsKeeper; import smecalculus.bezmen.validation.EdgeValidator; @PropertySource("classpath:messaging.properties") @@ -19,15 +19,15 @@ public class MessagingConfigBeans { private static final Logger LOG = LoggerFactory.getLogger(MessagingConfigBeans.class); @Bean - MessagingCfgMapper messagingCfgMapper() { - return new MessagingCfgMapperImpl(); + MessagingPropsMapper messagingPropsMapper() { + return new MessagingPropsMapperImpl(); } @Bean - 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); + MessagingProps messagingProps(PropsKeeper keeper, EdgeValidator validator, MessagingPropsMapper mapper) { + var propsEdge = keeper.read("bezmen.messaging", MessagingPropsEdge.class); + validator.validate(propsEdge); + LOG.info("Read {}", propsEdge); + return mapper.toDomain(propsEdge); } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java index 29192529..2f48c2b5 100644 --- a/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java +++ b/libs/messaging/src/main/java/smecalculus/bezmen/construction/MessagingProtocolModeCondition.java @@ -2,9 +2,8 @@ import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; -import java.util.Map; -import java.util.Set; import java.util.stream.Stream; +import lombok.NonNull; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -15,16 +14,15 @@ class MessagingProtocolModeCondition implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - Map attributes = - metadata.getAnnotationAttributes(ConditionalOnMessagingProtocolModes.class.getName()); - MessagingProtocolMode[] expectedModes = (MessagingProtocolMode[]) attributes.get("value"); - MessagingProps messagingProps = context.getBeanFactory().getBean(MessagingProps.class); - Set actualModes = messagingProps.protocolProps().protocolModes(); + var attributes = metadata.getAnnotationAttributes(ConditionalOnMessagingProtocolModes.class.getName()); + var expectedModes = (MessagingProtocolMode[]) attributes.get("value"); + var props = context.getBeanFactory().getBean(MessagingProps.class); + var actualModes = props.protocolProps().protocolModes(); return Stream.of(expectedModes).anyMatch(actualModes::contains); } @Override - public ConfigurationPhase getConfigurationPhase() { + public @NonNull ConfigurationPhase getConfigurationPhase() { return REGISTER_BEAN; } } diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMessageMapper.java b/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMessageMapper.java new file mode 100644 index 00000000..e8c08337 --- /dev/null +++ b/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMessageMapper.java @@ -0,0 +1,12 @@ +package smecalculus.bezmen.messaging; + +import org.mapstruct.Mapper; +import smecalculus.bezmen.core.SepulkaNewRequest; +import smecalculus.bezmen.core.SepulkaNewResponse; + +@Mapper +public interface SepulkaMessageMapper { + SepulkaNewRequest toDomain(SepulkaNewRequestEdge requestEdge); + + SepulkaNewResponseEdge toEdge(SepulkaNewResponse response); +} diff --git a/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMsgMapper.java b/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMsgMapper.java deleted file mode 100644 index 0299c734..00000000 --- a/libs/messaging/src/main/java/smecalculus/bezmen/messaging/SepulkaMsgMapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package smecalculus.bezmen.messaging; - -import org.mapstruct.Mapper; -import smecalculus.bezmen.core.SepulkaNewRequest; -import smecalculus.bezmen.core.SepulkaNewResponse; - -@Mapper -public interface SepulkaMsgMapper { - SepulkaNewRequest toDomain(SepulkaNewRequestMsg requestMsg); - - SepulkaNewResponseMsg toMsg(SepulkaNewResponse response); - - SepulkaNewResponse toDomain(SepulkaNewResponseMsg responseMsg); -} 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 19dbbb29..ebce0f94 100644 --- a/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java +++ b/libs/messaging/src/test/java/smecalculus/bezmen/construction/MessagingConfigBeansIT.java @@ -17,7 +17,7 @@ abstract class MessagingConfigBeansIT { @Test void defaultConfigShouldBeBackwardCompatible(@Autowired MessagingProps actualProps) { // given - MessagingProps expectedProps = messagingProps().build(); + var expectedProps = messagingProps().build(); // when // default construction // then diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java similarity index 89% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java index f7eaf189..0a3e4ff7 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/H2PropsEdge.java @@ -4,7 +4,7 @@ import lombok.Data; @Data -public class H2PropsCfg { +public class H2PropsEdge { @NotBlank String url; diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java similarity index 89% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java index d0839893..65a3ff2a 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/PostgresPropsEdge.java @@ -5,7 +5,7 @@ import lombok.ToString; @Data -public class PostgresPropsCfg { +public class PostgresPropsEdge { @NotBlank String url; diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java index f8010d0c..a54b9cf8 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.java @@ -1,6 +1,7 @@ package smecalculus.bezmen.configuration; import lombok.Builder; +import lombok.NonNull; @Builder -public record StateMappingProps(StateMappingMode mappingMode) {} +public record StateMappingProps(@NonNull StateMappingMode mappingMode) {} diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java similarity index 83% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java index dfd890f0..ace84796 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEdge.java @@ -4,7 +4,7 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class StateMappingPropsCfg { +public class StateMappingPropsEdge { @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 index c7bb4c25..cedc35dc 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingPropsEg.java @@ -4,10 +4,10 @@ public class StateMappingPropsEg { public static class Pojos { - public static StateMappingPropsCfg stateMappingPropsCfg() { - StateMappingPropsCfg propsCfg = new StateMappingPropsCfg(); - propsCfg.setMode(SPRING_DATA.name()); - return propsCfg; + public static StateMappingPropsEdge stateMappingPropsEdge() { + var propsEdge = new StateMappingPropsEdge(); + propsEdge.setMode(SPRING_DATA.name()); + return propsEdge; } } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java similarity index 58% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java index 1e55f192..0a7f6626 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEdge.java @@ -4,11 +4,11 @@ import lombok.Data; @Data -public class StoragePropsCfg { +public class StoragePropsEdge { @NotNull - StorageProtocolPropsCfg protocol; + StorageProtocolPropsEdge protocol; @NotNull - StateMappingPropsCfg mapping; + StateMappingPropsEdge 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 c4784ce7..07267645 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsEg.java @@ -1,17 +1,17 @@ package smecalculus.bezmen.configuration; import static smecalculus.bezmen.configuration.StateMappingPropsEg.Builders.stateMappingProps; -import static smecalculus.bezmen.configuration.StateMappingPropsEg.Pojos.stateMappingPropsCfg; +import static smecalculus.bezmen.configuration.StateMappingPropsEg.Pojos.stateMappingPropsEdge; import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Builders.storageProtocolProps; -import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Pojos.storageProtocolPropsCfg; +import static smecalculus.bezmen.configuration.StorageProtocolPropsEg.Pojos.storageProtocolPropsEdge; public class StoragePropsEg { public static class Pojos { - public static StoragePropsCfg storagePropsCfg() { - StoragePropsCfg propsCfg = new StoragePropsCfg(); - propsCfg.setProtocol(storageProtocolPropsCfg()); - propsCfg.setMapping(stateMappingPropsCfg()); - return propsCfg; + public static StoragePropsEdge storagePropsEdge() { + var propsEdge = new StoragePropsEdge(); + propsEdge.setProtocol(storageProtocolPropsEdge()); + propsEdge.setMapping(stateMappingPropsEdge()); + return propsEdge; } } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java similarity index 75% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java index 02ca7a8b..20f92e46 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageCfgMapper.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StoragePropsMapper.java @@ -4,19 +4,19 @@ import org.mapstruct.Mapping; @Mapper -public interface StorageCfgMapper { +public interface StoragePropsMapper { @Mapping(source = "protocol", target = "protocolProps") @Mapping(source = "mapping", target = "mappingProps") - StorageProps toDomain(StoragePropsCfg propsCfg); + StorageProps toDomain(StoragePropsEdge propsEdge); @Mapping(source = "mode", target = "protocolMode") @Mapping(source = "h2", target = "h2Props") @Mapping(source = "postgres", target = "postgresProps") - StorageProtocolProps toDomain(StorageProtocolPropsCfg propsCfg); + StorageProtocolProps toDomain(StorageProtocolPropsEdge propsEdge); @Mapping(source = "mode", target = "mappingMode") - StateMappingProps toDomain(StateMappingPropsCfg propsCfg); + StateMappingProps toDomain(StateMappingPropsEdge propsEdge); default StorageProtocolMode toProtocolMode(String mode) { return StorageProtocolMode.valueOf(mode.toUpperCase()); diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java similarity index 73% rename from libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java rename to libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java index 82a23b70..1ba82b09 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsCfg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEdge.java @@ -5,14 +5,14 @@ import smecalculus.bezmen.validation.ValueOfEnum; @Data -public class StorageProtocolPropsCfg { +public class StorageProtocolPropsEdge { @ValueOfEnum(StorageProtocolMode.class) String mode; @Optional - H2PropsCfg h2; + H2PropsEdge h2; @Optional - PostgresPropsCfg postgres; + PostgresPropsEdge postgres; } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java index e4e89b39..2154a710 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/configuration/StorageProtocolPropsEg.java @@ -2,10 +2,10 @@ public class StorageProtocolPropsEg { public static class Pojos { - public static StorageProtocolPropsCfg storageProtocolPropsCfg() { - StorageProtocolPropsCfg propsCfg = new StorageProtocolPropsCfg(); - propsCfg.setMode(StorageProtocolMode.H2.name()); - return propsCfg; + public static StorageProtocolPropsEdge storageProtocolPropsEdge() { + var propsEdge = new StorageProtocolPropsEdge(); + propsEdge.setMode(StorageProtocolMode.H2.name()); + return propsEdge; } } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java index 7af3d785..9bc58dc3 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingMyBatisBeans.java @@ -16,7 +16,7 @@ public class MappingMyBatisBeans { @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { - SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); + var factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); return factoryBean.getObject(); } diff --git a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java index d35a5637..9a2bad82 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/MappingSpringDataBeans.java @@ -14,7 +14,6 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.StorageProtocolProps; @ConditionalOnStateMappingMode(SPRING_DATA) @EnableJdbcRepositories("smecalculus.bezmen.storage.springdata") @@ -33,7 +32,7 @@ public PlatformTransactionManager transactionManager(DataSource dataSource) { @Bean public Dialect dialect(StorageProps storageProps) { - StorageProtocolProps storageProtocolProps = storageProps.protocolProps(); + var 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/StateMappingModeCondition.java b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java index ff5dd6ba..669192d3 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StateMappingModeCondition.java @@ -2,7 +2,7 @@ import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; -import java.util.Map; +import lombok.NonNull; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -13,15 +13,14 @@ class StateMappingModeCondition implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - Map attributes = - metadata.getAnnotationAttributes(ConditionalOnStateMappingMode.class.getName()); - StateMappingMode mode = (StateMappingMode) attributes.get("value"); - StorageProps props = context.getBeanFactory().getBean(StorageProps.class); + var attributes = metadata.getAnnotationAttributes(ConditionalOnStateMappingMode.class.getName()); + var mode = (StateMappingMode) attributes.get("value"); + var props = context.getBeanFactory().getBean(StorageProps.class); return mode == props.mappingProps().mappingMode(); } @Override - public ConfigurationPhase getConfigurationPhase() { + public @NonNull ConfigurationPhase getConfigurationPhase() { return REGISTER_BEAN; } } 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 2ffa68f3..78de9f9a 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageBeans.java @@ -8,7 +8,6 @@ import smecalculus.bezmen.configuration.H2Props; import smecalculus.bezmen.configuration.PostgresProps; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.StorageProtocolProps; @Configuration(proxyBeanMethods = false) @Import({StorageConfigBeans.class, MappingMyBatisBeans.class, MappingSpringDataBeans.class}) @@ -16,8 +15,8 @@ public class StorageBeans { @Bean public DataSource dataSource(StorageProps storageProps) { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - StorageProtocolProps storageProtocolProps = storageProps.protocolProps(); + var dataSource = new DriverManagerDataSource(); + var storageProtocolProps = storageProps.protocolProps(); switch (storageProtocolProps.protocolMode()) { case H2 -> configure(dataSource, storageProtocolProps.h2Props()); case POSTGRES -> configure(dataSource, storageProtocolProps.postgresProps()); 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 061cf4d7..b5b97f7b 100644 --- a/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java +++ b/libs/storage/src/main/java/smecalculus/bezmen/construction/StorageConfigBeans.java @@ -5,11 +5,11 @@ 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; +import smecalculus.bezmen.configuration.PropsKeeper; import smecalculus.bezmen.configuration.StorageProps; -import smecalculus.bezmen.configuration.StoragePropsCfg; +import smecalculus.bezmen.configuration.StoragePropsEdge; +import smecalculus.bezmen.configuration.StoragePropsMapper; +import smecalculus.bezmen.configuration.StoragePropsMapperImpl; import smecalculus.bezmen.validation.EdgeValidator; @PropertySource("classpath:storage.properties") @@ -19,15 +19,15 @@ public class StorageConfigBeans { private static final Logger LOG = LoggerFactory.getLogger(StorageConfigBeans.class); @Bean - StorageCfgMapper storageCfgMapper() { - return new StorageCfgMapperImpl(); + StoragePropsMapper storagePropsMapper() { + return new StoragePropsMapperImpl(); } @Bean - 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); + StorageProps storageProps(PropsKeeper keeper, EdgeValidator validator, StoragePropsMapper mapper) { + var propsEdge = keeper.read("bezmen.storage", StoragePropsEdge.class); + validator.validate(propsEdge); + LOG.info("Read {}", propsEdge); + return mapper.toDomain(propsEdge); } } 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 79bf441f..3651f064 100644 --- a/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java +++ b/libs/storage/src/test/java/smecalculus/bezmen/construction/StorageConfigBeansTest.java @@ -3,35 +3,35 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static smecalculus.bezmen.configuration.StoragePropsEg.Pojos.storagePropsCfg; +import static smecalculus.bezmen.configuration.StoragePropsEg.Pojos.storagePropsEdge; 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.configuration.PropsKeeper; +import smecalculus.bezmen.configuration.StoragePropsEdge; +import smecalculus.bezmen.configuration.StoragePropsMapper; +import smecalculus.bezmen.configuration.StoragePropsMapperImpl; import smecalculus.bezmen.validation.EdgeValidator; class StorageConfigBeansTest { private final StorageConfigBeans config = new StorageConfigBeans(); - private final StorageCfgMapper mapper = new StorageCfgMapperImpl(); + private final StoragePropsMapper mapper = new StoragePropsMapperImpl(); private EdgeValidator validatorMock; - private ConfigKeeper keeperMock; + private PropsKeeper keeperMock; @BeforeEach void setUp() { validatorMock = mock(EdgeValidator.class); - keeperMock = mock(ConfigKeeper.class); + keeperMock = mock(PropsKeeper.class); } @Test void shouldValidateConf() { // given - StoragePropsCfg expectedProps = storagePropsCfg(); + StoragePropsEdge expectedProps = storagePropsEdge(); // and - when(keeperMock.read("bezmen.storage", StoragePropsCfg.class)).thenReturn(expectedProps); + when(keeperMock.read("bezmen.storage", StoragePropsEdge.class)).thenReturn(expectedProps); // when config.storageProps(keeperMock, validatorMock, mapper); // then diff --git a/libs/testing/src/main/java/smecalculus/bezmen/construction/TestingBeans.java b/libs/testing/src/main/java/smecalculus/bezmen/construction/TestingBeans.java deleted file mode 100644 index 435fe674..00000000 --- a/libs/testing/src/main/java/smecalculus/bezmen/construction/TestingBeans.java +++ /dev/null @@ -1,22 +0,0 @@ -package smecalculus.bezmen.construction; - -import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.H2; - -import javax.sql.DataSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; - -@Configuration(proxyBeanMethods = false) -public class TestingBeans { - - @Bean - public DataSource dataSource() { - return new EmbeddedDatabaseBuilder() - .setType(H2) - .setName("testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;CASE_INSENSITIVE_IDENTIFIERS=true") - .addScript("schemas/sepulkarium/wipe.sql") - .addScript("schemas/sepulkarium/schema.sql") - .build(); - } -} diff --git a/libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWeb.java b/libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTest.java similarity index 75% rename from libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWeb.java rename to libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTest.java index 5cd065cb..3ab08015 100644 --- a/libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWeb.java +++ b/libs/testing/src/main/java/smecalculus/bezmen/messaging/SepulkaClientSpringWebTest.java @@ -6,20 +6,20 @@ import org.springframework.test.web.reactive.server.WebTestClient; @RequiredArgsConstructor -public class SepulkaClientSpringWeb implements SepulkaClient { +public class SepulkaClientSpringWebTest implements SepulkaClient { @NonNull private WebTestClient client; @Override - public SepulkaNewResponseMsg register(SepulkaNewRequestMsg request) { + public SepulkaNewResponseEdge register(SepulkaNewRequestEdge request) { return client.post() .uri("/sepulkas") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) .bodyValue(request) .exchange() - .expectBody(SepulkaNewResponseMsg.class) + .expectBody(SepulkaNewResponseEdge.class) .returnResult() .getResponseBody(); } diff --git a/tests/e2e/src/main/java/smecalculus/bezmen/StandBeans.java b/tests/e2e/src/main/java/smecalculus/bezmen/StandBeans.java index ef87f39d..8079e973 100644 --- a/tests/e2e/src/main/java/smecalculus/bezmen/StandBeans.java +++ b/tests/e2e/src/main/java/smecalculus/bezmen/StandBeans.java @@ -12,8 +12,8 @@ public class StandBeans { @Bean BezmenClient bezmenClient() { - ObjectMapper jsonMapper = new ObjectMapper(); - HttpClient client = HttpClient.newHttpClient(); + var jsonMapper = new ObjectMapper(); + var client = HttpClient.newHttpClient(); return new BezmenClientJavaHttp(jsonMapper, client); } } 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 aa51670a..40b14273 100644 --- a/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java +++ b/tests/e2e/src/test/java/smecalculus/bezmen/registration/SepulkaTest.java @@ -3,8 +3,8 @@ import static java.time.Duration.ofSeconds; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -import static smecalculus.bezmen.messaging.SepulkaNewRequestEg.Pojos.sepulkaNewRequestMsg; -import static smecalculus.bezmen.messaging.SepulkaNewResponseEg.Pojos.sepulkaNewResponseMsg; +import static smecalculus.bezmen.messaging.SepulkaNewRequestEg.Pojos.sepulkaNewRequestEdge; +import static smecalculus.bezmen.messaging.SepulkaNewResponseEg.Pojos.sepulkaNewResponseEdge; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; @@ -33,9 +33,9 @@ void beforeAll() { @Tag("smoke") void shouldRegisterSepulka() { // given - var request = sepulkaNewRequestMsg(); + var request = sepulkaNewRequestEdge(); // and - var expectedResponse = sepulkaNewResponseMsg(); + var expectedResponse = sepulkaNewResponseEdge(); // when var actualResponse = bezmenClient.register(request); // then