From 67ce33849823779760493705ab61dfd84537c9b3 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:04:36 +0200 Subject: [PATCH 01/41] draft impl for get and post --- .../eaiservice/MicroServiceApplication.java | 3 +- .../eaiservice/domain/BaseEntity.java | 9 +-- .../domain/wahlvorstand/Wahlvorstand.java | 41 ++++++++++ .../wahlvorstand/WahlvorstandFunktion.java | 9 +++ .../wahlvorstand/WahlvorstandRepository.java | 10 +++ .../wahlvorstand/Wahlvorstandsmitglied.java | 43 +++++++++++ .../common/exception/ExceptionConstants.java | 6 +- .../wahlvorstand/WahlvorstandController.java | 14 +++- .../rest/wahlvorstand/WahlvorstandMapper.java | 17 +++++ .../wahlvorstand/dto/WahlvorstandDTO.java | 4 +- .../dto/WahlvorstandFunktionDTO.java | 9 +++ .../dto/WahlvorstandsmitgliedDTO.java | 2 +- .../service/WahlvorstandService.java | 70 ++++++++++++++++++ .../resources/application-db-dummydata.yml | 5 ++ .../src/main/resources/application.yml | 7 +- .../h2/V1_1__wahlvorstandTestdaten.sql | 74 +++++++++++++++++++ .../h2/V1_0__createWahlvorstand.sql | 22 ++++++ 17 files changed, 329 insertions(+), 16 deletions(-) create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandRepository.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java create mode 100644 wls-eai-service/src/main/resources/application-db-dummydata.yml create mode 100644 wls-eai-service/src/main/resources/db/dummydata/h2/V1_1__wahlvorstandTestdaten.sql create mode 100644 wls-eai-service/src/main/resources/db/migrations/h2/V1_0__createWahlvorstand.sql diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplication.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplication.java index 114c80e4..bdafd422 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplication.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplication.java @@ -18,7 +18,8 @@ @ComponentScan( basePackages = { "org.springframework.data.jpa.convert.threeten", - "de.muenchen.oss.wahllokalsystem.eaiservice" + "de.muenchen.oss.wahllokalsystem.eaiservice", + "de.muenchen.oss.wahllokalsystem.wls.common.exception" } ) @EntityScan( diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/BaseEntity.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/BaseEntity.java index 48ec8a46..d5d7ceca 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/BaseEntity.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/BaseEntity.java @@ -6,7 +6,6 @@ import static java.sql.Types.VARCHAR; -import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; @@ -17,24 +16,24 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; -import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.annotations.UuidGenerator; @MappedSuperclass @NoArgsConstructor @Getter @Setter -@ToString +@ToString(onlyExplicitlyIncluded = true) @EqualsAndHashCode public abstract class BaseEntity implements Cloneable, Serializable { private static final long serialVersionUID = 1L; - @Column(name = "id", length = 36) @Id @GeneratedValue(generator = "uuid") - @GenericGenerator(name = "uuid", strategy = "uuid2") + @UuidGenerator @JdbcTypeCode(VARCHAR) + @ToString.Include private UUID id; } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java new file mode 100644 index 00000000..a5447201 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java @@ -0,0 +1,41 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand; + +import static java.sql.Types.VARCHAR; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import java.util.Set; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.hibernate.annotations.JdbcTypeCode; + +@Entity +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@ToString(onlyExplicitlyIncluded = true, callSuper = true) +public class Wahlvorstand extends BaseEntity { + + @NotNull + @ToString.Include + @JdbcTypeCode(VARCHAR) + private UUID wahlbezirkID; + + @NotNull + @Size(min = 1) + @OneToMany + @JoinColumn(name = "wahlvorstandID") + private Set mitglieder; + +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java new file mode 100644 index 00000000..3616dda2 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java @@ -0,0 +1,9 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand; + +public enum WahlvorstandFunktion { + W, //Wahlvorsteher*in + SB, //Schriftführer*in + SWB, //Stellvertretung Wahlvorsteher*in + SSB, //Stellvertretung Schriftführer*in + B //Beisitzer*in +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandRepository.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandRepository.java new file mode 100644 index 00000000..ed57b93d --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandRepository.java @@ -0,0 +1,10 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand; + +import java.util.Optional; +import java.util.UUID; +import org.springframework.data.repository.CrudRepository; + +public interface WahlvorstandRepository extends CrudRepository { + + Optional findFirstByWahlbezirkID(UUID wahlbezirkID); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java new file mode 100644 index 00000000..bc2c792d --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java @@ -0,0 +1,43 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.validation.constraints.NotNull; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Entity +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@ToString(onlyExplicitlyIncluded = true) +public class Wahlvorstandsmitglied extends BaseEntity { + + @NotNull + @ToString.Include + private String vorname; + + @NotNull + @ToString.Include + private String nachname; + + @NotNull + @ToString.Include + @Enumerated(EnumType.STRING) + private WahlvorstandFunktion funktion; + + @ToString.Include + private boolean anwesend; + + @ToString.Include + private LocalDateTime anwesenheitUpdatedOn; +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java index 81382e8f..752d9844 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java @@ -2,8 +2,6 @@ public class ExceptionConstants { - public static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103"; - public static final String CODE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "901"; public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "Fremdsystem hat Fehler geworfen"; public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM_MIT_MESSAGE = "Fremdsystem hat Fehler geworfen: %s"; @@ -11,6 +9,10 @@ public class ExceptionConstants { public static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102"; public static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen"; + private static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103"; + public static final de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper ID_NICHT_KONVERTIERBAR = new de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper( + CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR, ""); + /** * @throws IllegalAccessException when constructor is used */ diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 740b3fb8..9bfc6408 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -2,8 +2,11 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.WahlvorstandService; import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -14,17 +17,22 @@ @RestController @RequestMapping("/wahlvorstaende") +@RequiredArgsConstructor public class WahlvorstandController { + private final WahlvorstandService wahlvorstandService; + @GetMapping @ResponseStatus(HttpStatus.OK) - public WahlvorstandDTO loadWahlvorstand(@RequestParam("wahlbezirkID") String wahlbezirkID) { - throw new UnsupportedOperationException("Not supported yet."); + @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_LoadWahlvorstand')") + public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { + return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } @PostMapping @ResponseStatus(HttpStatus.OK) + @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_SaveAnwesenheit')") public void saveAnwesenheit(@Valid @RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { - throw new UnsupportedOperationException("Not supported yet."); + wahlvorstandService.setAnwesenheit(wahlvorstand); } } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java new file mode 100644 index 00000000..9ea18d2f --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java @@ -0,0 +1,17 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface WahlvorstandMapper { + + WahlvorstandDTO toDTO(Wahlvorstand wahlvorstand); + + @Mapping(target = "identifikator", source = "id") + WahlvorstandsmitgliedDTO toDTO(Wahlvorstandsmitglied wahlvorstandsmitglied); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandDTO.java index 7b7d3b8d..99f807cf 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandDTO.java @@ -2,10 +2,8 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import java.time.LocalDateTime; import java.util.Set; -public record WahlvorstandDTO(@NotNull LocalDateTime anwesenheitBeginn, - @NotNull String wahlbezirkID, +public record WahlvorstandDTO(@NotNull String wahlbezirkID, @NotNull @Size(min = 1) Set mitglieder) { } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java new file mode 100644 index 00000000..62e4cbcf --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java @@ -0,0 +1,9 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto; + +public enum WahlvorstandFunktionDTO { + W, //Wahlvorsteher*in + SB, //Schriftführer*in + SWB, //Stellvertretung Wahlvorsteher*in + SSB, //Stellvertretung Schriftführer*in + B //Beisitzer*in +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java index 16476c66..78d8d7bb 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java @@ -6,6 +6,6 @@ public record WahlvorstandsmitgliedDTO(@NotNull String identifikator, @NotNull String vorname, @NotNull String nachname, - @NotNull String funktion, + @NotNull WahlvorstandFunktionDTO funktion, @Schema(requiredMode = Schema.RequiredMode.REQUIRED) boolean anwesend) { } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java new file mode 100644 index 00000000..d150d823 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java @@ -0,0 +1,70 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.WahlvorstandMapper; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDateTime; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class WahlvorstandService { + + private final WahlvorstandRepository wahlvorstandRepository; + + private final ExceptionFactory exceptionFactory; + + private final WahlvorstandMapper wahlvorstandMapper; + + @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_LoadWahlvorstand')") + public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { + val wahlbezirkUUID = convertIDToUUIDOrThrow(wahlbezirkID); + return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkUUID).map(wahlvorstandMapper::toDTO).orElse(null); + } + + @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_SaveAnwesenheit')") + public void setAnwesenheit(final WahlvorstandsaktualisierungDTO aktualisierung) { + //TODO was ist wenn es den Wahlvorstand nicht gibt den man aktualisieren soll + val wahlvorstandToUpdate = wahlvorstandRepository.findFirstByWahlbezirkID(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); + if (wahlvorstandToUpdate.isPresent()) { + val entity = wahlvorstandToUpdate.get(); + updateAnwesenheitOfWahlvorstand(aktualisierung, entity); + wahlvorstandRepository.save(entity); + } + } + + private void updateAnwesenheitOfWahlvorstand(final WahlvorstandsaktualisierungDTO updateData, final Wahlvorstand existingWahlvorstand) { + updateData.mitglieder().forEach(mitgliedUpdateData -> { + val mitgliedToUpdate = existingWahlvorstand.getMitglieder().stream() + .filter(setElement -> setElement.getId().toString().equals(mitgliedUpdateData.identifikator())).findFirst(); + mitgliedToUpdate.ifPresent(mitglied -> { + updateAnwesenheitOfWahlvorstandsmitglied(updateData.anwesenheitBeginn(), mitgliedUpdateData, mitglied); + }); + }); + } + + private void updateAnwesenheitOfWahlvorstandsmitglied(final LocalDateTime timeOfUpdate, WahlvorstandsmitgliedAktualisierungDTO mitgliedUpdateData, + Wahlvorstandsmitglied mitglied) { + mitglied.setAnwesenheitUpdatedOn(timeOfUpdate); + mitglied.setAnwesend(mitgliedUpdateData.anwesend()); + } + + private UUID convertIDToUUIDOrThrow(final String id) { + try { + return UUID.fromString(id); + } catch (final IllegalArgumentException illegalArgumentException) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR); + } + } + +} diff --git a/wls-eai-service/src/main/resources/application-db-dummydata.yml b/wls-eai-service/src/main/resources/application-db-dummydata.yml new file mode 100644 index 00000000..41e67be6 --- /dev/null +++ b/wls-eai-service/src/main/resources/application-db-dummydata.yml @@ -0,0 +1,5 @@ +spring: + flyway: + locations: + - classpath:db/migrations/{vendor} + - classpath:db/dummydata/{vendor} \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/application.yml b/wls-eai-service/src/main/resources/application.yml index f1958466..7e2751c2 100644 --- a/wls-eai-service/src/main/resources/application.yml +++ b/wls-eai-service/src/main/resources/application.yml @@ -14,7 +14,8 @@ spring: oauth2: resourceserver: jwt: - jwk-set-uri: http://kubernetes.docker.internal:8100/auth/realms/${realm}/protocol/openid-connect/userinfo + jwk-set-uri: http://kubernetes.docker.internal:8100/auth/realms/${realm}/protocol/openid-connect/certs + @@ -24,6 +25,9 @@ security: oauth2: resource.user-info-uri: http://kubernetes.docker.internal:8100/auth/realms/${realm}/protocol/openid-connect/userinfo +service: + info: + oid: EAI-SERVICE # Define the local keycloak realm here realm: wls_realm @@ -36,6 +40,7 @@ server: include-stacktrace: never whitelabel: enabled: false + max-http-request-header-size: 32KB # Config for spring actuator endpoints management: diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V1_1__wahlvorstandTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V1_1__wahlvorstandTestdaten.sql new file mode 100644 index 00000000..ce912857 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V1_1__wahlvorstandTestdaten.sql @@ -0,0 +1,74 @@ +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0000-0000-000000000001'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000001', 'Homer', 'Simpson', 'W', false, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000002', 'Marge', 'Simpson', 'SB', false, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000003', 'Bart', 'Simpson', 'SWB', false, + '00000000-0000-0000-0001-000000000001', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000004', 'Lisa', 'Simpson', 'SSB', false, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000005', 'Maggie', 'Simpson', 'B', false, '00000000-0000-0000-0001-000000000001', + null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000002', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000001', 'Peter', 'Griffin', 'W', false, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000002', 'Lois', 'Griffin', 'SB', false, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000003', 'Megan', 'Griffin', 'SWB', false, + '00000000-0000-0000-0001-000000000002', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000004', 'Christopher', 'Griffin', 'SSB', false, + '00000000-0000-0000-0001-000000000002', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000005', 'Stewie', 'Griffin', 'B', false, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000006', 'Brian', 'Griffin', 'B', false, '00000000-0000-0000-0001-000000000002', + null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000003', '00000000-0000-0000-0000-000000000003'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000001', 'Grace', 'Hopper', 'W', false, '00000000-0000-0000-0001-000000000003', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000002', 'Ada', 'Lovelace', 'SB', false, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000003', 'Konrad', 'Zuse', 'SWB', false, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000004', 'Alan', 'Turing', 'SSB', false, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000005', 'Hedy', 'Lamarr', 'B', false, + '00000000-0000-0000-0001-000000000003', null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000004', '00000000-0000-0000-0000-000000000004'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000001', 'Diana', 'Prince', 'W', false, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000002', 'Clark', 'Kent', 'SB', false, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000003', 'Bruce', 'Wayne', 'SWB', false, + '00000000-0000-0000-0001-000000000004', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000004', 'Barry', 'Allen', 'SSB', false, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000005', 'Arthur', 'Curry', 'B', false, '00000000-0000-0000-0001-000000000004', + null); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V1_0__createWahlvorstand.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V1_0__createWahlvorstand.sql new file mode 100644 index 00000000..fdab5b2c --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V1_0__createWahlvorstand.sql @@ -0,0 +1,22 @@ +CREATE TABLE wahlvorstand +( + id VARCHAR2(36) NOT NULL, + wahlbezirkID VARCHAR2(36) NOT NULL, + + PRIMARY KEY (id) +); + +CREATE TABLE wahlvorstandsmitglied +( + id VARCHAR2(36) NOT NULL, + vorname VARCHAR2(255) NOT NULL, + nachname VARCHAR2(255) NOT NULL, + funktion VARCHAR2(512) NOT NULL, + anwesend boolean NOT NULL, + wahlvorstandID VARCHAR2(36) NOT NULL, + anwesenheitUpdatedOn TIMESTAMP, + + FOREIGN KEY (wahlvorstandID) REFERENCES wahlvorstand (id), + + PRIMARY KEY (id) +) \ No newline at end of file From 5dac61eb75ae280f0f9aa645a967d59fb9ecd9ff Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:04:59 +0200 Subject: [PATCH 02/41] add example requests for wahlvorstaende --- .../httpRequests/http-client.env.json | 10 +++ .../resources/httpRequests/wahlvorstand.http | 65 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 wls-eai-service/src/test/resources/httpRequests/http-client.env.json create mode 100644 wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http diff --git a/wls-eai-service/src/test/resources/httpRequests/http-client.env.json b/wls-eai-service/src/test/resources/httpRequests/http-client.env.json new file mode 100644 index 00000000..9f20d0ca --- /dev/null +++ b/wls-eai-service/src/test/resources/httpRequests/http-client.env.json @@ -0,0 +1,10 @@ +{ + "docker": { + "WLS_EAI_SERVICE_URL": "http://localhost:8300", + "SSO_URL": "http://kubernetes.docker.internal:8100" + }, + "nonDocker": { + "WLS_EAI_SERVICE_URL": "http://localhost:39146", + "SSO_URL": "http://kubernetes.docker.internal:8100" + } +} \ No newline at end of file diff --git a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http new file mode 100644 index 00000000..db840fb1 --- /dev/null +++ b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http @@ -0,0 +1,65 @@ +POST {{ SSO_URL }}/auth/realms/wls_realm/protocol/openid-connect/token +Content-Type: application/x-www-form-urlencoded + +password = test & +grant_type = password & +client_secret = top-secret & +client_id = wls & +username = wls_all + +> {% + client.global.set("auth_token", response.body.access_token); + client.global.set("token_type", response.body.token_type); +%} + +### get userinfo with auth_token +GET {{ SSO_URL }}/auth/realms/wls_realm/protocol/openid-connect/userinfo +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorstand wbz1 +GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-0000-0000-0000-000000000001 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorstand wbz2 +GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-0000-0000-0000-000000000002 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorstand wbz3 +GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-0000-0000-0000-000000000003 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorstand wbz4 +GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-0000-0000-0000-000000000004 +Authorization: {{ token_type }} {{ auth_token }} + +### POST Update Wahlvorstand wbz4 +POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +Authorization: {{ token_type }} {{ auth_token }} +Content-Type: application/json + +{ + "wahlbezirkID": "00000000-0000-0000-0000-000000000004", + "anwesenheitBeginn": "2024-06-14T19:01:12.456", + "mitglieder": [ + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000001" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000002" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000003" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000004" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000005" + } + ] +} From 66843d5bc2aff4243b925ff143d0be91842e3388 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:05:34 +0200 Subject: [PATCH 03/41] update keycloak config for eai wahlvorstaende --- .../add-authorities-eai-wahlvorstand.yml | 21 +++++++++++++++++++ .../create-group-all-eai-authorities.yml | 15 +++++++++++++ .../keycloak/migration/keycloak-changelog.yml | 4 +++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml create mode 100644 stack/keycloak/migration/create-group-all-eai-authorities.yml diff --git a/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml b/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml new file mode 100644 index 00000000..70392128 --- /dev/null +++ b/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml @@ -0,0 +1,21 @@ +id: add authorities eai wahlvorstand +author: MrSebastian +realm: ${SSO_REALM} +changes: + - addRole: + name: EAI_Wahlvorstaende_LoadWahlvorstand + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: EAI_Wahlvorstaende_LoadWahlvorstand + clientId: ${SSO_CLIENT_ID} + + - addRole: + name: EAI_Wahlvorstaende_SaveAnwesenheit + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: EAI_Wahlvorstaende_SaveAnwesenheit + clientId: ${SSO_CLIENT_ID} \ No newline at end of file diff --git a/stack/keycloak/migration/create-group-all-eai-authorities.yml b/stack/keycloak/migration/create-group-all-eai-authorities.yml new file mode 100644 index 00000000..015b47dc --- /dev/null +++ b/stack/keycloak/migration/create-group-all-eai-authorities.yml @@ -0,0 +1,15 @@ +id: create group allEaiAuthorities and link wls_all* +author: MrSebastian +realm: ${SSO_REALM} +changes: + - addGroup: + name: allEaiAuthorities + - assignGroup: + user: wls_all + group: allEaiAuthorities + - assignGroup: + user: wls_all_uwb + group: allEaiAuthorities + - assignGroup: + user: wls_all_bwb + group: allEaiAuthorities \ No newline at end of file diff --git a/stack/keycloak/migration/keycloak-changelog.yml b/stack/keycloak/migration/keycloak-changelog.yml index d0c75f88..aeca1229 100644 --- a/stack/keycloak/migration/keycloak-changelog.yml +++ b/stack/keycloak/migration/keycloak-changelog.yml @@ -24,4 +24,6 @@ includes: - path: add-authorities-wahlvorbereitung-unterbrechungsuhrzeit.yml - path: add-missing-repository-read-authorities.yml - path: add-authorities-wahlvorbereitung-fortsetzungsuhrzeit.yml - - path: add-authorities-wahlvorbereitung-eroeffnungsuhrzeit.yml \ No newline at end of file + - path: add-authorities-wahlvorbereitung-eroeffnungsuhrzeit.yml + - path: create-group-all-eai-authorities.yml + - path: add-authorities-eai-wahlvorstand.yml \ No newline at end of file From bdcf03a97ab92ac6577ed7f30c35c3f4ed408e12 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:31:10 +0200 Subject: [PATCH 04/41] update example requests with invalid requests --- .../resources/httpRequests/wahlvorstand.http | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http index db840fb1..9e9a277a 100644 --- a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http +++ b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http @@ -63,3 +63,80 @@ Content-Type: application/json } ] } + +### POST Update - bezirkID fehlt +POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +Authorization: {{ token_type }} {{ auth_token }} +Content-Type: application/json + +{ + "anwesenheitBeginn": "2024-06-14T19:01:12.456", + "mitglieder": [ + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000001" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000002" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000003" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000004" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000005" + } + ] +} + +### POST Update - anwesenheitBeginn fehlt +POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +Authorization: {{ token_type }} {{ auth_token }} +Content-Type: application/json + +{ + "wahlbezirkID": "00000000-0000-0000-0000-000000000004", + "mitglieder": [ + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000001" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000002" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000003" + }, + { + "anwesend": false, + "identifikator": "00000000-0000-0000-0004-000000000004" + }, + { + "anwesend": true, + "identifikator": "00000000-0000-0000-0004-000000000005" + } + ] +} + +### POST Update - Identifikator fehlt +POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +Authorization: {{ token_type }} {{ auth_token }} +Content-Type: application/json + +{ + "wahlbezirkID": "00000000-0000-0000-0000-000000000004", + "anwesenheitBeginn": "2024-06-14T19:01:12.456", + "mitglieder": [ + { + "anwesend": true + } + ] +} \ No newline at end of file From 54632f4ad6e4a8f167d1683d38bbb5a716cbff6b Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:31:51 +0200 Subject: [PATCH 05/41] add global exception handler --- .../exception/GlobalExceptionHandler.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..6b9bfd69 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java @@ -0,0 +1,32 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.exception; + +import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.AbstractExceptionHandler; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.DTOMapper; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ServiceIDFormatter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +@Slf4j +public class GlobalExceptionHandler extends AbstractExceptionHandler { + private final ServiceIDFormatter serviceIDFormatter; + + public GlobalExceptionHandler(final ServiceIDFormatter serviceIDFormatter, final DTOMapper dtoMapper) { + super(dtoMapper); + this.serviceIDFormatter = serviceIDFormatter; + } + + @ExceptionHandler + public ResponseEntity handleThrowables(final Throwable throwable) { + log.info("handling throwable", throwable); + return createResponse(getWahlExceptionDTO(throwable)); + } + + @Override + protected String getService() { + return serviceIDFormatter.getId(); + } +} From 4aee07812c2cf581b8e5311e1b2e7a8c1cfaf2db Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:32:13 +0200 Subject: [PATCH 06/41] use ExceptionDataWrapper --- .../common/exception/ExceptionConstants.java | 8 +++-- .../exception/ExceptionConstants.java | 32 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java index 752d9844..e46683c9 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java @@ -1,13 +1,17 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper; + public class ExceptionConstants { public static final String CODE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "901"; public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "Fremdsystem hat Fehler geworfen"; public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM_MIT_MESSAGE = "Fremdsystem hat Fehler geworfen: %s"; - public static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102"; - public static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen"; + private static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102"; + private static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen"; + public static final ExceptionDataWrapper DATENALLGEMEIN_PARAMETER_FEHLEN = new ExceptionDataWrapper(CODE_DATENALLGEMEIN_PARAMETER_FEHLEN, + MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN); private static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103"; public static final de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper ID_NICHT_KONVERTIERBAR = new de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper( diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/exception/ExceptionConstants.java index c6a90747..364f168a 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/exception/ExceptionConstants.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/exception/ExceptionConstants.java @@ -1,21 +1,33 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.exception; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper; + public class ExceptionConstants { //loadWahlvorstand - public static final String CODE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG = "001"; - public static final String MESSAGE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG = "Wahlvorstandskriterien sind nicht vollständig"; + private static final String CODE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG = "001"; + private static final String MESSAGE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG = "Wahlvorstandskriterien sind nicht vollständig"; + public static final ExceptionDataWrapper LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG = new ExceptionDataWrapper( + CODE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG, MESSAGE_LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG); //saveAnwesenheit - public static final String CODE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT = "002"; - public static final String MESSAGE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT = "Mindestens ein Identifikator für eine Aktualisierung fehlt"; + private static final String CODE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT = "002"; + private static final String MESSAGE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT = "Mindestens ein Identifikator für eine Aktualisierung fehlt"; + public static final ExceptionDataWrapper SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT = new ExceptionDataWrapper(CODE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT, + MESSAGE_SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT); - public static final String CODE_SAVEANWESENHEIT_BEZIRKID_FEHLT = "003"; - public static final String MESSAGE_SAVEANWESENHEIT_BEZIRKID_FEHLT = "Bezirk fehlt"; + private static final String CODE_SAVEANWESENHEIT_BEZIRKID_FEHLT = "003"; + private static final String MESSAGE_SAVEANWESENHEIT_BEZIRKID_FEHLT = "Bezirk fehlt"; + public static final ExceptionDataWrapper SAVEANWESENHEIT_BEZIRKID_FEHLT = new ExceptionDataWrapper(CODE_SAVEANWESENHEIT_BEZIRKID_FEHLT, + MESSAGE_SAVEANWESENHEIT_BEZIRKID_FEHLT); - public static final String CODE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT = "004"; - public static final String MESSAGE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT = "Es ist keine Information hinterlegt seit wann diese Anwesenheit gilt"; + private static final String CODE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT = "004"; + private static final String MESSAGE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT = "Es ist keine Information hinterlegt seit wann diese Anwesenheit gilt"; + public static final ExceptionDataWrapper SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT = new ExceptionDataWrapper(CODE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT, + MESSAGE_SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT); - public static final String CODE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION = "101"; - public static final String MESSAGE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION = "Die definierte Funktion des Wahlvorstandsmitgliedes ist nicht gueltig"; + private static final String CODE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION = "101"; + private static final String MESSAGE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION = "Die definierte Funktion des Wahlvorstandsmitgliedes ist nicht gueltig"; + public static final ExceptionDataWrapper DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION = new ExceptionDataWrapper( + CODE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION, MESSAGE_DATENALLGEMEIN_WAHLVORSTANDSMITGLIEDFUNKTION_UNGUELTIGE_FUNKTION); /** * @throws IllegalAccessException when constructor is used From 6ae6388976bff1d15b786011c9e203b92fc58809 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:32:52 +0200 Subject: [PATCH 07/41] remove auto validation --- .../eaiservice/rest/wahlvorstand/WahlvorstandController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 9bfc6408..6c430454 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -2,8 +2,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; -import de.muenchen.oss.wahllokalsystem.eaiservice.service.WahlvorstandService; -import jakarta.validation.Valid; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; @@ -32,7 +31,7 @@ public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") Stri @PostMapping @ResponseStatus(HttpStatus.OK) @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_SaveAnwesenheit')") - public void saveAnwesenheit(@Valid @RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { + public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); } } From 529a324f36421e4f275ec2b7cc7f6bc46ce68ec4 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:33:14 +0200 Subject: [PATCH 08/41] add validator and udpate authority to latest used --- .../add-authorities-eai-wahlvorstand.yml | 8 ++-- .../WahlvorstandService.java | 11 +++-- .../wahlvorstand/WahlvorstandValidator.java | 41 +++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) rename wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/{ => wahlvorstand}/WahlvorstandService.java (88%) create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java diff --git a/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml b/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml index 70392128..a5b5c17e 100644 --- a/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml +++ b/stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml @@ -3,19 +3,19 @@ author: MrSebastian realm: ${SSO_REALM} changes: - addRole: - name: EAI_Wahlvorstaende_LoadWahlvorstand + name: aoueai_BUSINESSACTION_LoadWahlvorstand clientRole: true clientId: ${SSO_CLIENT_ID} - assignRoleToGroup: group: allEaiAuthorities - role: EAI_Wahlvorstaende_LoadWahlvorstand + role: aoueai_BUSINESSACTION_LoadWahlvorstand clientId: ${SSO_CLIENT_ID} - addRole: - name: EAI_Wahlvorstaende_SaveAnwesenheit + name: aoueai_BUSINESSACTION_SaveAnwesenheit clientRole: true clientId: ${SSO_CLIENT_ID} - assignRoleToGroup: group: allEaiAuthorities - role: EAI_Wahlvorstaende_SaveAnwesenheit + role: aoueai_BUSINESSACTION_SaveAnwesenheit clientId: ${SSO_CLIENT_ID} \ No newline at end of file diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java similarity index 88% rename from wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java rename to wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index d150d823..ab66de1e 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -1,4 +1,4 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.service; +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; @@ -26,15 +26,20 @@ public class WahlvorstandService { private final WahlvorstandMapper wahlvorstandMapper; - @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_LoadWahlvorstand')") + private final WahlvorstandValidator wahlvorstandValidator; + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlvorstand')") public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { + wahlvorstandValidator.validateWahlbezirkIDOrThrow(wahlbezirkID); val wahlbezirkUUID = convertIDToUUIDOrThrow(wahlbezirkID); return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkUUID).map(wahlvorstandMapper::toDTO).orElse(null); } - @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_SaveAnwesenheit')") + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveAnwesenheit')") public void setAnwesenheit(final WahlvorstandsaktualisierungDTO aktualisierung) { //TODO was ist wenn es den Wahlvorstand nicht gibt den man aktualisieren soll + wahlvorstandValidator.valideSaveAnwesenheitDataOrThrow(aktualisierung); + val wahlvorstandToUpdate = wahlvorstandRepository.findFirstByWahlbezirkID(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); if (wahlvorstandToUpdate.isPresent()) { val entity = wahlvorstandToUpdate.get(); diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java new file mode 100644 index 00000000..e6eeead1 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java @@ -0,0 +1,41 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class WahlvorstandValidator { + + private final ExceptionFactory exceptionFactory; + + public void validateWahlbezirkIDOrThrow(final String wahlbezirkID) { + if (StringUtils.isBlank(wahlbezirkID)) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG); + } + } + + public void valideSaveAnwesenheitDataOrThrow(final WahlvorstandsaktualisierungDTO saveAnwesenheitData) { + if (saveAnwesenheitData == null) { + throw exceptionFactory.createFachlicheWlsException( + de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN); + } + + if (StringUtils.isBlank(saveAnwesenheitData.wahlbezirkID())) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT); + } + + if (saveAnwesenheitData.anwesenheitBeginn() == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT); + } + + if (saveAnwesenheitData.mitglieder() != null && saveAnwesenheitData.mitglieder().stream() + .anyMatch(mitglied -> StringUtils.isBlank(mitglied.identifikator()))) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT); + } + } +} From 3e3ab5152d1e589efc0cb29f146d5f09ceae6f55 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:52:47 +0200 Subject: [PATCH 09/41] preauthorized removed from controller --- .../eaiservice/rest/wahlvorstand/WahlvorstandController.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 6c430454..7d2c77d5 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -5,7 +5,6 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -23,14 +22,12 @@ public class WahlvorstandController { @GetMapping @ResponseStatus(HttpStatus.OK) - @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_LoadWahlvorstand')") public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } @PostMapping @ResponseStatus(HttpStatus.OK) - @PreAuthorize("hasAuthority('EAI_Wahlvorstaende_SaveAnwesenheit')") public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); } From f8409f4ccfdb18c9c59b1e1218a80ebe4d8048cb Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:53:13 +0200 Subject: [PATCH 10/41] update SecurityConfigurationTest with wahlvorstand --- .../SecurityConfigurationTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java index e5099fb8..de970e1c 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java @@ -1,15 +1,29 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.configuration; import static de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants.SPRING_TEST_PROFILE; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.fasterxml.jackson.databind.ObjectMapper; import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; +import java.time.LocalDateTime; +import java.util.Set; +import lombok.val; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithAnonymousUser; +import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @@ -22,6 +36,12 @@ class SecurityConfigurationTest { @Autowired MockMvc api; + @Autowired + ObjectMapper objectMapper; + + @MockBean + WahlvorstandService wahlvorstandService; + @Test void accessSecuredResourceRootThenUnauthorized() throws Exception { api.perform(get("/")) @@ -64,4 +84,39 @@ void accessUnsecuredResourceSwaggerUiThenOk() throws Exception { .andExpect(status().isOk()); } + @Nested + class Wahlvorstand { + @Test + @WithAnonymousUser + void accessGetWahlvorstandForWahlbezirkIDUnauthorizedThenUnauthorized() throws Exception { + api.perform(get("/wahlvorstaende?wahlbezirkID=wbzID")).andExpect(status().isUnauthorized()); + } + + @Test + @WithMockUser + void accessGetWahlvorstandForWahlbezirkIDAuthorizedThenOk() throws Exception { + api.perform(get("/wahlvorstaende?wahlbezirkID=wbzID")).andExpect(status().isOk()); + } + + @Test + @WithAnonymousUser + void accessSaveAnwesenheitUnauthorizedThenUnauthorized() throws Exception { + val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), + LocalDateTime.now()); + + api.perform(post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isUnauthorized()); + } + + @Test + @WithMockUser + void accessSaveAnwesenheitAuthorizedThenCreated() throws Exception { + val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), + LocalDateTime.now()); + + api.perform(post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isOk()); + } + } + } From c756413e8c92991e1e256acd9dd588f2e6f22f13 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:40:35 +0200 Subject: [PATCH 11/41] create wahlvorstand controller unit test --- .../WahlvorstandControllerTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java new file mode 100644 index 00000000..cad6399b --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java @@ -0,0 +1,45 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; +import java.time.LocalDateTime; +import java.util.Collections; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahlvorstandControllerTest { + + @Mock + WahlvorstandService wahlvorstandService; + + @InjectMocks + WahlvorstandController unitUnderTest; + + @Test + void loadWahlvorstand() { + val wahlbezirkID = "wahlbezirkID"; + val wahlvorstandFromService = new WahlvorstandDTO("wahlbezirkID", Collections.emptySet()); + + Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(wahlvorstandFromService); + + Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isSameAs(wahlvorstandFromService); + } + + @Test + void saveAnwesenheit() { + val updateData = new WahlvorstandsaktualisierungDTO("id", Collections.emptySet(), LocalDateTime.now()); + + unitUnderTest.saveAnwesenheit(updateData); + + Mockito.verify(wahlvorstandService).setAnwesenheit(updateData); + } + +} \ No newline at end of file From c8e30e26b01d940202ae83df3a220f37beda5459 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:58:01 +0200 Subject: [PATCH 12/41] define authorities for wahlvorstaende service --- .../oss/wahllokalsystem/eaiservice/Authorities.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java new file mode 100644 index 00000000..eefd9901 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java @@ -0,0 +1,11 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class Authorities { + + public static final String SERVICE_LOAD_WAHLVORSTAND = "aoueai_BUSINESSACTION_LoadWahlvorstand"; + public static final String SERVICE_SAVE_ANWESENHEIT = "aoueai_BUSINESSACTION_SaveAnwesenheit"; +} From 1578309f6d008edd3d6da3d893bd02b0ff077f20 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:14:01 +0200 Subject: [PATCH 13/41] wahlvorstand controller integration test for load --- ...WahlvorstandControllerIntegrationTest.java | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java new file mode 100644 index 00000000..4d98cdf1 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -0,0 +1,117 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand; + +import static de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants.SPRING_TEST_PROFILE; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; +import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDateTime; +import java.util.Set; +import java.util.UUID; +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.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest(classes = MicroServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +@ActiveProfiles(profiles = { SPRING_TEST_PROFILE, "no-security" }) +public class WahlvorstandControllerIntegrationTest { + + @Value("${service.info.oid}") + String serviceInfoOid; + + @Autowired + MockMvc api; + + @Autowired + ObjectMapper objectMapper; + + @Autowired + WahlvorstandRepository wahlvorstandRepository; + + @Autowired + WahlvorstandMapper wahlvorstandMapper; + + @Autowired + ExceptionFactory exceptionFactory; + + @AfterEach + void tearDown() { + wahlvorstandRepository.deleteAll(); + } + + @Nested + class LoadWahlvorstand { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLVORSTAND) + void noDataFound() throws Exception { + val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=" + UUID.randomUUID()); + + val response = api.perform(request).andExpect(status().isOk()).andReturn(); + + Assertions.assertThat(response.getResponse().getContentAsString()).isEmpty(); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLVORSTAND) + @Transactional + void dataFound() throws Exception { + val wahlbezirkID1 = UUID.randomUUID(); + val wahlvorstand1 = new Wahlvorstand(wahlbezirkID1, + Set.of(new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, true, LocalDateTime.now()), + new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, false, LocalDateTime.now()))); + val wahlvorstandToLoad = wahlvorstandRepository.save(wahlvorstand1); + + val wahlbezirkID2 = UUID.randomUUID(); + val wahlvorstand2 = new Wahlvorstand(wahlbezirkID2, + Set.of(new Wahlvorstandsmitglied("vorname21", "nachname21", WahlvorstandFunktion.B, true, LocalDateTime.now()), + new Wahlvorstandsmitglied("vorname22", "nachname22", WahlvorstandFunktion.SWB, false, LocalDateTime.now()))); + wahlvorstandRepository.save(wahlvorstand2); + + val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=" + wahlvorstandToLoad.getWahlbezirkID()); + + val response = api.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WahlvorstandDTO.class); + + val expectedResponseDTO = wahlvorstandMapper.toDTO(wahlvorstandToLoad); + + Assertions.assertThat(responseBodyAsDTO).isEqualTo(expectedResponseDTO); + } + + @Test + void wlsExceptionOnInvalidWahlbezirkIDFormat() throws Exception { + val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=wrongFormat"); + + val response = api.perform(request).andExpect(status().isBadRequest()).andReturn(); + val wlsExceptionDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WlsExceptionDTO.class); + + val expectedWlsException = new WlsExceptionDTO(WlsExceptionCategory.F, ExceptionConstants.ID_NICHT_KONVERTIERBAR.code(), serviceInfoOid, + ExceptionConstants.ID_NICHT_KONVERTIERBAR.message()); + + Assertions.assertThat(wlsExceptionDTO).isEqualTo(expectedWlsException); + } + } + +} From e666d6cdc23fd4b6131c387e67a212726306cfd9 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:30:49 +0200 Subject: [PATCH 14/41] move mapper to service package --- .../{rest => service}/wahlvorstand/WahlvorstandMapper.java | 2 +- .../eaiservice/service/wahlvorstand/WahlvorstandService.java | 1 - .../wahlvorstand/WahlvorstandControllerIntegrationTest.java | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) rename wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/{rest => service}/wahlvorstand/WahlvorstandMapper.java (90%) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapper.java similarity index 90% rename from wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java rename to wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapper.java index 9ea18d2f..6c626471 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandMapper.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapper.java @@ -1,4 +1,4 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand; +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index ab66de1e..39c00622 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -4,7 +4,6 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.WahlvorstandMapper; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index 4d98cdf1..42794c96 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -12,6 +12,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandMapper; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; @@ -37,7 +38,7 @@ @AutoConfigureMockMvc @ActiveProfiles(profiles = { SPRING_TEST_PROFILE, "no-security" }) public class WahlvorstandControllerIntegrationTest { - + @Value("${service.info.oid}") String serviceInfoOid; From ae1b89af24143075ea9ca01ed47cbe908f7b260a Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:38:50 +0200 Subject: [PATCH 15/41] create mapper test --- .../wahlvorstand/WahlvorstandMapperTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java new file mode 100644 index 00000000..a7284224 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java @@ -0,0 +1,41 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandFunktionDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedDTO; +import java.time.LocalDateTime; +import java.util.Set; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; + +class WahlvorstandMapperTest { + + private final WahlvorstandMapper unitUnderTest = Mappers.getMapper(WahlvorstandMapper.class); + + @Test + void toDTO() { + val wahlbezirkID = UUID.randomUUID(); + val mitglied1 = new Wahlvorstandsmitglied("vorname1", "nachname1", WahlvorstandFunktion.SWB, true, LocalDateTime.now()); + mitglied1.setId(UUID.randomUUID()); + val mitglied2 = new Wahlvorstandsmitglied("vorname2", "nachname2", WahlvorstandFunktion.B, false, LocalDateTime.now().minusDays(1)); + mitglied2.setId(UUID.randomUUID()); + val mitglieder = Set.of(mitglied1, mitglied2); + val entityToMap = new Wahlvorstand(wahlbezirkID, mitglieder); + + val result = unitUnderTest.toDTO(entityToMap); + + val expectedMitglieder = Set.of( + new WahlvorstandsmitgliedDTO(mitglied1.getId().toString(), mitglied1.getVorname(), mitglied1.getNachname(), WahlvorstandFunktionDTO.SWB, true), + new WahlvorstandsmitgliedDTO(mitglied2.getId().toString(), mitglied2.getVorname(), mitglied2.getNachname(), WahlvorstandFunktionDTO.B, false)); + val expectedResult = new WahlvorstandDTO(wahlbezirkID.toString(), expectedMitglieder); + + Assertions.assertThat(result).isEqualTo(expectedResult); + } + +} \ No newline at end of file From 35f0013a42cafaa7e6db33c66fa8b9b22edf34db Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:41:13 +0200 Subject: [PATCH 16/41] use optional in service --- .../wahlvorstand/WahlvorstandController.java | 2 +- .../wahlvorstand/WahlvorstandService.java | 5 ++-- .../WahlvorstandControllerTest.java | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 7d2c77d5..5cbcec02 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -23,7 +23,7 @@ public class WahlvorstandController { @GetMapping @ResponseStatus(HttpStatus.OK) public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { - return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); + return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID).orElse(null); } @PostMapping diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index 39c00622..f134988f 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -9,6 +9,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.time.LocalDateTime; +import java.util.Optional; import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.val; @@ -28,10 +29,10 @@ public class WahlvorstandService { private final WahlvorstandValidator wahlvorstandValidator; @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlvorstand')") - public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { + public Optional getWahlvorstandForWahlbezirk(final String wahlbezirkID) { wahlvorstandValidator.validateWahlbezirkIDOrThrow(wahlbezirkID); val wahlbezirkUUID = convertIDToUUIDOrThrow(wahlbezirkID); - return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkUUID).map(wahlvorstandMapper::toDTO).orElse(null); + return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkUUID).map(wahlvorstandMapper::toDTO); } @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveAnwesenheit')") diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java index cad6399b..2660de4e 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java @@ -5,8 +5,10 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; import java.time.LocalDateTime; import java.util.Collections; +import java.util.Optional; import lombok.val; import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -23,14 +25,29 @@ class WahlvorstandControllerTest { @InjectMocks WahlvorstandController unitUnderTest; - @Test - void loadWahlvorstand() { - val wahlbezirkID = "wahlbezirkID"; - val wahlvorstandFromService = new WahlvorstandDTO("wahlbezirkID", Collections.emptySet()); + @Nested + class LoadWahlvorstand { + + @Test + void gotDataFromService() { + val wahlbezirkID = "wahlbezirkID"; + val wahlvorstandFromService = new WahlvorstandDTO("wahlbezirkID", Collections.emptySet()); + + Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(Optional.of(wahlvorstandFromService)); + + Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isSameAs(wahlvorstandFromService); + } + + @Test + void gotNoDataFromService() { + + val wahlbezirkID = "wahlbezirkID"; + + Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(Optional.empty()); - Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(wahlvorstandFromService); + Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isNull(); + } - Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isSameAs(wahlvorstandFromService); } @Test From 1c9ed7118cab02000ae7c62b6712da1b04086eff Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:42:09 +0200 Subject: [PATCH 17/41] use lambda expression instead of statement --- .../eaiservice/service/wahlvorstand/WahlvorstandService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index f134988f..c9699620 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -52,9 +52,8 @@ private void updateAnwesenheitOfWahlvorstand(final WahlvorstandsaktualisierungDT updateData.mitglieder().forEach(mitgliedUpdateData -> { val mitgliedToUpdate = existingWahlvorstand.getMitglieder().stream() .filter(setElement -> setElement.getId().toString().equals(mitgliedUpdateData.identifikator())).findFirst(); - mitgliedToUpdate.ifPresent(mitglied -> { - updateAnwesenheitOfWahlvorstandsmitglied(updateData.anwesenheitBeginn(), mitgliedUpdateData, mitglied); - }); + mitgliedToUpdate.ifPresent(mitglied -> + updateAnwesenheitOfWahlvorstandsmitglied(updateData.anwesenheitBeginn(), mitgliedUpdateData, mitglied)); }); } From 828258574ed83cfab2b4b3849e0640efacb4d6bb Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:14:51 +0200 Subject: [PATCH 18/41] created tests for wahlvorstandservice --- .../wahlvorstand/WahlvorstandServiceTest.java | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java new file mode 100644 index 00000000..edb133a5 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -0,0 +1,173 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahlvorstandServiceTest { + + @Mock + WahlvorstandRepository wahlvorstandRepository; + + @Mock + ExceptionFactory exceptionFactory; + + @Mock + WahlvorstandMapper wahlvorstandMapper; + + @Mock + WahlvorstandValidator wahlvorstandValidator; + + @InjectMocks + WahlvorstandService unitUnderTest; + + @Nested + class GetWahlvorstandForWahlbezirk { + + @Test + void foundData() { + val wahlbezirkID = UUID.randomUUID(); + + val mockedEntity = new Wahlvorstand(); + val mockedMappedEntity = new WahlvorstandDTO("wahlbezirkID", Collections.emptySet()); + + Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.of(mockedEntity)); + Mockito.when(wahlvorstandMapper.toDTO(mockedEntity)).thenReturn(mockedMappedEntity); + + val result = unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString()); + + Assertions.assertThat(result).isEqualTo(Optional.of(mockedMappedEntity)); + } + + @Test + void foundNoData() { + val wahlbezirkID = UUID.randomUUID(); + + Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); + + val result = unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString()); + + Assertions.assertThat(result).isEmpty(); + } + + @Test + void exceptionForMalformedWahlbezirkID() { + val wahlbezirkID = "noAUUID"; + + val mockedException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID)).isSameAs(mockedException); + } + + @Test + void exceptionWhenWahlbezirkIDIsNotValid() { + val wahlbezirkID = UUID.randomUUID(); + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahlvorstandValidator).validateWahlbezirkIDOrThrow(wahlbezirkID.toString()); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString())) + .isSameAs(mockedValidationException); + } + } + + @Nested + class SetAnwesenheit { + + @Test + void existingDataIsUpdated() { + val wahlbezirkID = UUID.randomUUID(); + val mitglied1 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true); + val mitglied2 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false); + val mitgliederAktualisierung = Set.of(mitglied1, mitglied2); + val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitgliederAktualisierung, LocalDateTime.now()); + + val mockedEntityLastSavedDateTime = LocalDateTime.now().minusDays(1); + val mockedEntityMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.B, false, mockedEntityLastSavedDateTime); + mockedEntityMitglied1.setId(UUID.fromString(mitglied1.identifikator())); + // no mitglied2 is intended because request should match only a subset of existing data + val mockedEntityMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.SWB, true, mockedEntityLastSavedDateTime); + mockedEntityMitglied3.setId(UUID.randomUUID()); + val mockedEntity = new Wahlvorstand(wahlbezirkID, Set.of(mockedEntityMitglied1, mockedEntityMitglied3)); + + Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.of(mockedEntity)); + + unitUnderTest.setAnwesenheit(aktualisierung); + + val saveArgumentCaptor = ArgumentCaptor.forClass(Wahlvorstand.class); + Mockito.verify(wahlvorstandRepository).save(saveArgumentCaptor.capture()); + + val capturedSavedArgument = saveArgumentCaptor.getValue(); + val expectedMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.B, true, aktualisierung.anwesenheitBeginn()); + expectedMitglied1.setId(UUID.fromString(mitglied1.identifikator())); + val expectedMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.SWB, true, mockedEntityLastSavedDateTime); + expectedMitglied3.setId(mockedEntityMitglied3.getId()); + val expectedSavedArgument = new Wahlvorstand(wahlbezirkID, Set.of(expectedMitglied1, expectedMitglied3)); + Assertions.assertThat(capturedSavedArgument).isEqualTo(expectedSavedArgument); + } + + @Test + void noUpdateWhenWahlvorstandDoesntExists() { + val wahlbezirkID = UUID.randomUUID(); + val mitglied1 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true); + val mitglied2 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false); + val mitgliederAktualisierung = Set.of(mitglied1, mitglied2); + val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitgliederAktualisierung, LocalDateTime.now()); + + Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); + + unitUnderTest.setAnwesenheit(aktualisierung); + + Mockito.verify(wahlvorstandRepository, Mockito.times(0)).save(Mockito.any(Wahlvorstand.class)); + } + + @Test + void validationFailed() { + val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), Collections.emptySet(), LocalDateTime.now()); + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahlvorstandValidator).valideSaveAnwesenheitDataOrThrow(aktualisierung); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.setAnwesenheit(aktualisierung)).isSameAs(mockedValidationException); + } + + @Test + void exceptionBecauseOfWahlbezirkIDOfParameterIsInvalid() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy( + () -> unitUnderTest.setAnwesenheit(new WahlvorstandsaktualisierungDTO("malformedID", Collections.emptySet(), LocalDateTime.now()))) + .isSameAs(mockedWlsException); + } + } + +} \ No newline at end of file From 229998564775530e95ab9d7e58085c5b61e180f5 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:21:20 +0200 Subject: [PATCH 19/41] remove unintended noSec and randomPort of test --- .../wahlvorstand/WahlvorstandControllerIntegrationTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index 42794c96..ee40fb70 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -34,9 +34,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.transaction.annotation.Transactional; -@SpringBootTest(classes = MicroServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = MicroServiceApplication.class) @AutoConfigureMockMvc -@ActiveProfiles(profiles = { SPRING_TEST_PROFILE, "no-security" }) +@ActiveProfiles(profiles = { SPRING_TEST_PROFILE }) public class WahlvorstandControllerIntegrationTest { @Value("${service.info.oid}") @@ -102,6 +102,7 @@ void dataFound() throws Exception { } @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLVORSTAND) void wlsExceptionOnInvalidWahlbezirkIDFormat() throws Exception { val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=wrongFormat"); From d30355fceafb9bf6178064bba1bb43bdddf6b3ba Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:47:27 +0200 Subject: [PATCH 20/41] all constants with all authorities required to access service --- .../oss/wahllokalsystem/eaiservice/Authorities.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java index eefd9901..148ecb28 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java @@ -8,4 +8,11 @@ public class Authorities { public static final String SERVICE_LOAD_WAHLVORSTAND = "aoueai_BUSINESSACTION_LoadWahlvorstand"; public static final String SERVICE_SAVE_ANWESENHEIT = "aoueai_BUSINESSACTION_SaveAnwesenheit"; + + public static final String[] ALL_AUTHORITIES_GETWAHLVORSTANDFORWAHLBEZIRK = { + SERVICE_LOAD_WAHLVORSTAND + }; + public static final String[] ALL_AUTHORIRITES_SETANWESENHEIT = { + SERVICE_SAVE_ANWESENHEIT + }; } From d666cf28eb4dfec4f42f5a1867524a2d662cac1c Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:02:18 +0200 Subject: [PATCH 21/41] create WahlvorstandServiceSecurityTest --- .../WahlvorstandServiceSecurityTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java new file mode 100644 index 00000000..76dc4e42 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java @@ -0,0 +1,89 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.testing.SecurityUtils; +import java.time.LocalDateTime; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Stream; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.aggregator.ArgumentsAccessor; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest(classes = MicroServiceApplication.class) + +@ActiveProfiles({ TestConstants.SPRING_TEST_PROFILE }) +public class WahlvorstandServiceSecurityTest { + + @Autowired + WahlvorstandService wahlvorstandService; + + @Nested + class GetWahlvorstandForWahlbezirk { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.ALL_AUTHORITIES_GETWAHLVORSTANDFORWAHLBEZIRK); + + Assertions.assertThatNoException().isThrownBy(() -> wahlvorstandService.getWahlvorstandForWahlbezirk(UUID.randomUUID().toString())); + } + + @ParameterizedTest(name = "{index} - {1} missing") + @MethodSource("getMissingAuthoritiesVariations") + void anyMissingAuthorityCausesFail(final ArgumentsAccessor argumentsAccessor) { + SecurityUtils.runWith(argumentsAccessor.get(0, String[].class)); + + Assertions.assertThatThrownBy(() -> wahlvorstandService.getWahlvorstandForWahlbezirk(UUID.randomUUID().toString())) + .isInstanceOf(AccessDeniedException.class); + } + + private static Stream getMissingAuthoritiesVariations() { + return SecurityUtils.buildArgumentsForMissingAuthoritiesVariations(Authorities.ALL_AUTHORITIES_GETWAHLVORSTANDFORWAHLBEZIRK); + } + } + + @Nested + class SetAnwesenheit { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.ALL_AUTHORIRITES_SETANWESENHEIT); + + val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), + Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false)), LocalDateTime.now()); + + Assertions.assertThatNoException().isThrownBy(() -> wahlvorstandService.setAnwesenheit(aktualisierung)); + } + + @ParameterizedTest(name = "{index} - {1} missing") + @MethodSource("getMissingAuthoritiesVariations") + void anyMissingAuthorityCausesFail(final ArgumentsAccessor argumentsAccessor) { + SecurityUtils.runWith(argumentsAccessor.get(0, String[].class)); + + val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), + Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false)), LocalDateTime.now()); + + Assertions.assertThatThrownBy(() -> wahlvorstandService.setAnwesenheit(aktualisierung)) + .isInstanceOf(AccessDeniedException.class); + } + + private static Stream getMissingAuthoritiesVariations() { + return SecurityUtils.buildArgumentsForMissingAuthoritiesVariations(Authorities.ALL_AUTHORIRITES_SETANWESENHEIT); + } + + } + +} From a948e675e6f935e5468b7fb9ce059f8b1bea6f8e Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:03:15 +0200 Subject: [PATCH 22/41] add lombok builder to dtos --- .../rest/wahlvorstand/dto/WahlvorstandsaktualisierungDTO.java | 2 ++ .../dto/WahlvorstandsmitgliedAktualisierungDTO.java | 2 ++ .../rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsaktualisierungDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsaktualisierungDTO.java index 7183cb59..a04462a0 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsaktualisierungDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsaktualisierungDTO.java @@ -4,7 +4,9 @@ import jakarta.validation.constraints.Size; import java.time.LocalDateTime; import java.util.Set; +import lombok.Builder; +@Builder public record WahlvorstandsaktualisierungDTO(@NotNull String wahlbezirkID, @NotNull @Size(min = 1) Set mitglieder, @NotNull LocalDateTime anwesenheitBeginn) { diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedAktualisierungDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedAktualisierungDTO.java index a11a7276..a021d943 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedAktualisierungDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedAktualisierungDTO.java @@ -2,7 +2,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; +import lombok.Builder; +@Builder public record WahlvorstandsmitgliedAktualisierungDTO(@NotNull String identifikator, @Schema(requiredMode = Schema.RequiredMode.REQUIRED) boolean anwesend) { } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java index 78d8d7bb..138fcc65 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java @@ -2,7 +2,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; +import lombok.Builder; +@Builder public record WahlvorstandsmitgliedDTO(@NotNull String identifikator, @NotNull String vorname, @NotNull String nachname, From 350600c967338a2d75efc04e43ba6a567eb151e3 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:18:32 +0200 Subject: [PATCH 23/41] add validator tests --- .../WahlvorstandValidatorTest.java | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java new file mode 100644 index 00000000..bd1ef786 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java @@ -0,0 +1,185 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Set; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahlvorstandValidatorTest { + + @Mock + ExceptionFactory exceptionFactory; + + @InjectMocks + WahlvorstandValidator unitUnderTest; + + @Nested + class ValidateWahlbezirkIDOrThrow { + + @Test + void noExceptionWhenIdIsValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validateWahlbezirkIDOrThrow(UUID.randomUUID().toString())); + } + + @Test + void exceptionWhenIDIsNUll() { + val mockedFachlicheWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedFachlicheWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateWahlbezirkIDOrThrow(null)).isSameAs(mockedFachlicheWlsException); + } + + @Test + void exceptionWhenIDIsEmptyString() { + val mockedFachlicheWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedFachlicheWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateWahlbezirkIDOrThrow("")).isSameAs(mockedFachlicheWlsException); + } + + @Test + void exceptionWhenIDIsBlankString() { + val mockedFachlicheWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLVORSTAND_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedFachlicheWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateWahlbezirkIDOrThrow(" ")).isSameAs(mockedFachlicheWlsException); + } + } + + @Nested + class ValideSaveAnwesenheitDataOrThrow { + + @Test + void noExceptionWhenAktualisierungIsValid() { + val validDTO = initValidAktualisierung().build(); + + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(validDTO)); + } + + @Test + void exceptionWhenAktualisierungIsNull() { + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException( + de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(null)).isSameAs(mockedValidationException); + } + + @Test + void exceptionWhenWahlbezirkIdIsNull() { + val invalidDTO = initValidAktualisierung().wahlbezirkID(null).build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + } + + @Test + void exceptionWhenWahlbezirkIdIsEmpty() { + val invalidDTO = initValidAktualisierung().wahlbezirkID("").build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + } + + @Test + void exceptionWhenWahlbezirkIdIsBlank() { + val invalidDTO = initValidAktualisierung().wahlbezirkID(" ").build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + } + + @Test + void exceptionWhenAnwesenheitBeginnIsNull() { + val invalidDTO = initValidAktualisierung().anwesenheitBeginn(null).build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + + } + + @Nested + class ExceptionWhenMitgliederIdIsInvalid { + + @Test + void isNull() { + val invalidDTO = initValidAktualisierung().mitglieder( + Set.of(initValidMitgliedAktualisierung().build(), initValidMitgliedAktualisierung().identifikator(null).build())).build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + .isSameAs(mockedValidationException); + } + + @Test + void isEmptyString() { + val invalidDTO = initValidAktualisierung().mitglieder( + Set.of(initValidMitgliedAktualisierung().build(), initValidMitgliedAktualisierung().identifikator("").build())).build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + .isSameAs(mockedValidationException); + } + + @Test + void isBankString() { + val invalidDTO = initValidAktualisierung().mitglieder( + Set.of(initValidMitgliedAktualisierung().build(), initValidMitgliedAktualisierung().identifikator(" ").build())).build(); + + val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) + .thenReturn(mockedValidationException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + .isSameAs(mockedValidationException); + } + } + + private WahlvorstandsaktualisierungDTO.WahlvorstandsaktualisierungDTOBuilder initValidAktualisierung() { + return WahlvorstandsaktualisierungDTO.builder().anwesenheitBeginn(LocalDateTime.now()).wahlbezirkID("wahlbezirkID") + .mitglieder(Collections.emptySet()); + } + + private WahlvorstandsmitgliedAktualisierungDTO.WahlvorstandsmitgliedAktualisierungDTOBuilder initValidMitgliedAktualisierung() { + return WahlvorstandsmitgliedAktualisierungDTO.builder().identifikator("mitgliedId"); + } + } + +} \ No newline at end of file From d3b093452f26b40c4289e8e6b90e433af6b81a1e Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:16:03 +0200 Subject: [PATCH 24/41] implement 404 on loadWahlvorstand --- .../exception/GlobalExceptionHandler.java | 6 ++++++ .../eaiservice/exception/NotFoundException.java | 17 +++++++++++++++++ .../wahlvorstand/WahlvorstandController.java | 3 +-- .../wahlvorstand/WahlvorstandService.java | 10 +++++++--- .../WahlvorstandControllerIntegrationTest.java | 2 +- .../WahlvorstandControllerTest.java | 13 +------------ .../WahlvorstandServiceSecurityTest.java | 4 +++- .../wahlvorstand/WahlvorstandServiceTest.java | 8 ++++---- .../resources/httpRequests/wahlvorstand.http | 4 ++++ 9 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/NotFoundException.java diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java index 6b9bfd69..e88960d3 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java @@ -25,6 +25,12 @@ public ResponseEntity handleThrowables(final Throwable throwabl return createResponse(getWahlExceptionDTO(throwable)); } + @ExceptionHandler + public ResponseEntity handleNotFoundException(final NotFoundException notFoundException) { + log.debug("not found entity {} with id {}", notFoundException.getEntityClass(), notFoundException.getRequestedID()); + return ResponseEntity.notFound().build(); + } + @Override protected String getService() { return serviceIDFormatter.getId(); diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/NotFoundException.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/NotFoundException.java new file mode 100644 index 00000000..3a144d60 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/NotFoundException.java @@ -0,0 +1,17 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.exception; + +import java.util.UUID; +import lombok.Getter; + +@Getter +public class NotFoundException extends RuntimeException { + + private final UUID requestedID; + + private final Class entityClass; + + public NotFoundException(UUID requestID, Class entityClass) { + this.requestedID = requestID; + this.entityClass = entityClass; + } +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 5cbcec02..f475503a 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -21,9 +21,8 @@ public class WahlvorstandController { private final WahlvorstandService wahlvorstandService; @GetMapping - @ResponseStatus(HttpStatus.OK) public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { - return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID).orElse(null); + return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } @PostMapping diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index c9699620..29b2d346 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -3,13 +3,13 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.time.LocalDateTime; -import java.util.Optional; import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.val; @@ -29,10 +29,10 @@ public class WahlvorstandService { private final WahlvorstandValidator wahlvorstandValidator; @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlvorstand')") - public Optional getWahlvorstandForWahlbezirk(final String wahlbezirkID) { + public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { wahlvorstandValidator.validateWahlbezirkIDOrThrow(wahlbezirkID); val wahlbezirkUUID = convertIDToUUIDOrThrow(wahlbezirkID); - return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkUUID).map(wahlvorstandMapper::toDTO); + return wahlvorstandMapper.toDTO(findByWahlbezirkIDOrThrow(wahlbezirkUUID)); } @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveAnwesenheit')") @@ -71,4 +71,8 @@ private UUID convertIDToUUIDOrThrow(final String id) { } } + private Wahlvorstand findByWahlbezirkIDOrThrow(final UUID wahlbezirkID) { + return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID).orElseThrow(() -> new NotFoundException(wahlbezirkID, Wahlvorstand.class)); + } + } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index ee40fb70..58b380ab 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -70,7 +70,7 @@ class LoadWahlvorstand { void noDataFound() throws Exception { val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=" + UUID.randomUUID()); - val response = api.perform(request).andExpect(status().isOk()).andReturn(); + val response = api.perform(request).andExpect(status().isNotFound()).andReturn(); Assertions.assertThat(response.getResponse().getContentAsString()).isEmpty(); } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java index 2660de4e..179f09fd 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java @@ -5,7 +5,6 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; import java.time.LocalDateTime; import java.util.Collections; -import java.util.Optional; import lombok.val; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Nested; @@ -33,21 +32,11 @@ void gotDataFromService() { val wahlbezirkID = "wahlbezirkID"; val wahlvorstandFromService = new WahlvorstandDTO("wahlbezirkID", Collections.emptySet()); - Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(Optional.of(wahlvorstandFromService)); + Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(wahlvorstandFromService); Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isSameAs(wahlvorstandFromService); } - @Test - void gotNoDataFromService() { - - val wahlbezirkID = "wahlbezirkID"; - - Mockito.when(wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID)).thenReturn(Optional.empty()); - - Assertions.assertThat(unitUnderTest.loadWahlvorstand(wahlbezirkID)).isNull(); - } - } @Test diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java index 76dc4e42..0d4393fd 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java @@ -3,6 +3,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; import de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; import de.muenchen.oss.wahllokalsystem.wls.common.testing.SecurityUtils; @@ -38,7 +39,8 @@ class GetWahlvorstandForWahlbezirk { void accessGranted() { SecurityUtils.runWith(Authorities.ALL_AUTHORITIES_GETWAHLVORSTANDFORWAHLBEZIRK); - Assertions.assertThatNoException().isThrownBy(() -> wahlvorstandService.getWahlvorstandForWahlbezirk(UUID.randomUUID().toString())); + Assertions.assertThatException().isThrownBy(() -> wahlvorstandService.getWahlvorstandForWahlbezirk(UUID.randomUUID().toString())).isInstanceOf( + NotFoundException.class); } @ParameterizedTest(name = "{index} - {1} missing") diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index edb133a5..44eb982f 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -4,6 +4,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; @@ -59,7 +60,7 @@ void foundData() { val result = unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString()); - Assertions.assertThat(result).isEqualTo(Optional.of(mockedMappedEntity)); + Assertions.assertThat(result).isSameAs(mockedMappedEntity); } @Test @@ -68,9 +69,8 @@ void foundNoData() { Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); - val result = unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString()); - - Assertions.assertThat(result).isEmpty(); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString())) + .usingRecursiveComparison().isEqualTo(new NotFoundException(wahlbezirkID, Wahlvorstand.class)); } @Test diff --git a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http index 9e9a277a..b5ed9181 100644 --- a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http +++ b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http @@ -32,6 +32,10 @@ Authorization: {{ token_type }} {{ auth_token }} GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-0000-0000-0000-000000000004 Authorization: {{ token_type }} {{ auth_token }} +### GET Wahlvorstand not found +GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-9999-0000-0000-000000000000 +Authorization: {{ token_type }} {{ auth_token }} + ### POST Update Wahlvorstand wbz4 POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende Authorization: {{ token_type }} {{ auth_token }} From 6dab999811a9a0abe19cc5c30afd9f18178d515b Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:14:14 +0200 Subject: [PATCH 25/41] 404 when wahlvorstand to update doesnt exists --- .../service/wahlvorstand/WahlvorstandService.java | 10 +++------- .../wahlvorstand/WahlvorstandServiceSecurityTest.java | 2 +- .../service/wahlvorstand/WahlvorstandServiceTest.java | 5 +++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index 29b2d346..b4adbc3c 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -37,15 +37,11 @@ public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveAnwesenheit')") public void setAnwesenheit(final WahlvorstandsaktualisierungDTO aktualisierung) { - //TODO was ist wenn es den Wahlvorstand nicht gibt den man aktualisieren soll wahlvorstandValidator.valideSaveAnwesenheitDataOrThrow(aktualisierung); - val wahlvorstandToUpdate = wahlvorstandRepository.findFirstByWahlbezirkID(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); - if (wahlvorstandToUpdate.isPresent()) { - val entity = wahlvorstandToUpdate.get(); - updateAnwesenheitOfWahlvorstand(aktualisierung, entity); - wahlvorstandRepository.save(entity); - } + val wahlvorstandToUpdate = findByWahlbezirkIDOrThrow(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); + updateAnwesenheitOfWahlvorstand(aktualisierung, wahlvorstandToUpdate); + wahlvorstandRepository.save(wahlvorstandToUpdate); } private void updateAnwesenheitOfWahlvorstand(final WahlvorstandsaktualisierungDTO updateData, final Wahlvorstand existingWahlvorstand) { diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java index 0d4393fd..6b22a2f2 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceSecurityTest.java @@ -67,7 +67,7 @@ void accessGranted() { val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false)), LocalDateTime.now()); - Assertions.assertThatNoException().isThrownBy(() -> wahlvorstandService.setAnwesenheit(aktualisierung)); + Assertions.assertThatException().isThrownBy(() -> wahlvorstandService.setAnwesenheit(aktualisierung)).isInstanceOf(NotFoundException.class); } @ParameterizedTest(name = "{index} - {1} missing") diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index 44eb982f..883fd54a 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -133,7 +133,7 @@ void existingDataIsUpdated() { } @Test - void noUpdateWhenWahlvorstandDoesntExists() { + void exceptionWhenWahlvorstandDoesNotExists() { val wahlbezirkID = UUID.randomUUID(); val mitglied1 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true); val mitglied2 = new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false); @@ -142,7 +142,8 @@ void noUpdateWhenWahlvorstandDoesntExists() { Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); - unitUnderTest.setAnwesenheit(aktualisierung); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.setAnwesenheit(aktualisierung)).usingRecursiveComparison() + .isEqualTo(new NotFoundException(wahlbezirkID, Wahlvorstand.class)); Mockito.verify(wahlvorstandRepository, Mockito.times(0)).save(Mockito.any(Wahlvorstand.class)); } From 0fdc55296a04bbeb3a36123863b5c8a41dec7276 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:31:36 +0200 Subject: [PATCH 26/41] add tests for setanwesenheit --- .../domain/wahlvorstand/Wahlvorstand.java | 12 +-- ...WahlvorstandControllerIntegrationTest.java | 73 +++++++++++++++++++ 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java index a5447201..4f503f68 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java @@ -3,12 +3,11 @@ import static java.sql.Types.VARCHAR; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.util.Set; +import java.util.Collection; import java.util.UUID; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -32,10 +31,7 @@ public class Wahlvorstand extends BaseEntity { @JdbcTypeCode(VARCHAR) private UUID wahlbezirkID; - @NotNull - @Size(min = 1) - @OneToMany - @JoinColumn(name = "wahlvorstandID") - private Set mitglieder; + @OneToMany(cascade = CascadeType.ALL) + private Collection mitglieder; } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index 58b380ab..a0abd8c8 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -1,6 +1,7 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand; import static de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants.SPRING_TEST_PROFILE; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; @@ -12,10 +13,13 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandMapper; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import jakarta.persistence.EntityManager; import java.time.LocalDateTime; import java.util.Set; import java.util.UUID; @@ -28,6 +32,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; @@ -57,6 +62,9 @@ public class WahlvorstandControllerIntegrationTest { @Autowired ExceptionFactory exceptionFactory; + @Autowired + EntityManager entityManager; + @AfterEach void tearDown() { wahlvorstandRepository.deleteAll(); @@ -116,4 +124,69 @@ void wlsExceptionOnInvalidWahlbezirkIDFormat() throws Exception { } } + @Nested + class SaveAnwesenheit { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_SAVE_ANWESENHEIT) + @Transactional + void personsAreUpdated() throws Exception { + val wahlbezirkID = UUID.randomUUID(); + val oldUpdatedDate = LocalDateTime.now().minusDays(1); + val mitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, true, oldUpdatedDate); + val mitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, false, oldUpdatedDate); + val mitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandFunktion.SWB, false, oldUpdatedDate); + val wahlvorstand1 = new Wahlvorstand(wahlbezirkID, + Set.of(mitglied1, mitglied2, mitglied3)); + val wahlvorstandToUpdate = wahlvorstandRepository.save(wahlvorstand1); + + val updateDateTime = LocalDateTime.now(); + val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(mitglied1.getId().toString(), false), + new WahlvorstandsmitgliedAktualisierungDTO(mitglied2.getId().toString(), true)); + val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitglieder, updateDateTime); + val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + objectMapper.writeValueAsString(aktualisierung)); + + api.perform(request).andExpect(status().isOk()); + + val updatedEntity = wahlvorstandRepository.findById(wahlvorstandToUpdate.getId()); + val expectedEntityMitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, false, updateDateTime); + expectedEntityMitglied1.setId(mitglied1.getId()); + val expectedEntityMitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, true, updateDateTime); + expectedEntityMitglied2.setId(mitglied2.getId()); + val expectedEntityMitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandFunktion.SWB, false, oldUpdatedDate); + expectedEntityMitglied3.setId(mitglied3.getId()); + val expectedUpdatedEntity = new Wahlvorstand(wahlbezirkID, Set.of(expectedEntityMitglied1, expectedEntityMitglied2, expectedEntityMitglied3)); + expectedUpdatedEntity.setId(wahlvorstandToUpdate.getId()); + + Assertions.assertThat(updatedEntity.get()).usingRecursiveComparison().isEqualTo(expectedUpdatedEntity); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_SAVE_ANWESENHEIT) + void HttpStatusNotFoundWhenWahlvorstandDoesNotExists() throws Exception { + val updateDateTime = LocalDateTime.now(); + val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), + new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); + val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, updateDateTime); + val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + objectMapper.writeValueAsString(aktualisierung)); + + api.perform(request).andExpect(status().isNotFound()); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_SAVE_ANWESENHEIT) + void HttpStatusBadRequestWhenRequestIsInvalid() throws Exception { + val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), + new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); + val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, null); + val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + objectMapper.writeValueAsString(aktualisierung)); + + api.perform(request).andExpect(status().isBadRequest()); + + } + } + } From 2aacae934fb4678e81d90c55a3434bf53bf8e79b Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:32:12 +0200 Subject: [PATCH 27/41] spotless:apply --- .../eaiservice/rest/wahlvorstand/WahlvorstandController.java | 3 ++- .../eaiservice/service/wahlvorstand/WahlvorstandService.java | 3 +-- .../rest/wahlvorstand/WahlvorstandControllerTest.java | 2 +- .../service/wahlvorstand/WahlvorstandMapperTest.java | 2 +- .../service/wahlvorstand/WahlvorstandServiceTest.java | 4 ++-- .../service/wahlvorstand/WahlvorstandValidatorTest.java | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index f475503a..7a5c2fc5 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -21,7 +21,8 @@ public class WahlvorstandController { private final WahlvorstandService wahlvorstandService; @GetMapping - public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { + public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") + String wahlbezirkID) { return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index b4adbc3c..207e4985 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -48,8 +48,7 @@ private void updateAnwesenheitOfWahlvorstand(final WahlvorstandsaktualisierungDT updateData.mitglieder().forEach(mitgliedUpdateData -> { val mitgliedToUpdate = existingWahlvorstand.getMitglieder().stream() .filter(setElement -> setElement.getId().toString().equals(mitgliedUpdateData.identifikator())).findFirst(); - mitgliedToUpdate.ifPresent(mitglied -> - updateAnwesenheitOfWahlvorstandsmitglied(updateData.anwesenheitBeginn(), mitgliedUpdateData, mitglied)); + mitgliedToUpdate.ifPresent(mitglied -> updateAnwesenheitOfWahlvorstandsmitglied(updateData.anwesenheitBeginn(), mitgliedUpdateData, mitglied)); }); } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java index 179f09fd..ae18b74a 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerTest.java @@ -48,4 +48,4 @@ void saveAnwesenheit() { Mockito.verify(wahlvorstandService).setAnwesenheit(updateData); } -} \ No newline at end of file +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java index a7284224..e51dd6c9 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java @@ -38,4 +38,4 @@ void toDTO() { Assertions.assertThat(result).isEqualTo(expectedResult); } -} \ No newline at end of file +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index 883fd54a..8428be1a 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -166,9 +166,9 @@ void exceptionBecauseOfWahlbezirkIDOfParameterIsInvalid() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedWlsException); Assertions.assertThatException().isThrownBy( - () -> unitUnderTest.setAnwesenheit(new WahlvorstandsaktualisierungDTO("malformedID", Collections.emptySet(), LocalDateTime.now()))) + () -> unitUnderTest.setAnwesenheit(new WahlvorstandsaktualisierungDTO("malformedID", Collections.emptySet(), LocalDateTime.now()))) .isSameAs(mockedWlsException); } } -} \ No newline at end of file +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java index bd1ef786..d69c3916 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java @@ -78,7 +78,7 @@ void noExceptionWhenAktualisierungIsValid() { void exceptionWhenAktualisierungIsNull() { val mockedValidationException = FachlicheWlsException.withCode("").buildWithMessage(""); Mockito.when(exceptionFactory.createFachlicheWlsException( - de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN)) + de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN)) .thenReturn(mockedValidationException); Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(null)).isSameAs(mockedValidationException); @@ -182,4 +182,4 @@ private WahlvorstandsmitgliedAktualisierungDTO.WahlvorstandsmitgliedAktualisieru } } -} \ No newline at end of file +} From 236fd6ffd3a0236fb592f7390ac7e2a31e3222f2 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:35:34 +0200 Subject: [PATCH 28/41] change resource for anwesenheit --- .../rest/wahlvorstand/WahlvorstandController.java | 2 +- .../eaiservice/configuration/SecurityConfigurationTest.java | 4 ++-- .../wahlvorstand/WahlvorstandControllerIntegrationTest.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 7a5c2fc5..604f84d3 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -26,7 +26,7 @@ public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } - @PostMapping + @PostMapping("anwesenheit") @ResponseStatus(HttpStatus.OK) public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java index de970e1c..f6099c14 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java @@ -104,7 +104,7 @@ void accessSaveAnwesenheitUnauthorizedThenUnauthorized() throws Exception { val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), LocalDateTime.now()); - api.perform(post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON) + api.perform(post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isUnauthorized()); } @@ -114,7 +114,7 @@ void accessSaveAnwesenheitAuthorizedThenCreated() throws Exception { val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), LocalDateTime.now()); - api.perform(post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON) + api.perform(post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isOk()); } } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index a0abd8c8..92c64173 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -144,7 +144,7 @@ void personsAreUpdated() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(mitglied1.getId().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(mitglied2.getId().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitglieder, updateDateTime); - val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isOk()); @@ -169,7 +169,7 @@ void HttpStatusNotFoundWhenWahlvorstandDoesNotExists() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, updateDateTime); - val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isNotFound()); @@ -181,7 +181,7 @@ void HttpStatusBadRequestWhenRequestIsInvalid() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, null); - val request = MockMvcRequestBuilders.post("/wahlvorstaende").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isBadRequest()); From 3990e4540b9c6b345494d618913ade32bc1d2a86 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:38:35 +0200 Subject: [PATCH 29/41] use put for update instead of post --- .../rest/wahlvorstand/WahlvorstandController.java | 4 ++-- .../eaiservice/configuration/SecurityConfigurationTest.java | 6 +++--- .../wahlvorstand/WahlvorstandControllerIntegrationTest.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index 604f84d3..cad86aa2 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -26,7 +26,7 @@ public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } - @PostMapping("anwesenheit") + @PutMapping("anwesenheit") @ResponseStatus(HttpStatus.OK) public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java index f6099c14..0bb9f7e1 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java @@ -3,7 +3,7 @@ import static de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants.SPRING_TEST_PROFILE; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; @@ -104,7 +104,7 @@ void accessSaveAnwesenheitUnauthorizedThenUnauthorized() throws Exception { val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), LocalDateTime.now()); - api.perform(post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) + api.perform(put("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isUnauthorized()); } @@ -114,7 +114,7 @@ void accessSaveAnwesenheitAuthorizedThenCreated() throws Exception { val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), LocalDateTime.now()); - api.perform(post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) + api.perform(put("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(wahlvorstandAktualisierung))).andExpect(status().isOk()); } } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index 92c64173..e62d27ca 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -144,7 +144,7 @@ void personsAreUpdated() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(mitglied1.getId().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(mitglied2.getId().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitglieder, updateDateTime); - val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.put("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isOk()); @@ -169,7 +169,7 @@ void HttpStatusNotFoundWhenWahlvorstandDoesNotExists() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, updateDateTime); - val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.put("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isNotFound()); @@ -181,7 +181,7 @@ void HttpStatusBadRequestWhenRequestIsInvalid() throws Exception { val mitglieder = Set.of(new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), false), new WahlvorstandsmitgliedAktualisierungDTO(UUID.randomUUID().toString(), true)); val aktualisierung = new WahlvorstandsaktualisierungDTO(UUID.randomUUID().toString(), mitglieder, null); - val request = MockMvcRequestBuilders.post("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( + val request = MockMvcRequestBuilders.put("/wahlvorstaende/anwesenheit").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isBadRequest()); From bec3f6eeb7140141e58e88b7b2d849833c9e402f Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:42:05 +0200 Subject: [PATCH 30/41] create test for global exception handler --- .../exception/GlobalExceptionHandlerTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandlerTest.java diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandlerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandlerTest.java new file mode 100644 index 00000000..6933e67f --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandlerTest.java @@ -0,0 +1,34 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.exception; + +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.DTOMapper; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ServiceIDFormatter; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.ResponseEntity; + +@ExtendWith(MockitoExtension.class) +class GlobalExceptionHandlerTest { + + @Mock + DTOMapper dtoMapper; + + @Mock + ServiceIDFormatter serviceIDFormatter; + + @InjectMocks + GlobalExceptionHandler unitUnderTest; + + @Test + void handleNotFoundException() { + val result = unitUnderTest.handleNotFoundException(new NotFoundException(UUID.randomUUID(), Object.class)); + + Assertions.assertThat(result).isEqualTo(ResponseEntity.notFound().build()); + } + +} From 14c98e72989dc93946c248dd1585df42883a5288 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 08:57:07 +0200 Subject: [PATCH 31/41] fix missing joincolumn --- .../eaiservice/domain/wahlvorstand/Wahlvorstand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java index 4f503f68..0ba36db9 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstand.java @@ -5,6 +5,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.validation.constraints.NotNull; import java.util.Collection; @@ -32,6 +33,7 @@ public class Wahlvorstand extends BaseEntity { private UUID wahlbezirkID; @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "wahlvorstandid") private Collection mitglieder; } From 49e0219560e4b08c157fb88fc7c98311fcea8e42 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:15:40 +0200 Subject: [PATCH 32/41] remove http status annotation because its default --- .../eaiservice/rest/wahlvorstand/WahlvorstandController.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index cad86aa2..b58c6c53 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -4,13 +4,11 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @RestController @@ -27,7 +25,6 @@ public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") } @PutMapping("anwesenheit") - @ResponseStatus(HttpStatus.OK) public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); } From 5c354653963e5cb882e45650dffa2163b4f6d266 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:17:38 +0200 Subject: [PATCH 33/41] add operation description --- .../eaiservice/rest/wahlvorstand/WahlvorstandController.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java index b58c6c53..b6140507 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandController.java @@ -3,6 +3,7 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -19,12 +20,14 @@ public class WahlvorstandController { private final WahlvorstandService wahlvorstandService; @GetMapping + @Operation(description = "Abrufen des Wahlvorstandes für einen bestimmten Wahlbezirk") public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID") String wahlbezirkID) { return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID); } @PutMapping("anwesenheit") + @Operation(description = "Aktualisieren der Anwesenheit der Wahlvorstandsmitglieder eines bestimmten Wahlbezirkes") public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) { wahlvorstandService.setAnwesenheit(wahlvorstand); } From b8f819fee25275276289011b20f31fd373027280 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:51:17 +0200 Subject: [PATCH 34/41] fix testname --- .../eaiservice/configuration/SecurityConfigurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java index 0bb9f7e1..08edbc33 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/configuration/SecurityConfigurationTest.java @@ -110,7 +110,7 @@ void accessSaveAnwesenheitUnauthorizedThenUnauthorized() throws Exception { @Test @WithMockUser - void accessSaveAnwesenheitAuthorizedThenCreated() throws Exception { + void accessSaveAnwesenheitAuthorizedThenOk() throws Exception { val wahlvorstandAktualisierung = new WahlvorstandsaktualisierungDTO("wbzID", Set.of(new WahlvorstandsmitgliedAktualisierungDTO("id", true)), LocalDateTime.now()); From 275031e5e14e35382fb8e1549c13cdd7b865cbea Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:52:25 +0200 Subject: [PATCH 35/41] remove empty line --- .../rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index e62d27ca..54fe44fe 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -185,7 +185,6 @@ void HttpStatusBadRequestWhenRequestIsInvalid() throws Exception { objectMapper.writeValueAsString(aktualisierung)); api.perform(request).andExpect(status().isBadRequest()); - } } From 1bed2c8fc2cee1af48ef210ceda5b4fa78c56142 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:15:13 +0200 Subject: [PATCH 36/41] ignore AbbreviationAsWordInName on method --- wls-eai-service/checkstyle.xml | 5 +++++ .../eaiservice/service/wahlvorstand/WahlvorstandService.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/wls-eai-service/checkstyle.xml b/wls-eai-service/checkstyle.xml index 37f7f0e7..14f0ae03 100644 --- a/wls-eai-service/checkstyle.xml +++ b/wls-eai-service/checkstyle.xml @@ -14,6 +14,11 @@ + + + + + diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index 207e4985..561b47c8 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -58,7 +58,9 @@ private void updateAnwesenheitOfWahlvorstandsmitglied(final LocalDateTime timeOf mitglied.setAnwesend(mitgliedUpdateData.anwesend()); } + //CHECKSTYLE.OFF: AbbreviationAsWordInName - illegal match cause UUID should not be shortened private UUID convertIDToUUIDOrThrow(final String id) { + //CHECKSTYLE.ON: AbbreviationAsWordInName try { return UUID.fromString(id); } catch (final IllegalArgumentException illegalArgumentException) { From af55421d43054bf8b1f05963d4268626cd59cc60 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:53:20 +0200 Subject: [PATCH 37/41] add missing oracle sql files --- .../oracle/V1_1__wahlvorstandTestdaten.sql | 74 +++++++++++++++++++ .../oracle/V1_0__createWahlvorstand.sql | 22 ++++++ 2 files changed, 96 insertions(+) create mode 100644 wls-eai-service/src/main/resources/db/dummydata/oracle/V1_1__wahlvorstandTestdaten.sql create mode 100644 wls-eai-service/src/main/resources/db/migrations/oracle/V1_0__createWahlvorstand.sql diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V1_1__wahlvorstandTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V1_1__wahlvorstandTestdaten.sql new file mode 100644 index 00000000..b84ba42b --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V1_1__wahlvorstandTestdaten.sql @@ -0,0 +1,74 @@ +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0000-0000-000000000001'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000001', 'Homer', 'Simpson', 'W', 0, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000002', 'Marge', 'Simpson', 'SB', 0, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000003', 'Bart', 'Simpson', 'SWB', 0, + '00000000-0000-0000-0001-000000000001', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000004', 'Lisa', 'Simpson', 'SSB', 0, '00000000-0000-0000-0001-000000000001', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0001-000000000005', 'Maggie', 'Simpson', 'B', 0, '00000000-0000-0000-0001-000000000001', + null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000002', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000001', 'Peter', 'Griffin', 'W', 0, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000002', 'Lois', 'Griffin', 'SB', 0, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000003', 'Megan', 'Griffin', 'SWB', 0, + '00000000-0000-0000-0001-000000000002', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000004', 'Christopher', 'Griffin', 'SSB', 0, + '00000000-0000-0000-0001-000000000002', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000005', 'Stewie', 'Griffin', 'B', 0, '00000000-0000-0000-0001-000000000002', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0002-000000000006', 'Brian', 'Griffin', 'B', 0, '00000000-0000-0000-0001-000000000002', + null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000003', '00000000-0000-0000-0000-000000000003'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000001', 'Grace', 'Hopper', 'W', 0, '00000000-0000-0000-0001-000000000003', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000002', 'Ada', 'Lovelace', 'SB', 0, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000003', 'Konrad', 'Zuse', 'SWB', 0, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000004', 'Alan', 'Turing', 'SSB', 0, + '00000000-0000-0000-0001-000000000003', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0003-000000000005', 'Hedy', 'Lamarr', 'B', 0, + '00000000-0000-0000-0001-000000000003', null); + +INSERT INTO wahlvorstand +VALUES ('00000000-0000-0000-0001-000000000004', '00000000-0000-0000-0000-000000000004'); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000001', 'Diana', 'Prince', 'W', 0, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000002', 'Clark', 'Kent', 'SB', 0, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000003', 'Bruce', 'Wayne', 'SWB', 0, + '00000000-0000-0000-0001-000000000004', null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000004', 'Barry', 'Allen', 'SSB', 0, '00000000-0000-0000-0001-000000000004', + null); +INSERT INTO wahlvorstandsmitglied +VALUES ('00000000-0000-0000-0004-000000000005', 'Arthur', 'Curry', 'B', 0, '00000000-0000-0000-0001-000000000004', + null); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V1_0__createWahlvorstand.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V1_0__createWahlvorstand.sql new file mode 100644 index 00000000..4d48f5af --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V1_0__createWahlvorstand.sql @@ -0,0 +1,22 @@ +CREATE TABLE wahlvorstand +( + id VARCHAR2(36) NOT NULL, + wahlbezirkID VARCHAR2(36) NOT NULL, + + PRIMARY KEY (id) +); + +CREATE TABLE wahlvorstandsmitglied +( + id VARCHAR2(36) NOT NULL, + vorname VARCHAR2(255) NOT NULL, + nachname VARCHAR2(255) NOT NULL, + funktion VARCHAR2(512) NOT NULL, + anwesend NUMBER NOT NULL, + wahlvorstandID VARCHAR2(36) NOT NULL, + anwesenheitUpdatedOn TIMESTAMP, + + FOREIGN KEY (wahlvorstandID) REFERENCES wahlvorstand (id), + + PRIMARY KEY (id) +) \ No newline at end of file From c47f99791311e4fb4b03828d40dae4979c050130 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:53:51 +0200 Subject: [PATCH 38/41] fix wrong method and path in example requests --- .../resources/httpRequests/wahlvorstand.http | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http index b5ed9181..bf8e6061 100644 --- a/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http +++ b/wls-eai-service/src/test/resources/httpRequests/wahlvorstand.http @@ -36,8 +36,8 @@ Authorization: {{ token_type }} {{ auth_token }} GET {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende?wahlbezirkID=00000000-9999-0000-0000-000000000000 Authorization: {{ token_type }} {{ auth_token }} -### POST Update Wahlvorstand wbz4 -POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +### PUT Update Wahlvorstand wbz4 +PUT {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende/anwesenheit Authorization: {{ token_type }} {{ auth_token }} Content-Type: application/json @@ -68,8 +68,8 @@ Content-Type: application/json ] } -### POST Update - bezirkID fehlt -POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +### PUT Update - bezirkID fehlt +PUT {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende/anwesenheit Authorization: {{ token_type }} {{ auth_token }} Content-Type: application/json @@ -99,8 +99,8 @@ Content-Type: application/json ] } -### POST Update - anwesenheitBeginn fehlt -POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +### PUT Update - anwesenheitBeginn fehlt +PUT {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende/anwesenheit Authorization: {{ token_type }} {{ auth_token }} Content-Type: application/json @@ -130,8 +130,8 @@ Content-Type: application/json ] } -### POST Update - Identifikator fehlt -POST {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende +### PUT Update - Identifikator fehlt +PUT {{ WLS_EAI_SERVICE_URL }}/wahlvorstaende/anwesenheit Authorization: {{ token_type }} {{ auth_token }} Content-Type: application/json From 612fc822de4c170a8ea7b698cf0373f3c5243212 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:56:53 +0200 Subject: [PATCH 39/41] streamline naming in validator --- .../wahlvorstand/WahlvorstandService.java | 2 +- .../wahlvorstand/WahlvorstandValidator.java | 2 +- .../wahlvorstand/WahlvorstandServiceTest.java | 2 +- .../WahlvorstandValidatorTest.java | 20 +++++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index 561b47c8..3b2c971c 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -37,7 +37,7 @@ public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveAnwesenheit')") public void setAnwesenheit(final WahlvorstandsaktualisierungDTO aktualisierung) { - wahlvorstandValidator.valideSaveAnwesenheitDataOrThrow(aktualisierung); + wahlvorstandValidator.validateSaveAnwesenheitDataOrThrow(aktualisierung); val wahlvorstandToUpdate = findByWahlbezirkIDOrThrow(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); updateAnwesenheitOfWahlvorstand(aktualisierung, wahlvorstandToUpdate); diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java index e6eeead1..9bf8fa60 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidator.java @@ -19,7 +19,7 @@ public void validateWahlbezirkIDOrThrow(final String wahlbezirkID) { } } - public void valideSaveAnwesenheitDataOrThrow(final WahlvorstandsaktualisierungDTO saveAnwesenheitData) { + public void validateSaveAnwesenheitDataOrThrow(final WahlvorstandsaktualisierungDTO saveAnwesenheitData) { if (saveAnwesenheitData == null) { throw exceptionFactory.createFachlicheWlsException( de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN); diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index 8428be1a..f7856127 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -154,7 +154,7 @@ void validationFailed() { val mockedValidationException = new RuntimeException("validation failed"); - Mockito.doThrow(mockedValidationException).when(wahlvorstandValidator).valideSaveAnwesenheitDataOrThrow(aktualisierung); + Mockito.doThrow(mockedValidationException).when(wahlvorstandValidator).validateSaveAnwesenheitDataOrThrow(aktualisierung); Assertions.assertThatException().isThrownBy(() -> unitUnderTest.setAnwesenheit(aktualisierung)).isSameAs(mockedValidationException); } diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java index d69c3916..ba43dba8 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandValidatorTest.java @@ -65,13 +65,13 @@ void exceptionWhenIDIsBlankString() { } @Nested - class ValideSaveAnwesenheitDataOrThrow { + class ValidateSaveAnwesenheitDataOrThrow { @Test void noExceptionWhenAktualisierungIsValid() { val validDTO = initValidAktualisierung().build(); - Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(validDTO)); + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(validDTO)); } @Test @@ -81,7 +81,7 @@ void exceptionWhenAktualisierungIsNull() { de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(null)).isSameAs(mockedValidationException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(null)).isSameAs(mockedValidationException); } @Test @@ -92,7 +92,7 @@ void exceptionWhenWahlbezirkIdIsNull() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); } @Test @@ -103,7 +103,7 @@ void exceptionWhenWahlbezirkIdIsEmpty() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); } @Test @@ -114,7 +114,7 @@ void exceptionWhenWahlbezirkIdIsBlank() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_BEZIRKID_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); } @Test @@ -125,7 +125,7 @@ void exceptionWhenAnwesenheitBeginnIsNull() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_ANWESENHEITBEGINN_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)).isSameAs(mockedValidationException); } @@ -141,7 +141,7 @@ void isNull() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)) .isSameAs(mockedValidationException); } @@ -154,7 +154,7 @@ void isEmptyString() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)) .isSameAs(mockedValidationException); } @@ -167,7 +167,7 @@ void isBankString() { Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEANWESENHEIT_IDENTIFIKATOR_FEHLT)) .thenReturn(mockedValidationException); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.valideSaveAnwesenheitDataOrThrow(invalidDTO)) + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validateSaveAnwesenheitDataOrThrow(invalidDTO)) .isSameAs(mockedValidationException); } } From a0a62d6f73c2a41db4f31e2a22996ffd4b5d9e4e Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:02:15 +0200 Subject: [PATCH 40/41] improve naming of class --- .../wahlvorstand/Wahlvorstandsmitglied.java | 2 +- ...va => WahlvorstandsmitgliedsFunktion.java} | 2 +- .../dto/WahlvorstandsmitgliedDTO.java | 2 +- ...=> WahlvorstandsmitgliedsFunktionDTO.java} | 2 +- ...WahlvorstandControllerIntegrationTest.java | 22 +++++++++---------- .../wahlvorstand/WahlvorstandMapperTest.java | 14 +++++++----- .../wahlvorstand/WahlvorstandServiceTest.java | 10 ++++----- 7 files changed, 28 insertions(+), 26 deletions(-) rename wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/{WahlvorstandFunktion.java => WahlvorstandsmitgliedsFunktion.java} (84%) rename wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/{WahlvorstandFunktionDTO.java => WahlvorstandsmitgliedsFunktionDTO.java} (83%) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java index bc2c792d..897ee872 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/Wahlvorstandsmitglied.java @@ -33,7 +33,7 @@ public class Wahlvorstandsmitglied extends BaseEntity { @NotNull @ToString.Include @Enumerated(EnumType.STRING) - private WahlvorstandFunktion funktion; + private WahlvorstandsmitgliedsFunktion funktion; @ToString.Include private boolean anwesend; diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandsmitgliedsFunktion.java similarity index 84% rename from wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java rename to wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandsmitgliedsFunktion.java index 3616dda2..d25698de 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandFunktion.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlvorstand/WahlvorstandsmitgliedsFunktion.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand; -public enum WahlvorstandFunktion { +public enum WahlvorstandsmitgliedsFunktion { W, //Wahlvorsteher*in SB, //Schriftführer*in SWB, //Stellvertretung Wahlvorsteher*in diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java index 138fcc65..1218eb5e 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedDTO.java @@ -8,6 +8,6 @@ public record WahlvorstandsmitgliedDTO(@NotNull String identifikator, @NotNull String vorname, @NotNull String nachname, - @NotNull WahlvorstandFunktionDTO funktion, + @NotNull WahlvorstandsmitgliedsFunktionDTO funktion, @Schema(requiredMode = Schema.RequiredMode.REQUIRED) boolean anwesend) { } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedsFunktionDTO.java similarity index 83% rename from wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java rename to wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedsFunktionDTO.java index 62e4cbcf..8959983e 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandFunktionDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/dto/WahlvorstandsmitgliedsFunktionDTO.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto; -public enum WahlvorstandFunktionDTO { +public enum WahlvorstandsmitgliedsFunktionDTO { W, //Wahlvorsteher*in SB, //Schriftführer*in SWB, //Stellvertretung Wahlvorsteher*in diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java index 54fe44fe..bd96fb51 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahlvorstand/WahlvorstandControllerIntegrationTest.java @@ -8,9 +8,9 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; -import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandsmitgliedsFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; @@ -89,14 +89,14 @@ void noDataFound() throws Exception { void dataFound() throws Exception { val wahlbezirkID1 = UUID.randomUUID(); val wahlvorstand1 = new Wahlvorstand(wahlbezirkID1, - Set.of(new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, true, LocalDateTime.now()), - new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, false, LocalDateTime.now()))); + Set.of(new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandsmitgliedsFunktion.B, true, LocalDateTime.now()), + new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandsmitgliedsFunktion.SWB, false, LocalDateTime.now()))); val wahlvorstandToLoad = wahlvorstandRepository.save(wahlvorstand1); val wahlbezirkID2 = UUID.randomUUID(); val wahlvorstand2 = new Wahlvorstand(wahlbezirkID2, - Set.of(new Wahlvorstandsmitglied("vorname21", "nachname21", WahlvorstandFunktion.B, true, LocalDateTime.now()), - new Wahlvorstandsmitglied("vorname22", "nachname22", WahlvorstandFunktion.SWB, false, LocalDateTime.now()))); + Set.of(new Wahlvorstandsmitglied("vorname21", "nachname21", WahlvorstandsmitgliedsFunktion.B, true, LocalDateTime.now()), + new Wahlvorstandsmitglied("vorname22", "nachname22", WahlvorstandsmitgliedsFunktion.SWB, false, LocalDateTime.now()))); wahlvorstandRepository.save(wahlvorstand2); val request = MockMvcRequestBuilders.get("/wahlvorstaende?wahlbezirkID=" + wahlvorstandToLoad.getWahlbezirkID()); @@ -133,9 +133,9 @@ class SaveAnwesenheit { void personsAreUpdated() throws Exception { val wahlbezirkID = UUID.randomUUID(); val oldUpdatedDate = LocalDateTime.now().minusDays(1); - val mitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, true, oldUpdatedDate); - val mitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, false, oldUpdatedDate); - val mitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandFunktion.SWB, false, oldUpdatedDate); + val mitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandsmitgliedsFunktion.B, true, oldUpdatedDate); + val mitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandsmitgliedsFunktion.SWB, false, oldUpdatedDate); + val mitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandsmitgliedsFunktion.SWB, false, oldUpdatedDate); val wahlvorstand1 = new Wahlvorstand(wahlbezirkID, Set.of(mitglied1, mitglied2, mitglied3)); val wahlvorstandToUpdate = wahlvorstandRepository.save(wahlvorstand1); @@ -150,11 +150,11 @@ void personsAreUpdated() throws Exception { api.perform(request).andExpect(status().isOk()); val updatedEntity = wahlvorstandRepository.findById(wahlvorstandToUpdate.getId()); - val expectedEntityMitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandFunktion.B, false, updateDateTime); + val expectedEntityMitglied1 = new Wahlvorstandsmitglied("vorname11", "nachname11", WahlvorstandsmitgliedsFunktion.B, false, updateDateTime); expectedEntityMitglied1.setId(mitglied1.getId()); - val expectedEntityMitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandFunktion.SWB, true, updateDateTime); + val expectedEntityMitglied2 = new Wahlvorstandsmitglied("vorname12", "nachname12", WahlvorstandsmitgliedsFunktion.SWB, true, updateDateTime); expectedEntityMitglied2.setId(mitglied2.getId()); - val expectedEntityMitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandFunktion.SWB, false, oldUpdatedDate); + val expectedEntityMitglied3 = new Wahlvorstandsmitglied("vorname13", "nachname13", WahlvorstandsmitgliedsFunktion.SWB, false, oldUpdatedDate); expectedEntityMitglied3.setId(mitglied3.getId()); val expectedUpdatedEntity = new Wahlvorstand(wahlbezirkID, Set.of(expectedEntityMitglied1, expectedEntityMitglied2, expectedEntityMitglied3)); expectedUpdatedEntity.setId(wahlvorstandToUpdate.getId()); diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java index e51dd6c9..9c2cef97 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandMapperTest.java @@ -1,11 +1,11 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; -import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandsmitgliedsFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandFunktionDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedsFunktionDTO; import java.time.LocalDateTime; import java.util.Set; import java.util.UUID; @@ -21,9 +21,9 @@ class WahlvorstandMapperTest { @Test void toDTO() { val wahlbezirkID = UUID.randomUUID(); - val mitglied1 = new Wahlvorstandsmitglied("vorname1", "nachname1", WahlvorstandFunktion.SWB, true, LocalDateTime.now()); + val mitglied1 = new Wahlvorstandsmitglied("vorname1", "nachname1", WahlvorstandsmitgliedsFunktion.SWB, true, LocalDateTime.now()); mitglied1.setId(UUID.randomUUID()); - val mitglied2 = new Wahlvorstandsmitglied("vorname2", "nachname2", WahlvorstandFunktion.B, false, LocalDateTime.now().minusDays(1)); + val mitglied2 = new Wahlvorstandsmitglied("vorname2", "nachname2", WahlvorstandsmitgliedsFunktion.B, false, LocalDateTime.now().minusDays(1)); mitglied2.setId(UUID.randomUUID()); val mitglieder = Set.of(mitglied1, mitglied2); val entityToMap = new Wahlvorstand(wahlbezirkID, mitglieder); @@ -31,8 +31,10 @@ void toDTO() { val result = unitUnderTest.toDTO(entityToMap); val expectedMitglieder = Set.of( - new WahlvorstandsmitgliedDTO(mitglied1.getId().toString(), mitglied1.getVorname(), mitglied1.getNachname(), WahlvorstandFunktionDTO.SWB, true), - new WahlvorstandsmitgliedDTO(mitglied2.getId().toString(), mitglied2.getVorname(), mitglied2.getNachname(), WahlvorstandFunktionDTO.B, false)); + new WahlvorstandsmitgliedDTO(mitglied1.getId().toString(), mitglied1.getVorname(), mitglied1.getNachname(), + WahlvorstandsmitgliedsFunktionDTO.SWB, true), + new WahlvorstandsmitgliedDTO(mitglied2.getId().toString(), mitglied2.getVorname(), mitglied2.getNachname(), WahlvorstandsmitgliedsFunktionDTO.B, + false)); val expectedResult = new WahlvorstandDTO(wahlbezirkID.toString(), expectedMitglieder); Assertions.assertThat(result).isEqualTo(expectedResult); diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index f7856127..6587d788 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -1,9 +1,9 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstand; -import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandsmitgliedsFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; @@ -109,10 +109,10 @@ void existingDataIsUpdated() { val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitgliederAktualisierung, LocalDateTime.now()); val mockedEntityLastSavedDateTime = LocalDateTime.now().minusDays(1); - val mockedEntityMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.B, false, mockedEntityLastSavedDateTime); + val mockedEntityMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandsmitgliedsFunktion.B, false, mockedEntityLastSavedDateTime); mockedEntityMitglied1.setId(UUID.fromString(mitglied1.identifikator())); // no mitglied2 is intended because request should match only a subset of existing data - val mockedEntityMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.SWB, true, mockedEntityLastSavedDateTime); + val mockedEntityMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandsmitgliedsFunktion.SWB, true, mockedEntityLastSavedDateTime); mockedEntityMitglied3.setId(UUID.randomUUID()); val mockedEntity = new Wahlvorstand(wahlbezirkID, Set.of(mockedEntityMitglied1, mockedEntityMitglied3)); @@ -124,9 +124,9 @@ void existingDataIsUpdated() { Mockito.verify(wahlvorstandRepository).save(saveArgumentCaptor.capture()); val capturedSavedArgument = saveArgumentCaptor.getValue(); - val expectedMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.B, true, aktualisierung.anwesenheitBeginn()); + val expectedMitglied1 = new Wahlvorstandsmitglied("", "", WahlvorstandsmitgliedsFunktion.B, true, aktualisierung.anwesenheitBeginn()); expectedMitglied1.setId(UUID.fromString(mitglied1.identifikator())); - val expectedMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandFunktion.SWB, true, mockedEntityLastSavedDateTime); + val expectedMitglied3 = new Wahlvorstandsmitglied("", "", WahlvorstandsmitgliedsFunktion.SWB, true, mockedEntityLastSavedDateTime); expectedMitglied3.setId(mockedEntityMitglied3.getId()); val expectedSavedArgument = new Wahlvorstand(wahlbezirkID, Set.of(expectedMitglied1, expectedMitglied3)); Assertions.assertThat(capturedSavedArgument).isEqualTo(expectedSavedArgument); From e535dd6b49ab0b7da0d034e8b689e5d68dadf441 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:09:47 +0200 Subject: [PATCH 41/41] remove unnecessary full qualified classname --- .../eaiservice/rest/common/exception/ExceptionConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java index e46683c9..16096ad2 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/common/exception/ExceptionConstants.java @@ -14,7 +14,7 @@ public class ExceptionConstants { MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN); private static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103"; - public static final de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper ID_NICHT_KONVERTIERBAR = new de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper( + public static final ExceptionDataWrapper ID_NICHT_KONVERTIERBAR = new ExceptionDataWrapper( CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR, ""); /**