Skip to content
Snippets Groups Projects
Commit 0a6c34ca authored by Krzysztof Witukiewicz's avatar Krzysztof Witukiewicz
Browse files

Merge branch 'OZG-7526-signatur-bug-kein-hotfix' into 'main'

Ozg 7526 signatur bug kein hotfix

See merge request !9
parents a71dd855 a679f750
Branches
Tags
1 merge request!9Ozg 7526 signatur bug kein hotfix
......@@ -23,8 +23,6 @@
*/
package de.ozgcloud.alfa.postfach;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
......@@ -46,9 +44,4 @@ public class PostfachProperties {
*/
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 @@
*/
package de.ozgcloud.alfa.postfach;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
......@@ -57,19 +56,14 @@ class PostfachSettingsService {
public PostfachSettings getPostfachSettings(VorgangWithEingang vorgang) {
return PostfachSettings.builder()
.features(Features.builder()
.reply(isReplyToMessageAllowed(vorgang))
.build())
.settings(Settings.builder()
.signatur(getSignatur(vorgang.getOrganisationseinheitenID()))
.build())
.features(Features.builder().reply(isReplyToMessageAllowed(vorgang)).build())
.settings(Settings.builder().signatur(getSignatur()).build())
.build();
}
String getSignatur(String organisationseinheitenID) {
String getSignatur() {
refreshPostfachProperties();
var settings = getOrganisationsEinheitSettings(organisationseinheitenID);
return settings.map(OrganisationsEinheitSettings::getSignatur).orElseGet(postfachProperties::getSignatur);
return postfachProperties.getSignatur();
}
void refreshPostfachProperties() {
......@@ -98,19 +92,4 @@ class PostfachSettingsService {
.findFirst()
.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;
@SpringBootTest(classes = { PostfachPropertiesTestConfiguration.class })
class PostfachPropertiesTest {
private static final String ORGANISATIONSEINHEITEN_ID = "oe1";
private static final String TEST_SIG = "test1";
private static final String TEST_ORGANISATIONS_SIG = OrganisationsEinheitSettingsTestFactory.TEST_SIGNATUR;
@DisplayName("Test loading postfach configuration")
@Nested
@TestPropertySource(properties = {
PostfachProperties.PREFIX + ".signatur=" + TEST_SIG,
PostfachProperties.PREFIX + ".organisations-einheit-settings." + ORGANISATIONSEINHEITEN_ID + ".signatur=" + TEST_ORGANISATIONS_SIG,
PostfachProperties.PREFIX + ".signatur=" + TEST_SIG
})
class TestLoadingPostfachProperties {
......@@ -58,34 +56,9 @@ class PostfachPropertiesTest {
}
@Test
void shouldHaveOrganisationsEinheitSettings() {
assertThat(postfachProperties.getOrganisationsEinheitSettings()).isNotNull();
}
}
}
@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);
void shouldHaveSignatur() {
assertThat(postfachProperties.getSignatur()).isEqualTo(TEST_SIG);
}
@Test
void shouldHaveOrganisationsEinheitSetting() {
assertThat(postfachProperties.getOrganisationsEinheitSettings().get(ORGANISATIONSEINHEITEN_ID)).hasFieldOrPropertyWithValue("signatur",
TEST_ORGANISATIONS_SIG);
}
}
}
......@@ -26,11 +26,7 @@ package de.ozgcloud.alfa.postfach;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
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.DisplayName;
......@@ -46,7 +42,6 @@ import org.springframework.test.util.ReflectionTestUtils;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.collaboration.OrganisationsEinheitTestFactory;
import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory;
......@@ -156,12 +151,12 @@ class PostfachSettingsServiceTest {
void shouldGetSignatur() {
callService();
verify(service).getSignatur(vorgang.getOrganisationseinheitenID());
verify(service).getSignatur();
}
@Test
void shouldSetSignatur() {
doReturn(SettingsTestFactory.SIGNATUR).when(service).getSignatur(vorgang.getOrganisationseinheitenID());
doReturn(SettingsTestFactory.SIGNATUR).when(service).getSignatur();
var postfach = callService();
......@@ -183,40 +178,6 @@ class PostfachSettingsServiceTest {
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
void shouldGetSignatur() {
callService();
......@@ -234,10 +195,8 @@ class PostfachSettingsServiceTest {
assertThat(signatur).isEqualTo(SettingsTestFactory.SIGNATUR);
}
}
private String callService() {
return service.getSignatur(OrganisationsEinheitTestFactory.ID);
return service.getSignatur();
}
}
......@@ -380,82 +339,4 @@ class PostfachSettingsServiceTest {
private void setPostfachConfigGroup(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