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

Merge branch 'master' into OZG-7000-feature-toggles

parents 27236eef 5585d2d5
Branches
Tags
No related merge requests found
......@@ -64,8 +64,10 @@ class SettingService {
}
PostfachSettingBody getSettingWithPostfachFromDb() {
var postfach = repository.findOneByName(POSTFACH_SETTING_ITEM_NAME);
return postfach.isPresent() ? (PostfachSettingBody) postfach.get().getSettingBody() : PostfachSettingBody.builder().build();
return repository.findOneByName(POSTFACH_SETTING_ITEM_NAME)
.map(Setting::getSettingBody)
.map(PostfachSettingBody.class::cast)
.orElse(PostfachSettingBody.builder().build());
}
Map<String, OrganisationsEinheitSettings> getOrganisationsEinheitSettings() {
......
......@@ -28,6 +28,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -35,6 +36,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheit;
import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheitTestFactory;
......@@ -52,11 +54,6 @@ class SettingEnvironmentITCase {
@Autowired
private MongoOperations mongoOperations;
private Setting settingWithPostfach = SettingTestFactory.createBuilder()
.name("Postfach")
.settingBody(PostfachSettingBodyTestFactory.create())
.build();
@Test
@SneakyThrows
void shouldHaveHttpEndpoint() {
......@@ -65,35 +62,111 @@ class SettingEnvironmentITCase {
result.andExpect(status().isOk());
}
@DisplayName("Get alfa settings")
@Nested
class TestFindOne {
@BeforeEach
void fillDb() {
mongoOperations.dropCollection(Setting.class);
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(settingWithPostfach);
mongoOperations.save(OrganisationsEinheitTestFactory.create());
class TestGetAlfaSettings {
@Nested
class OnInitialStartup {
@BeforeEach
void fillDb() {
fillDbWithInitialSetting();
}
@Test
@SneakyThrows
void shouldHandleEmptySetting() {
var result = getAlfaSettings();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createInitialYaml());
}
}
@Test
@SneakyThrows
void shouldReturnValuesForVorgangManager() {
var result = mockMvc.perform(get("/configserver/OzgCloud_VorgangManager-profile.yaml"));
@Nested
class OnSettingsAvailable {
@BeforeEach
void fillDb() {
fillDbWithPostfachSetting();
}
@Test
@SneakyThrows
void shouldReturnValuesForAlfa() {
var result = getAlfaSettings();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createVorgangManagerYaml());
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createAlfaYaml());
}
}
@Test
@SneakyThrows
void shouldReturnValuesForAlfa() {
var result = mockMvc.perform(get("/configserver/Alfa-any.yaml"));
private ResultActions getAlfaSettings() throws Exception {
return mockMvc.perform(get("/configserver/Alfa-any.yaml")).andExpect(status().isOk());
}
}
@Nested
class TestGetVorgangManagerSettings {
@Nested
class OnInitialStartup {
@BeforeEach
void fillDb() {
fillDbWithInitialSetting();
}
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createAlfaYaml());
@Test
@SneakyThrows
void shouldHandleEmptySetting() {
var result = getVorgangManagerSettings();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createInitialYaml());
}
}
@Nested
class OnSettingsAvailable {
@BeforeEach
void fillDb() {
fillDbWithPostfachSetting();
}
@Test
@SneakyThrows
void shouldReturnValuesForVorgangManager() {
var result = getVorgangManagerSettings();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString()))
.isEqualTo(YamlTestFactory.createVorgangManagerYaml());
}
}
private String formatLineBreaks(String text) {
return text.replaceAll("\\\\\\s+\\\\", "").replace("\\n", "\n");
private ResultActions getVorgangManagerSettings() throws Exception {
return mockMvc.perform(get("/configserver/OzgCloud_VorgangManager-profile.yaml")).andExpect(status().isOk());
}
}
private String formatLineBreaks(String text) {
return text.replaceAll("\\\\\\s+\\\\", "").replace("\\n", "\n");
}
private void fillDbWithInitialSetting() {
var initialSetting = Setting.builder().name("Postfach").build();
mongoOperations.dropCollection(Setting.class);
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(initialSetting);
}
private void fillDbWithPostfachSetting() {
var postfachSetting = SettingTestFactory.createBuilder()
.name("Postfach")
.settingBody(PostfachSettingBodyTestFactory.create())
.build();
mongoOperations.dropCollection(Setting.class);
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(postfachSetting);
mongoOperations.save(OrganisationsEinheitTestFactory.create());
}
}
\ No newline at end of file
......@@ -62,9 +62,6 @@ class SettingServiceTest {
private final PostfachSettingBody postfach = PostfachSettingBodyTestFactory.create();
private static final String POSTFACH = "Postfach";
private final Setting settingWithPostfach = SettingTestFactory.createBuilder().name(POSTFACH).settingBody(postfach).build();
@Nested
class TestGetAlfaSettingDTO {
......@@ -147,9 +144,15 @@ class SettingServiceTest {
@Nested
class TestGetSettingWithPostfachFromDb {
private static final String POSTFACH = "Postfach";
private final Setting emptyPostfachSetting = SettingTestFactory.createBuilder().name(POSTFACH).build();
private final Setting postfachSettingWithBody = SettingTestFactory.createBuilder().name(POSTFACH).settingBody(postfach).build();
@Test
void shouldCallRepository() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(settingWithPostfach));
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(postfachSettingWithBody));
service.getSettingWithPostfachFromDb();
......@@ -158,7 +161,7 @@ class SettingServiceTest {
@Test
void shouldReturnPostfachSettingBody() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(settingWithPostfach));
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(postfachSettingWithBody));
var returnedBody = service.getSettingWithPostfachFromDb();
......@@ -166,13 +169,22 @@ class SettingServiceTest {
}
@Test
void shouldReturnEmptyPostfachSettingBodyForEmptySetting() {
void shouldReturnEmptyPostfachSettingBodyWhenSettingNotFound() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.empty());
var returnedBody = service.getSettingWithPostfachFromDb();
assertThat(returnedBody).usingRecursiveComparison().isEqualTo(PostfachSettingBody.builder().build());
}
@Test
void shouldReturnEmptyPostfachSettingBodyForSettingWithoutBody() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(emptyPostfachSetting));
var returnedBody = service.getSettingWithPostfachFromDb();
assertThat(returnedBody).usingRecursiveComparison().isEqualTo(PostfachSettingBody.builder().build());
}
}
@Nested
......
......@@ -51,4 +51,8 @@ public class YamlTestFactory {
OrganisationsEinheitTestFactory.ORGANISATIONS_EINHEIT_ID,
OrganisationsEinheitSettingsTestFactory.SIGNATUR);
}
public static String createInitialYaml() {
return TestUtils.loadTextFile("yamlTemplates/settings/initial.yaml.tmpl");
}
}
ozgcloud:
postfach:
signatur: null
organisationsEinheitSettings: {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment