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

OZG-7126 throw exception on postfachType null and no distinct configured...

OZG-7126 throw exception on postfachType null and no distinct configured postfachRemoteService; ajdust log warn -> error
parent 5031da56
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ import org.springframework.context.ApplicationEventPublisher; ...@@ -42,6 +42,7 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.nachrichten.antragraum.AntragraumService; import de.ozgcloud.nachrichten.antragraum.AntragraumService;
import de.ozgcloud.nachrichten.attributes.ClientAttributeService; import de.ozgcloud.nachrichten.attributes.ClientAttributeService;
import de.ozgcloud.nachrichten.info.InfoManagerService; import de.ozgcloud.nachrichten.info.InfoManagerService;
...@@ -274,14 +275,18 @@ class PostfachService { ...@@ -274,14 +275,18 @@ class PostfachService {
} }
Optional<PostfachRemoteService> findPostfachRemoteService(String postfachType) { Optional<PostfachRemoteService> findPostfachRemoteService(String postfachType) {
return getPostfachRemoteServices() var remoteServices = getPostfachRemoteServices().toList();
if (Objects.isNull(postfachType) && remoteServices.size() != 1) {
throw new TechnicalException("PostfachType is null and no distinct PostfachService is configured.");
}
return remoteServices.stream()
.filter(remoteService -> hasPostfachType(remoteService, postfachType)) .filter(remoteService -> hasPostfachType(remoteService, postfachType))
.findFirst(); .findFirst();
} }
private boolean hasPostfachType(PostfachRemoteService postfachRemoteService, String postfachType) { private boolean hasPostfachType(PostfachRemoteService postfachRemoteService, String postfachType) {
if (Objects.isNull(postfachType)) { if (Objects.isNull(postfachType)) {
LOG.warn("PostfachType is null - use existing PostfachService with type %s.".formatted(postfachRemoteService.getPostfachType())); LOG.error("PostfachType is null - use existing PostfachService with type %s.".formatted(postfachRemoteService.getPostfachType()));
return true; return true;
} }
return StringUtils.equals(postfachRemoteService.getPostfachType(), postfachType); return StringUtils.equals(postfachRemoteService.getPostfachType(), postfachType);
......
...@@ -52,6 +52,7 @@ import org.springframework.boot.logging.LogLevel; ...@@ -52,6 +52,7 @@ import org.springframework.boot.logging.LogLevel;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.nachrichten.antragraum.AntragraumService; import de.ozgcloud.nachrichten.antragraum.AntragraumService;
import de.ozgcloud.nachrichten.attributes.ClientAttributeService; import de.ozgcloud.nachrichten.attributes.ClientAttributeService;
import de.ozgcloud.nachrichten.info.InfoManagerService; import de.ozgcloud.nachrichten.info.InfoManagerService;
...@@ -877,14 +878,27 @@ class PostfachServiceTest { ...@@ -877,14 +878,27 @@ class PostfachServiceTest {
assertThat(foundRemoteService).isEmpty(); assertThat(foundRemoteService).isEmpty();
} }
@Test @DisplayName("on postfachType null")
void shouldReturnRemoteServiceOnPostfachTypeNull() { @Nested
when(remoteService.getPostfachType()).thenReturn("BAYERN_ID"); class TestOnPostfachTypeNull {
doReturn(Stream.of(remoteService)).when(service).getPostfachRemoteServices();
var foundRemoteService = service.findPostfachRemoteService(null); @Test
void shouldReturnRemoteService() {
when(remoteService.getPostfachType()).thenReturn("BAYERN_ID");
doReturn(Stream.of(remoteService)).when(service).getPostfachRemoteServices();
assertThat(foundRemoteService).hasValue(remoteService); var foundRemoteService = service.findPostfachRemoteService(null);
assertThat(foundRemoteService).hasValue(remoteService);
}
@Test
void shouldThrowExceptionMultipleConfiguredRemoteServices() {
doReturn(Stream.of(anotherRemoteService, remoteService)).when(service).getPostfachRemoteServices();
assertThatThrownBy(() -> service.findPostfachRemoteService(null))
.isInstanceOf(TechnicalException.class);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment