Skip to content
Snippets Groups Projects
Commit f6af3bab authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4949 Refactoring setting classes

parent c42c351e
No related branches found
No related tags found
No related merge requests found
Showing
with 381 additions and 63 deletions
/* /*
* Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den * Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das
* Ministerpräsidenten des Landes Schleswig-Holstein * Ministerium für Energiewende, Klimaschutz, Umwelt und Natur
* Staatskanzlei * Zentrales IT-Management
* Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
* *
* Lizenziert unter der EUPL, Version 1.2 oder - sobald * Lizenziert unter der EUPL, Version 1.2 oder - sobald
* diese von der Europäischen Kommission genehmigt wurden - * diese von der Europäischen Kommission genehmigt wurden -
...@@ -21,7 +20,8 @@ ...@@ -21,7 +20,8 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.common;
package de.ozgcloud.admin.common.errorhandling;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
......
package de.ozgcloud.admin.configurationparameter;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
@Component
public class DataRestConfiguration implements RepositoryRestConfigurer {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
config.exposeIdsFor(ConfigurationParameter.class);
}
}
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import java.util.List; import java.util.List;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import java.util.Map; import java.util.Map;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import java.util.List; import java.util.List;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -36,13 +36,15 @@ import lombok.extern.jackson.Jacksonized; ...@@ -36,13 +36,15 @@ import lombok.extern.jackson.Jacksonized;
@Builder @Builder
@Getter @Getter
@Jacksonized @Jacksonized
@Document(ConfigurationParameter.COLLECTION_NAME) @Document(Settings.COLLECTION_NAME)
public class ConfigurationParameter { public class Settings {
static final String COLLECTION_NAME = "settings"; static final String COLLECTION_NAME = "settings";
@Id @Id
private String name; private String id;
private String name;
@Valid @Valid
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXTERNAL_PROPERTY, property = "name") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXTERNAL_PROPERTY, property = "name")
private Settings settings; private SettingsBody settingsBody;
} }
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import de.ozgcloud.admin.settings.postfach.Postfach;
@JsonSubTypes({ @JsonSubTypes({
@Type(value = PostfachDaten.class, name = "Postfach") @Type(value = Postfach.class, name = "Postfach")
}) })
public interface Settings { public interface SettingsBody {
} }
...@@ -19,15 +19,15 @@ ...@@ -19,15 +19,15 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
class ConfigurationParameterConstants { public class SettingsConstants {
static final String REL = "params"; static final String REL = "settings";
static final String PATH = "param"; public static final String PATH = "settings";
} }
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import java.util.List;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -27,11 +29,13 @@ import org.springframework.data.mongodb.repository.MongoRepository; ...@@ -27,11 +29,13 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@RepositoryRestResource(collectionResourceRel = ConfigurationParameterConstants.REL, path = ConfigurationParameterConstants.PATH) @RepositoryRestResource(collectionResourceRel = SettingsConstants.REL, path = SettingsConstants.PATH)
@Validated @Validated
interface ConfigurationParameterRepository extends MongoRepository<ConfigurationParameter, String> { interface SettingsRepository extends MongoRepository<Settings, String> {
@Override @Override
@Valid @Valid
ConfigurationParameter save(ConfigurationParameter entity); Settings save(Settings entity);
List<Settings> findByName(String name);
} }
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings.postfach;
import static de.ozgcloud.admin.common.ValidationMessageCodes.*; import static de.ozgcloud.admin.common.errorhandling.ValidationMessageCodes.*;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings.postfach;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import de.ozgcloud.admin.settings.SettingsBody;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.extern.jackson.Jacksonized; import lombok.extern.jackson.Jacksonized;
...@@ -9,7 +10,7 @@ import lombok.extern.jackson.Jacksonized; ...@@ -9,7 +10,7 @@ import lombok.extern.jackson.Jacksonized;
@Getter @Getter
@Jacksonized @Jacksonized
@Builder @Builder
class PostfachDaten implements Settings { public class Postfach implements SettingsBody {
@Valid @Valid
private Absender absender; private Absender absender;
private String signatur; private String signatur;
......
...@@ -79,7 +79,7 @@ class SecurityConfigurationITCase { ...@@ -79,7 +79,7 @@ class SecurityConfigurationITCase {
@SneakyThrows @SneakyThrows
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = { @ValueSource(strings = {
"/api", "/api/configuration", "/api/configuration/param", "/api", "/api/configuration", "/api/configuration/settings",
"/unknown", "/unknown",
}) })
void shouldDeny(String path) { void shouldDeny(String path) {
...@@ -147,7 +147,7 @@ class SecurityConfigurationITCase { ...@@ -147,7 +147,7 @@ class SecurityConfigurationITCase {
@ValueSource(strings = { @ValueSource(strings = {
"/api/frontendEnvironment", "/api/frontendEnvironment",
"/configserver/name/profile", "/configserver/name/profile",
"/api", "/api/configuration", "/api/configuration/param", "/api", "/api/configuration", "/api/configuration/settings",
}) })
@WithJwt(CLAIMS) @WithJwt(CLAIMS)
void shouldAllow(String path) { void shouldAllow(String path) {
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import java.util.Map; import java.util.Map;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
...@@ -42,7 +42,7 @@ import lombok.SneakyThrows; ...@@ -42,7 +42,7 @@ import lombok.SneakyThrows;
@DataITCase @DataITCase
@AutoConfigureMockMvc @AutoConfigureMockMvc
@WithMockUser @WithMockUser
class ConfigurationParameterITCase { class SettingsITCase {
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
...@@ -58,14 +58,16 @@ class ConfigurationParameterITCase { ...@@ -58,14 +58,16 @@ class ConfigurationParameterITCase {
@BeforeEach @BeforeEach
void init() { void init() {
mongoOperations.dropCollection(ConfigurationParameter.class); mongoOperations.dropCollection(Settings.class);
mongoOperations.save(ConfigurationParameterTestFactory.create()); mongoOperations.save(SettingsTestFactory.create());
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveStatusOkForExisting() { void shouldHaveStatusOkForExisting() {
var result = doPerform(ConfigurationParameterTestFactory.NAME); var id = mongoOperations.findAll(Settings.class).get(0).getId();
var result = doPerform(id);
result.andExpect(status().isOk()); result.andExpect(status().isOk());
} }
...@@ -80,7 +82,7 @@ class ConfigurationParameterITCase { ...@@ -80,7 +82,7 @@ class ConfigurationParameterITCase {
@SneakyThrows @SneakyThrows
private ResultActions doPerform(String id) { private ResultActions doPerform(String id) {
return mockMvc.perform(get(String.join("/", restProperties.getBasePath(), ConfigurationParameterConstants.PATH, id))); return mockMvc.perform(get(String.join("/", restProperties.getBasePath(), SettingsConstants.PATH, id)));
} }
} }
......
...@@ -19,17 +19,15 @@ ...@@ -19,17 +19,15 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings;
public class ConfigurationParameterTestFactory { public class SettingsTestFactory {
public static final String NAME = "Postfach";
public static final PostfachDaten POSTFACH_DATEN = PostfachDatenTestFactory.create();
public static ConfigurationParameter create() { public static Settings create() {
return createBuilder().build(); return createBuilder().build();
} }
public static ConfigurationParameter.ConfigurationParameterBuilder createBuilder() { public static Settings.SettingsBuilder createBuilder() {
return ConfigurationParameter.builder().name(NAME).settings(POSTFACH_DATEN); return Settings.builder();
} }
} }
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings.postfach;
import java.util.Random; import java.util.Random;
......
package de.ozgcloud.admin.configurationparameter; package de.ozgcloud.admin.settings.postfach;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;
...@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -23,13 +25,19 @@ import com.fasterxml.jackson.databind.DeserializationFeature; ...@@ -23,13 +25,19 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import de.ozgcloud.admin.settings.Settings;
import de.ozgcloud.admin.settings.SettingsBody;
import de.ozgcloud.admin.settings.SettingsConstants;
import de.ozgcloud.admin.settings.SettingsTestFactory;
import de.ozgcloud.common.test.DataITCase; import de.ozgcloud.common.test.DataITCase;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@DataITCase @DataITCase
@AutoConfigureMockMvc @AutoConfigureMockMvc
@WithMockUser @WithMockUser
public class PostfachDatenITCase { public class PostfachITCase {
private final String NAME = "Postfach";
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
...@@ -39,11 +47,16 @@ public class PostfachDatenITCase { ...@@ -39,11 +47,16 @@ public class PostfachDatenITCase {
@Autowired @Autowired
private RepositoryRestProperties restProperties; private RepositoryRestProperties restProperties;
private ConfigurationParameter postfachConfig = ConfigurationParameterTestFactory.create(); private Settings postfachSetting = SettingsTestFactory.createBuilder()
.name(NAME)
.settingsBody(PostfachTestFactory.create())
.build();
private Query queryForPostfach = new Query().addCriteria(Criteria.where("name").in(NAME));
@AfterEach @AfterEach
void clear() { void clear() {
mongoOperations.dropCollection(ConfigurationParameter.class); mongoOperations.dropCollection(Settings.class);
} }
@Nested @Nested
...@@ -52,45 +65,36 @@ public class PostfachDatenITCase { ...@@ -52,45 +65,36 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveStatusCreated() { void shouldHaveStatusCreated() {
var result = performPost(postfachConfig); var result = performPost(postfachSetting);
result.andExpect(status().isCreated()); result.andExpect(status().isCreated());
} }
@Test
@SneakyThrows
void shouldCreateNoMoreThanOneEntry() {
performPost(postfachConfig);
performPost(ConfigurationParameterTestFactory.create());
assertThat(mongoOperations.findAll(ConfigurationParameter.class)).hasSize(1);
}
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateWithValues() { void shouldCreateWithValues() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class)) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class))
.usingRecursiveComparison().isEqualTo(ConfigurationParameterTestFactory.create()); .usingRecursiveComparison().ignoringFields("id").isEqualTo(postfachSetting);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateObjectWithName() { void shouldCreateObjectWithName() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class)) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class))
.hasFieldOrProperty("name"); .hasFieldOrProperty("name");
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateObjectWithSettings() { void shouldCreateObjectWithSettings() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class)) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class))
.hasFieldOrProperty("settings"); .hasFieldOrProperty("settingsBody");
} }
@Nested @Nested
...@@ -99,38 +103,38 @@ public class PostfachDatenITCase { ...@@ -99,38 +103,38 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldBeInstanceOfPostfachDaten() { void shouldBeInstanceOfPostfachDaten() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).isInstanceOf(PostfachDaten.class); .getSettingsBody()).isInstanceOf(Postfach.class);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateObjectWithAbsender() { void shouldCreateObjectWithAbsender() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).hasFieldOrProperty("absender"); .getSettingsBody()).hasFieldOrProperty("absender");
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateObjectWithSignatur() { void shouldCreateObjectWithSignatur() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).hasFieldOrPropertyWithValue("signatur", PostfachDatenTestFactory.SIGNATUR); .getSettingsBody()).hasFieldOrPropertyWithValue("signatur", PostfachTestFactory.SIGNATUR);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldCreateEmptySignatur() { void shouldCreateEmptySignatur() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.signatur("").build(); .signatur("").build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isCreated()); result.andExpect(status().isCreated());
} }
...@@ -141,21 +145,21 @@ public class PostfachDatenITCase { ...@@ -141,21 +145,21 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveName() { void shouldHaveName() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(((PostfachDaten) mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(((Postfach) mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).getAbsender()).hasFieldOrPropertyWithValue("name", AbsenderTestFactory.NAME); .getSettingsBody()).getAbsender()).hasFieldOrPropertyWithValue("name", AbsenderTestFactory.NAME);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldNotCreateEmptyName() { void shouldNotCreateEmptyName() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.absender(AbsenderTestFactory.createBuilder().name("").build()) .absender(AbsenderTestFactory.createBuilder().name("").build())
.build(); .build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isUnprocessableEntity()); result.andExpect(status().isUnprocessableEntity());
} }
...@@ -163,21 +167,21 @@ public class PostfachDatenITCase { ...@@ -163,21 +167,21 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveAnschrift() { void shouldHaveAnschrift() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(((PostfachDaten) mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(((Postfach) mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).getAbsender()).hasFieldOrPropertyWithValue("anschrift", AbsenderTestFactory.ANSCHRIFT); .getSettingsBody()).getAbsender()).hasFieldOrPropertyWithValue("anschrift", AbsenderTestFactory.ANSCHRIFT);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldNotCreateEmptyAnschrift() { void shouldNotCreateEmptyAnschrift() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.absender(AbsenderTestFactory.createBuilder().anschrift("").build()) .absender(AbsenderTestFactory.createBuilder().anschrift("").build())
.build(); .build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isUnprocessableEntity()); result.andExpect(status().isUnprocessableEntity());
} }
...@@ -185,21 +189,21 @@ public class PostfachDatenITCase { ...@@ -185,21 +189,21 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveDienst() { void shouldHaveDienst() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(((PostfachDaten) mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(((Postfach) mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).getAbsender()).hasFieldOrPropertyWithValue("dienst", AbsenderTestFactory.DIENST); .getSettingsBody()).getAbsender()).hasFieldOrPropertyWithValue("dienst", AbsenderTestFactory.DIENST);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldNotCreateEmptyDienst() { void shouldNotCreateEmptyDienst() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.absender(AbsenderTestFactory.createBuilder().dienst("").build()) .absender(AbsenderTestFactory.createBuilder().dienst("").build())
.build(); .build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isUnprocessableEntity()); result.andExpect(status().isUnprocessableEntity());
} }
...@@ -207,21 +211,21 @@ public class PostfachDatenITCase { ...@@ -207,21 +211,21 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveMandant() { void shouldHaveMandant() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(((PostfachDaten) mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(((Postfach) mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).getAbsender()).hasFieldOrPropertyWithValue("mandant", AbsenderTestFactory.MANDANT); .getSettingsBody()).getAbsender()).hasFieldOrPropertyWithValue("mandant", AbsenderTestFactory.MANDANT);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldNotCreateEmptyMandant() { void shouldNotCreateEmptyMandant() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.absender(AbsenderTestFactory.createBuilder().mandant("").build()) .absender(AbsenderTestFactory.createBuilder().mandant("").build())
.build(); .build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isUnprocessableEntity()); result.andExpect(status().isUnprocessableEntity());
} }
...@@ -229,60 +233,64 @@ public class PostfachDatenITCase { ...@@ -229,60 +233,64 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveGemeindeschluessel() { void shouldHaveGemeindeschluessel() {
performPost(postfachConfig); performPost(postfachSetting);
assertThat(((PostfachDaten) mongoOperations.findById(ConfigurationParameterTestFactory.NAME, ConfigurationParameter.class) assertThat(((Postfach) mongoOperations.findOne(queryForPostfach, Settings.class)
.getSettings()).getAbsender()).hasFieldOrPropertyWithValue("gemeindeschluessel", AbsenderTestFactory.GEMEINDESCHLUESSEL); .getSettingsBody()).getAbsender()).hasFieldOrPropertyWithValue("gemeindeschluessel",
AbsenderTestFactory.GEMEINDESCHLUESSEL);
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldNotCreateEmptyGemeindeschluessel() { void shouldNotCreateEmptyGemeindeschluessel() {
var errorPostfachSetting = PostfachDatenTestFactory.createBuilder() var errorPostfach = PostfachTestFactory.createBuilder()
.absender(AbsenderTestFactory.createBuilder().gemeindeschluessel("").build()) .absender(AbsenderTestFactory.createBuilder().gemeindeschluessel("").build())
.build(); .build();
var errorPostfachConfig = createErrorPostfachConfig(errorPostfachSetting); var errorPostfachSetting = createErrorPostfachSetting(errorPostfach);
var result = performPost(errorPostfachConfig); var result = performPost(errorPostfachSetting);
result.andExpect(status().isUnprocessableEntity()); result.andExpect(status().isUnprocessableEntity());
} }
} }
private ConfigurationParameter createErrorPostfachConfig(Settings postfachSettings) { private Settings createErrorPostfachSetting(SettingsBody postfach) {
return ConfigurationParameterTestFactory.createBuilder().settings(postfachSettings).build(); return SettingsTestFactory.createBuilder().name(NAME).settingsBody(postfach).build();
} }
} }
@SneakyThrows @SneakyThrows
private ResultActions performPost(ConfigurationParameter configurationParameter) { private ResultActions performPost(Settings setting) {
var postBody = convertConfigurationParameterToString(configurationParameter); var postBody = convertSettingToString(setting);
return mockMvc.perform(post(String.join("/", restProperties.getBasePath(), return mockMvc.perform(post(String.join("/", restProperties.getBasePath(),
ConfigurationParameterConstants.PATH)) SettingsConstants.PATH))
.with(csrf()) .with(csrf())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(postBody)); .content(postBody));
} }
@SneakyThrows @SneakyThrows
private String convertConfigurationParameterToString(ConfigurationParameter configurationParameter) { private String convertSettingToString(Settings setting) {
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).setSerializationInclusion(Include.NON_NULL); ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).setSerializationInclusion(Include.NON_NULL);
return mapper.writeValueAsString(configurationParameter); return mapper.writeValueAsString(setting);
} }
} }
@Nested @Nested
class TestGet { class TestGet {
private String id;
@BeforeEach @BeforeEach
void init() { void init() {
mongoOperations.save(postfachConfig); mongoOperations.save(postfachSetting);
id = mongoOperations.findOne(queryForPostfach, Settings.class).getId();
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveStatusOkForExisting() { void shouldHaveStatusOkForExisting() {
var result = doPerform(ConfigurationParameterTestFactory.NAME); var result = performGet();
result.andExpect(status().isOk()); result.andExpect(status().isOk());
} }
...@@ -290,16 +298,16 @@ public class PostfachDatenITCase { ...@@ -290,16 +298,16 @@ public class PostfachDatenITCase {
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveInstanceOfPostfachDaten() { void shouldHaveInstanceOfPostfachDaten() {
var result = doPerform(ConfigurationParameterTestFactory.NAME); var result = performGet();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
assertThat(mapper.readValue(result.andReturn().getResponse().getContentAsString(), ConfigurationParameter.class).getSettings()) assertThat(mapper.readValue(result.andReturn().getResponse().getContentAsString(), Settings.class).getSettingsBody())
.isInstanceOf(PostfachDaten.class); .isInstanceOf(Postfach.class);
} }
@SneakyThrows @SneakyThrows
private ResultActions doPerform(String id) { private ResultActions performGet() {
return mockMvc.perform(get(String.join("/", restProperties.getBasePath(), ConfigurationParameterConstants.PATH, id))); return mockMvc.perform(get(String.join("/", restProperties.getBasePath(), SettingsConstants.PATH, id)));
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment