From e9bc500e4f6f8b9b7a7638dbab5761498b6fc8e4 Mon Sep 17 00:00:00 2001 From: Nic12345678 <162564162+Nic12345678@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:14:39 +0200 Subject: [PATCH 1/3] TheEntity und BaseEntity entfernt --- .../briefwahlservice/domain/BaseEntity.java | 40 ------- .../briefwahlservice/domain/TheEntity.java | 43 ------- .../rest/TheEntityRepository.java | 112 ------------------ .../security/AuthoritiesEnum.java | 19 --- .../h2/V0_1__createTableTheEntity.sql | 5 - .../oracle/V0_1__createTableTheEntity.sql | 5 - .../briefwahlservice/TestConstants.java | 11 -- .../UnicodeConfigurationTest.java | 24 ---- .../rest/TheEntityRepositoryTest.java | 55 --------- 9 files changed, 314 deletions(-) delete mode 100644 wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/BaseEntity.java delete mode 100644 wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/TheEntity.java delete mode 100644 wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepository.java delete mode 100644 wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/security/AuthoritiesEnum.java delete mode 100644 wls-briefwahl-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql delete mode 100644 wls-briefwahl-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql delete mode 100644 wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepositoryTest.java diff --git a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/BaseEntity.java b/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/BaseEntity.java deleted file mode 100644 index 261aecd90..000000000 --- a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/BaseEntity.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.domain; - -import static java.sql.Types.VARCHAR; - -import jakarta.persistence.Column; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.MappedSuperclass; -import java.io.Serializable; -import java.util.UUID; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.JdbcTypeCode; - -@MappedSuperclass -@NoArgsConstructor -@Getter -@Setter -@ToString -@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") - @JdbcTypeCode(VARCHAR) - private UUID id; - -} diff --git a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/TheEntity.java b/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/TheEntity.java deleted file mode 100644 index 0a4389fc3..000000000 --- a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/domain/TheEntity.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.domain; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * This class represents a TheEntity. - *

- * The entity's content will be loaded according to the reference variable. - *

- */ -@Entity -// Definition of getter, setter, ... -@Getter -@Setter -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -@NoArgsConstructor -public class TheEntity extends BaseEntity { - - private static final long serialVersionUID = 1L; - - // ========= // - // Variables // - // ========= // - - @Column(name = "textattribute", nullable = false, length = 8) - @NotNull - @Size(min = 2, max = 8) - private String textAttribute; - -} diff --git a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepository.java b/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepository.java deleted file mode 100644 index a66536f88..000000000 --- a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepository.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.rest; - -import de.muenchen.oss.wahllokalsystem.briefwahlservice.domain.TheEntity; -import java.util.Optional; -import java.util.UUID; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.data.repository.CrudRepository; -import org.springframework.security.access.prepost.PreAuthorize; - -/** - * Provides a Repository for {@link TheEntity}. This Repository is exported as a REST resource. - *

- * The Repository handles CRUD Operations. Every Operation is secured and takes care of the tenancy. - * For specific Documentation on how the generated REST point - * behaves, please consider the Spring Data Rest Reference - * here. - *

- */ -@PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_READ_THEENTITY.name())") -public interface TheEntityRepository extends CrudRepository { //NOSONAR - - /** - * Name for the specific cache. - */ - String CACHE = "THEENTITY_CACHE"; - - /** - * Get one specific {@link TheEntity} by its unique id. - * - * @param id The identifier of the {@link TheEntity}. - * @return The {@link TheEntity} with the requested id. - */ - @Override - @Cacheable(value = CACHE, key = "#p0") - Optional findById(UUID id); - - /** - * Create or update a {@link TheEntity}. - *

- * If the id already exists, the {@link TheEntity} will be overridden, hence update. If the id does - * not already exist, a new {@link TheEntity} will be - * created, hence create. - *

- * - * @param theEntity The {@link TheEntity} that will be saved. - * @return the saved {@link TheEntity}. - */ - @Override - @CachePut(value = CACHE, key = "#p0.id") - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_WRITE_THEENTITY.name())") - S save(S theEntity); - - /** - * Create or update a collection of {@link TheEntity}. - *

- * If the id already exists, the {@link TheEntity}s will be overridden, hence update. If the id does - * not already exist, the new {@link TheEntity}s will be - * created, hence create. - *

- * - * @param entities The {@link TheEntity} that will be saved. - * @return the collection saved {@link TheEntity}. - */ - @Override - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_WRITE_THEENTITY.name())") - Iterable saveAll(Iterable entities); - - /** - * Delete the {@link TheEntity} by a specified id. - * - * @param id the unique id of the {@link TheEntity} that will be deleted. - */ - @Override - @CacheEvict(value = CACHE, key = "#p0") - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_DELETE_THEENTITY.name())") - void deleteById(UUID id); - - /** - * Delete a {@link TheEntity} by entity. - * - * @param entity The {@link TheEntity} that will be deleted. - */ - @Override - @CacheEvict(value = CACHE, key = "#p0.id") - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_DELETE_THEENTITY.name())") - void delete(TheEntity entity); - - /** - * Delete multiple {@link TheEntity} entities by their id. - * - * @param entities The Iterable of {@link TheEntity} that will be deleted. - */ - @Override - @CacheEvict(value = CACHE, allEntries = true) - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_DELETE_THEENTITY.name())") - void deleteAll(Iterable entities); - - /** - * Delete all {@link TheEntity} entities. - */ - @Override - @CacheEvict(value = CACHE, allEntries = true) - @PreAuthorize("hasAuthority(T(de.muenchen.oss.wahllokalsystem.briefwahlservice.security.AuthoritiesEnum).WLS_BRIEFWAHL_SERVICE_DELETE_THEENTITY.name())") - void deleteAll(); - -} diff --git a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/security/AuthoritiesEnum.java b/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/security/AuthoritiesEnum.java deleted file mode 100644 index 4dcc9c51e..000000000 --- a/wls-briefwahl-service/src/main/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/security/AuthoritiesEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.security; - -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.security.access.prepost.PreAuthorize; - -/** - * Each possible authority in this project is represented by an enum. The enums are used within the - * {@link PagingAndSortingRepository} in the annotation e.g. - * {@link PreAuthorize}. - */ -public enum AuthoritiesEnum { - WLS_BRIEFWAHL_SERVICE_READ_THEENTITY, WLS_BRIEFWAHL_SERVICE_WRITE_THEENTITY, WLS_BRIEFWAHL_SERVICE_DELETE_THEENTITY, - // add your authorities here and also add these new authorities to sso-authorisation.json. - -} diff --git a/wls-briefwahl-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql b/wls-briefwahl-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql deleted file mode 100644 index 1f2b83f72..000000000 --- a/wls-briefwahl-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE theEntity -( - id varchar2(36) NOT NULL primary key, - textAttribute varchar2(8) NOT NULL -) \ No newline at end of file diff --git a/wls-briefwahl-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql b/wls-briefwahl-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql deleted file mode 100644 index 1f2b83f72..000000000 --- a/wls-briefwahl-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE theEntity -( - id varchar2(36) NOT NULL primary key, - textAttribute varchar2(8) NOT NULL -) \ No newline at end of file diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java index 5d23a4b7c..969b0308d 100644 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java +++ b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java @@ -19,15 +19,4 @@ public final class TestConstants { public static final String SPRING_NO_SECURITY_PROFILE = "no-security"; - @NoArgsConstructor - @Getter - @Setter - @EqualsAndHashCode(callSuper = true) - @ToString(callSuper = true) - public static class TheEntityDto extends RepresentationModel { - - private String textAttribute; - - } - } diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java index d1df5d2f6..649b9a48c 100644 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java +++ b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java @@ -6,15 +6,8 @@ import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_NO_SECURITY_PROFILE; import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_TEST_PROFILE; -import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.TheEntityDto; -import static org.junit.jupiter.api.Assertions.assertEquals; import de.muenchen.oss.wahllokalsystem.briefwahlservice.MicroServiceApplication; -import de.muenchen.oss.wahllokalsystem.briefwahlservice.domain.TheEntity; -import de.muenchen.oss.wahllokalsystem.briefwahlservice.rest.TheEntityRepository; -import java.net.URI; -import java.util.UUID; -import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -48,29 +41,12 @@ class UnicodeConfigurationTest { @Autowired private TestRestTemplate testRestTemplate; - @Autowired - private TheEntityRepository theEntityRepository; - @Test @Disabled void testForNfcNormalization() { // Persist entity with decomposed string. - final TheEntityDto theEntityDto = new TheEntityDto(); - theEntityDto.setTextAttribute(TEXT_ATTRIBUTE_DECOMPOSED); - assertEquals(TEXT_ATTRIBUTE_DECOMPOSED.length(), theEntityDto.getTextAttribute().length()); - final TheEntityDto response = testRestTemplate.postForEntity(URI.create(ENTITY_ENDPOINT_URL), theEntityDto, TheEntityDto.class).getBody(); - - // Check whether response contains a composed string. - assertEquals(TEXT_ATTRIBUTE_COMPOSED, response.getTextAttribute()); - assertEquals(TEXT_ATTRIBUTE_COMPOSED.length(), response.getTextAttribute().length()); - // Extract uuid from self link. - final UUID uuid = UUID.fromString(StringUtils.substringAfterLast(response.getRequiredLink("self").getHref(), "/")); - // Check persisted entity contains a composed string via JPA repository. - final TheEntity theEntity = theEntityRepository.findById(uuid).orElse(null); - assertEquals(TEXT_ATTRIBUTE_COMPOSED, theEntity.getTextAttribute()); - assertEquals(TEXT_ATTRIBUTE_COMPOSED.length(), theEntity.getTextAttribute().length()); } } diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepositoryTest.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepositoryTest.java deleted file mode 100644 index 69ef7bf69..000000000 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/rest/TheEntityRepositoryTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.rest; - -import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_NO_SECURITY_PROFILE; -import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_TEST_PROFILE; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import de.muenchen.oss.wahllokalsystem.briefwahlservice.MicroServiceApplication; -import de.muenchen.oss.wahllokalsystem.briefwahlservice.domain.TheEntity; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -@SpringBootTest( - classes = { MicroServiceApplication.class }, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "spring.datasource.url=jdbc:h2:mem:wls;DB_CLOSE_ON_EXIT=FALSE", - "refarch.gracefulshutdown.pre-wait-seconds=0" - } -) -@ActiveProfiles(profiles = { SPRING_TEST_PROFILE, SPRING_NO_SECURITY_PROFILE }) -class TheEntityRepositoryTest { - - @Autowired - private TheEntityRepository repository; - - @Test - @Transactional(propagation = Propagation.REQUIRED, noRollbackFor = Exception.class) - void testSave() { - - // Implement your logic here by replacing and/or extending the code - - // initialize - TheEntity original = new TheEntity(); - original.setTextAttribute("test"); - - // persist - original = repository.save(original); - - // check - TheEntity persisted = repository.findById(original.getId()).orElse(null); - assertNotNull(persisted); - assertEquals(original, persisted); - - } - -} From 0f460a3ba57d1f82411dd988978d753a33349f7c Mon Sep 17 00:00:00 2001 From: Nic12345678 <162564162+Nic12345678@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:49:57 +0200 Subject: [PATCH 2/3] NfcTest enabled und implementiert, CacheControlTest removed TestConstants bereinigt --- .../briefwahlservice/TestConstants.java | 5 -- .../CacheControlConfigurationTest.java | 51 ------------------- .../UnicodeConfigurationTest.java | 34 +++++++++++-- 3 files changed, 31 insertions(+), 59 deletions(-) delete mode 100644 wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/CacheControlConfigurationTest.java diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java index 969b0308d..a1fa8ece2 100644 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java +++ b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/TestConstants.java @@ -5,12 +5,7 @@ package de.muenchen.oss.wahllokalsystem.briefwahlservice; import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import org.springframework.hateoas.RepresentationModel; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class TestConstants { diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/CacheControlConfigurationTest.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/CacheControlConfigurationTest.java deleted file mode 100644 index 1e2809db5..000000000 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/CacheControlConfigurationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik - * der Landeshauptstadt München, 2024 - */ -package de.muenchen.oss.wahllokalsystem.briefwahlservice.configuration; - -import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_NO_SECURITY_PROFILE; -import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_TEST_PROFILE; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import de.muenchen.oss.wahllokalsystem.briefwahlservice.MicroServiceApplication; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest( - classes = { MicroServiceApplication.class }, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "spring.datasource.url=jdbc:h2:mem:testexample;DB_CLOSE_ON_EXIT=FALSE", - "refarch.gracefulshutdown.pre-wait-seconds=0" - } -) -@ActiveProfiles(profiles = { SPRING_TEST_PROFILE, SPRING_NO_SECURITY_PROFILE }) -class CacheControlConfigurationTest { - - private static final String ENTITY_ENDPOINT_URL = "/theEntities"; - - private static final String EXPECTED_CACHE_CONTROL_HEADER_VALUES = "no-cache, no-store, must-revalidate"; - - @Autowired - private TestRestTemplate testRestTemplate; - - @Test - @Disabled - void testForCacheControlHeadersForEntityEndpoint() { - ResponseEntity response = testRestTemplate.exchange(ENTITY_ENDPOINT_URL, HttpMethod.GET, null, String.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertTrue(response.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL)); - assertEquals(EXPECTED_CACHE_CONTROL_HEADER_VALUES, response.getHeaders().getCacheControl()); - } - -} diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java index 649b9a48c..a369a49b6 100644 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java +++ b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java @@ -8,11 +8,18 @@ import static de.muenchen.oss.wahllokalsystem.briefwahlservice.TestConstants.SPRING_TEST_PROFILE; import de.muenchen.oss.wahllokalsystem.briefwahlservice.MicroServiceApplication; -import org.junit.jupiter.api.Disabled; +import de.muenchen.oss.wahllokalsystem.briefwahlservice.common.beanstandetewahlbriefe.Zurueckweisungsgrund; +import de.muenchen.oss.wahllokalsystem.briefwahlservice.domain.BeanstandeteWahlbriefeRepository; +import de.muenchen.oss.wahllokalsystem.briefwahlservice.rest.beanstandetewahlbriefe.BeanstandeteWahlbriefeDTO; +import java.net.URI; +import java.util.Map; +import lombok.val; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.data.util.Streamable; import org.springframework.test.context.ActiveProfiles; @SpringBootTest( @@ -26,7 +33,7 @@ @ActiveProfiles(profiles = { SPRING_TEST_PROFILE, SPRING_NO_SECURITY_PROFILE }) class UnicodeConfigurationTest { - private static final String ENTITY_ENDPOINT_URL = "/theEntities"; + private static final String BEANSTANDETE_WAHLBRIEFE_ENDPOINT_URL = "/businessActions/beanstandeteWahlbriefe/"; /** * Decomposed string: String "Ä-é" represented with unicode letters "A◌̈-e◌́" @@ -41,12 +48,33 @@ class UnicodeConfigurationTest { @Autowired private TestRestTemplate testRestTemplate; + @Autowired + private BeanstandeteWahlbriefeRepository beanstandeteWahlbriefeRepository; + @Test - @Disabled void testForNfcNormalization() { // Persist entity with decomposed string. + val wahlbezirkID = "wahlbezirkID"; + val waehlerVerzeichnisNummer = 1L; + val key1 = "key1"; + val key2 = "key2"; + val beanstandeteWahlbriefeDTO = createControllerBeanstandeteWahlbriefeDTO(wahlbezirkID, waehlerVerzeichnisNummer, key1, key2, TEXT_ATTRIBUTE_DECOMPOSED); + Assertions.assertThat((String)beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[0]).hasSize(key1.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); + Assertions.assertThat((String)beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[1]).hasSize(key2.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); + testRestTemplate.postForEntity(URI.create(BEANSTANDETE_WAHLBRIEFE_ENDPOINT_URL + wahlbezirkID + "/" + waehlerVerzeichnisNummer), beanstandeteWahlbriefeDTO, Void.class); + + val beantstandeteWahlbriefeInRepo = Streamable.of(beanstandeteWahlbriefeRepository.findAll()).toList(); + Assertions.assertThat(beantstandeteWahlbriefeInRepo).hasSize(1); + Assertions.assertThat(beantstandeteWahlbriefeInRepo.get(0).getBeanstandeteWahlbriefe().keySet().toArray()[0]).isEqualTo(key1 + TEXT_ATTRIBUTE_COMPOSED); + Assertions.assertThat(beantstandeteWahlbriefeInRepo.get(0).getBeanstandeteWahlbriefe().keySet().toArray()[1]).isEqualTo(key2 + TEXT_ATTRIBUTE_COMPOSED); + } + private BeanstandeteWahlbriefeDTO createControllerBeanstandeteWahlbriefeDTO(String wahlbezirkID, Long waehlerverzeichnisNummer, String key1, String key2, String textAttributeDecomposed) { + return new BeanstandeteWahlbriefeDTO(wahlbezirkID, waehlerverzeichnisNummer, + Map.of(key1 + textAttributeDecomposed, new Zurueckweisungsgrund[]{Zurueckweisungsgrund.NICHT_WAHLBERECHTIGT, Zurueckweisungsgrund.GEGENSTAND_IM_UMSCHLAG}, + key2 + textAttributeDecomposed, new Zurueckweisungsgrund[]{Zurueckweisungsgrund.UNTERSCHRIFT_FEHLT, Zurueckweisungsgrund.LOSE_STIMMZETTEL}) + ); } } From 63419c5ea688b295626933547802390311473869 Mon Sep 17 00:00:00 2001 From: Nic12345678 <162564162+Nic12345678@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:00:23 +0200 Subject: [PATCH 3/3] spotless fix --- .../UnicodeConfigurationTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java index a369a49b6..721b712ce 100644 --- a/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java +++ b/wls-briefwahl-service/src/test/java/de/muenchen/oss/wahllokalsystem/briefwahlservice/configuration/UnicodeConfigurationTest.java @@ -58,11 +58,15 @@ void testForNfcNormalization() { val waehlerVerzeichnisNummer = 1L; val key1 = "key1"; val key2 = "key2"; - val beanstandeteWahlbriefeDTO = createControllerBeanstandeteWahlbriefeDTO(wahlbezirkID, waehlerVerzeichnisNummer, key1, key2, TEXT_ATTRIBUTE_DECOMPOSED); - Assertions.assertThat((String)beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[0]).hasSize(key1.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); - Assertions.assertThat((String)beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[1]).hasSize(key2.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); + val beanstandeteWahlbriefeDTO = createControllerBeanstandeteWahlbriefeDTO(wahlbezirkID, waehlerVerzeichnisNummer, key1, key2, + TEXT_ATTRIBUTE_DECOMPOSED); + Assertions.assertThat((String) beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[0]) + .hasSize(key1.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); + Assertions.assertThat((String) beanstandeteWahlbriefeDTO.beanstandeteWahlbriefe().keySet().toArray()[1]) + .hasSize(key2.length() + TEXT_ATTRIBUTE_DECOMPOSED.length()); - testRestTemplate.postForEntity(URI.create(BEANSTANDETE_WAHLBRIEFE_ENDPOINT_URL + wahlbezirkID + "/" + waehlerVerzeichnisNummer), beanstandeteWahlbriefeDTO, Void.class); + testRestTemplate.postForEntity(URI.create(BEANSTANDETE_WAHLBRIEFE_ENDPOINT_URL + wahlbezirkID + "/" + waehlerVerzeichnisNummer), + beanstandeteWahlbriefeDTO, Void.class); val beantstandeteWahlbriefeInRepo = Streamable.of(beanstandeteWahlbriefeRepository.findAll()).toList(); Assertions.assertThat(beantstandeteWahlbriefeInRepo).hasSize(1); @@ -70,11 +74,13 @@ void testForNfcNormalization() { Assertions.assertThat(beantstandeteWahlbriefeInRepo.get(0).getBeanstandeteWahlbriefe().keySet().toArray()[1]).isEqualTo(key2 + TEXT_ATTRIBUTE_COMPOSED); } - private BeanstandeteWahlbriefeDTO createControllerBeanstandeteWahlbriefeDTO(String wahlbezirkID, Long waehlerverzeichnisNummer, String key1, String key2, String textAttributeDecomposed) { + private BeanstandeteWahlbriefeDTO createControllerBeanstandeteWahlbriefeDTO(String wahlbezirkID, Long waehlerverzeichnisNummer, String key1, String key2, + String textAttributeDecomposed) { return new BeanstandeteWahlbriefeDTO(wahlbezirkID, waehlerverzeichnisNummer, - Map.of(key1 + textAttributeDecomposed, new Zurueckweisungsgrund[]{Zurueckweisungsgrund.NICHT_WAHLBERECHTIGT, Zurueckweisungsgrund.GEGENSTAND_IM_UMSCHLAG}, - key2 + textAttributeDecomposed, new Zurueckweisungsgrund[]{Zurueckweisungsgrund.UNTERSCHRIFT_FEHLT, Zurueckweisungsgrund.LOSE_STIMMZETTEL}) - ); + Map.of(key1 + textAttributeDecomposed, + new Zurueckweisungsgrund[] { Zurueckweisungsgrund.NICHT_WAHLBERECHTIGT, Zurueckweisungsgrund.GEGENSTAND_IM_UMSCHLAG }, + key2 + textAttributeDecomposed, + new Zurueckweisungsgrund[] { Zurueckweisungsgrund.UNTERSCHRIFT_FEHLT, Zurueckweisungsgrund.LOSE_STIMMZETTEL })); } }