Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ozg-cloud/app/eingang-manager
1 result
Show changes
Commits on Source (2)
......@@ -102,7 +102,12 @@ public class ServiceKontoFactory {
}
int getPostfachAddressType(Map<String, Object> restResponseName) {
return getMailboxType(restResponseName);
try {
return getMailboxType(restResponseName);
} catch (RuntimeException e) {
LOG.error("Error while getting mailbox type from rest response name", e);
return POSTFACH_ADDRESS_DEFAULT;
}
}
private Integer getMailboxType(Map<String, Object> restResponseName) {
......
......@@ -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.*;
......@@ -34,6 +35,8 @@ 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 +44,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,8 +107,9 @@ class ServiceKontoFactoryTest {
@Nested
class TestWithRestResponseName {
@DisplayName("should call buildOsiPostfachV1Address")
@Test
void shouldCallBuildAddresses() {
void shouldCallBuildOsiPostfachV1Address() {
getPostfachAddresses();
verify(factory).buildOsiPostfachV1Address(any(), anyInt());
......@@ -123,11 +127,62 @@ class ServiceKontoFactoryTest {
assertThat(addresses.get(0).getType()).isEqualTo(PostfachAddressTestFactory.POSTFACH_ADDRESS_TYPE);
}
@DisplayName("should return with postfach address type")
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3 })
void shouldReturnWithPostfachAddressType(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 addresses = buildServiceKonto(formDataWithPostfachAddressType);
var types = addresses.getPostfachAddresses()
.stream()
.map(PostfachAddress::getType)
.toList();
assertThat(types).containsExactly(postfachAddressType);
}
private List<PostfachAddress> getPostfachAddresses() {
return buildServiceKonto(FORM_DATA).getPostfachAddresses();
}
}
@DisplayName("with bad rest_response_name")
@Nested
class TestWithBadRestResponseName {
private final FormData formDataWithBadRestResponseName = FormDataUtils.from(FORM_DATA)
.put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of())).build();
@DisplayName("should call buildOsiPostfachV1Address")
@Test
void shouldCallBuildOsiPostfachV1Address() {
getPostfachAddresses();
verify(factory).buildOsiPostfachV1Address(any(), anyInt());
}
@DisplayName("should return postfach address with default type")
@Test
void shouldReturnPostfachAddressWithDefaultType() {
var addresses = getPostfachAddresses();
assertThat(addresses)
.extracting("type")
.containsExactly(POSTFACH_ADDRESS_DEFAULT);
}
private List<PostfachAddress> getPostfachAddresses() {
return buildServiceKonto(formDataWithBadRestResponseName).getPostfachAddresses();
}
}
@DisplayName("without rest_response_name")
@Nested
class TestWithoutRestResponseName {
......