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

prj-42 implement save draft grpc endpoint

parent 59c883d3
Branches
Tags
No related merge requests found
package de.itvsh.ozg.mail.postfach;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper
public interface GrpcPostfachNachrichtMapper {
@Mapping(target = "attachments", source = "attachmentList")
@Mapping(target = "createdAt", ignore = true) // heute?
@Mapping(target = "createdBy", ignore = true) // TODO
@Mapping(target = "direction", constant = "OUT")
@Mapping(target = "messageCode", ignore = true)
@Mapping(target = "messageId", ignore = true)
@Mapping(target = "postfachAddress", ignore = true) // uh
@Mapping(target = "postfachId", ignore = true)
@Mapping(target = "sentAt", ignore = true)
@Mapping(target = "sentSuccessful", ignore = true)
@Mapping(target = "vorgangId", ignore = true)
PostfachNachricht mapFromGrpc(GrpcPostfachNachricht nachricht);
}
......@@ -37,6 +37,17 @@ class PostfachGrpcService extends PostfachServiceImplBase {
@Autowired
private PostfachNachrichtMapper mapper;
@Autowired
private GrpcPostfachNachrichtMapper nachrichtMapper;
@Override
public void saveNachrichtDraft(GrpcSaveNachrichtDraftRequest request, StreamObserver<GrpcSaveNachrichtDrafResponse> response) {
var nachrichtId = service.saveDraft(request.getVorgangId(), nachrichtMapper.mapFromGrpc(request.getNachricht()));
response.onNext(GrpcSaveNachrichtDrafResponse.newBuilder().setNachrichtId(nachrichtId).build());
response.onCompleted();
}
@Override
public void sendPostfachMail(GrpcSendPostfachMailRequest req, StreamObserver<GrpcSendPostfachMailResponse> response) {
service.sendMail(req.getCommandId(), req.getContext().getUser().getId(), mapper.fromGrpcMail(req.getMail()));
......
......@@ -64,6 +64,12 @@ class PostfachService {
@Autowired
private ApplicationEventPublisher publisher;
public String saveDraft(String vorgangId, PostfachNachricht nachricht) {
persistMail(null, null);
// TODO implement me
return null;
}
public void sendMail(String commandId, String userId, @Valid PostfachNachricht mail) {
var sendResponse = handleSendMail(commandId, mail);
persistSentMail(userId, addMailSentInformation(mail, sendResponse));
......
package de.itvsh.ozg.mail.postfach;
import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory;
public class GrpcSaveNachrichtDraftRequestTestFactory {
static GrpcSaveNachrichtDraftRequest create() {
return createBuilder().build();
}
static GrpcSaveNachrichtDraftRequest.Builder createBuilder() {
return GrpcSaveNachrichtDraftRequest.newBuilder()
.setVorgangId(MessageTestFactory.VORGANG_ID);
}
}
......@@ -27,7 +27,9 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
......@@ -35,25 +37,72 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory;
import io.grpc.stub.StreamObserver;
class PostfachGrpcServiceTest {
@InjectMocks // NOSONAR
@InjectMocks
private PostfachGrpcService service;
@Mock
private PostfachService postfachService;
@Mock
private GrpcPostfachNachrichtMapper nachrichtMapper;
@Spy
private PostfachNachrichtMapper mapper = Mappers.getMapper(PostfachNachrichtMapper.class);
@Nested
class TestSaveNachrichtDraft {
@Mock
private StreamObserver<GrpcSaveNachrichtDrafResponse> responseObserver;
@Captor
private ArgumentCaptor<GrpcSaveNachrichtDrafResponse> responseCaptor;
@BeforeEach
void init() {
when(postfachService.saveDraft(any(),any())).thenReturn(PostfachNachrichtTestFactory.ID);
when(nachrichtMapper.mapFromGrpc(any())).thenReturn(PostfachNachrichtTestFactory.create());
}
@Test
void shouldCallService() {
var nachricht = PostfachNachrichtTestFactory.create();
when(nachrichtMapper.mapFromGrpc(any())).thenReturn(nachricht);
service.saveNachrichtDraft(GrpcSaveNachrichtDraftRequestTestFactory.create(), responseObserver);
verify(postfachService).saveDraft(MessageTestFactory.VORGANG_ID, nachricht);
}
@Test
void shouldSendResponse() {
service.saveNachrichtDraft(GrpcSaveNachrichtDraftRequestTestFactory.create(), responseObserver);
verify(responseObserver).onNext(responseCaptor.capture());
assertThat(responseCaptor.getValue().getNachrichtId()).isEqualTo(PostfachNachrichtTestFactory.ID);
}
@Test
void shouldCompleteCall() {
service.saveNachrichtDraft(GrpcSaveNachrichtDraftRequestTestFactory.create(), responseObserver);
verify(responseObserver).onCompleted();
}
}
@Nested
class TestSendMail {
@Mock // NOSONAR
@Mock
private StreamObserver<GrpcSendPostfachMailResponse> responseObserver;
@Captor // NOSONAR
@Captor
private ArgumentCaptor<PostfachNachricht> mailCaptor;
@Test
......@@ -165,7 +214,7 @@ class PostfachGrpcServiceTest {
@Nested
class TestResendMail {
@Mock // NOSONAR
@Mock
private StreamObserver<GrpcResendPostfachMailResponse> responseObserver;
@Test
......@@ -195,7 +244,7 @@ class PostfachGrpcServiceTest {
private final GrpcIsPostfachConfiguredRequest request = GrpcIsPostfachConfiguredRequest.newBuilder().build();
@Mock // NOSONAR
@Mock
private StreamObserver<GrpcIsPostfachConfiguredResponse> responseObserver;
@Test
......
......@@ -78,6 +78,25 @@ class PostfachServiceTest {
static final String COMMAND_ID = UUID.randomUUID().toString();
static final String USER_ID = UUID.randomUUID().toString();
@Nested
class TestSaveDraft {
@Captor
private ArgumentCaptor<Optional<String>> userIdCaptor;
@BeforeEach
void init() {
doNothing().when(service).persistMail(any(), any());
}
@Test
void shouldUseUserIdFromContext() {
service.saveDraft(MessageTestFactory.VORGANG_ID, PostfachNachrichtTestFactory.create());
verify(service).persistMail(userIdCaptor.capture(), any());
}
}
@Nested
class TestSendMail {
......
......@@ -39,7 +39,7 @@ message GrpcSendPostfachMailRequest {
}
message GrpcSaveNachrichtDraftRequest {
string createFor = 1;
string vorgangId = 1;
GrpcPostfachNachricht nachricht = 2;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment