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

OZG-4768 Antwort zur Rückfrage implementiert

parent 90dc8a5a
Branches
Tags
No related merge requests found
......@@ -50,7 +50,11 @@ class AntragraumGrpcService extends AntragraumServiceGrpc.AntragraumServiceImplB
@Override
public void sendRueckfrageAnswer(GrpcSendRueckfrageAnswerRequest request, StreamObserver<GrpcCommand> streamObserver) {
throw new NotImplementedException("sendRueckfrageAnswer not implemented yet");
}
var answer = request.getAnswer();
var commandId = antragraumService.sendRueckfrageAnswer(request.getSamlToken(), answer.getRueckfrageId(), mapper.toPostfachNachricht(answer));
streamObserver.onNext(GrpcCommand.newBuilder().setId(commandId).build());
streamObserver.onCompleted();
}
}
......@@ -41,4 +41,21 @@ interface AntragraumNachrichtMapper {
@Mapping(source = "attachments", target = "attachmentFileIdList")
@Mapping(target = "status", constant = DEFAULT_STATUS)
GrpcRueckfrage toGrpc(PostfachNachricht postfachNachricht);
@Mapping(target = "mailBody", source = "answerText")
@Mapping(target = "attachments", source = "attachmentFileIdList")
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "createdBy", ignore = true)
@Mapping(target = "direction", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "messageCode", ignore = true)
@Mapping(target = "messageId", ignore = true)
@Mapping(target = "postfachAddress", ignore = true)
@Mapping(target = "postfachId", ignore = true)
@Mapping(target = "replyOption", ignore = true)
@Mapping(target = "sentAt", ignore = true)
@Mapping(target = "sentSuccessful", ignore = true)
@Mapping(target = "subject", ignore = true)
@Mapping(target = "vorgangId", ignore = true)
PostfachNachricht toPostfachNachricht(GrpcRueckfrageAnswer answer);
}
......@@ -82,6 +82,16 @@ public class AntragraumService {
return postfachNachrichtService.findRueckfragen(postfachId);
}
public Stream<PostfachNachricht> findRueckfrageAnswers(String rueckfrageId) {
return postfachNachrichtService.findAnswers(rueckfrageId);
}
public String sendRueckfrageAnswer(String samlToken, String rueckfrageId, PostfachNachricht nachricht) {
verifyToken(samlToken);
return postfachNachrichtService.persistAnswer(rueckfrageId, nachricht);
}
void verifyToken(String token) {
var errors = verifier.verify(token);
if (CollectionUtils.isNotEmpty(errors)) {
......
......@@ -23,6 +23,7 @@ package de.ozgcloud.nachrichten.antragraum;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
......@@ -34,6 +35,7 @@ import org.mockito.Spy;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import de.ozgcloud.vorgang.grpc.command.GrpcCommand;
import io.grpc.stub.StreamObserver;
class AntragraumGrpcServiceTest {
......@@ -81,4 +83,39 @@ class AntragraumGrpcServiceTest {
}
}
}
@Nested
class TestSendAnswer {
@Mock
private StreamObserver<GrpcCommand> streamObserver;
@BeforeEach
void setup() {
when(antragraumService.sendRueckfrageAnswer(anyString(), anyString(), any(PostfachNachricht.class)))
.thenReturn(UUID.randomUUID().toString());
when(mapper.toPostfachNachricht(any(GrpcRueckfrageAnswer.class))).thenReturn(PostfachNachrichtTestFactory.create());
}
@Test
void shouldCallMapper() {
antragsraumGrpcService.sendRueckfrageAnswer(GrpcSendRueckfrageAnswerRequestTestFactory.create(), streamObserver);
verify(mapper).toPostfachNachricht(any(GrpcRueckfrageAnswer.class));
}
@Test
void shouldCallOnNext() {
antragsraumGrpcService.sendRueckfrageAnswer(GrpcSendRueckfrageAnswerRequestTestFactory.create(), streamObserver);
verify(streamObserver).onNext(any(GrpcCommand.class));
}
@Test
void shouldCallOnCompleted() {
antragsraumGrpcService.sendRueckfrageAnswer(GrpcSendRueckfrageAnswerRequestTestFactory.create(), streamObserver);
verify(streamObserver).onCompleted();
}
}
}
\ No newline at end of file
......@@ -24,9 +24,11 @@ import static org.assertj.core.api.Assertions.*;
import java.time.format.DateTimeFormatter;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
......@@ -34,6 +36,9 @@ class AntragraumNachrichtMapperTest {
AntragraumNachrichtMapper mapper = Mappers.getMapper(AntragraumNachrichtMapper.class);
@Nested
class TestMapRueckfrage {
@Test
void shouldMapVorgangId() {
var result = map();
......@@ -63,7 +68,7 @@ class AntragraumNachrichtMapperTest {
}
@Test
void shouldMapSentAt() {
void shouldMapSendAt() {
var result = map();
assertThat(result.getSentAt()).isEqualTo(PostfachNachrichtTestFactory.SENT_AT.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
......@@ -87,4 +92,27 @@ class AntragraumNachrichtMapperTest {
private GrpcRueckfrage map() {
return mapper.toGrpc(PostfachNachrichtTestFactory.create());
}
}
@Nested
class TestMapAnswerToPostfachNachricht {
@Test
void shouldMapText() {
var result = map();
assertThat(result.getMailBody()).isEqualTo(GrpcRueckfrageAnswerTestFactory.TEXT);
}
@Test
void shouldMapAttachmentIds() {
var result = map();
assertThat(result.getAttachments()).isEqualTo(GrpcRueckfrageAnswerTestFactory.ATTACHMENT_ID_LIST);
}
private PostfachNachricht map() {
return mapper.toPostfachNachricht(GrpcRueckfrageAnswerTestFactory.create());
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment