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

Merge pull request 'OZG-4089_schnittstelle_antragsraum' (#292) from...

Merge pull request 'OZG-4089_schnittstelle_antragsraum' (#292) from OZG-4089_schnittstelle_antragsraum into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/vorgang-manager/pulls/292


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents 59d34db7 cd44e74c
Branches
Tags
No related merge requests found
Showing
with 220 additions and 90 deletions
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.antragraum;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
...@@ -13,12 +13,12 @@ import lombok.Setter; ...@@ -13,12 +13,12 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
@Configuration @Configuration
@ConditionalOnProperty(AntragsraumProperties.PROPERTY_ANTRAGSRAUM_URL) @ConditionalOnProperty(AntragraumProperties.PROPERTY_ANTRAGSRAUM_URL)
@ConfigurationProperties(prefix = "ozgcloud.antragsraum") @ConfigurationProperties(prefix = "ozgcloud.antragraum")
@Validated @Validated
class AntragsraumProperties { public class AntragraumProperties {
static final String PROPERTY_ANTRAGSRAUM_URL = "ozgcloud.antragsraum.url"; public static final String PROPERTY_ANTRAGSRAUM_URL = "ozgcloud.antragraum.url";
@NotEmpty @NotEmpty
private String url; private String url;
......
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.antragraum;
import static java.util.Objects.*; import static java.util.Objects.*;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.NachrichtenManagerProperties; import de.ozgcloud.nachrichten.NachrichtenManagerProperties;
import de.ozgcloud.nachrichten.postfach.PostfachException; import lombok.RequiredArgsConstructor;
import de.ozgcloud.nachrichten.postfach.PostfachMessageCode;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
@Service @Service
@ConditionalOnProperty(AntragsraumProperties.PROPERTY_ANTRAGSRAUM_URL) @RequiredArgsConstructor
public class AntragsraumService { @ConditionalOnProperty(AntragraumProperties.PROPERTY_ANTRAGSRAUM_URL)
public class AntragraumService {
static final String USER_NOTIFICATION_TEMPLATE = """ static final String USER_NOTIFICATION_TEMPLATE = """
Guten Tag, Guten Tag,
...@@ -28,14 +26,8 @@ public class AntragsraumService { ...@@ -28,14 +26,8 @@ public class AntragsraumService {
Ihre digitale Verwaltung Ihre digitale Verwaltung
"""; """;
@Autowired private final AntragraumProperties properties;
private AntragsraumProperties properties; private final NachrichtenManagerProperties nachrichtenManagerProperties;
@Autowired
private NachrichtenManagerProperties nachrichtenManagerProperties;
@Autowired
private InfomanagerRemoteService infomanagerRemoteService;
@PostConstruct @PostConstruct
void init() { void init() {
...@@ -52,20 +44,4 @@ public class AntragsraumService { ...@@ -52,20 +44,4 @@ public class AntragsraumService {
return USER_NOTIFICATION_TEMPLATE.formatted(getAntragsraumUrl()); return USER_NOTIFICATION_TEMPLATE.formatted(getAntragsraumUrl());
} }
public void notifyAntragsraum(PostfachNachricht postfachNachricht) {
try {
infomanagerRemoteService.sendNotification(builInfomanagerNachricht(postfachNachricht));
} catch (RuntimeException e) {
throw new PostfachException("Error while sending notification to Antragsraum", PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE, e);
}
}
InfomanagerNachricht builInfomanagerNachricht(PostfachNachricht postfachNachricht) {
return InfomanagerNachricht.builder()
.nachrichtId(postfachNachricht.getId())
.vorgangId(postfachNachricht.getVorgangId())
.postfachId(postfachNachricht.getPostfachId())
.nachrichtenManagerUrl(nachrichtenManagerProperties.getUrl())
.build();
}
} }
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -8,7 +8,7 @@ import de.ozgcloud.info.nachricht.NachrichtServiceGrpc.NachrichtServiceBlockingS ...@@ -8,7 +8,7 @@ import de.ozgcloud.info.nachricht.NachrichtServiceGrpc.NachrichtServiceBlockingS
import net.devh.boot.grpc.client.inject.GrpcClient; import net.devh.boot.grpc.client.inject.GrpcClient;
@Service @Service
class InfomanagerRemoteService { class InfoManagerRemoteService {
@GrpcClient("info-manager") @GrpcClient("info-manager")
private NachrichtServiceBlockingStub nachrichtServiceStub; private NachrichtServiceBlockingStub nachrichtServiceStub;
...@@ -16,12 +16,12 @@ class InfomanagerRemoteService { ...@@ -16,12 +16,12 @@ class InfomanagerRemoteService {
@Autowired @Autowired
private InfomanagerNachrichtMapper nachrichtMapper; private InfomanagerNachrichtMapper nachrichtMapper;
public String sendNotification(InfomanagerNachricht nachricht) { public String sendNotification(InfoManagerRequest nachricht) {
var grpcNewNachrichtReply = nachrichtServiceStub.saveNewNachricht(buildNachrichtRequest(nachricht)); var grpcNewNachrichtReply = nachrichtServiceStub.saveNewNachricht(buildNachrichtRequest(nachricht));
return grpcNewNachrichtReply.getStatus(); return grpcNewNachrichtReply.getStatus();
} }
GrpcNewNachrichtRequest buildNachrichtRequest(InfomanagerNachricht nachricht) { GrpcNewNachrichtRequest buildNachrichtRequest(InfoManagerRequest nachricht) {
return GrpcNewNachrichtRequest.newBuilder().setNachricht(nachrichtMapper.toGrpc(nachricht)).build(); return GrpcNewNachrichtRequest.newBuilder().setNachricht(nachrichtMapper.toGrpc(nachricht)).build();
} }
......
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
@Builder @Builder
@Getter @Getter
public class InfomanagerNachricht { public class InfoManagerRequest {
private String nachrichtId; private String nachrichtId;
private String vorgangId; private String vorgangId;
......
package de.ozgcloud.nachrichten.info;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import de.ozgcloud.nachrichten.NachrichtenManagerProperties;
import de.ozgcloud.nachrichten.antragraum.AntragraumProperties;
import de.ozgcloud.nachrichten.postfach.PostfachException;
import de.ozgcloud.nachrichten.postfach.PostfachMessageCode;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@ConditionalOnProperty(AntragraumProperties.PROPERTY_ANTRAGSRAUM_URL)
public class InfoManagerService {
private final InfoManagerRemoteService infomanagerRemoteService;
private final NachrichtenManagerProperties nachrichtenManagerProperties;
public void notifyInfoManager(PostfachNachricht postfachNachricht) {
try {
infomanagerRemoteService.sendNotification(builInfomanagerRequest(postfachNachricht));
} catch (RuntimeException e) {
throw new PostfachException("Error while sending notification to Antragsraum", PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE, e);
}
}
InfoManagerRequest builInfomanagerRequest(PostfachNachricht postfachNachricht) {
return InfoManagerRequest.builder()
.nachrichtId(postfachNachricht.getId())
.vorgangId(postfachNachricht.getVorgangId())
.postfachId(postfachNachricht.getPostfachId())
.nachrichtenManagerUrl(nachrichtenManagerProperties.getUrl())
.build();
}
}
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
...@@ -9,6 +9,6 @@ import de.ozgcloud.info.nachricht.GrpcNachricht; ...@@ -9,6 +9,6 @@ import de.ozgcloud.info.nachricht.GrpcNachricht;
interface InfomanagerNachrichtMapper { interface InfomanagerNachrichtMapper {
@Mapping(target = "nachrichtenListUrl", source = "nachrichtenManagerUrl") @Mapping(target = "nachrichtenListUrl", source = "nachrichtenManagerUrl")
GrpcNachricht toGrpc(InfomanagerNachricht infomanagerNachricht); GrpcNachricht toGrpc(InfoManagerRequest infomanagerNachricht);
} }
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
...@@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import de.ozgcloud.nachrichten.antragraum.AntragraumProperties;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -14,7 +15,7 @@ import lombok.Setter; ...@@ -14,7 +15,7 @@ import lombok.Setter;
@Setter @Setter
@Configuration @Configuration
@ConfigurationProperties(prefix = "grpc.client.info-manager") @ConfigurationProperties(prefix = "grpc.client.info-manager")
@ConditionalOnProperty(AntragsraumProperties.PROPERTY_ANTRAGSRAUM_URL) @ConditionalOnProperty(AntragraumProperties.PROPERTY_ANTRAGSRAUM_URL)
@Validated @Validated
public class InfomanagerProperties { public class InfomanagerProperties {
......
...@@ -42,4 +42,23 @@ public interface PersistPostfachNachrichtService { ...@@ -42,4 +42,23 @@ public interface PersistPostfachNachrichtService {
// TODO use file id as soon it is available // TODO use file id as soon it is available
String persistAttachment(String vorgangId, AttachmentFile attachment); String persistAttachment(String vorgangId, AttachmentFile attachment);
Stream<PostfachNachricht> findRueckfragen(String postfachId);
/**
* Persists the given answer
*
* @param answer The given answer
* @param rueckfrageId The ID of the original Rueckfrage
* @return
*/
String persistAnswer(String rueckfrageId, PostfachNachricht answer);
/**
* Returns all Answers given for the Rueckfrage identified by id
*
* @param rueckfrageId ID of the Rueckfrage to load answers for.
* @return all Answers
*/
Stream<PostfachNachricht> findAnswers(String rueckfrageId);
} }
...@@ -39,10 +39,11 @@ import org.springframework.context.ApplicationEventPublisher; ...@@ -39,10 +39,11 @@ 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.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.postfach.PostfachNachricht.Direction; import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht.ReplyOption; import de.ozgcloud.nachrichten.postfach.PostfachNachricht.ReplyOption;
import de.ozgcloud.nachrichten.postfach.antragsraum.AntragsraumService;
import de.ozgcloud.nachrichten.postfach.osi.OsiPostfachServerProcessException; import de.ozgcloud.nachrichten.postfach.osi.OsiPostfachServerProcessException;
import de.ozgcloud.vorgang.callcontext.CurrentUserService; import de.ozgcloud.vorgang.callcontext.CurrentUserService;
import lombok.NonNull; import lombok.NonNull;
...@@ -75,8 +76,10 @@ class PostfachService { ...@@ -75,8 +76,10 @@ class PostfachService {
@Autowired @Autowired
private CurrentUserService userService; private CurrentUserService userService;
@Autowired(required = false) @Autowired
private AntragsraumService antragsraumService; private Optional<InfoManagerService> infomanagerService;
@Autowired
private Optional<AntragraumService> antragraumService;
public void saveDraft(String vorgangId, PostfachNachricht nachricht) { public void saveDraft(String vorgangId, PostfachNachricht nachricht) {
persistMail(userService.getUser().getUserId(), persistMail(userService.getUser().getUserId(),
...@@ -155,7 +158,7 @@ class PostfachService { ...@@ -155,7 +158,7 @@ class PostfachService {
Optional<PostfachNachricht> processForAntragsraum(PostfachNachricht mail) { Optional<PostfachNachricht> processForAntragsraum(PostfachNachricht mail) {
if (isNotifyAntragsraum(mail.getReplyOption())) { if (isNotifyAntragsraum(mail.getReplyOption())) {
antragsraumService.notifyAntragsraum(mail); infomanagerService.ifPresent(infoManager -> infoManager.notifyInfoManager(mail));
return adjustMail(mail); return adjustMail(mail);
} }
return Optional.empty(); return Optional.empty();
...@@ -166,7 +169,7 @@ class PostfachService { ...@@ -166,7 +169,7 @@ class PostfachService {
} }
Optional<PostfachNachricht> adjustMail(PostfachNachricht nachricht) { Optional<PostfachNachricht> adjustMail(PostfachNachricht nachricht) {
return getAntragsraumService().map(antragsraum -> nachricht.toBuilder().mailBody(antragsraum.getUserNotificationText()).build()); return antragraumService.map(antragraum -> nachricht.toBuilder().mailBody(antragraum.getUserNotificationText()).build());
} }
SendPostfachNachrichtResponse proceedwithWarnException(String commandId, OsiPostfachServerProcessException e) { SendPostfachNachrichtResponse proceedwithWarnException(String commandId, OsiPostfachServerProcessException e) {
...@@ -228,11 +231,7 @@ class PostfachService { ...@@ -228,11 +231,7 @@ class PostfachService {
} }
boolean isPostfachWithAntragsraum(PostfachRemoteService postfachRemoteService) { boolean isPostfachWithAntragsraum(PostfachRemoteService postfachRemoteService) {
return POSTFACH_TYPES_WITH_ANTRAGSRAUM.contains(postfachRemoteService.getPostfachType()) && getAntragsraumService().isPresent(); return POSTFACH_TYPES_WITH_ANTRAGSRAUM.contains(postfachRemoteService.getPostfachType()) && infomanagerService.isPresent();
}
Optional<AntragsraumService> getAntragsraumService() {
return Optional.ofNullable(antragsraumService);
} }
private void ifPostfachConfigured(Runnable block) { private void ifPostfachConfigured(Runnable block) {
......
package de.ozgcloud.nachrichten.antragraum;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import de.ozgcloud.nachrichten.NachrichtenManagerProperties;
import de.ozgcloud.nachrichten.antragraum.AntragraumProperties;
import de.ozgcloud.nachrichten.antragraum.AntragraumService;
class AntragraumServiceTest {
@InjectMocks
private AntragraumService service;
@Mock
private AntragraumProperties properties;
@Mock
private NachrichtenManagerProperties nachrichtenManagerProperties;
@Nested
class TestGetAntragsraumUrl {
private static final String URL = "url";
@Test
void shouldReturnUrl() {
when(properties.getUrl()).thenReturn(URL);
var url = service.getAntragsraumUrl();
assertThat(url).isEqualTo(URL);
}
}
}
\ No newline at end of file
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.antragraum;
import de.ozgcloud.info.nachricht.GrpcNachricht; import de.ozgcloud.info.nachricht.GrpcNachricht;
import de.ozgcloud.nachrichten.info.InfoManagerRequestTestFactory;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
...@@ -15,6 +16,6 @@ public class GrpcNachrichtTestFactory { ...@@ -15,6 +16,6 @@ public class GrpcNachrichtTestFactory {
.setNachrichtId(PostfachNachrichtTestFactory.ID) .setNachrichtId(PostfachNachrichtTestFactory.ID)
.setVorgangId(MessageTestFactory.VORGANG_ID) .setVorgangId(MessageTestFactory.VORGANG_ID)
.setPostfachId(MessageTestFactory.POSTFACH_ID) .setPostfachId(MessageTestFactory.POSTFACH_ID)
.setNachrichtenListUrl(InfomanagerNachrichtTestFactory.NACHRICHTEN_MANAGER_URL); .setNachrichtenListUrl(InfoManagerRequestTestFactory.NACHRICHTEN_MANAGER_URL);
} }
} }
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -15,11 +16,11 @@ import de.ozgcloud.info.nachricht.GrpcNewNachrichtReply; ...@@ -15,11 +16,11 @@ import de.ozgcloud.info.nachricht.GrpcNewNachrichtReply;
import de.ozgcloud.info.nachricht.GrpcNewNachrichtRequest; import de.ozgcloud.info.nachricht.GrpcNewNachrichtRequest;
import de.ozgcloud.info.nachricht.NachrichtServiceGrpc.NachrichtServiceBlockingStub; import de.ozgcloud.info.nachricht.NachrichtServiceGrpc.NachrichtServiceBlockingStub;
class InfomanagerRemoteServiceTest { class InfoManagerRemoteServiceTest {
@Spy @Spy
@InjectMocks @InjectMocks
private InfomanagerRemoteService service; private InfoManagerRemoteService service;
@Mock @Mock
private NachrichtServiceBlockingStub nachrichtServiceStub; private NachrichtServiceBlockingStub nachrichtServiceStub;
...@@ -59,7 +60,7 @@ class InfomanagerRemoteServiceTest { ...@@ -59,7 +60,7 @@ class InfomanagerRemoteServiceTest {
} }
private String sendNotification() { private String sendNotification() {
return service.sendNotification(InfomanagerNachrichtTestFactory.create()); return service.sendNotification(InfoManagerRequestTestFactory.create());
} }
} }
...@@ -76,7 +77,7 @@ class InfomanagerRemoteServiceTest { ...@@ -76,7 +77,7 @@ class InfomanagerRemoteServiceTest {
@Test @Test
void shouldCallMapper() { void shouldCallMapper() {
var nachricht = InfomanagerNachrichtTestFactory.create(); var nachricht = InfoManagerRequestTestFactory.create();
service.buildNachrichtRequest(nachricht); service.buildNachrichtRequest(nachricht);
...@@ -85,7 +86,7 @@ class InfomanagerRemoteServiceTest { ...@@ -85,7 +86,7 @@ class InfomanagerRemoteServiceTest {
@Test @Test
void shouldSetNachricht() { void shouldSetNachricht() {
var grpcRequest = service.buildNachrichtRequest(InfomanagerNachrichtTestFactory.create()); var grpcRequest = service.buildNachrichtRequest(InfoManagerRequestTestFactory.create());
assertThat(grpcRequest.getNachricht()).isEqualTo(grpcNachricht); assertThat(grpcRequest.getNachricht()).isEqualTo(grpcNachricht);
} }
......
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.antragsraum.InfomanagerNachricht.InfomanagerNachrichtBuilder;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
public class InfomanagerNachrichtTestFactory { public class InfoManagerRequestTestFactory {
public static final String NACHRICHTEN_MANAGER_URL = "nachrichten-manager"; public static final String NACHRICHTEN_MANAGER_URL = "nachrichten-manager";
public static InfomanagerNachricht create() {
public static InfoManagerRequest create() {
return createBuilder().build(); return createBuilder().build();
} }
private static InfomanagerNachrichtBuilder createBuilder() { private static InfoManagerRequest.InfoManagerRequestBuilder createBuilder() {
return InfomanagerNachricht.builder() return InfoManagerRequest.builder()
.nachrichtId(PostfachNachrichtTestFactory.ID) .nachrichtId(PostfachNachrichtTestFactory.ID)
.vorgangId(MessageTestFactory.VORGANG_ID) .vorgangId(MessageTestFactory.VORGANG_ID)
.postfachId(MessageTestFactory.POSTFACH_ID) .postfachId(MessageTestFactory.POSTFACH_ID)
......
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -17,37 +18,19 @@ import de.ozgcloud.nachrichten.postfach.PostfachNachricht; ...@@ -17,37 +18,19 @@ import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
class AntragsraumServiceTest { class InfoManagerServiceTest {
@Spy @Spy
@InjectMocks @InjectMocks
private AntragsraumService service; private InfoManagerService service;
@Mock @Mock
private AntragsraumProperties properties; private InfoManagerRemoteService infomanagerRemoteService;
@Mock @Mock
private NachrichtenManagerProperties nachrichtenManagerProperties; private NachrichtenManagerProperties nachrichtenManagerProperties;
@Mock
private InfomanagerRemoteService infomanagerRemoteService;
@Nested @Nested
class TestGetAntragsraumUrl { class TestNotifyInfoManager {
private static final String URL = "url";
@Test
void shouldReturnUrl() {
when(properties.getUrl()).thenReturn(URL);
var url = service.getAntragsraumUrl();
assertThat(url).isEqualTo(URL);
}
}
@Nested
class TestNotifyAntragsraum {
private static final String NACHRICHTEN_MANAGER_URL = "nachrichtenManagerUrl"; private static final String NACHRICHTEN_MANAGER_URL = "nachrichtenManagerUrl";
...@@ -55,17 +38,17 @@ class AntragsraumServiceTest { ...@@ -55,17 +38,17 @@ class AntragsraumServiceTest {
@Test @Test
void shouldCallBuildInfomanagerNachricht() { void shouldCallBuildInfomanagerNachricht() {
service.notifyAntragsraum(postfachNachricht); service.notifyInfoManager(postfachNachricht);
verify(service).builInfomanagerNachricht(postfachNachricht); verify(service).builInfomanagerRequest(postfachNachricht);
} }
@Test @Test
void shouldCallInfoManagerRemoteService() { void shouldCallInfoManagerRemoteService() {
var infomanagerNachricht = InfomanagerNachrichtTestFactory.create(); var infomanagerNachricht = InfoManagerRequestTestFactory.create();
doReturn(infomanagerNachricht).when(service).builInfomanagerNachricht(any()); doReturn(infomanagerNachricht).when(service).builInfomanagerRequest(any());
service.notifyAntragsraum(postfachNachricht); service.notifyInfoManager(postfachNachricht);
verify(infomanagerRemoteService).sendNotification(infomanagerNachricht); verify(infomanagerRemoteService).sendNotification(infomanagerNachricht);
} }
...@@ -75,7 +58,7 @@ class AntragsraumServiceTest { ...@@ -75,7 +58,7 @@ class AntragsraumServiceTest {
var causeException = new RuntimeException(); var causeException = new RuntimeException();
when(infomanagerRemoteService.sendNotification(any())).thenThrow(causeException); when(infomanagerRemoteService.sendNotification(any())).thenThrow(causeException);
var exception = assertThrows(PostfachException.class, () -> service.notifyAntragsraum(postfachNachricht)); var exception = assertThrows(PostfachException.class, () -> service.notifyInfoManager(postfachNachricht));
assertThat(exception.getMessageCode()).isEqualTo(PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE); assertThat(exception.getMessageCode()).isEqualTo(PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE);
} }
...@@ -84,38 +67,38 @@ class AntragsraumServiceTest { ...@@ -84,38 +67,38 @@ class AntragsraumServiceTest {
@Test @Test
void shouldSetNachrichtId() { void shouldSetNachrichtId() {
var infomanagerNachricht = buildInfomanagerNachricht(); var request = buildInfomanagerNachricht();
assertThat(infomanagerNachricht.getNachrichtId()).isEqualTo(PostfachNachrichtTestFactory.ID); assertThat(request.getNachrichtId()).isEqualTo(PostfachNachrichtTestFactory.ID);
} }
@Test @Test
void shouldSetVorgangId() { void shouldSetVorgangId() {
var infomanagerNachricht = buildInfomanagerNachricht(); var request = buildInfomanagerNachricht();
assertThat(infomanagerNachricht.getVorgangId()).isEqualTo(MessageTestFactory.VORGANG_ID); assertThat(request.getVorgangId()).isEqualTo(MessageTestFactory.VORGANG_ID);
} }
@Test @Test
void shouldSetPostfachId() { void shouldSetPostfachId() {
var infomanagerNachricht = buildInfomanagerNachricht(); var request = buildInfomanagerNachricht();
assertThat(infomanagerNachricht.getPostfachId()).isEqualTo(MessageTestFactory.POSTFACH_ID); assertThat(request.getPostfachId()).isEqualTo(MessageTestFactory.POSTFACH_ID);
} }
@Test @Test
void shouldSetNachrichtenManagerUrl() { void shouldSetNachrichtenManagerUrl() {
when(nachrichtenManagerProperties.getUrl()).thenReturn(NACHRICHTEN_MANAGER_URL); when(nachrichtenManagerProperties.getUrl()).thenReturn(NACHRICHTEN_MANAGER_URL);
var infomanagerNachricht = buildInfomanagerNachricht(); var request = buildInfomanagerNachricht();
assertThat(infomanagerNachricht.getNachrichtenManagerUrl()).isEqualTo(NACHRICHTEN_MANAGER_URL); assertThat(request.getNachrichtenManagerUrl()).isEqualTo(NACHRICHTEN_MANAGER_URL);
} }
private InfomanagerNachricht buildInfomanagerNachricht() { private InfoManagerRequest buildInfomanagerNachricht() {
return service.builInfomanagerNachricht(postfachNachricht); return service.builInfomanagerRequest(postfachNachricht);
}
} }
} }
} }
}
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.info;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
...@@ -38,10 +38,10 @@ class InfomanagerNachrichtMapperTest { ...@@ -38,10 +38,10 @@ class InfomanagerNachrichtMapperTest {
void shouldMapNachrichtenManagerUrl() { void shouldMapNachrichtenManagerUrl() {
var result = map(); var result = map();
assertThat(result.getNachrichtenListUrl()).isEqualTo(InfomanagerNachrichtTestFactory.NACHRICHTEN_MANAGER_URL); assertThat(result.getNachrichtenListUrl()).isEqualTo(InfoManagerRequestTestFactory.NACHRICHTEN_MANAGER_URL);
} }
private GrpcNachricht map() { private GrpcNachricht map() {
return mapper.toGrpc(InfomanagerNachrichtTestFactory.create()); return mapper.toGrpc(InfoManagerRequestTestFactory.create());
} }
} }
\ No newline at end of file
...@@ -2,7 +2,6 @@ package de.ozgcloud.nachrichten.postfach; ...@@ -2,7 +2,6 @@ package de.ozgcloud.nachrichten.postfach;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
......
...@@ -48,11 +48,13 @@ import org.mockito.Mock; ...@@ -48,11 +48,13 @@ import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LogLevel;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;
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.postfach.PostfachNachricht.Direction; import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht.ReplyOption; import de.ozgcloud.nachrichten.postfach.PostfachNachricht.ReplyOption;
import de.ozgcloud.nachrichten.postfach.antragsraum.AntragsraumService;
import de.ozgcloud.nachrichten.postfach.osi.MessageAttachmentService; import de.ozgcloud.nachrichten.postfach.osi.MessageAttachmentService;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
import de.ozgcloud.nachrichten.postfach.osi.OsiPostfachServerProcessException; import de.ozgcloud.nachrichten.postfach.osi.OsiPostfachServerProcessException;
...@@ -83,8 +85,10 @@ class PostfachServiceTest { ...@@ -83,8 +85,10 @@ class PostfachServiceTest {
@Mock @Mock
private CurrentUserService userService; private CurrentUserService userService;
@Mock @Spy
private AntragsraumService antragsraumService; private Optional<AntragraumService> antragsraumService = Optional.of(mock(AntragraumService.class));
@Spy
private Optional<InfoManagerService> infomanagerService = Optional.of(mock(InfoManagerService.class));
static final String COMMAND_ID = UUID.randomUUID().toString(); static final String COMMAND_ID = UUID.randomUUID().toString();
static final String USER_ID = UUID.randomUUID().toString(); static final String USER_ID = UUID.randomUUID().toString();
...@@ -256,7 +260,7 @@ class PostfachServiceTest { ...@@ -256,7 +260,7 @@ class PostfachServiceTest {
service.processForAntragsraum(mail); service.processForAntragsraum(mail);
verify(antragsraumService).notifyAntragsraum(mail); verify(infomanagerService.get()).notifyInfoManager(mail);
} }
@Test @Test
...@@ -314,7 +318,7 @@ class PostfachServiceTest { ...@@ -314,7 +318,7 @@ class PostfachServiceTest {
@Test @Test
void shouldReturnEmptyIfNoAntragsraum() { void shouldReturnEmptyIfNoAntragsraum() {
doReturn(Optional.empty()).when(service).getAntragsraumService(); ReflectionTestUtils.setField(service, "antragraumService", Optional.empty());
var result = adjustMail(); var result = adjustMail();
...@@ -325,7 +329,7 @@ class PostfachServiceTest { ...@@ -325,7 +329,7 @@ class PostfachServiceTest {
void shouldAdjustMailBody() { void shouldAdjustMailBody() {
when(mail.toBuilder()).thenReturn(PostfachNachrichtTestFactory.createBuilder()); when(mail.toBuilder()).thenReturn(PostfachNachrichtTestFactory.createBuilder());
var expectedMailBody = "Antragsraum Text"; var expectedMailBody = "Antragsraum Text";
when(antragsraumService.getUserNotificationText()).thenReturn(expectedMailBody); when(antragsraumService.get().getUserNotificationText()).thenReturn(expectedMailBody);
var result = adjustMail(); var result = adjustMail();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment