From 000507d585a7c68c974ca51743bdf01129f71fd0 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:57:47 +0200 Subject: [PATCH 01/24] fix package name for generated open api classes --- wls-basisdaten-service/pom.xml | 4 ++-- .../clients/KonfigurierterWahltagClientImpl.java | 4 ++-- .../clients/KonfigurierterWahltagClientMapper.java | 2 +- .../configuration/BasePathConfiguration.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 72c48055e..39dd89fdd 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -433,8 +433,8 @@ java resttemplate - ${project.groupId}.basisdatenservice.infomanagement.client - ${project.groupId}.basisdatenservice.infomanagement.model + ${project.groupId}.basisdatenservice.eai.infomanagement.client + ${project.groupId}.basisdatenservice.eai.infomanagement.model false false diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImpl.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImpl.java index 16a856a5c..ede341bbb 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImpl.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImpl.java @@ -1,9 +1,9 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; import de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration.Profiles; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.client.KonfigurierterWahltagControllerApi; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.client.KonfigurierterWahltagControllerApi; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KonfigurierterWahltagClient; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KonfigurierterWahltagModel; import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException; diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java index 4b054c49f..64267eb78 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KonfigurierterWahltagModel; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java index 2892019d1..d62e4c77c 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java @@ -16,7 +16,7 @@ public class BasePathConfiguration { String infomanagementBasePath; private final de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.ApiClient eaiApiClient; - private final de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.ApiClient infomanagementApiClient; + private final de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.ApiClient infomanagementApiClient; @PostConstruct public void updateBasePaths() { From d45005aae3bd89c8f483792acf8134e50ffa8af8 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:12:18 +0200 Subject: [PATCH 02/24] remove unused variable --- .../basisdatenservice/clients/WahlenClientMapper.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahlenClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahlenClientMapper.java index 7f19624d2..3e6f67e44 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahlenClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahlenClientMapper.java @@ -8,13 +8,10 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; -import org.mapstruct.factory.Mappers; @Mapper public interface WahlenClientMapper { - WahlenClientMapper INSTANCE = Mappers.getMapper(WahlenClientMapper.class); - @Mapping(target = "waehlerverzeichnisnummer", source = ".", qualifiedByName = "setWZeroIfNotExisting") @Mapping(target = "reihenfolge", source = ".", qualifiedByName = "setRZeroIfNotExisting") @Mapping(target = "farbe", ignore = true) From 25311fa3b21b56d311eb444314c4c3bd32ac7ef5 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:59:19 +0200 Subject: [PATCH 03/24] fix imports in tests after reconfiguration in generation --- .../clients/KonfigurierterWahltagClientImplTest.java | 4 ++-- .../clients/KonfigurierterWahltagClientMapperTest.java | 2 +- .../rest/kopfdaten/KopfdatenControllerIntegrationTest.java | 2 +- .../services/kopfdaten/KopfdatenServiceSecurityTest.java | 2 +- .../basisdatenservice/utils/MockDataFactory.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImplTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImplTest.java index 6798281ce..34052c084 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImplTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientImplTest.java @@ -1,8 +1,8 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.client.KonfigurierterWahltagControllerApi; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.client.KonfigurierterWahltagControllerApi; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KonfigurierterWahltagModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java index 1d92eafc5..be9a18d90 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import java.time.LocalDate; import lombok.val; diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java index 6450c726f..ec4fecd43 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java @@ -12,8 +12,8 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.KopfdatenRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.Stimmzettelgebietsart; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KopfdatenModelMapper; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java index f6503782b..5349559da 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java @@ -7,7 +7,7 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.KopfdatenRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.Stimmzettelgebietsart; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.BasisdatenDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.Authorities; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java index 36bfe97ce..300136136 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java @@ -13,7 +13,7 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.StimmzettelgebietDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlbezirkDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.infomanagement.model.KonfigurierterWahltagDTO; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.infomanagement.model.KonfigurierterWahltagDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.kopfdaten.KopfdatenDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.kopfdaten.StimmzettelgebietsartDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahlbezirke.WahlbezirkartDTO; From 298b9fc58d776fbde564f8292a8d0f2b243033b7 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:22:29 +0200 Subject: [PATCH 04/24] removed @Named in Mapping --- .../clients/KonfigurierterWahltagClientMapper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java index 64267eb78..7d5b3594c 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java @@ -4,15 +4,13 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.KonfigurierterWahltagModel; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Named; @Mapper public interface KonfigurierterWahltagClientMapper { - @Mapping(target = "active", source = "wahltagStatus", qualifiedByName = "mapWahltagStatusEnumStringToModelBoolean") + @Mapping(target = "active", source = "wahltagStatus") KonfigurierterWahltagModel fromRemoteClientDTOToModel(KonfigurierterWahltagDTO konfigurierterWahltagDTO); - @Named("mapWahltagStatusEnumStringToModelBoolean") default boolean mapWahltagStatusEnumStringToModelBoolean(KonfigurierterWahltagDTO.WahltagStatusEnum wahltagStatus) { if (wahltagStatus.equals(KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV)) { return true; From d0361d568392bfb7eb3e9d1380b9ab8ff27dbbe5 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:22:57 +0200 Subject: [PATCH 05/24] optimize enum mapping with switch case --- .../clients/KonfigurierterWahltagClientMapper.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java index 7d5b3594c..65ea180f5 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java @@ -12,11 +12,9 @@ public interface KonfigurierterWahltagClientMapper { KonfigurierterWahltagModel fromRemoteClientDTOToModel(KonfigurierterWahltagDTO konfigurierterWahltagDTO); default boolean mapWahltagStatusEnumStringToModelBoolean(KonfigurierterWahltagDTO.WahltagStatusEnum wahltagStatus) { - if (wahltagStatus.equals(KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV)) { - return true; - } else if (wahltagStatus.equals(KonfigurierterWahltagDTO.WahltagStatusEnum.INAKTIV)) { - return false; - } - return false; + return switch (wahltagStatus) { + case AKTIV -> true; + case INAKTIV -> false; + }; } } From 6b8259b7d0c621c359bdcc0f6e70eb7f7a74d58f Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:36:52 +0200 Subject: [PATCH 06/24] use WahlWithNummer as Parametertype in eaiClient --- .../clients/DummyClientImpl.java | 30 +++++++++---------- .../KonfigurierterWahltagClientMapper.java | 4 +-- .../clients/WahldatenClientImpl.java | 6 ++-- .../services/kopfdaten/KopfdatenService.java | 4 ++- .../services/kopfdaten/WahldatenClient.java | 7 ++--- .../clients/DummyClientImplTest.java | 12 ++++---- .../clients/WahldatenClientImplTest.java | 9 ++++-- .../kopfdaten/KopfdatenServiceTest.java | 10 +++++-- 8 files changed, 45 insertions(+), 37 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImpl.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImpl.java index 53c480b1a..c8bf141a6 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImpl.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImpl.java @@ -88,28 +88,28 @@ public KonfigurierterWahltagModel getKonfigurierterWahltag() throws WlsException } @Override - public BasisdatenModel loadBasisdaten(LocalDate forDate, String wahlterminNummer) throws WlsException { + public BasisdatenModel loadBasisdaten(WahltagWithNummer wahltagWithNummer) throws WlsException { return new BasisdatenModel( - Set.of(new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID1_1", forDate), - new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID1_2", forDate), - new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID2_1", forDate), - new BasisstrukturdatenModel("wahlID2", "szgID", "wahlbezirkID2_2", forDate), - new BasisstrukturdatenModel("wahlID2", "szgIDOther", "wahlbezirkID2_2", forDate)), + Set.of(new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID1_1", wahltagWithNummer.wahltag()), + new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID1_2", wahltagWithNummer.wahltag()), + new BasisstrukturdatenModel("wahlID1", "szgID", "wahlbezirkID2_1", wahltagWithNummer.wahltag()), + new BasisstrukturdatenModel("wahlID2", "szgID", "wahlbezirkID2_2", wahltagWithNummer.wahltag()), + new BasisstrukturdatenModel("wahlID2", "szgIDOther", "wahlbezirkID2_2", wahltagWithNummer.wahltag())), Set.of( - new WahlModel("wahlID1", "Bundestagswahl", 1L, 1L, forDate, Wahlart.BTW, new Farbe(0, 1, 2), "0"), - new WahlModel("wahlID2", "Europawahl", 2L, 1L, forDate, Wahlart.EUW, new Farbe(3, 4, 5), "1")), + new WahlModel("wahlID1", "Bundestagswahl", 1L, 1L, wahltagWithNummer.wahltag(), Wahlart.BTW, new Farbe(0, 1, 2), "0"), + new WahlModel("wahlID2", "Europawahl", 2L, 1L, wahltagWithNummer.wahltag(), Wahlart.EUW, new Farbe(3, 4, 5), "1")), Set.of( - new WahlbezirkModel("wahlbezirkID1_1", WahlbezirkArtModel.UWB, "1201", forDate, "0", "wahlID1"), - new WahlbezirkModel("wahlbezirkID1_2", WahlbezirkArtModel.BWB, "1251", forDate, "0", "wahlID1"), - new WahlbezirkModel("wahlbezirkID2_1", WahlbezirkArtModel.UWB, "1202", forDate, "0", "wahlID1"), - new WahlbezirkModel("wahlbezirkID2_2", WahlbezirkArtModel.BWB, "1252", forDate, "0", "wahlID1"), - new WahlbezirkModel("wahlbezirkID2_2", WahlbezirkArtModel.BWB, "1252", forDate, "1", "wahlID2") + new WahlbezirkModel("wahlbezirkID1_1", WahlbezirkArtModel.UWB, "1201", wahltagWithNummer.wahltag(), "0", "wahlID1"), + new WahlbezirkModel("wahlbezirkID1_2", WahlbezirkArtModel.BWB, "1251", wahltagWithNummer.wahltag(), "0", "wahlID1"), + new WahlbezirkModel("wahlbezirkID2_1", WahlbezirkArtModel.UWB, "1202", wahltagWithNummer.wahltag(), "0", "wahlID1"), + new WahlbezirkModel("wahlbezirkID2_2", WahlbezirkArtModel.BWB, "1252", wahltagWithNummer.wahltag(), "0", "wahlID1"), + new WahlbezirkModel("wahlbezirkID2_2", WahlbezirkArtModel.BWB, "1252", wahltagWithNummer.wahltag(), "1", "wahlID2") ), Set.of( - new StimmzettelgebietModel("szgID", "120", "Munich", forDate, StimmzettelgebietsartModel.SG), - new StimmzettelgebietModel("szgIDOther", "920", "Munich Center", forDate, StimmzettelgebietsartModel.SB))); + new StimmzettelgebietModel("szgID", "120", "Munich", wahltagWithNummer.wahltag(), StimmzettelgebietsartModel.SG), + new StimmzettelgebietModel("szgIDOther", "920", "Munich Center", wahltagWithNummer.wahltag(), StimmzettelgebietsartModel.SB))); } @Override diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java index 65ea180f5..3522cb56c 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapper.java @@ -13,8 +13,8 @@ public interface KonfigurierterWahltagClientMapper { default boolean mapWahltagStatusEnumStringToModelBoolean(KonfigurierterWahltagDTO.WahltagStatusEnum wahltagStatus) { return switch (wahltagStatus) { - case AKTIV -> true; - case INAKTIV -> false; + case AKTIV -> true; + case INAKTIV -> false; }; } } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImpl.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImpl.java index 6393449e8..f3471ec92 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImpl.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImpl.java @@ -6,9 +6,9 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.BasisdatenModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.WahldatenClient; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; -import java.time.LocalDate; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Profile; @@ -25,11 +25,11 @@ public class WahldatenClientImpl implements WahldatenClient { private final WahldatenClientMapper wahldatenClientMapper; @Override - public BasisdatenModel loadBasisdaten(LocalDate forDate, String wahlterminNummer) throws WlsException { + public BasisdatenModel loadBasisdaten(WahltagWithNummer wahltagWithNummer) throws WlsException { final BasisdatenDTO basisdatenDTO; try { - basisdatenDTO = wahldatenControllerApi.loadBasisdaten(forDate, wahlterminNummer); + basisdatenDTO = wahldatenControllerApi.loadBasisdaten(wahltagWithNummer.wahltag(), wahltagWithNummer.wahltagNummer()); } catch (final Exception exception) { log.info("exception on getBasisdaten from external", exception); throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.FAILED_COMMUNICATION_WITH_EAI); diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java index 4f54bc5d0..1fe6c8d78 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java @@ -1,6 +1,7 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.KopfdatenRepository; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; import lombok.RequiredArgsConstructor; @@ -38,7 +39,8 @@ public KopfdatenModel getKopfdaten(BezirkUndWahlID bezirkUndWahlID) { bezirkUndWahlID.getWahlID()); final InitializeKopfdaten kopfDataInitializer = new InitializeKopfdaten(exceptionFactory); KonfigurierterWahltagModel konfigurierterWahltagModel = konfigurierterWahltagClient.getKonfigurierterWahltag(); - BasisdatenModel basisdatenModel = wahldatenClient.loadBasisdaten(konfigurierterWahltagModel.wahltag(), konfigurierterWahltagModel.nummer()); + BasisdatenModel basisdatenModel = wahldatenClient.loadBasisdaten( + new WahltagWithNummer(konfigurierterWahltagModel.wahltag(), konfigurierterWahltagModel.nummer())); kopfdatenModel = kopfDataInitializer.initKopfdata(bezirkUndWahlID.getWahlID(), bezirkUndWahlID.getWahlbezirkID(), basisdatenModel); kopfdatenRepository.save(kopfdatenModelMapper.toEntity(kopfdatenModel)); } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/WahldatenClient.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/WahldatenClient.java index aef4decb5..f47f60ff6 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/WahldatenClient.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/WahldatenClient.java @@ -1,13 +1,12 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException; -import java.time.LocalDate; public interface WahldatenClient { /** - * @param forDate the date of the election - * @param withNummer the number of the "Wahltermin" same with number of the "Wahltag" + * @param wahltagWithNummer filter for requested Basisdaten * @return BasisdatenDTO * @throws WlsException * {@link de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException} if @@ -15,5 +14,5 @@ public interface WahldatenClient { * {@link de.muenchen.oss.wahllokalsystem.wls.common.exception.TechnischeWlsException} * if there were trouble during communication */ - BasisdatenModel loadBasisdaten(LocalDate forDate, String withNummer) throws WlsException; + BasisdatenModel loadBasisdaten(WahltagWithNummer wahltagWithNummer) throws WlsException; } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java index 3d9258729..da5bc7824 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java @@ -50,7 +50,7 @@ class LoadBasisdaten { @Test void resultHasRightTypeAndAllPropertiesContainingData() { - val result = unitUnderTest.loadBasisdaten(LocalDate.now(), "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); Assertions.assertThat(result).isInstanceOf(BasisdatenModel.class); Assertions.assertThat(result).hasNoNullFieldsOrProperties(); Assertions.assertThat(result.basisstrukturdaten()).size().isPositive(); @@ -61,7 +61,7 @@ void resultHasRightTypeAndAllPropertiesContainingData() { @Test void forEveryBasistrutkturdatenCorespondingAtLeastOneWahlOneWahlbezirkAndOneStimmzettelgebiet() { - val result = unitUnderTest.loadBasisdaten(LocalDate.now(), "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); result.basisstrukturdaten().forEach((bsd) -> { Assertions.assertThat(result.wahlen()).anyMatch(w -> w.wahlID().equals(bsd.wahlID())); Assertions.assertThat(result.wahlbezirke()).anyMatch(wbz -> wbz.wahlbezirkID().equals(bsd.wahlbezirkID())); @@ -71,7 +71,7 @@ void forEveryBasistrutkturdatenCorespondingAtLeastOneWahlOneWahlbezirkAndOneStim @Test void forEveryWahlCorespondingAtLeastOneBasistrutkturdatenAndOneWahlbezirk() { - val result = unitUnderTest.loadBasisdaten(LocalDate.now(), "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); result.wahlen().forEach((wahl) -> { Assertions.assertThat(result.basisstrukturdaten()).anyMatch(bsd -> bsd.wahlID().equals(wahl.wahlID())); Assertions.assertThat(result.wahlbezirke()).anyMatch(wbz -> wbz.wahlID().equals(wahl.wahlID())); @@ -80,7 +80,7 @@ void forEveryWahlCorespondingAtLeastOneBasistrutkturdatenAndOneWahlbezirk() { @Test void forEveryWahlbezirkCorespondingAtLeastOneBasistrutkturdatenAndOneWahl() { - val result = unitUnderTest.loadBasisdaten(LocalDate.now(), "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); result.wahlbezirke().forEach((wbz) -> { Assertions.assertThat(result.basisstrukturdaten()).anyMatch(bsd -> bsd.wahlbezirkID().equals(wbz.wahlbezirkID())); Assertions.assertThat(result.wahlen()).anyMatch(wahl -> wahl.wahlID().equals(wbz.wahlID())); @@ -89,7 +89,7 @@ void forEveryWahlbezirkCorespondingAtLeastOneBasistrutkturdatenAndOneWahl() { @Test void forEveryStimmzettelgebietCorespondingAtLeastOneBasistrutkturdaten() { - val result = unitUnderTest.loadBasisdaten(LocalDate.now(), "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); for (StimmzettelgebietModel szg : result.stimmzettelgebiete()) { Assertions.assertThat(result.basisstrukturdaten()).anyMatch(bsd -> bsd.stimmzettelgebietID().equals(szg.identifikator())); } @@ -98,7 +98,7 @@ void forEveryStimmzettelgebietCorespondingAtLeastOneBasistrutkturdaten() { @Test void allUnderobjectsHaveRequestedDate() { val aDate = LocalDate.now(); - val result = unitUnderTest.loadBasisdaten(aDate, "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(aDate, "0")); Assertions.assertThat(result.basisstrukturdaten()).allMatch(bsd -> bsd.wahltag().equals(aDate)); Assertions.assertThat(result.wahlen()).allMatch(w -> w.wahltag().equals(aDate)); Assertions.assertThat(result.wahlbezirke()).allMatch(wbz -> wbz.wahltag().equals(aDate)); diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImplTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImplTest.java index ad09ab016..1fc1a3f9d 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImplTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientImplTest.java @@ -1,9 +1,11 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; import static org.mockito.ArgumentMatchers.any; + import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.client.WahldatenControllerApi; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.BasisdatenModel; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.TechnischeWlsException; @@ -50,7 +52,7 @@ void clientResponseIsMapped() { Mockito.when(wahldatenClientMapper.fromRemoteClientDTOToModel(mockedClientResponse)) .thenReturn(mockedMappedClientResponse); - val result = unitUnderTest.loadBasisdaten(testDate, "0"); + val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(testDate, "0")); Assertions.assertThat(result).isSameAs(mockedMappedClientResponse); } @@ -62,7 +64,8 @@ void exceptionWhenClientResponseIsNull() { Mockito.when(wahldatenControllerApi.loadBasisdaten(any(), any())).thenReturn(null); Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETKOPFDATEN_NO_BASISDATEN)).thenReturn(mockedWlsException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.loadBasisdaten(LocalDate.now(), "0")).isSameAs(mockedWlsException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0"))) + .isSameAs(mockedWlsException); } @Test @@ -74,7 +77,7 @@ void controllerApiExceptionIsMapped() { Mockito.when(wahldatenControllerApi.loadBasisdaten(any(), any())) .thenThrow(new RestClientException("error occurs while attempting to invoke the API")); Mockito.when(exceptionFactory.createTechnischeWlsException(ExceptionConstants.FAILED_COMMUNICATION_WITH_EAI)).thenThrow(mockedException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.loadBasisdaten(testDate, "0")).isSameAs(mockedException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.loadBasisdaten(new WahltagWithNummer(testDate, "0"))).isSameAs(mockedException); } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java index c3b1c4f78..7432cb011 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java @@ -4,6 +4,7 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.Stimmzettelgebietsart; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.common.StimmzettelgebietsartModel; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; @@ -61,7 +62,8 @@ void dataIsLoadedFromRemoteIfNotExistingInRepo() { Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.ofNullable(null)); Mockito.lenient().when(kopfdatenModelMapper.toModel(null)).thenReturn(null); Mockito.when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); - Mockito.when(wahldatenClient.loadBasisdaten(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer())) + Mockito.when(wahldatenClient.loadBasisdaten( + new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) .thenReturn(mockedBasisdatenModelFromClient); val result = unitUnderTest.getKopfdaten(bezirkUndWahlId); @@ -93,7 +95,8 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { Mockito.when(kopfdatenModelMapper.toModel(kopfdatenEntityInRepo)).thenReturn(expectedKopfdaten); Mockito.lenient().when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); Mockito.lenient() - .when(wahldatenClient.loadBasisdaten(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer())) + .when(wahldatenClient.loadBasisdaten( + new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) .thenReturn(mockedBasisdatenModelFromClient); val result = unitUnderTest.getKopfdaten(bezirkUndWahlId); @@ -112,7 +115,8 @@ void throwsFachlicheWlsExceptionIfBasisdataPartialEmptyOrNotConsistent() { Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.ofNullable(null)); Mockito.lenient().when(kopfdatenModelMapper.toModel(null)).thenReturn(null); Mockito.when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); - Mockito.when(wahldatenClient.loadBasisdaten(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer())) + Mockito.when(wahldatenClient.loadBasisdaten( + new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) .thenReturn(mockedBasisdatenModelFromClient); val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.INITIALIZE_KOPFDATEN_NO_BASISSTRUKTURDATEN)) From 843b9bf9ee52b647de71374cb75baec6c85f81eb Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:17:20 +0200 Subject: [PATCH 07/24] added factory methods for testdata with less arguments --- .../basisdatenservice/utils/MockDataFactory.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java index 300136136..32873f4bb 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java @@ -47,6 +47,10 @@ public static KopfdatenDTO createControllerKopfdatenDTO(String wahlID, String wa wahlbezirkNummer); } + public static KopfdatenModel createKopfdatenModelFor(String wahlID, String wahlbezirkID) { + return createKopfdatenModelFor(wahlID, wahlbezirkID, null, null, null, null, null); + } + public static KopfdatenModel createKopfdatenModelFor(String wahlID, String wahlbezirkID, StimmzettelgebietsartModel szga, String szGebietsNummer, String szGebietsName, String wahlname, String wahlbezirkNummer) { return new KopfdatenModel( @@ -59,6 +63,10 @@ public static KopfdatenModel createKopfdatenModelFor(String wahlID, String wahlb wahlbezirkNummer); } + public static Kopfdaten createKopfdatenEntityFor(String wahlID, String wahlbezirkID) { + return createKopfdatenEntityFor(wahlID, wahlbezirkID, null, null, null, null, null); + } + public static Kopfdaten createKopfdatenEntityFor(String wahlID, String wahlbezirkID, Stimmzettelgebietsart szga, String szGebietsName, String szGebietsNummer, String wahlname, String wahlbezirkNummer) { Kopfdaten kopfdaten = new Kopfdaten(); From 843dbf81daa3766a4c318ec88414c210603179af Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:18:40 +0200 Subject: [PATCH 08/24] use InitializeKopfdaten as Bean --- .../services/kopfdaten/InitializeKopfdaten.java | 2 ++ .../services/kopfdaten/KopfdatenService.java | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/InitializeKopfdaten.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/InitializeKopfdaten.java index 79400afb7..1fd9aa30f 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/InitializeKopfdaten.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/InitializeKopfdaten.java @@ -7,8 +7,10 @@ import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; import lombok.RequiredArgsConstructor; import lombok.val; +import org.springframework.stereotype.Component; @RequiredArgsConstructor +@Component public class InitializeKopfdaten { private final ExceptionFactory exceptionFactory; diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java index 1fe6c8d78..7e11a3628 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenService.java @@ -2,7 +2,6 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.KopfdatenRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -21,7 +20,7 @@ public class KopfdatenService { private final WahldatenClient wahldatenClient; private final KopfdatenRepository kopfdatenRepository; private final KopfdatenModelMapper kopfdatenModelMapper; - private final ExceptionFactory exceptionFactory; + private final InitializeKopfdaten kopfDataInitializer; @PreAuthorize("hasAuthority('Basisdaten_BUSINESSACTION_GetKopfdaten')") @Transactional @@ -37,7 +36,6 @@ public KopfdatenModel getKopfdaten(BezirkUndWahlID bezirkUndWahlID) { } else { log.error("#getKopfdaten: Für Wahlbezirk {} mit WahlID {} waren keine Kopfdaten in der Datenbank", bezirkUndWahlID.getWahlbezirkID(), bezirkUndWahlID.getWahlID()); - final InitializeKopfdaten kopfDataInitializer = new InitializeKopfdaten(exceptionFactory); KonfigurierterWahltagModel konfigurierterWahltagModel = konfigurierterWahltagClient.getKonfigurierterWahltag(); BasisdatenModel basisdatenModel = wahldatenClient.loadBasisdaten( new WahltagWithNummer(konfigurierterWahltagModel.wahltag(), konfigurierterWahltagModel.nummer())); From b380261974a234e6e8ef85964584cb76c0ebcba7 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:19:03 +0200 Subject: [PATCH 09/24] update and optimized tests with initializer as bean --- .../kopfdaten/KopfdatenServiceTest.java | 63 +++++-------------- 1 file changed, 15 insertions(+), 48 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java index 7432cb011..9931338a7 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceTest.java @@ -1,13 +1,12 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten; +import static org.mockito.ArgumentMatchers.any; + import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.KopfdatenRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.kopfdaten.Stimmzettelgebietsart; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.common.StimmzettelgebietsartModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; import java.time.LocalDate; import java.util.Optional; @@ -34,7 +33,7 @@ class KopfdatenServiceTest { KopfdatenValidator kopfdatenValidator; @Mock - ExceptionFactory exceptionFactory; + InitializeKopfdaten initializeKopfdaten; @Mock WahldatenClient wahldatenClient; @@ -50,81 +49,49 @@ class GetKopfdaten { @Test void dataIsLoadedFromRemoteIfNotExistingInRepo() { - val bezirkUndWahlId = new BezirkUndWahlID("wahlID1", "wahlbezirkID1_1"); + val wahlID = "wahlID1"; + val wahlbezrkID = "wahlbezirkID1_1"; + val bezirkUndWahlId = new BezirkUndWahlID(wahlID, wahlbezrkID); val forDate = LocalDate.now().plusMonths(1); val mockedKonfigurierterWahltagFromClient = MockDataFactory.createClientKonfigurierterWahltagModel(forDate, true); val mockedBasisdatenModelFromClient = MockDataFactory.createBasisdatenModel(mockedKonfigurierterWahltagFromClient.wahltag()); + val mockedKopfdatenModelByInitializer = MockDataFactory.createKopfdatenModelFor(wahlID, wahlbezrkID); + val mockedKopfdatenModelMappedToEntity = MockDataFactory.createKopfdatenEntityFor(wahlID, wahlbezrkID); - val expectedKopfdatenFromClient = MockDataFactory.createKopfdatenModelFor("wahlID1", "wahlbezirkID1_1", - StimmzettelgebietsartModel.SG, "120", "Munich", - "Bundestagswahl", "1201"); - - Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.ofNullable(null)); - Mockito.lenient().when(kopfdatenModelMapper.toModel(null)).thenReturn(null); + Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.empty()); + Mockito.when(kopfdatenModelMapper.toEntity(mockedKopfdatenModelByInitializer)).thenReturn(mockedKopfdatenModelMappedToEntity); Mockito.when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); Mockito.when(wahldatenClient.loadBasisdaten( new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) .thenReturn(mockedBasisdatenModelFromClient); + Mockito.when(initializeKopfdaten.initKopfdata(wahlID, wahlbezrkID, mockedBasisdatenModelFromClient)).thenReturn(mockedKopfdatenModelByInitializer); val result = unitUnderTest.getKopfdaten(bezirkUndWahlId); - Assertions.assertThat(result).isEqualTo(expectedKopfdatenFromClient); + Assertions.assertThat(result).isEqualTo(mockedKopfdatenModelByInitializer); + Mockito.verify(kopfdatenValidator).validWahlIdUndWahlbezirkIDOrThrow(bezirkUndWahlId); + Mockito.verify(kopfdatenRepository).save(mockedKopfdatenModelMappedToEntity); } @Test void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { val bezirkUndWahlId = new BezirkUndWahlID("wahlID1", "wahlbezirkID1_1"); - val forDate = LocalDate.now().plusMonths(1); val kopfdatenEntityInRepo = MockDataFactory.createKopfdatenEntityFor("wahlID1", "wahlbezirkID1_1", Stimmzettelgebietsart.SG, "Munich-Repo", "120", "Bundestagswahl", "1201"); - val mockedKonfigurierterWahltagFromClient = MockDataFactory.createClientKonfigurierterWahltagModel(forDate, true); - val mockedBasisdatenModelFromClient = MockDataFactory.createBasisdatenModel(mockedKonfigurierterWahltagFromClient.wahltag()); - val expectedKopfdaten = MockDataFactory.createKopfdatenModelFor("wahlID1", "wahlbezirkID1_1", StimmzettelgebietsartModel.SG, "120", "Munich-Repo", "Bundestagswahl", "1201"); - val notExpectedRemoteKopfdaten = MockDataFactory.createKopfdatenModelFor("wahlID1", "wahlbezirkID1_1", - StimmzettelgebietsartModel.SG, "120", "Munich", - "Bundestagswahl", "1201"); - Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.of(kopfdatenEntityInRepo)); Mockito.when(kopfdatenModelMapper.toModel(kopfdatenEntityInRepo)).thenReturn(expectedKopfdaten); - Mockito.lenient().when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); - Mockito.lenient() - .when(wahldatenClient.loadBasisdaten( - new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) - .thenReturn(mockedBasisdatenModelFromClient); val result = unitUnderTest.getKopfdaten(bezirkUndWahlId); Assertions.assertThat(result).isEqualTo(expectedKopfdaten); - Assertions.assertThat(result).isNotEqualTo(notExpectedRemoteKopfdaten); Mockito.verify(kopfdatenValidator).validWahlIdUndWahlbezirkIDOrThrow(bezirkUndWahlId); - } - - @Test - void throwsFachlicheWlsExceptionIfBasisdataPartialEmptyOrNotConsistent() { - val bezirkUndWahlId = new BezirkUndWahlID("wahlID99", "wahlbezirkID1_99"); - val forDate = LocalDate.now().plusMonths(1); - val mockedKonfigurierterWahltagFromClient = MockDataFactory.createClientKonfigurierterWahltagModel(forDate, true); - val mockedBasisdatenModelFromClient = MockDataFactory.createBasisdatenModel(mockedKonfigurierterWahltagFromClient.wahltag()); - - Mockito.when(kopfdatenRepository.findById(bezirkUndWahlId)).thenReturn(Optional.ofNullable(null)); - Mockito.lenient().when(kopfdatenModelMapper.toModel(null)).thenReturn(null); - Mockito.when(konfigurierterWahltagClient.getKonfigurierterWahltag()).thenReturn(mockedKonfigurierterWahltagFromClient); - Mockito.when(wahldatenClient.loadBasisdaten( - new WahltagWithNummer(mockedKonfigurierterWahltagFromClient.wahltag(), mockedKonfigurierterWahltagFromClient.nummer()))) - .thenReturn(mockedBasisdatenModelFromClient); - val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); - Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.INITIALIZE_KOPFDATEN_NO_BASISSTRUKTURDATEN)) - .thenReturn(mockedWlsException); - Mockito.lenient().when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.INITIALIZE_KOPFDATEN_NO_WAHL_WAHLBEZIRK_STIMMZETTELGEBIET)) - .thenReturn(mockedWlsException); - - Assertions.assertThatThrownBy(() -> unitUnderTest.getKopfdaten(bezirkUndWahlId)).isInstanceOf(FachlicheWlsException.class); + Mockito.verify(kopfdatenRepository, Mockito.times(0)).save(any()); } } } From 858e9d3302a4524499470dff7c94cb9a831abe5d Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:37:50 +0200 Subject: [PATCH 10/24] fix unnecessary repo clearing --- .../services/kopfdaten/KopfdatenServiceSecurityTest.java | 6 ------ .../basisdatenservice/utils/Authorities.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java index 5349559da..cdfebfc12 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/kopfdaten/KopfdatenServiceSecurityTest.java @@ -79,7 +79,6 @@ void accessGranted() throws Exception { @MethodSource("getMissingAuthoritiesVariationsRepoEmpty") void missingAuthorityCausesFailWithAccessDeniedCaseEmptyRepo(final ArgumentsAccessor argumentsAccessor) throws Exception { SecurityUtils.runWith(argumentsAccessor.get(0, String[].class)); - emptyTheRepository(); // mock infomanagement konfigurierterWahltag KonfigurierterWahltagDTO infomanagementKonfigurierterWahltag = MockDataFactory.createClientKonfigurierterWahltagDTO(LocalDate.now().plusMonths(1), KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV); @@ -104,11 +103,6 @@ private static Stream getMissingAuthoritiesVariationsRepoEmpty() { return SecurityUtils.buildArgumentsForMissingAuthoritiesVariations(Authorities.ALL_AUTHORITIES_READ_KOPFDATEN); } - private void emptyTheRepository() { - SecurityUtils.runWith(Authorities.REPOSITORY_DELETE_KOPFDATEN); - kopfdatenRepository.deleteAll(); - } - @ParameterizedTest(name = "{index} - {1} missing") @MethodSource("getMissingAuthoritiesVariationsRepoHasData") void missingAuthorityCausesFailWithAccessDeniedCaseRepoHasData(final ArgumentsAccessor argumentsAccessor) throws Exception { diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java index 2ac8632af..72dc3c053 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java @@ -172,8 +172,6 @@ public class Authorities { SERVICE_GET_KOPFDATEN, REPOSITORY_READ_KOPFDATEN, REPOSITORY_WRITE_KOPFDATEN, - S2S_INFOMANAGEMENT_SERVICE_GET_KONFIGURIERTERWAHLTAG, - S2S_INFOMANAGEMENT_REPOSITORY_READ_KONFIGURIERTERWAHLTAG }; public static final String[] ALL_AUTHORITIES_KOPFDATEN = { From 701d4fe6d8789b06cedb483beea7f7ad9f6562a4 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:05:29 +0200 Subject: [PATCH 11/24] optimise mapstruct mapper with use parameter --- .../clients/WahldatenClientMapper.java | 15 +------ .../clients/WahldatenClientMapperTest.java | 43 +++---------------- 2 files changed, 6 insertions(+), 52 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapper.java index 056c785fc..f4447d7a1 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapper.java @@ -1,24 +1,11 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.BasisdatenDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlbezirkDTO; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.BasisdatenModel; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke.WahlbezirkModel; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; -@Mapper +@Mapper(uses = { WahlbezirkeClientMapper.class, WahlenClientMapper.class }) public interface WahldatenClientMapper { BasisdatenModel fromRemoteClientDTOToModel(BasisdatenDTO basisdatenDTO); - - default WahlModel wahlDTOToWahlModel(WahlDTO wahlDTO) { - return Mappers.getMapper(WahlenClientMapper.class).toModel(wahlDTO); - } - - default WahlbezirkModel walbezirkDTOToWahlbezirkModel(WahlbezirkDTO wahlbezirkDTO) { - return Mappers.getMapper(WahlbezirkeClientMapper.class).fromClientDTOToModel(wahlbezirkDTO); - } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapperTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapperTest.java index 84c084fd4..ebbdc8a12 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapperTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/WahldatenClientMapperTest.java @@ -1,52 +1,19 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Farbe; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahlart; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import java.time.LocalDate; import lombok.val; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.mapstruct.factory.Mappers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +@SpringBootTest(classes = { WahldatenClientMapperImpl.class, WahlbezirkeClientMapperImpl.class, WahlenClientMapperImpl.class }) class WahldatenClientMapperTest { - private final WahldatenClientMapper unitUnderTest = Mappers.getMapper(WahldatenClientMapper.class); - - @Nested - class WahlDTOToWahlModel { - - @Test - void isMapped() { - val aNowMoment = LocalDate.now(); - val wahl1 = new WahlDTO(); - wahl1.setIdentifikator("identifikatorWahl1"); - wahl1.setNummer("nummerWahl1"); - wahl1.setName("nameWahl1"); - wahl1.setWahlart(WahlDTO.WahlartEnum.BAW); - wahl1.setWahltag(aNowMoment); - - Assertions.assertThat(wahl1).hasNoNullFieldsOrProperties(); - - val result = unitUnderTest.wahlDTOToWahlModel(wahl1); - - val expectedWahl = new WahlModel( - "identifikatorWahl1", - "nameWahl1", - 1L, - 1L, - aNowMoment, - Wahlart.BAW, - new Farbe(0, 0, 0), - "nummerWahl1"); - - Assertions.assertThat(result).usingRecursiveComparison().isEqualTo(expectedWahl); - } - - } + @Autowired + private WahldatenClientMapper unitUnderTest; @Nested class FromRemoteClientDTOToModel { From f0e31e81b2e9a90ce69fdd349c290e26c4590a23 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:11:09 +0200 Subject: [PATCH 12/24] =?UTF-8?q?=F0=9F=8E=A8=20use=20isNotEmpty=20instead?= =?UTF-8?q?=20of=20check=20by=20size=20is=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basisdatenservice/clients/DummyClientImplTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java index da5bc7824..b516f0b99 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java @@ -53,10 +53,10 @@ void resultHasRightTypeAndAllPropertiesContainingData() { val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); Assertions.assertThat(result).isInstanceOf(BasisdatenModel.class); Assertions.assertThat(result).hasNoNullFieldsOrProperties(); - Assertions.assertThat(result.basisstrukturdaten()).size().isPositive(); - Assertions.assertThat(result.wahlen()).size().isPositive(); - Assertions.assertThat(result.wahlbezirke()).size().isPositive(); - Assertions.assertThat(result.stimmzettelgebiete()).size().isPositive(); + Assertions.assertThat(result.basisstrukturdaten()).isNotEmpty(); + Assertions.assertThat(result.wahlen()).isNotEmpty(); + Assertions.assertThat(result.wahlbezirke()).isNotEmpty(); + Assertions.assertThat(result.stimmzettelgebiete()).isNotEmpty(); } @Test @@ -123,7 +123,7 @@ class LoadWahlbezirke { @Test void resultIsAnArrayWithPositiveSize() { val result = unitUnderTest.loadWahlbezirke(LocalDate.now(), "0"); - Assertions.assertThat(result).size().isPositive(); + Assertions.assertThat(result).isNotEmpty(); } } } From 7439fb85a944eda782cdaba268fbe040494c2b22 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:11:59 +0200 Subject: [PATCH 13/24] remove not required type check --- .../basisdatenservice/clients/DummyClientImplTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java index b516f0b99..081b99a9c 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/DummyClientImplTest.java @@ -1,6 +1,5 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.clients; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.BasisdatenModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.kopfdaten.StimmzettelgebietModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahltagWithNummer; import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; @@ -51,7 +50,6 @@ class LoadBasisdaten { @Test void resultHasRightTypeAndAllPropertiesContainingData() { val result = unitUnderTest.loadBasisdaten(new WahltagWithNummer(LocalDate.now(), "0")); - Assertions.assertThat(result).isInstanceOf(BasisdatenModel.class); Assertions.assertThat(result).hasNoNullFieldsOrProperties(); Assertions.assertThat(result.basisstrukturdaten()).isNotEmpty(); Assertions.assertThat(result.wahlen()).isNotEmpty(); From 177830860f8349867023cdf079e827095bb43b64 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:13:53 +0200 Subject: [PATCH 14/24] =?UTF-8?q?=F0=9F=8E=A8=20improved=20testname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clients/KonfigurierterWahltagClientMapperTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java index be9a18d90..8542ef6ee 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/clients/KonfigurierterWahltagClientMapperTest.java @@ -17,7 +17,7 @@ class KonfigurierterWahltagClientMapperTest { class FromRemoteClientDTOToModel { @Test - void isMappedIfStatusAktive() { + void isMappedWithStatusAktive() { val konfigurierterWahltagDTO = MockDataFactory.createClientKonfigurierterWahltagDTO(LocalDate.now().plusMonths(1), KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV); @@ -31,7 +31,7 @@ void isMappedIfStatusAktive() { } @Test - void isMappedIfStatusInaktive() { + void isMappedWithStatusInaktive() { val konfigurierterWahltagDTO = MockDataFactory.createClientKonfigurierterWahltagDTO(LocalDate.now().plusMonths(1), KonfigurierterWahltagDTO.WahltagStatusEnum.INAKTIV); From fe488c19e870780f8af64a952242cd03922a2f97 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:23:42 +0200 Subject: [PATCH 15/24] =?UTF-8?q?=F0=9F=8E=A8=20reduce=20test=20complexity?= =?UTF-8?q?=20and=20improve=20naming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KopfdatenControllerIntegrationTest.java | 63 +------------------ 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java index ec4fecd43..a384e5a21 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/kopfdaten/KopfdatenControllerIntegrationTest.java @@ -127,22 +127,12 @@ void externalDataIsPersisted() throws Exception { .withBody(objectMapper.writeValueAsBytes(eaiBasisdaten)))); val wahlID1 = "wahlID1"; - val wahlID2 = "wahlID2"; val wahlbezirkID1 = "wahlbezirkID1_1"; - val wahlbezirkID2 = "wahlbezirkID2_1"; val request1 = MockMvcRequestBuilders.get("/businessActions/kopfdaten/" + wahlID1 + "/" + wahlbezirkID1); - val request2 = MockMvcRequestBuilders.get("/businessActions/kopfdaten/" + wahlID2 + "/" + wahlbezirkID2); - val request3 = MockMvcRequestBuilders.get("/businessActions/kopfdaten/" + wahlID1 + "/" + wahlbezirkID2); val expectedKopfdaten1 = MockDataFactory.createKopfdatenEntityFor("wahlID1", "wahlbezirkID1_1", Stimmzettelgebietsart.SG, "Munich", "120", "Bundestagswahl", "1201"); - val expectedKopfdaten2 = MockDataFactory.createKopfdatenEntityFor("wahlID2", "wahlbezirkID2_1", - Stimmzettelgebietsart.SB, "Munich Center", "920", - "Europawahl", "1252"); - val expectedKopfdaten3 = MockDataFactory.createKopfdatenEntityFor("wahlID1", "wahlbezirkID2_1", - Stimmzettelgebietsart.SG, "Munich", "120", - "Bundestagswahl", "1202"); api.perform(request1).andExpect(status().isOk()); List dataFromRepo = (List) kopfdatenRepository.findAllById(List.of(new BezirkUndWahlID("wahlID1", "wahlbezirkID1_1"))); @@ -150,28 +140,11 @@ void externalDataIsPersisted() throws Exception { Assertions.assertThat(dataFromRepo) .usingRecursiveComparison().ignoringCollectionOrder() .isEqualTo(expectedListOfData1); - kopfdatenRepository.deleteAll(); - - api.perform(request2).andExpect(status().isOk()); - dataFromRepo = (List) kopfdatenRepository.findAllById(List.of(new BezirkUndWahlID("wahlID2", "wahlbezirkID2_1"))); - val expectedListOfData2 = List.of(expectedKopfdaten2); - Assertions.assertThat(dataFromRepo) - .usingRecursiveComparison().ignoringCollectionOrder() - .isEqualTo(expectedListOfData2); - kopfdatenRepository.deleteAll(); - - api.perform(request3).andExpect(status().isOk()); - dataFromRepo = (List) kopfdatenRepository.findAllById(List.of(new BezirkUndWahlID("wahlID1", "wahlbezirkID2_1"))); - val expectedListOfData3 = List.of(expectedKopfdaten3); - - Assertions.assertThat(dataFromRepo) - .usingRecursiveComparison().ignoringCollectionOrder() - .isEqualTo(expectedListOfData3); } @Test @Transactional - void loadFromExternalOnlyIfNotFoundInRepo() throws Exception { + void loadExistingDataFromRepoNoRemoteData() throws Exception { val kopfdatenEntity1 = MockDataFactory.createKopfdatenEntityFor("wahlID1", "wahlbezirkID1_1", Stimmzettelgebietsart.SG, "Munich-Repo1", "120", "Bundestagswahl", "1201"); @@ -190,38 +163,6 @@ void loadFromExternalOnlyIfNotFoundInRepo() throws Exception { val expectedResponseBody_1 = dtoMapper.toDTO( modelMapper.toModel(kopfdatenEntity1)); Assertions.assertThat(responseBodyAsDTO_1).isEqualTo(expectedResponseBody_1); - - kopfdatenRepository.deleteAll(); - - // mock infomanagement konfigurierterWahltag - KonfigurierterWahltagDTO infomanagementKonfigurierterWahltag = MockDataFactory.createClientKonfigurierterWahltagDTO(LocalDate.now().plusMonths(1), - KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV); - WireMock.stubFor(WireMock.get("/businessActions/konfigurierterWahltag") - .willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.OK.value()) - .withBody(objectMapper.writeValueAsBytes(infomanagementKonfigurierterWahltag)))); - // mock eai getBasisdaten - BasisdatenDTO eaiBasisdaten = MockDataFactory.createClientBasisdatenDTO(LocalDate.now().plusMonths(1)); - WireMock.stubFor(WireMock - .get("/wahldaten/basisdaten?forDate=" + LocalDate.now().plusMonths(1) + "&withNummer=" + infomanagementKonfigurierterWahltag.getNummer()) - .willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.OK.value()) - .withBody(objectMapper.writeValueAsBytes(eaiBasisdaten)))); - - val responseFromController_2 = api.perform(request).andExpect(status().isOk()).andReturn(); - val responseBodyAsDTO_2 = objectMapper.readValue(responseFromController_2.getResponse().getContentAsString(), - de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.kopfdaten.KopfdatenDTO.class); - //After calling 2 Clients infomanagement and eai - WireMock.verify(2, WireMock.anyRequestedFor(WireMock.anyUrl())); - - val notExpectedResponseBody_2 = dtoMapper.toDTO( - modelMapper.toModel(kopfdatenEntity1)); - Assertions.assertThat(responseBodyAsDTO_2).isNotEqualTo(notExpectedResponseBody_2); - val kopfdatenEntity3 = MockDataFactory.createKopfdatenEntityFor("wahlID1", "wahlbezirkID1_1", - Stimmzettelgebietsart.SG, "Munich", "120", - "Bundestagswahl", "1201"); - val expectedResponseBody_2 = dtoMapper.toDTO( - modelMapper.toModel(kopfdatenEntity3)); - Assertions.assertThat(responseBodyAsDTO_2).isEqualTo(expectedResponseBody_2); - } @Test @@ -295,7 +236,7 @@ void fachlicheWlsExceptionWhenNoKonfigurierterWahltagNoContent() throws Exceptio } @Test - void fachlichecheWlsExceptionWhenKopfdatenNoContent() throws Exception { + void fachlicheWlsExceptionWhenKopfdatenNoContent() throws Exception { KonfigurierterWahltagDTO infomanagementKonfigurierterWahltag = MockDataFactory.createClientKonfigurierterWahltagDTO(LocalDate.now().plusMonths(1), KonfigurierterWahltagDTO.WahltagStatusEnum.AKTIV); From 621cda8aaafa1e4c850a0d0ee33538ae4c2c7d6c Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:24:17 +0200 Subject: [PATCH 16/24] fix typo --- .../services/wahlbezirke/WahlbezirkModelMapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java index de92c5413..dc90431c6 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java @@ -27,7 +27,7 @@ class WahlbezirkModelMapperTest { ExceptionFactory exceptionFactory; @Test - void fromListOfWahlbezirkModeltoListOfWahlbezirkEntities() { + void fromListOfWahlbezirkModelToListOfWahlbezirkEntities() { val modelsToMap = MockDataFactory.createListOfWahlbezirkModel("", LocalDate.now()); val result = unitUnderTest.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(modelsToMap); From ba8c546a4b18e479120aa138422977e4704ab221 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:39:30 +0200 Subject: [PATCH 17/24] refactor: move data enrichment from mapper to service --- .../wahlbezirke/WahlbezirkModelMapper.java | 27 +--------- .../wahlbezirke/WahlbezirkeService.java | 24 ++++++--- .../WahlbezirkeControllerIntegrationTest.java | 8 +-- .../WahlbezirkModelMapperTest.java | 49 ------------------- .../wahlbezirke/WahlbezirkeServiceTest.java | 7 --- 5 files changed, 21 insertions(+), 94 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java index 24cc3aebc..12d635857 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java @@ -2,12 +2,8 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahlbezirk; import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlbezirkDTO; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; -import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Set; import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -19,27 +15,8 @@ public interface WahlbezirkModelMapper { @Mapping(source = "wahlbezirkArt", target = "wahlbezirkart") Wahlbezirk fromDTOtoEntity(WahlbezirkDTO dto); - List fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(List wahlbezirkModelList); + Collection fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(Collection wahlbezirkModelList); List fromListOfWahlbezirkEntityToListOfWahlbezirkModel(List wahlbezirkEntityList); - default List toWahlbezirkModelListMergedWithWahlenInfo(Set remoteWahlbezirke, List wahlen, - ExceptionFactory exceptionFactory) { - if (remoteWahlbezirke == null) { - throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_DATA); - } - List list = new ArrayList<>(); - List remoteList = this.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(remoteWahlbezirke.stream().toList()); - remoteList.forEach(wahlbezirk -> { - if (null != wahlen) { - WahlModel searchedWahl = wahlen.stream().filter(wahl -> wahlbezirk.getWahlnummer().equals(wahl.nummer())).findFirst().orElse(null); - if (null != searchedWahl) { - wahlbezirk.setWahlID(searchedWahl.wahlID()); - } - } - list.add(wahlbezirk); - }); - return this.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(list); - } - } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java index 055e79c1d..afefc0ca9 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java @@ -1,12 +1,15 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahlbezirk; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahlbezirkRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahltag; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahltagRepository; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahl; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.WahlRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModelMapper; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.util.Collection; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -49,17 +52,24 @@ public List getWahlbezirke(final String wahltagID) { val wahltagObjekt = wahltag.get(); if (wahlbezirkRepository.countByWahltag(wahltagObjekt.getWahltag()) == 0) { log.error("#getWahlbezirke: Für wahltagID {} waren keine Wahlbezirke in der Datenbank", wahltagID); - wahlbezirkRepository.saveAll( - wahlbezirkModelMapper.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities( - wahlbezirkModelMapper.toWahlbezirkModelListMergedWithWahlenInfo( - wahlbezirkeClient.loadWahlbezirke(wahltagObjekt.getWahltag(), wahltagObjekt.getNummer()), - wahlModelMapper.fromListOfWahlEntityToListOfWahlModel( - wahlRepository.findByWahltagOrderByReihenfolge(wahltagObjekt.getWahltag())), - exceptionFactory))); + val wahlbezirkeOfWahltag = wahlbezirkeClient.loadWahlbezirke(wahltagObjekt.getWahltag(), wahltagObjekt.getNummer()); + val wahlbezirkeAsEntities = wahlbezirkModelMapper.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(wahlbezirkeOfWahltag); + + val wahlenOfWahltag = wahlRepository.findByWahltagOrderByReihenfolge(wahltagObjekt.getWahltag()); + wahlbezirkeAsEntities.forEach(wahlbezirk -> linkFirstMatchingWahl(wahlbezirk, wahlenOfWahltag)); + + wahlbezirkRepository.saveAll(wahlbezirkeAsEntities); } return wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(wahlbezirkRepository.findByWahltag(wahltagObjekt.getWahltag())); } else { throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG); } } + + private void linkFirstMatchingWahl(final Wahlbezirk wahlbezirk, final Collection wahlen) { + val searchedWahl = wahlen.stream().filter(wahl -> wahlbezirk.getWahlnummer().equals(wahl.getNummer())).findFirst().orElse(null); + if (null != searchedWahl) { + wahlbezirk.setWahlID(searchedWahl.getWahlID()); + } + } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahlbezirke/WahlbezirkeControllerIntegrationTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahlbezirke/WahlbezirkeControllerIntegrationTest.java index e2c5d9f46..c264295f9 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahlbezirke/WahlbezirkeControllerIntegrationTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahlbezirke/WahlbezirkeControllerIntegrationTest.java @@ -3,6 +3,7 @@ import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_NO_SECURITY_PROFILE; import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_TEST_PROFILE; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.client.WireMock; import de.muenchen.oss.wahllokalsystem.basisdatenservice.MicroServiceApplication; @@ -119,12 +120,7 @@ void loadedFromExternal() throws Exception { de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahlbezirke.WahlbezirkDTO[].class); val expectedResponseBody = wahlbezirkDTOMapper - .fromListOfWahlbezirkModelToListOfWahlbezirkDTO( - - wahlbezirkModelMapper.toWahlbezirkModelListMergedWithWahlenInfo( - wahlbezirkeClientMapper.fromRemoteSetOfDTOsToSetOfModels(eaiWahlbezirke), - wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlRepository.findByWahltagOrderByReihenfolge(forWahltagDate)), - exceptionFactory)); + .fromListOfWahlbezirkModelToListOfWahlbezirkDTO(List.copyOf(wahlbezirkeClientMapper.fromRemoteSetOfDTOsToSetOfModels(eaiWahlbezirke))); Assertions.assertThat(responseBodyAsDTO).containsExactlyInAnyOrderElementsOf(expectedResponseBody); } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java index dc90431c6..4dc33525e 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapperTest.java @@ -1,30 +1,15 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.MicroServiceApplication; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahl; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModelMapper; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.time.LocalDate; -import java.util.HashSet; -import java.util.List; import lombok.val; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(classes = MicroServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK) class WahlbezirkModelMapperTest { private final WahlbezirkModelMapper unitUnderTest = Mappers.getMapper(WahlbezirkModelMapper.class); - private final WahlModelMapper wahlModelMapper = Mappers.getMapper(WahlModelMapper.class); - - @Autowired - ExceptionFactory exceptionFactory; @Test void fromListOfWahlbezirkModelToListOfWahlbezirkEntities() { @@ -45,38 +30,4 @@ void fromListOfWahlbezirkEntityToListOfWahlbezirkModel() { val expectedResult = MockDataFactory.createListOfWahlbezirkModel("", LocalDate.now()); Assertions.assertThat(result).isEqualTo(expectedResult); } - - @Nested - class ToWahlbezirkModelListMergedWithWahlenInfo { - - @Test - void throwsFachlicheWlsExceptionIfNullRemoteWahlbezirke() { - val wahlModels = MockDataFactory.createWahlModelList("", LocalDate.now()); - Assertions.assertThatCode(() -> unitUnderTest.toWahlbezirkModelListMergedWithWahlenInfo(null, wahlModels, exceptionFactory)) - .isInstanceOf(FachlicheWlsException.class); - } - - @Test - void doesNotThrowExceptionIfRemoteWahlbezirkeIsSizeZero() { - val setOfModels = new HashSet(); - val wahlModels = MockDataFactory.createWahlModelList("", LocalDate.now()); - - Assertions.assertThat(setOfModels).isEmpty(); - Assertions.assertThatCode(() -> unitUnderTest.toWahlbezirkModelListMergedWithWahlenInfo(setOfModels, wahlModels, exceptionFactory)) - .doesNotThrowAnyException(); - } - - @Test - void isMappingAndMergingCorrectlyWithWahlen() { - val modelsToMap = MockDataFactory.createSetOfWahlbezirkModel("", LocalDate.now()); - List wahlen = MockDataFactory.createWahlEntityList(); - val aTestWahlID = "aRandomIDThatShouldBeTakenIntoWahlbezirkeToMergeWith"; - wahlen.forEach((wahl) -> wahl.setWahlID(aTestWahlID)); - val wahlModels = wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlen); - - val result = unitUnderTest.toWahlbezirkModelListMergedWithWahlenInfo(modelsToMap, wahlModels, exceptionFactory); - - Assertions.assertThat(result).allMatch((mergedWahlbezirk) -> mergedWahlbezirk.wahlID().equals(aTestWahlID)); - } - } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index ce6234e79..f5452e061 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -79,9 +79,6 @@ void dataIsLoadedFromRemoteIfNotExistingInRepo() { Mockito.when(wahlbezirkeClient.loadWahlbezirke(wahltag.get().getWahltag(), wahltag.get().getNummer())) .thenReturn(mockedwahlbezirkeModelFromClient); Mockito.when(wahlRepository.findByWahltagOrderByReihenfolge(wahltag.get().getWahltag())).thenReturn(wahlen); - Mockito.when(wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlen)).thenReturn(wahlModels); - Mockito.when(wahlbezirkModelMapper.toWahlbezirkModelListMergedWithWahlenInfo(mockedwahlbezirkeModelFromClient, wahlModels, exceptionFactory)) - .thenReturn(mergedWahlbezirkeWithWahlen); Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.get().getWahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) .thenReturn(mergedWahlbezirkeWithWahlen); @@ -117,10 +114,6 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { .thenReturn(notExpectedMockedwahlbezirkeModelFromClient); Mockito.lenient().when(wahlRepository.findByWahltagOrderByReihenfolge(wahltag.get().getWahltag())).thenReturn(wahlen); Mockito.lenient().when(wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlen)).thenReturn(notExpectedWahlModels); - Mockito.lenient() - .when(wahlbezirkModelMapper.toWahlbezirkModelListMergedWithWahlenInfo(notExpectedMockedwahlbezirkeModelFromClient, notExpectedWahlModels, - exceptionFactory)) - .thenReturn(mergedWahlbezirkeWithWahlen); Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.get().getWahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) From 4936004695e81a6ea9e45d9894f97c2860e2e2b8 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:43:17 +0200 Subject: [PATCH 18/24] remove unnecessary stubbings --- .../services/wahlbezirke/WahlbezirkeServiceTest.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index f5452e061..24411aaa8 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -97,7 +97,6 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { val wahltag = MockDataFactory.createWahltagList("").stream().filter((wtg) -> wtg.getWahltagID().equals(wahltagID)).findFirst(); val mockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("", wahltag.get().getWahltag()); val notExpectedMockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("NotExpected", wahltag.get().getWahltag()); - val wahlen = MockDataFactory.createWahlEntityList().stream().filter((wahl) -> wahl.getWahltag().equals(wahltag.get().getWahltag())).toList(); val wahlModels = MockDataFactory.createWahlModelList("", wahltag.get().getWahltag()).stream() .filter((wahl) -> wahl.wahltag().equals(wahltag.get().getWahltag())).toList(); val notExpectedWahlModels = MockDataFactory.createWahlModelList("NotExpected", wahltag.get().getWahltag()).stream() @@ -110,11 +109,6 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(wahltag); Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.get().getWahltag())).thenReturn(3); - Mockito.lenient().when(wahlbezirkeClient.loadWahlbezirke(wahltag.get().getWahltag(), wahltag.get().getNummer())) - .thenReturn(notExpectedMockedwahlbezirkeModelFromClient); - Mockito.lenient().when(wahlRepository.findByWahltagOrderByReihenfolge(wahltag.get().getWahltag())).thenReturn(wahlen); - Mockito.lenient().when(wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlen)).thenReturn(notExpectedWahlModels); - Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.get().getWahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) .thenReturn(mergedWahlbezirkeWithWahlen); From c3dd9fbb849045ca035c1233d7fdbf979490e074 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:49:39 +0200 Subject: [PATCH 19/24] remove unused class --- .../services/wahlbezirke/WahlbezirkeService.java | 3 --- .../services/wahlbezirke/WahlbezirkeServiceTest.java | 3 --- 2 files changed, 6 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java index afefc0ca9..efc51e337 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java @@ -7,7 +7,6 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahl; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.WahlRepository; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModelMapper; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.util.Collection; import java.util.List; @@ -37,8 +36,6 @@ public class WahlbezirkeService { private final WahlbezirkModelMapper wahlbezirkModelMapper; - private final WahlModelMapper wahlModelMapper; - @PreAuthorize( "hasAuthority('Basisdaten_BUSINESSACTION_GetWahlbezirke')" ) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index 24411aaa8..5ccb28d9e 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -8,7 +8,6 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.common.WahlbezirkArtModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModelMapper; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; @@ -41,8 +40,6 @@ class WahlbezirkeServiceTest { @Mock WahlbezirkModelMapper wahlbezirkModelMapper; @Mock - WahlModelMapper wahlModelMapper; - @Mock WahlbezirkeClient wahlbezirkeClient; @InjectMocks From 77837103c1c5fd75789b17c878d4bc73d403463c Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:05:03 +0200 Subject: [PATCH 20/24] access foreign repos via service --- .../wahlbezirke/WahlbezirkeService.java | 46 +++++-------- .../wahlbezirke/WahlbezirkeValidator.java | 8 --- .../services/wahlen/WahlenService.java | 6 ++ .../WahlbezirkeServiceSecurityTest.java | 1 + .../wahlbezirke/WahlbezirkeServiceTest.java | 67 ++++++++----------- .../wahlbezirke/WahlbezirkeValidatorTest.java | 26 ------- .../basisdatenservice/utils/Authorities.java | 2 + 7 files changed, 53 insertions(+), 103 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java index efc51e337..b79888c8b 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java @@ -2,15 +2,11 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahlbezirk; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahlbezirkRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahltag; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahltagRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahl; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.WahlRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlenService; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltageService; import java.util.Collection; import java.util.List; -import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -24,16 +20,14 @@ public class WahlbezirkeService { private final WahlbezirkRepository wahlbezirkRepository; - private final WahlRepository wahlRepository; + private final WahlenService wahlenService; - private final WahltagRepository wahltagRepository; + private final WahltageService wahltageService; private final WahlbezirkeValidator wahlbezirkeValidator; private final WahlbezirkeClient wahlbezirkeClient; - private final ExceptionFactory exceptionFactory; - private final WahlbezirkModelMapper wahlbezirkModelMapper; @PreAuthorize( @@ -43,30 +37,24 @@ public List getWahlbezirke(final String wahltagID) { log.info("#getWahlbezirke"); wahlbezirkeValidator.validWahltagIDParamOrThrow(wahltagID); - Optional wahltag = wahltagRepository.findById(wahltagID); - wahlbezirkeValidator.validateWahltagForSearchingWahltagID(wahltag); - if (wahltag.isPresent()) { - val wahltagObjekt = wahltag.get(); - if (wahlbezirkRepository.countByWahltag(wahltagObjekt.getWahltag()) == 0) { - log.error("#getWahlbezirke: Für wahltagID {} waren keine Wahlbezirke in der Datenbank", wahltagID); - val wahlbezirkeOfWahltag = wahlbezirkeClient.loadWahlbezirke(wahltagObjekt.getWahltag(), wahltagObjekt.getNummer()); - val wahlbezirkeAsEntities = wahlbezirkModelMapper.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(wahlbezirkeOfWahltag); + val wahltag = wahltageService.getWahltagByID(wahltagID); + if (wahlbezirkRepository.countByWahltag(wahltag.wahltag()) == 0) { + log.error("#getWahlbezirke: Für wahltagID {} waren keine Wahlbezirke in der Datenbank", wahltagID); + val wahlbezirkeOfWahltag = wahlbezirkeClient.loadWahlbezirke(wahltag.wahltag(), wahltag.nummer()); + val wahlbezirkeAsEntities = wahlbezirkModelMapper.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(wahlbezirkeOfWahltag); - val wahlenOfWahltag = wahlRepository.findByWahltagOrderByReihenfolge(wahltagObjekt.getWahltag()); - wahlbezirkeAsEntities.forEach(wahlbezirk -> linkFirstMatchingWahl(wahlbezirk, wahlenOfWahltag)); + val wahlenOfWahltag = wahlenService.getExistingWahlenOrderedByReihenfolge(wahltagID); + wahlbezirkeAsEntities.forEach(wahlbezirk -> linkFirstMatchingWahl(wahlbezirk, wahlenOfWahltag)); - wahlbezirkRepository.saveAll(wahlbezirkeAsEntities); - } - return wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(wahlbezirkRepository.findByWahltag(wahltagObjekt.getWahltag())); - } else { - throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG); + wahlbezirkRepository.saveAll(wahlbezirkeAsEntities); } + return wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(wahlbezirkRepository.findByWahltag(wahltag.wahltag())); } - private void linkFirstMatchingWahl(final Wahlbezirk wahlbezirk, final Collection wahlen) { - val searchedWahl = wahlen.stream().filter(wahl -> wahlbezirk.getWahlnummer().equals(wahl.getNummer())).findFirst().orElse(null); + private void linkFirstMatchingWahl(final Wahlbezirk wahlbezirk, final Collection wahlen) { + val searchedWahl = wahlen.stream().filter(wahl -> wahlbezirk.getWahlnummer().equals(wahl.nummer())).findFirst().orElse(null); if (null != searchedWahl) { - wahlbezirk.setWahlID(searchedWahl.getWahlID()); + wahlbezirk.setWahlID(searchedWahl.wahlID()); } } } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidator.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidator.java index 8603694f5..93579e0f9 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidator.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidator.java @@ -1,9 +1,7 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahltag; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -20,10 +18,4 @@ public void validWahltagIDParamOrThrow(final String wahltagID) { } } - public void validateWahltagForSearchingWahltagID(final Optional wahltag) { - if (wahltag.isEmpty() || null == wahltag.get().getWahltag()) { - throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG); - } - } - } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlen/WahlenService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlen/WahlenService.java index 882b21881..acc97bfbd 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlen/WahlenService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlen/WahlenService.java @@ -48,6 +48,12 @@ public List getWahlen(String wahltagID) { return wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlRepository.findByWahltagOrderByReihenfolge(wahltagValue.wahltag())); } + @PreAuthorize("hasAuthority('Basisdaten_BUSINESSACTION_GetWahlen')") + public List getExistingWahlenOrderedByReihenfolge(final String wahltagID) { + val wahltagValue = wahltageService.getWahltagByID(wahltagID); + return wahlModelMapper.fromListOfWahlEntityToListOfWahlModel(wahlRepository.findByWahltagOrderByReihenfolge(wahltagValue.wahltag())); + } + @PreAuthorize("hasAuthority('Basisdaten_BUSINESSACTION_PostWahlen')") @Transactional public void postWahlen(final WahlenWriteModel wahlenWriteModel) { diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceSecurityTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceSecurityTest.java index 9aafa60cb..e66332216 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceSecurityTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceSecurityTest.java @@ -127,6 +127,7 @@ private static Stream getMissingAuthoritiesVariationsRepoHasData() { List onlyNecessaryAuthorities = new ArrayList<>(Arrays.asList(Authorities.ALL_AUTHORITIES_GET_WAHLBEZIRKE)); onlyNecessaryAuthorities.remove(Authorities.REPOSITORY_WRITE_WAHLBEZIRK); onlyNecessaryAuthorities.remove(Authorities.REPOSITORY_READ_WAHL); + onlyNecessaryAuthorities.remove(Authorities.SERVICE_GET_WAHLEN); return SecurityUtils.buildArgumentsForMissingAuthoritiesVariations(onlyNecessaryAuthorities.toArray(new String[0])); } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index 5ccb28d9e..f124b4176 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -3,17 +3,16 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahlbezirk; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahlbezirkArt; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahlbezirkRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahltagRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.WahlRepository; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.common.WahlbezirkArtModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlModel; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlenService; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltagModel; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltageService; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.Set; import lombok.val; import org.assertj.core.api.Assertions; @@ -30,9 +29,9 @@ class WahlbezirkeServiceTest { @Mock WahlbezirkeValidator wahlbezirkeValidator; @Mock - WahltagRepository wahltagRepository; + WahltageService wahltageService; @Mock - WahlRepository wahlRepository; + WahlenService wahlenService; @Mock ExceptionFactory exceptionFactory; @Mock @@ -48,35 +47,25 @@ class WahlbezirkeServiceTest { @Nested class GetWahlbezirke { - @Test - void throwsFachlicheWlsExceptionIfNoWahltagPresentInRepository() { - val wahltagID = "_identifikatorWahltag1"; - Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(Optional.empty()); - val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); - Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG)) - .thenReturn(mockedWlsException); - Assertions.assertThatThrownBy(() -> unitUnderTest.getWahlbezirke(wahltagID)).isInstanceOf(FachlicheWlsException.class); - Mockito.verify(wahlbezirkeValidator).validWahltagIDParamOrThrow(wahltagID); - } - @Test void dataIsLoadedFromRemoteIfNotExistingInRepo() { val wahltagID = "_identifikatorWahltag3"; + val wahltagDate = LocalDate.now(); - val wahltag = MockDataFactory.createWahltagList("").stream().filter((wtg) -> wtg.getWahltagID().equals(wahltagID)).findFirst(); - val mockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("", wahltag.get().getWahltag()); - val wahlen = MockDataFactory.createWahlEntityList().stream().filter((wahl) -> wahl.getWahltag().equals(wahltag.get().getWahltag())).toList(); - val wahlModels = MockDataFactory.createWahlModelList("", wahltag.get().getWahltag()).stream() - .filter((wahl) -> wahl.wahltag().equals(wahltag.get().getWahltag())).toList(); + val wahltag = new WahltagModel(wahltagID, wahltagDate, "", ""); + val mockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("", wahltag.wahltag()); + val wahlen = MockDataFactory.createWahlModelList("", wahltagDate); + val wahlModels = MockDataFactory.createWahlModelList("", wahltag.wahltag()).stream() + .filter((wahl) -> wahl.wahltag().equals(wahltag.wahltag())).toList(); val mergedWahlbezirkeWithWahlen = mergeWahlbezirkeWithWahlen(mockedwahlbezirkeModelFromClient, wahlModels); val mergedWahlbezirkEntitiesFromRepo = buildWahlbezirEntitiesFromModels(mergedWahlbezirkeWithWahlen); - Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(wahltag); - Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.get().getWahltag())).thenReturn(0); - Mockito.when(wahlbezirkeClient.loadWahlbezirke(wahltag.get().getWahltag(), wahltag.get().getNummer())) + Mockito.when(wahltageService.getWahltagByID(wahltagID)).thenReturn(wahltag); + Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.wahltag())).thenReturn(0); + Mockito.when(wahlbezirkeClient.loadWahlbezirke(wahltag.wahltag(), wahltag.nummer())) .thenReturn(mockedwahlbezirkeModelFromClient); - Mockito.when(wahlRepository.findByWahltagOrderByReihenfolge(wahltag.get().getWahltag())).thenReturn(wahlen); - Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.get().getWahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); + Mockito.when(wahlenService.getExistingWahlenOrderedByReihenfolge(wahltagID)).thenReturn(wahlen); + Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.wahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) .thenReturn(mergedWahlbezirkeWithWahlen); @@ -84,29 +73,28 @@ void dataIsLoadedFromRemoteIfNotExistingInRepo() { Assertions.assertThat(result).isEqualTo(mergedWahlbezirkeWithWahlen); Mockito.verify(wahlbezirkeValidator).validWahltagIDParamOrThrow(wahltagID); - Mockito.verify(wahlbezirkeValidator).validateWahltagForSearchingWahltagID(wahltag); } @Test void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { val wahltagID = "_identifikatorWahltag3"; - val wahltag = MockDataFactory.createWahltagList("").stream().filter((wtg) -> wtg.getWahltagID().equals(wahltagID)).findFirst(); - val mockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("", wahltag.get().getWahltag()); - val notExpectedMockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("NotExpected", wahltag.get().getWahltag()); - val wahlModels = MockDataFactory.createWahlModelList("", wahltag.get().getWahltag()).stream() - .filter((wahl) -> wahl.wahltag().equals(wahltag.get().getWahltag())).toList(); - val notExpectedWahlModels = MockDataFactory.createWahlModelList("NotExpected", wahltag.get().getWahltag()).stream() - .filter((wahl) -> wahl.wahltag().equals(wahltag.get().getWahltag())).toList(); + val wahltag = new WahltagModel(wahltagID, LocalDate.now(), "", ""); + val mockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("", wahltag.wahltag()); + val notExpectedMockedwahlbezirkeModelFromClient = MockDataFactory.createSetOfWahlbezirkModel("NotExpected", wahltag.wahltag()); + val wahlModels = MockDataFactory.createWahlModelList("", wahltag.wahltag()).stream() + .filter((wahl) -> wahl.wahltag().equals(wahltag.wahltag())).toList(); + val notExpectedWahlModels = MockDataFactory.createWahlModelList("NotExpected", wahltag.wahltag()).stream() + .filter((wahl) -> wahl.wahltag().equals(wahltag.wahltag())).toList(); val mergedWahlbezirkeWithWahlen = mergeWahlbezirkeWithWahlen(mockedwahlbezirkeModelFromClient, wahlModels); val mergedWahlbezirkEntitiesFromRepo = buildWahlbezirEntitiesFromModels(mergedWahlbezirkeWithWahlen); val notExpectedMergedWahlbezirkeWithWahlen = mergeWahlbezirkeWithWahlen(notExpectedMockedwahlbezirkeModelFromClient, notExpectedWahlModels); - Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(wahltag); - Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.get().getWahltag())).thenReturn(3); + Mockito.when(wahltageService.getWahltagByID(wahltagID)).thenReturn(wahltag); + Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.wahltag())).thenReturn(3); - Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.get().getWahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); + Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.wahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) .thenReturn(mergedWahlbezirkeWithWahlen); @@ -115,7 +103,6 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { Assertions.assertThat(result).isNotEqualTo(notExpectedMergedWahlbezirkeWithWahlen); Mockito.verify(wahlbezirkeValidator).validWahltagIDParamOrThrow(wahltagID); - Mockito.verify(wahlbezirkeValidator).validateWahltagForSearchingWahltagID(wahltag); } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java index a957e1415..54b34a6ce 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java @@ -1,7 +1,6 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke; import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import lombok.val; @@ -45,29 +44,4 @@ void exceptionWhenWahlIDisNullOrEmptyOrBlank() { Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow(requestParam3)).isSameAs(mockedWlsException); } } - - @Nested - class ValidateWahltagForSearchingWahltagID { - - final FachlicheWlsException mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); - - @Test - void noExceptionWhenRequestParamIsValid() { - val requestParam = MockDataFactory.createWahltagList("").stream().findFirst(); - Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validateWahltagForSearchingWahltagID(requestParam)); - } - - @Test - void exceptionWhenWahlIDisEmptyOrHasNoWahltagProperty() { - val emptyRequestParam = MockDataFactory.createWahltagList("").stream().filter((wtg) -> wtg.getWahltagID().equals("somethingThatNotExists")) - .findFirst(); - val noWahltagRequestParam = MockDataFactory.createWahltagList("").stream().findFirst(); - noWahltagRequestParam.ifPresent(wahltag -> wahltag.setWahltag(null)); - - Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG)) - .thenReturn(mockedWlsException); - Assertions.assertThatThrownBy(() -> unitUnderTest.validateWahltagForSearchingWahltagID(emptyRequestParam)).isSameAs(mockedWlsException); - Assertions.assertThatThrownBy(() -> unitUnderTest.validateWahltagForSearchingWahltagID(noWahltagRequestParam)).isSameAs(mockedWlsException); - } - } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java index 72dc3c053..59e059af2 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/Authorities.java @@ -188,6 +188,8 @@ public class Authorities { public static final String[] ALL_AUTHORITIES_GET_WAHLBEZIRKE = { SERVICE_GET_WAHLBEZIRKE, + SERVICE_GET_WAHLTAG, + SERVICE_GET_WAHLEN, REPOSITORY_READ_WAHLTAG, REPOSITORY_READ_WAHL, REPOSITORY_READ_WAHLBEZIRK, From a6b05b0c31e6da283ce3830ed72cae37ef0c25c2 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:17:09 +0200 Subject: [PATCH 21/24] replace count by exists --- .../domain/WahlbezirkRepository.java | 2 +- .../wahlbezirke/WahlbezirkeService.java | 2 +- .../domain/WahlbezirkRepositoryTest.java | 62 +++++++++++-------- .../wahlbezirke/WahlbezirkeServiceTest.java | 4 +- .../utils/MockDataFactory.java | 5 ++ 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepository.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepository.java index 7c838c316..528ecc076 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepository.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepository.java @@ -19,7 +19,7 @@ public interface WahlbezirkRepository extends CrudRepository @PreAuthorize("hasAuthority('Basisdaten_DELETE_Wahlbezirk')") void deleteByWahltag(LocalDate wahltag); - int countByWahltag(LocalDate wahltag); + boolean existsByWahltag(LocalDate wahltag); List findByWahltag(LocalDate wahltag); diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java index b79888c8b..e453a8e32 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeService.java @@ -38,7 +38,7 @@ public List getWahlbezirke(final String wahltagID) { wahlbezirkeValidator.validWahltagIDParamOrThrow(wahltagID); val wahltag = wahltageService.getWahltagByID(wahltagID); - if (wahlbezirkRepository.countByWahltag(wahltag.wahltag()) == 0) { + if (!wahlbezirkRepository.existsByWahltag(wahltag.wahltag())) { log.error("#getWahlbezirke: Für wahltagID {} waren keine Wahlbezirke in der Datenbank", wahltagID); val wahlbezirkeOfWahltag = wahlbezirkeClient.loadWahlbezirke(wahltag.wahltag(), wahltag.nummer()); val wahlbezirkeAsEntities = wahlbezirkModelMapper.fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(wahlbezirkeOfWahltag); diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepositoryTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepositoryTest.java index 36a22499d..b861e2a4f 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepositoryTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkRepositoryTest.java @@ -2,6 +2,7 @@ import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_NO_SECURITY_PROFILE; import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_TEST_PROFILE; + import de.muenchen.oss.wahllokalsystem.basisdatenservice.MicroServiceApplication; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; import java.time.LocalDate; @@ -10,6 +11,7 @@ import lombok.val; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -42,23 +44,39 @@ void findByWahltag() { Assertions.assertThat(foundWahlbezirke).allMatch((wbz) -> wbz.getWahltag().equals(wahltag)); } - @Test - void countByWahltag() { - val wahltag1 = LocalDate.now(); - val wahltag2 = LocalDate.now().plusDays(1); - List wahlbezirkeToSave1 = MockDataFactory.createListOfWahlbezirkEntity("praefix1", wahltag1); - repository.saveAll(wahlbezirkeToSave1); - List wahlbezirkeToSave2 = MockDataFactory.createListOfWahlbezirkEntity("praefix2", wahltag2); - repository.saveAll(wahlbezirkeToSave2); + @Nested + class ExistsByWahltag { + + @Test + void trueWhenOneExists() { + val wahltag1 = LocalDate.now(); + val wahltag2 = LocalDate.now().plusDays(1); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag1)); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag2)); - List foundWahlbezirke = repository.findAll(); - Assertions.assertThat(foundWahlbezirke.size()).isEqualTo(wahlbezirkeToSave1.size() + wahlbezirkeToSave2.size()); + Assertions.assertThat(repository.existsByWahltag(wahltag1)).isTrue(); + } - int foundByWahltag1 = repository.countByWahltag(wahltag1); - int foundByWahltag2 = repository.countByWahltag(wahltag2); + @Test + void trueWhenMoreThanOneExists() { + val wahltag1 = LocalDate.now(); + val wahltag2 = LocalDate.now().plusDays(1); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag1)); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag1)); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag2)); + + Assertions.assertThat(repository.existsByWahltag(wahltag1)).isTrue(); + } + + @Test + void falseWhenZeroExists() { + val wahltag1 = LocalDate.now(); + val wahltag2 = LocalDate.now().plusDays(1); + repository.save(MockDataFactory.createWahlbezirkEntity(wahltag2)); + + Assertions.assertThat(repository.existsByWahltag(wahltag1)).isFalse(); + } - Assertions.assertThat(foundByWahltag1).isEqualTo(wahlbezirkeToSave1.size()); - Assertions.assertThat(foundByWahltag2).isEqualTo(wahlbezirkeToSave2.size()); } @Test @@ -70,19 +88,9 @@ void deleteByWahltag() { List wahlbezirkeToSave2 = MockDataFactory.createListOfWahlbezirkEntity("praefix2", wahltag2); repository.saveAll(wahlbezirkeToSave2); - List foundWahlbezirke = repository.findAll(); - Assertions.assertThat(foundWahlbezirke.size()).isEqualTo(wahlbezirkeToSave1.size() + wahlbezirkeToSave2.size()); - - repository.deleteByWahltag(wahltag1); - - int foundByWahltag1 = repository.countByWahltag(wahltag1); - int foundByWahltag2 = repository.countByWahltag(wahltag2); - - Assertions.assertThat(foundByWahltag1).isEqualTo(0); - Assertions.assertThat(foundByWahltag2).isEqualTo(wahlbezirkeToSave2.size()); - repository.deleteByWahltag(wahltag2); - List foundWahlbezirkeZero = repository.findAll(); - Assertions.assertThat(foundWahlbezirkeZero.size()).isEqualTo(0); + + List foundWahlbezirkeAfterDelete = repository.findAll(); + Assertions.assertThat(foundWahlbezirkeAfterDelete.size()).isEqualTo(wahlbezirkeToSave1.size()); } } diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index f124b4176..a207eaba8 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -61,7 +61,7 @@ void dataIsLoadedFromRemoteIfNotExistingInRepo() { val mergedWahlbezirkEntitiesFromRepo = buildWahlbezirEntitiesFromModels(mergedWahlbezirkeWithWahlen); Mockito.when(wahltageService.getWahltagByID(wahltagID)).thenReturn(wahltag); - Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.wahltag())).thenReturn(0); + Mockito.when(wahlbezirkRepository.existsByWahltag(wahltag.wahltag())).thenReturn(false); Mockito.when(wahlbezirkeClient.loadWahlbezirke(wahltag.wahltag(), wahltag.nummer())) .thenReturn(mockedwahlbezirkeModelFromClient); Mockito.when(wahlenService.getExistingWahlenOrderedByReihenfolge(wahltagID)).thenReturn(wahlen); @@ -92,7 +92,7 @@ void dataIsLoadedFromRepoIfPresentAndNotFromRemoteClient() { val notExpectedMergedWahlbezirkeWithWahlen = mergeWahlbezirkeWithWahlen(notExpectedMockedwahlbezirkeModelFromClient, notExpectedWahlModels); Mockito.when(wahltageService.getWahltagByID(wahltagID)).thenReturn(wahltag); - Mockito.when(wahlbezirkRepository.countByWahltag(wahltag.wahltag())).thenReturn(3); + Mockito.when(wahlbezirkRepository.existsByWahltag(wahltag.wahltag())).thenReturn(true); Mockito.when(wahlbezirkRepository.findByWahltag(wahltag.wahltag())).thenReturn(mergedWahlbezirkEntitiesFromRepo); Mockito.when(wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(mergedWahlbezirkEntitiesFromRepo)) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java index 32873f4bb..e955bee73 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/utils/MockDataFactory.java @@ -30,6 +30,7 @@ import java.time.LocalDate; import java.util.List; import java.util.Set; +import java.util.UUID; import lombok.val; public class MockDataFactory { @@ -311,6 +312,10 @@ public static Set createSetOfClientWahlbezirkDTO(LocalDate aDate) return Set.of(wahlbezirk1, wahlbezirk2, wahlbezirk3, wahlbezirk4); } + public static Wahlbezirk createWahlbezirkEntity(final LocalDate wahltagDate) { + return new Wahlbezirk(UUID.randomUUID().toString(), wahltagDate, "nummer", WahlbezirkArt.UWB, "nummer", "wahlID"); + } + public static List createListOfWahlbezirkEntity(String praefix, LocalDate aDate) { val wahlbezirk1 = new Wahlbezirk(); wahlbezirk1.setWahlbezirkID(praefix + "wahlbezirkID1_1"); From 9fbf79af796f7a10326f9c1d21cf68a32ef2001f Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:20:45 +0200 Subject: [PATCH 22/24] separate testcases --- .../wahlbezirke/WahlbezirkeValidatorTest.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java index 54b34a6ce..9c72f1521 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeValidatorTest.java @@ -34,14 +34,27 @@ void noExceptionWhenRequestParamIsValid() { } @Test - void exceptionWhenWahlIDisNullOrEmptyOrBlank() { - val requestParam2 = ""; - val requestParam3 = " "; + void exceptionWhenWahltagIDIsNull() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_PARAMETER_UNVOLLSTAENDIG)) .thenReturn(mockedWlsException); + Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow(null)).isSameAs(mockedWlsException); - Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow(requestParam2)).isSameAs(mockedWlsException); - Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow(requestParam3)).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenWahltagIDIsEmpty() { + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_PARAMETER_UNVOLLSTAENDIG)) + .thenReturn(mockedWlsException); + + Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow("")).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenWahltagIDIsBlank() { + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_PARAMETER_UNVOLLSTAENDIG)) + .thenReturn(mockedWlsException); + + Assertions.assertThatThrownBy(() -> unitUnderTest.validWahltagIDParamOrThrow(" ")).isSameAs(mockedWlsException); } } } From 384be0058deb60e20836875cfba801e3caa7383b Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:22:02 +0200 Subject: [PATCH 23/24] remove unused property --- .../services/wahlbezirke/WahlbezirkeServiceTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java index a207eaba8..4f06b3ce5 100644 --- a/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java +++ b/wls-basisdaten-service/src/test/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkeServiceTest.java @@ -9,7 +9,6 @@ import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltagModel; import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltag.WahltageService; import de.muenchen.oss.wahllokalsystem.basisdatenservice.utils.MockDataFactory; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -33,8 +32,6 @@ class WahlbezirkeServiceTest { @Mock WahlenService wahlenService; @Mock - ExceptionFactory exceptionFactory; - @Mock WahlbezirkRepository wahlbezirkRepository; @Mock WahlbezirkModelMapper wahlbezirkModelMapper; From 0efc6a11996d21b2321f9bfa297ef8bb488b3e97 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:42:04 +0200 Subject: [PATCH 24/24] remove unused mapping --- .../services/wahlbezirke/WahlbezirkModelMapper.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java index 12d635857..cd8de549d 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlbezirke/WahlbezirkModelMapper.java @@ -1,20 +1,14 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlbezirke; import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahlbezirk; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.model.WahlbezirkDTO; import java.util.Collection; import java.util.List; import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; @Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) public interface WahlbezirkModelMapper { - @Mapping(source = "identifikator", target = "wahlbezirkID") - @Mapping(source = "wahlbezirkArt", target = "wahlbezirkart") - Wahlbezirk fromDTOtoEntity(WahlbezirkDTO dto); - Collection fromListOfWahlbezirkModeltoListOfWahlbezirkEntities(Collection wahlbezirkModelList); List fromListOfWahlbezirkEntityToListOfWahlbezirkModel(List wahlbezirkEntityList);