generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from it-at-m/155-implementierung-wahlbeteiligung
155 implementierung wahlbeteiligung
- Loading branch information
Showing
21 changed files
with
743 additions
and
32 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
stack/keycloak/migration/add-authorities-eai-wahlbeteiligung.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
id: add authorities eai wahlbeteiligung | ||
author: dragonfly28 | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addRole: | ||
name: aoueai_BUSINESSACTION_SaveWahlbeteiligung | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allEaiAuthorities | ||
role: aoueai_BUSINESSACTION_SaveWahlbeteiligung | ||
clientId: ${SSO_CLIENT_ID} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...va/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahlbeteiligung/Wahlbeteiligung.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung; | ||
|
||
import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; | ||
import jakarta.persistence.Entity; | ||
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) | ||
@ToString(onlyExplicitlyIncluded = true, callSuper = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Wahlbeteiligung extends BaseEntity { | ||
|
||
@NotNull | ||
@ToString.Include | ||
String wahlID; | ||
|
||
@NotNull | ||
@ToString.Include | ||
String wahlbezirkID; | ||
|
||
@NotNull | ||
@ToString.Include | ||
long anzahlWaehler; | ||
|
||
@NotNull | ||
@ToString.Include | ||
LocalDateTime meldeZeitpunkt; | ||
} |
7 changes: 7 additions & 0 deletions
7
...chen/oss/wahllokalsystem/eaiservice/domain/wahlbeteiligung/WahlbeteiligungRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung; | ||
|
||
import java.util.UUID; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface WahlbeteiligungRepository extends CrudRepository<Wahlbeteiligung, UUID> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
...hen/oss/wahllokalsystem/eaiservice/rest/wahlbeteiligung/exception/ExceptionConstants.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...uenchen/oss/wahllokalsystem/eaiservice/service/wahlbeteiligung/WahlbeteiligungMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlbeteiligung; | ||
|
||
import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung.Wahlbeteiligung; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto.WahlbeteiligungsMeldungDTO; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface WahlbeteiligungMapper { | ||
|
||
WahlbeteiligungsMeldungDTO toDTO(Wahlbeteiligung entity); | ||
|
||
@Mapping(target = "id", ignore = true) | ||
Wahlbeteiligung toEntity(WahlbeteiligungsMeldungDTO dto); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...enchen/oss/wahllokalsystem/eaiservice/service/wahlbeteiligung/WahlbeteiligungService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlbeteiligung; | ||
|
||
import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung.WahlbeteiligungRepository; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto.WahlbeteiligungsMeldungDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.parameters.P; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class WahlbeteiligungService { | ||
|
||
private final WahlbeteiligungRepository wahlbeteiligungRepository; | ||
|
||
private final WahlbeteiligungMapper wahlbeteiligungMapper; | ||
|
||
private final WahlbeteiligungValidator wahlbeteiligungValidator; | ||
|
||
@PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_SaveWahlbeteiligung')") | ||
public void saveWahlbeteiligung(@P("wahlbeteiligungToSet") final WahlbeteiligungsMeldungDTO wahlbeteiligungToSet) { | ||
log.debug("#saveWahlbeteiligung"); | ||
|
||
wahlbeteiligungValidator.validDTOToSetOrThrow(wahlbeteiligungToSet); | ||
|
||
wahlbeteiligungRepository.save(wahlbeteiligungMapper.toEntity(wahlbeteiligungToSet)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...chen/oss/wahllokalsystem/eaiservice/service/wahlbeteiligung/WahlbeteiligungValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlbeteiligung; | ||
|
||
import de.muenchen.oss.wahllokalsystem.eaiservice.exception.ExceptionConstants; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto.WahlbeteiligungsMeldungDTO; | ||
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 WahlbeteiligungValidator { | ||
|
||
private final ExceptionFactory exceptionFactory; | ||
|
||
public void validDTOToSetOrThrow(WahlbeteiligungsMeldungDTO wahlbeteiligungToSet) { | ||
if (wahlbeteiligungToSet == null) { | ||
throw exceptionFactory.createFachlicheWlsException( | ||
de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN); | ||
} | ||
|
||
if (StringUtils.isBlank(wahlbeteiligungToSet.wahlbezirkID())) { | ||
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT); | ||
} | ||
|
||
if (StringUtils.isBlank(wahlbeteiligungToSet.wahlID())) { | ||
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEWAHLBETEILIGUNG_WAHLID_FEHLT); | ||
} | ||
|
||
if (wahlbeteiligungToSet.meldeZeitpunkt() == null) { | ||
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
wls-eai-service/src/main/resources/db/migrations/h2/V3_7__createWahlbeteiligung.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE wahlbeteiligung | ||
( | ||
id VARCHAR2(36) NOT NULL, | ||
wahlbezirkID VARCHAR2(36) NOT NULL, | ||
wahlID VARCHAR2(36) NOT NULL, | ||
anzahlWaehler BIGINT NOT NULL, | ||
meldeZeitpunkt TIMESTAMP NOT NULL, | ||
|
||
PRIMARY KEY (id) | ||
); |
10 changes: 10 additions & 0 deletions
10
wls-eai-service/src/main/resources/db/migrations/oracle/V3_7__createWahlbeteiligung.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE wahlbeteiligung | ||
( | ||
id VARCHAR2(36) NOT NULL, | ||
wahlbezirkID VARCHAR2(36) NOT NULL, | ||
wahlID VARCHAR2(36) NOT NULL, | ||
anzahlWaehler NUMBER NOT NULL, | ||
meldeZeitpunkt TIMESTAMP NOT NULL, | ||
|
||
PRIMARY KEY (id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...lokalsystem/eaiservice/rest/wahlbeteiligung/WahlbeteiligungControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung; | ||
|
||
import static de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants.SPRING_TEST_PROFILE; | ||
import static org.mockito.ArgumentMatchers.any; | ||
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; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung.Wahlbeteiligung; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlbeteiligung.WahlbeteiligungRepository; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto.WahlbeteiligungsMeldungDTO; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlbeteiligung.WahlbeteiligungMapper; | ||
import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlbeteiligung.WahlbeteiligungValidator; | ||
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 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.mockito.Mockito; | ||
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.boot.test.mock.mockito.SpyBean; | ||
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; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@SpringBootTest(classes = MicroServiceApplication.class) | ||
@AutoConfigureMockMvc | ||
@ActiveProfiles(profiles = { SPRING_TEST_PROFILE }) | ||
public class WahlbeteiligungControllerIntegrationTest { | ||
|
||
@Value("${service.info.oid}") | ||
String serviceInfoOid; | ||
|
||
@Autowired | ||
MockMvc api; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
WahlbeteiligungRepository wahlbeteiligungRepository; | ||
|
||
@Autowired | ||
WahlbeteiligungMapper wahlbeteiligungMapper; | ||
|
||
@SpyBean | ||
WahlbeteiligungValidator wahlbeteiligungValidator; | ||
|
||
@Autowired | ||
ExceptionFactory exceptionFactory; | ||
|
||
@Autowired | ||
EntityManager entityManager; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
wahlbeteiligungRepository.deleteAll(); | ||
} | ||
|
||
@Nested | ||
class SaveWahlbeteiligungsMeldung { | ||
|
||
@Test | ||
@WithMockUser(authorities = Authorities.SERVICE_SAVE_WAHLBETEILIGUNG) | ||
@Transactional | ||
void meldungIsSaved() throws Exception { | ||
val wahlID = "wahlID1"; | ||
val wahlbezirkID = "00000000-0000-0000-0000-000000000001"; | ||
val anzahlWaehler = 150; | ||
val meldeZeitpunkt = LocalDateTime.now(); | ||
|
||
val requestBody = new WahlbeteiligungsMeldungDTO(wahlID, wahlbezirkID, anzahlWaehler, meldeZeitpunkt); | ||
val request = MockMvcRequestBuilders.post("/wahlbeteiligung").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( | ||
objectMapper.writeValueAsString(requestBody)); | ||
|
||
val response = api.perform(request).andExpect(status().isOk()).andReturn(); | ||
|
||
val savedWahlbeteiligung = wahlbeteiligungRepository.findAll().iterator().next(); | ||
|
||
Assertions.assertThat(response.getResponse().getContentAsString()).isEmpty(); | ||
|
||
val expectedSavedWahlbeteiligung = new Wahlbeteiligung(requestBody.wahlID(), requestBody.wahlbezirkID(), requestBody.anzahlWaehler(), | ||
requestBody.meldeZeitpunkt()); | ||
|
||
Assertions.assertThat(savedWahlbeteiligung).usingRecursiveComparison().ignoringFields("id").isEqualTo(expectedSavedWahlbeteiligung); | ||
} | ||
|
||
@Test | ||
@WithMockUser(authorities = Authorities.SERVICE_SAVE_WAHLBETEILIGUNG) | ||
@Transactional | ||
void validationExceptionOccurredAndIsMapped() throws Exception { | ||
|
||
val wahlbezirkID = "00000000-0000-0000-0000-000000000001"; | ||
val anzahlWaehler = 150; | ||
val meldeZeitpunkt = LocalDateTime.now(); | ||
|
||
val requestBody = new WahlbeteiligungsMeldungDTO(null, wahlbezirkID, anzahlWaehler, meldeZeitpunkt); | ||
val request = MockMvcRequestBuilders.post("/wahlbeteiligung").with(csrf()).contentType(MediaType.APPLICATION_JSON).content( | ||
objectMapper.writeValueAsString(requestBody)); | ||
|
||
val mockedExceptionMessage = "mocked null pointer exception"; | ||
val mockedValidationException = new NullPointerException(mockedExceptionMessage); | ||
Mockito.doThrow(mockedValidationException).when(wahlbeteiligungValidator).validDTOToSetOrThrow(any()); | ||
|
||
val response = api.perform(request).andExpect(status().isInternalServerError()).andReturn(); | ||
val responseBodyDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WlsExceptionDTO.class); | ||
|
||
val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.T, "999", "EAI-SERVICE", ""); | ||
|
||
Assertions.assertThat(responseBodyDTO).usingRecursiveComparison().ignoringFields("message").isEqualTo(expectedWlsExceptionDTO); | ||
Assertions.assertThat(responseBodyDTO.message()).contains(mockedExceptionMessage); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.