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

OZG-7526 OZG-7527 Signatur nur aus Postfach lesen

parent a71dd855
No related branches found
No related tags found
1 merge request!9Ozg 7526 signatur bug kein hotfix
...@@ -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);
}
} }
...@@ -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