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

OZG-7239 OZG-7286 Extend IT case

parent 910f87f5
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder ...@@ -28,6 +28,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -35,6 +36,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock ...@@ -35,6 +36,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
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;
import org.springframework.test.web.servlet.ResultActions;
import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheit; import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheit;
import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheitTestFactory; import de.ozgcloud.admin.organisationseinheit.OrganisationsEinheitTestFactory;
...@@ -52,11 +54,6 @@ class SettingEnvironmentITCase { ...@@ -52,11 +54,6 @@ class SettingEnvironmentITCase {
@Autowired @Autowired
private MongoOperations mongoOperations; private MongoOperations mongoOperations;
private Setting settingWithPostfach = SettingTestFactory.createBuilder()
.name("Postfach")
.settingBody(PostfachSettingBodyTestFactory.create())
.build();
@Test @Test
@SneakyThrows @SneakyThrows
void shouldHaveHttpEndpoint() { void shouldHaveHttpEndpoint() {
...@@ -65,35 +62,111 @@ class SettingEnvironmentITCase { ...@@ -65,35 +62,111 @@ class SettingEnvironmentITCase {
result.andExpect(status().isOk()); result.andExpect(status().isOk());
} }
@DisplayName("Get alfa settings")
@Nested @Nested
class TestFindOne { class TestGetAlfaSettings {
@Nested
class OnInitialStartup {
@BeforeEach @BeforeEach
void fillDb() { void fillDb() {
mongoOperations.dropCollection(Setting.class); fillDbWithInitialSettings();
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(settingWithPostfach);
mongoOperations.save(OrganisationsEinheitTestFactory.create());
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldReturnValuesForVorgangManager() { void shouldHandleEmptySetting() {
var result = mockMvc.perform(get("/configserver/OzgCloud_VorgangManager-profile.yaml")); var result = getAlfaSetting();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createVorgangManagerYaml()); assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createInitialYaml());
}
}
@Nested
class OnSettingsAvailable {
@BeforeEach
void fillDb() {
fillDbWithPostfachSettings();
} }
@Test @Test
@SneakyThrows @SneakyThrows
void shouldReturnValuesForAlfa() { void shouldReturnValuesForAlfa() {
var result = mockMvc.perform(get("/configserver/Alfa-any.yaml")); var result = getAlfaSetting();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createAlfaYaml()); assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createAlfaYaml());
} }
}
private ResultActions getAlfaSetting() throws Exception {
return mockMvc.perform(get("/configserver/Alfa-any.yaml")).andExpect(status().isOk());
}
}
@Nested
class TestGetVorgangManagerSettings {
@Nested
class OnInitialStartup {
@BeforeEach
void fillDb() {
fillDbWithInitialSettings();
}
@Test
@SneakyThrows
void shouldHandleEmptySetting() {
var result = getVorgangManagerSetting();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString())).isEqualTo(YamlTestFactory.createInitialYaml());
}
}
@Nested
class OnSettingsAvailable {
@BeforeEach
void fillDb() {
fillDbWithPostfachSettings();
}
@Test
@SneakyThrows
void shouldReturnValuesForVorgangManager() {
var result = getVorgangManagerSetting();
assertThat(formatLineBreaks(result.andReturn().getResponse().getContentAsString()))
.isEqualTo(YamlTestFactory.createVorgangManagerYaml());
}
}
private ResultActions getVorgangManagerSetting() throws Exception {
return mockMvc.perform(get("/configserver/OzgCloud_VorgangManager-profile.yaml")).andExpect(status().isOk());
}
}
private String formatLineBreaks(String text) { private String formatLineBreaks(String text) {
return text.replaceAll("\\\\\\s+\\\\", "").replace("\\n", "\n"); return text.replaceAll("\\\\\\s+\\\\", "").replace("\\n", "\n");
} }
private void fillDbWithInitialSettings() {
var initialSetting = Setting.builder().name("Postfach").build();
mongoOperations.dropCollection(Setting.class);
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(initialSetting);
}
private void fillDbWithPostfachSettings() {
var postfachSettings = SettingTestFactory.createBuilder()
.name("Postfach")
.settingBody(PostfachSettingBodyTestFactory.create())
.build();
mongoOperations.dropCollection(Setting.class);
mongoOperations.dropCollection(OrganisationsEinheit.class);
mongoOperations.save(postfachSettings);
mongoOperations.save(OrganisationsEinheitTestFactory.create());
} }
} }
\ No newline at end of file
...@@ -51,4 +51,8 @@ public class YamlTestFactory { ...@@ -51,4 +51,8 @@ public class YamlTestFactory {
OrganisationsEinheitTestFactory.ORGANISATIONS_EINHEIT_ID, OrganisationsEinheitTestFactory.ORGANISATIONS_EINHEIT_ID,
OrganisationsEinheitSettingsTestFactory.SIGNATUR); 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