Skip to content
Snippets Groups Projects
Commit ec6bd408 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

Merge branch 'develop' into 'main'

Änderungen von Dataport

See merge request !16
parents 8d55a1b3 698bdfc2
Branches
Tags
1 merge request!16Änderungen von Dataport
......@@ -28,6 +28,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
......@@ -102,6 +103,7 @@ public class VorgangService {
List<String> getOrganisationsEinheitIds(FormData formData) {
return formData.getZustaendigeStelles().stream()
.map(ZustaendigeStelle::getOrganisationseinheitenId)
.filter(Objects::nonNull)
.toList();
}
......
......@@ -306,6 +306,19 @@ class VorgangServiceTest {
class TestGetOrganisationseinheitIds {
private final FormData preservedFormData = FormDataTestFactory.create();
@DisplayName("should exclude nulls")
@Test
void shouldExcludeNulls() {
var formDataWithNull = FormDataTestFactory.createBuilder()
.clearZustaendigeStelles()
.zustaendigeStelles(List.of(ZustaendigeStelleTestFactory.createBuilder().organisationseinheitenId(null).build()))
.build();
var organisationseinheitIds = service.getOrganisationsEinheitIds(formDataWithNull);
assertThat(organisationseinheitIds).isEmpty();
}
@DisplayName("should return")
@Test
void shouldReturn() {
......
......@@ -23,11 +23,13 @@
*/
package de.ozgcloud.eingang.semantik.common;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;
......@@ -102,16 +104,28 @@ public class ServiceKontoFactory {
}
int getPostfachAddressType(Map<String, Object> restResponseName) {
return getMailboxType(restResponseName);
return getMailboxType(restResponseName)
.orElseGet(() -> {
LOG.warn("Mailbox type not found in rest_response_name! Using default value '{}'", POSTFACH_ADDRESS_DEFAULT);
return POSTFACH_ADDRESS_DEFAULT;
});
}
private Integer getMailboxType(Map<String, Object> restResponseName) {
return (Integer) getMemberScope(restResponseName).get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE);
private Optional<Integer> getMailboxType(Map<String, Object> restResponseName) {
return getMemberScope(restResponseName)
.map(scope -> scope.get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE))
.filter(Integer.class::isInstance)
.map(Integer.class::cast);
}
@SuppressWarnings("unchecked")
private Map<String, Object> getMemberScope(Map<String, Object> restResponseName) {
return ((List<Map<String, Object>>) restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE)).get(0);
private Optional<Map<String, Object>> getMemberScope(Map<String, Object> restResponseName) {
return Optional.ofNullable(restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE))
.filter(List.class::isInstance)
.map(List.class::cast)
.map(Collection::stream)
.flatMap(Stream::findFirst)
.filter(Map.class::isInstance);
}
public Optional<ServiceKonto> createBayernIdServiceKonto(Map<String, Object> formDataHeaders) {
......
......@@ -23,6 +23,7 @@
*/
package de.ozgcloud.eingang.semantik.common;
import static de.ozgcloud.eingang.semantik.common.ServiceKontoFactory.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
......@@ -30,10 +31,13 @@ import static org.mockito.Mockito.*;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks;
import org.mockito.Spy;
......@@ -41,10 +45,10 @@ import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.FormDataUtils;
import de.ozgcloud.eingang.common.formdata.PostfachAddressTestFactory;
import de.ozgcloud.eingang.common.formdata.ServiceKonto;
import de.ozgcloud.eingang.common.formdata.ServiceKonto.PostfachAddress;
import de.ozgcloud.eingang.common.formdata.ServiceKonto.TrustLevel;
import de.ozgcloud.eingang.common.formdata.ServiceKontoTestFactory;
import de.ozgcloud.eingang.common.formdata.StringBasedIdentifier;
import de.ozgcloud.eingang.common.formdata.ServiceKonto.PostfachAddress;
class ServiceKontoFactoryTest {
......@@ -104,15 +108,16 @@ class ServiceKontoFactoryTest {
@Nested
class TestWithRestResponseName {
@DisplayName("should call buildOsiPostfachV1Address")
@Test
void shouldCallBuildAddresses() {
void shouldCallBuildOsiPostfachV1Address() {
getPostfachAddresses();
verify(factory).buildOsiPostfachV1Address(any(), anyInt());
}
@Test
void shouldReturnPostfachAddresses() {
void shouldBuildPostfachAddresses() {
var addresses = getPostfachAddresses();
assertThat(addresses).hasSize(1);
......@@ -123,11 +128,58 @@ class ServiceKontoFactoryTest {
assertThat(addresses.get(0).getType()).isEqualTo(PostfachAddressTestFactory.POSTFACH_ADDRESS_TYPE);
}
@DisplayName("should build with postfach address type")
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3 })
void shouldBuildWithPostfachAddressType(int postfachAddressType) {
var formDataWithPostfachAddressType = FormDataUtils.from(FORM_DATA)
.put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of(
ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE,
List.of(Map.of(ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE,
postfachAddressType))))
)
.build();
var serviceKonto = buildServiceKonto(formDataWithPostfachAddressType);
assertThat(serviceKonto)
.extracting(ServiceKonto::getPostfachAddresses, InstanceOfAssertFactories.list(PostfachAddress.class))
.extracting(PostfachAddress::getType)
.containsExactly(postfachAddressType);
}
private List<PostfachAddress> getPostfachAddresses() {
return buildServiceKonto(FORM_DATA).getPostfachAddresses();
}
}
@DisplayName("with unexpected rest_response_name")
@Nested
class TestWithUnexpectedRestResponseName {
private final FormData formDataWithUnexpectedRestResponseName = FormDataUtils.from(FORM_DATA)
.put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of())).build();
@DisplayName("should call buildOsiPostfachV1Address")
@Test
void shouldCallBuildOsiPostfachV1Address() {
buildServiceKonto(formDataWithUnexpectedRestResponseName);
verify(factory).buildOsiPostfachV1Address(any(), anyInt());
}
@DisplayName("should build postfach address with default type")
@Test
void shouldBuildPostfachAddressWithDefaultType() {
var serviceKonto = buildServiceKonto(formDataWithUnexpectedRestResponseName);
assertThat(serviceKonto)
.extracting(ServiceKonto::getPostfachAddresses, InstanceOfAssertFactories.list(PostfachAddress.class))
.extracting(PostfachAddress::getType)
.containsExactly(POSTFACH_ADDRESS_DEFAULT);
}
}
@DisplayName("without rest_response_name")
@Nested
class TestWithoutRestResponseName {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment