Skip to content
Snippets Groups Projects
Commit a920152f authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

Merge remote-tracking branch 'origin/main' into OZG-6461-historie-refactoring

parents 30fd7b50 0a6c34ca
No related branches found
No related tags found
1 merge request!5Ozg 6461 historie refactoring
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
*/ */
package de.ozgcloud.alfa.postfach; package de.ozgcloud.alfa.postfach;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -46,9 +44,4 @@ public class PostfachProperties { ...@@ -46,9 +44,4 @@ public class PostfachProperties {
*/ */
private String signatur = ""; private String signatur = "";
/**
* Settings that are linked to an Organisationseinheit. Configured by administration config server.
*/
private Map<String, Map<String, Object>> organisationsEinheitSettings = Map.of();
} }
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
*/ */
package de.ozgcloud.alfa.postfach; package de.ozgcloud.alfa.postfach;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -57,19 +56,14 @@ class PostfachSettingsService { ...@@ -57,19 +56,14 @@ class PostfachSettingsService {
public PostfachSettings getPostfachSettings(VorgangWithEingang vorgang) { public PostfachSettings getPostfachSettings(VorgangWithEingang vorgang) {
return PostfachSettings.builder() return PostfachSettings.builder()
.features(Features.builder() .features(Features.builder().reply(isReplyToMessageAllowed(vorgang)).build())
.reply(isReplyToMessageAllowed(vorgang)) .settings(Settings.builder().signatur(getSignatur()).build())
.build())
.settings(Settings.builder()
.signatur(getSignatur(vorgang.getOrganisationseinheitenID()))
.build())
.build(); .build();
} }
String getSignatur(String organisationseinheitenID) { String getSignatur() {
refreshPostfachProperties(); refreshPostfachProperties();
var settings = getOrganisationsEinheitSettings(organisationseinheitenID); return postfachProperties.getSignatur();
return settings.map(OrganisationsEinheitSettings::getSignatur).orElseGet(postfachProperties::getSignatur);
} }
void refreshPostfachProperties() { void refreshPostfachProperties() {
...@@ -98,19 +92,4 @@ class PostfachSettingsService { ...@@ -98,19 +92,4 @@ class PostfachSettingsService {
.findFirst() .findFirst()
.orElse(false); .orElse(false);
} }
Optional<OrganisationsEinheitSettings> getOrganisationsEinheitSettings(String organisationId) {
return Optional.ofNullable(organisationId)
.map(this::getOrganisationsEinheitPostfachSettings)
.map(this::mapOrganisationsEinheitSettings);
}
OrganisationsEinheitSettings mapOrganisationsEinheitSettings(Map<String, Object> organisationsEinheitSettings) {
var signatur = Optional.ofNullable(organisationsEinheitSettings.get(FIELD_SIGNATUR)).map(Object::toString).orElse(null);
return OrganisationsEinheitSettings.builder().signatur(signatur).build();
}
private Map<String, Object> getOrganisationsEinheitPostfachSettings(String organisationId) {
return postfachProperties.getOrganisationsEinheitSettings().get(organisationId);
}
} }
...@@ -34,15 +34,13 @@ import org.springframework.test.context.TestPropertySource; ...@@ -34,15 +34,13 @@ import org.springframework.test.context.TestPropertySource;
@SpringBootTest(classes = { PostfachPropertiesTestConfiguration.class }) @SpringBootTest(classes = { PostfachPropertiesTestConfiguration.class })
class PostfachPropertiesTest { class PostfachPropertiesTest {
private static final String ORGANISATIONSEINHEITEN_ID = "oe1";
private static final String TEST_SIG = "test1"; private static final String TEST_SIG = "test1";
private static final String TEST_ORGANISATIONS_SIG = OrganisationsEinheitSettingsTestFactory.TEST_SIGNATUR;
@DisplayName("Test loading postfach configuration") @DisplayName("Test loading postfach configuration")
@Nested @Nested
@TestPropertySource(properties = { @TestPropertySource(properties = {
PostfachProperties.PREFIX + ".signatur=" + TEST_SIG, PostfachProperties.PREFIX + ".signatur=" + TEST_SIG
PostfachProperties.PREFIX + ".organisations-einheit-settings." + ORGANISATIONSEINHEITEN_ID + ".signatur=" + TEST_ORGANISATIONS_SIG,
}) })
class TestLoadingPostfachProperties { class TestLoadingPostfachProperties {
...@@ -58,34 +56,9 @@ class PostfachPropertiesTest { ...@@ -58,34 +56,9 @@ class PostfachPropertiesTest {
} }
@Test @Test
void shouldHaveOrganisationsEinheitSettings() { void shouldHaveSignatur() {
assertThat(postfachProperties.getOrganisationsEinheitSettings()).isNotNull(); assertThat(postfachProperties.getSignatur()).isEqualTo(TEST_SIG);
}
}
}
@DisplayName("Test mapping organisations einheit settings")
@Nested
@TestPropertySource(properties = {
PostfachProperties.PREFIX + ".signatur=" + TEST_SIG,
PostfachProperties.PREFIX + ".organisations-einheit-settings.oe1.signatur=" + TEST_ORGANISATIONS_SIG,
})
class TestMapOrganisationsEinheitSettings {
@Autowired
private PostfachProperties postfachProperties;
@Test
void shouldHaveOrganisationsEinheit() {
var props = postfachProperties.getOrganisationsEinheitSettings();
assertThat(props).containsKey(ORGANISATIONSEINHEITEN_ID);
} }
@Test
void shouldHaveOrganisationsEinheitSetting() {
assertThat(postfachProperties.getOrganisationsEinheitSettings().get(ORGANISATIONSEINHEITEN_ID)).hasFieldOrPropertyWithValue("signatur",
TEST_ORGANISATIONS_SIG);
} }
} }
} }
...@@ -26,11 +26,7 @@ package de.ozgcloud.alfa.postfach; ...@@ -26,11 +26,7 @@ package de.ozgcloud.alfa.postfach;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -46,7 +42,6 @@ import org.springframework.test.util.ReflectionTestUtils; ...@@ -46,7 +42,6 @@ import org.springframework.test.util.ReflectionTestUtils;
import com.thedeanda.lorem.LoremIpsum; import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.collaboration.OrganisationsEinheitTestFactory;
import de.ozgcloud.alfa.common.FeatureToggleProperties; import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory; import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory; import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory;
...@@ -156,12 +151,12 @@ class PostfachSettingsServiceTest { ...@@ -156,12 +151,12 @@ class PostfachSettingsServiceTest {
void shouldGetSignatur() { void shouldGetSignatur() {
callService(); callService();
verify(service).getSignatur(vorgang.getOrganisationseinheitenID()); verify(service).getSignatur();
} }
@Test @Test
void shouldSetSignatur() { void shouldSetSignatur() {
doReturn(SettingsTestFactory.SIGNATUR).when(service).getSignatur(vorgang.getOrganisationseinheitenID()); doReturn(SettingsTestFactory.SIGNATUR).when(service).getSignatur();
var postfach = callService(); var postfach = callService();
...@@ -183,40 +178,6 @@ class PostfachSettingsServiceTest { ...@@ -183,40 +178,6 @@ class PostfachSettingsServiceTest {
verify(service).refreshPostfachProperties(); verify(service).refreshPostfachProperties();
} }
@Test
void shouldGetOrganisationEinheitSettings() {
callService();
verify(service).getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
}
@Nested
class OnExistingOrganisationsEinheitSignatur {
@BeforeEach
void setUp() {
doReturn(Optional.of(OrganisationsEinheitSettingsTestFactory.create())).when(service)
.getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
}
@Test
void shouldReturnOrganisationsEinheitSignatur() {
var signatur = callService();
assertThat(signatur).isEqualTo(OrganisationsEinheitSettingsTestFactory.TEST_SIGNATUR);
}
}
@Nested
class OnNoOrganisationsEinheitSignatur {
@BeforeEach
void setUp() {
doReturn(Optional.empty()).when(service)
.getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
}
@Test @Test
void shouldGetSignatur() { void shouldGetSignatur() {
callService(); callService();
...@@ -234,10 +195,8 @@ class PostfachSettingsServiceTest { ...@@ -234,10 +195,8 @@ class PostfachSettingsServiceTest {
assertThat(signatur).isEqualTo(SettingsTestFactory.SIGNATUR); assertThat(signatur).isEqualTo(SettingsTestFactory.SIGNATUR);
} }
}
private String callService() { private String callService() {
return service.getSignatur(OrganisationsEinheitTestFactory.ID); return service.getSignatur();
} }
} }
...@@ -380,82 +339,4 @@ class PostfachSettingsServiceTest { ...@@ -380,82 +339,4 @@ class PostfachSettingsServiceTest {
private void setPostfachConfigGroup(PostfachConfigGroup postfachConfigGroup) { private void setPostfachConfigGroup(PostfachConfigGroup postfachConfigGroup) {
ReflectionTestUtils.setField(service, "postfachConfigGroup", postfachConfigGroup); ReflectionTestUtils.setField(service, "postfachConfigGroup", postfachConfigGroup);
} }
@Nested
class TestGetOrganisationsEinheitSettings {
@Nested
class OnOrganisationIdNotNull {
private final OrganisationsEinheitSettings organisationsEinheitSettings = OrganisationsEinheitSettingsTestFactory.create();
private final Map<String, Object> organisationsEinheitSettingsMap = Map.of(PostfachSettingsService.FIELD_SIGNATUR,
OrganisationsEinheitSettingsTestFactory.TEST_SIGNATUR);
@BeforeEach
void setUp() {
when(postfachProperties.getOrganisationsEinheitSettings()).thenReturn(
Map.of(OrganisationsEinheitTestFactory.ID, organisationsEinheitSettingsMap));
}
@Test
void shouldGetOrganisationsEinheitSettings() {
service.getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
verify(postfachProperties).getOrganisationsEinheitSettings();
}
@Test
void shouldMapToOrganisationsEinheitSettings() {
service.getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
verify(service).mapOrganisationsEinheitSettings(organisationsEinheitSettingsMap);
}
@Test
void shouldReturnSettings() {
var settings = service.getOrganisationsEinheitSettings(OrganisationsEinheitTestFactory.ID);
assertThat(settings).isPresent().get().usingRecursiveComparison().isEqualTo(organisationsEinheitSettings);
}
@Test
void shouldReturnEmpty() {
var settings = service.getOrganisationsEinheitSettings(UUID.randomUUID().toString());
assertThat(settings).isEmpty();
}
}
@Nested
class OnOrganisationIdNull {
@Test
void shouldReturnEmpty() {
var settings = service.getOrganisationsEinheitSettings(null);
assertThat(settings).isEmpty();
}
}
}
@Nested
class TestMapOrganisationsEinheitSettings {
private final String signatur = LoremIpsum.getInstance().getWords(2);
private final Map<String, Object> organisationsEinheitSettings = Map.of(PostfachSettingsService.FIELD_SIGNATUR, signatur);
@Test
void shouldMap() {
var settings = service.mapOrganisationsEinheitSettings(organisationsEinheitSettings);
assertThat(settings.getSignatur()).isEqualTo(signatur);
}
@Test
void shouldReturnSettingsWithNullSignatur() {
var settings = service.mapOrganisationsEinheitSettings(Collections.emptyMap());
assertThat(settings.getSignatur()).isNull();
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment