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

OZG-6259 get vorgang and trigger create collaboration vorgang

parent cc6c26c6
No related branches found
No related tags found
No related merge requests found
Showing
with 81 additions and 33 deletions
......@@ -23,14 +23,15 @@
*/
package de.ozgcloud.vorgang.collaboration;
import de.ozgcloud.vorgang.vorgang.Vorgang;
import lombok.Builder;
import lombok.Getter;
@Builder
@Builder(toBuilder = true)
@Getter
public class CollaborationRequest {
public class CreateCollaborationVorgangRequest {
private String vorgangId;
private Vorgang vorgang;
private int collaborationLevel;
private String zustaendigeStelle;
}
......@@ -24,12 +24,14 @@
package de.ozgcloud.vorgang.collaboration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import de.ozgcloud.vorgang.vorgang.GrpcCollaborationRequest;
@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN)
public interface CollaborationRequestMapper {
public interface CreateCollaborationVorgangRequestMapper {
CollaborationRequest mapFrom(GrpcCollaborationRequest grpcCollaborationRequest);
@Mapping(target = "vorgang", ignore = true)
CreateCollaborationVorgangRequest mapFrom(GrpcCollaborationRequest grpcCollaborationRequest);
}
......@@ -25,8 +25,9 @@ package de.ozgcloud.vorgang.vorgang;
import org.springframework.data.domain.Page;
import de.ozgcloud.vorgang.collaboration.CollaborationRequestMapper;
import de.ozgcloud.vorgang.collaboration.CollaborationService;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequest;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequestMapper;
import io.grpc.stub.StreamObserver;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.server.service.GrpcService;
......@@ -45,7 +46,7 @@ class GrpcVorgangService extends VorgangServiceGrpc.VorgangServiceImplBase {
private final IncomingFileMapper incomingFileMapper;
private final IncomingFileGroupMapper incomingFileGroupMapper;
private final CollaborationService collaborationService;
private final CollaborationRequestMapper collaborationRequestMapper;
private final CreateCollaborationVorgangRequestMapper createCollaborationVorgangRequestMapper;
@Override
public void startCreation(GrpcCreateVorgangRequest request, StreamObserver<GrpcCreateVorgangResponse> responseObserver) {
......@@ -114,12 +115,16 @@ class GrpcVorgangService extends VorgangServiceGrpc.VorgangServiceImplBase {
public void createCollaborationVorgang(GrpcCreateCollaborationVorgangRequest request,
StreamObserver<GrpcCreateCollaborationVorgangResponse> responseObserver) {
if (request.hasCollaborationRequest()) {
var collaborationRequest = collaborationRequestMapper.mapFrom(request.getCollaborationRequest());
var collaborationVorgangId = collaborationService.createCollaborationVorgang(collaborationRequest);
var collaborationVorgangId = collaborationService.createCollaborationVorgang(buildCreateCollaborationVorgangRequest(request));
responseObserver.onNext(GrpcCreateCollaborationVorgangResponse.newBuilder().setVorgangId(collaborationVorgangId).build());
} else {
responseObserver.onNext(GrpcCreateCollaborationVorgangResponse.newBuilder().build());
}
responseObserver.onCompleted();
}
CreateCollaborationVorgangRequest buildCreateCollaborationVorgangRequest(GrpcCreateCollaborationVorgangRequest request) {
var vorgang = vorgangService.getById(request.getCollaborationRequest().getVorgangId());
return createCollaborationVorgangRequestMapper.mapFrom(request.getCollaborationRequest()).toBuilder().vorgang(vorgang).build();
}
}
\ No newline at end of file
......@@ -124,9 +124,9 @@ class CollaborationITCase {
var collaborationVorgang = loadCollaborationVorgang(vorgangId);
assertThat(collaborationVorgang.getHeader()).extracting(VorgangHead::getCollaborationLevel)
.isEqualTo(CollaborationRequestTestFactory.COLLABORATION_LEVEL);
.isEqualTo(CreateCollaborationVorgangRequestTestFactory.COLLABORATION_LEVEL);
assertThat(collaborationVorgang.getHeader()).extracting(VorgangHead::getOrganisationsEinheitId)
.isEqualTo(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
.isEqualTo(CreateCollaborationVorgangRequestTestFactory.ZUSTAENDIGE_STELLE);
assertThat(collaborationVorgang.getClientAttributes()).isEmpty();
}
......@@ -139,7 +139,7 @@ class CollaborationITCase {
.bodyObject(Map.of(
"titel", TITEL,
"anfrage", ANFRAGE,
"zustaendigeStelle", CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE
"zustaendigeStelle", CreateCollaborationVorgangRequestTestFactory.ZUSTAENDIGE_STELLE
))
.build();
}
......
......@@ -51,7 +51,7 @@ class CollaborationServiceTest {
@Nested
class TestCreateCollaborationVorgang {
private static final CollaborationRequest COLLABORATION_REQUEST = CollaborationRequestTestFactory.create();
private static final CreateCollaborationVorgangRequest COLLABORATION_REQUEST = CreateCollaborationVorgangRequestTestFactory.create();
private static final String COLLABORATION_VORGANG_ID = "collaboratino-vorgang-id";
@Mock
......
......@@ -28,14 +28,14 @@ import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
class CollaborationRequestMapperTest {
class CreateCollaborationVorgangRequestMapperTest {
private final CollaborationRequestMapper mapper = Mappers.getMapper(CollaborationRequestMapper.class);
private final CreateCollaborationVorgangRequestMapper mapper = Mappers.getMapper(CreateCollaborationVorgangRequestMapper.class);
@Test
void shouldMapFromGrpc() {
var result = mapper.mapFrom(GrpcCollaborationRequestTestFactory.create());
assertThat(result).usingRecursiveComparison().isEqualTo(CollaborationRequestTestFactory.create());
assertThat(result).usingRecursiveComparison().ignoringFields("vorgang").isEqualTo(CreateCollaborationVorgangRequestTestFactory.create());
}
}
\ No newline at end of file
......@@ -23,21 +23,21 @@
*/
package de.ozgcloud.vorgang.collaboration;
import de.ozgcloud.vorgang.collaboration.CollaborationRequest.CollaborationRequestBuilder;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequest.CreateCollaborationVorgangRequestBuilder;
import de.ozgcloud.vorgang.vorgang.VorgangTestFactory;
public class CollaborationRequestTestFactory {
public class CreateCollaborationVorgangRequestTestFactory {
public static final int COLLABORATION_LEVEL = 1;
public static final String ZUSTAENDIGE_STELLE = "zustaendige-stelle";
public static CollaborationRequest create() {
public static CreateCollaborationVorgangRequest create() {
return createBuilder().build();
}
public static CollaborationRequestBuilder createBuilder() {
return CollaborationRequest.builder()
.vorgangId(VorgangTestFactory.ID)
public static CreateCollaborationVorgangRequestBuilder createBuilder() {
return CreateCollaborationVorgangRequest.builder()
.vorgang(VorgangTestFactory.create())
.zustaendigeStelle(ZUSTAENDIGE_STELLE)
.collaborationLevel(COLLABORATION_LEVEL);
}
......
......@@ -35,7 +35,7 @@ public class GrpcCollaborationRequestTestFactory {
public static GrpcCollaborationRequest.Builder createBuilder() {
return GrpcCollaborationRequest.newBuilder()
.setVorgangId(VorgangTestFactory.ID)
.setZustaendigeStelle(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE)
.setCollaborationLevel(CollaborationRequestTestFactory.COLLABORATION_LEVEL);
.setZustaendigeStelle(CreateCollaborationVorgangRequestTestFactory.ZUSTAENDIGE_STELLE)
.setCollaborationLevel(CreateCollaborationVorgangRequestTestFactory.COLLABORATION_LEVEL);
}
}
......@@ -41,10 +41,10 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.data.domain.Page;
import de.ozgcloud.vorgang.collaboration.CollaborationRequest;
import de.ozgcloud.vorgang.collaboration.CollaborationRequestMapper;
import de.ozgcloud.vorgang.collaboration.CollaborationRequestTestFactory;
import de.ozgcloud.vorgang.collaboration.CollaborationService;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequest;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequestMapper;
import de.ozgcloud.vorgang.collaboration.CreateCollaborationVorgangRequestTestFactory;
import de.ozgcloud.vorgang.collaboration.GrpcCollaborationRequestTestFactory;
import io.grpc.stub.StreamObserver;
......@@ -81,7 +81,7 @@ class GrpcVorgangServiceTest {
@Mock
private CollaborationService collaborationService;
@Mock
private CollaborationRequestMapper collaborationRequestMapper;
private CreateCollaborationVorgangRequestMapper createCollaborationVorgangRequestMapper;
@Nested
class TestCreate {
......@@ -356,26 +356,26 @@ class GrpcVorgangServiceTest {
private static final GrpcCreateCollaborationVorgangRequest REQUEST = GrpcCreateCollaborationVorgangRequest.newBuilder()
.setCollaborationRequest(GRPC_COLLABORATION_REQUEST).build();
private static final String COLLABORATION_VORGANG_ID = "collaboration-vorgang-id";
private static final CollaborationRequest COLLABORATION_REQUEST = CollaborationRequestTestFactory.create();
private static final CreateCollaborationVorgangRequest CREATE_COLLABORATION_VORGANG_REQUEST = CreateCollaborationVorgangRequestTestFactory.create();
@BeforeEach
void init() {
when(collaborationRequestMapper.mapFrom(any())).thenReturn(COLLABORATION_REQUEST);
doReturn(CREATE_COLLABORATION_VORGANG_REQUEST).when(service).buildCreateCollaborationVorgangRequest(any());
when(collaborationService.createCollaborationVorgang(any())).thenReturn(COLLABORATION_VORGANG_ID);
}
@Test
void shouldCallMapCollaborationRequest() {
void shouldCallBuildCreateCollaborationVorgangRequest() {
createCollaborationVorgang();
verify(collaborationRequestMapper).mapFrom(GRPC_COLLABORATION_REQUEST);
verify(service).buildCreateCollaborationVorgangRequest(REQUEST);
}
@Test
void shouldCallCreateCollaborationVorgang() {
createCollaborationVorgang();
verify(collaborationService).createCollaborationVorgang(COLLABORATION_REQUEST);
verify(collaborationService).createCollaborationVorgang(CREATE_COLLABORATION_VORGANG_REQUEST);
}
@Test
......@@ -422,4 +422,44 @@ class GrpcVorgangServiceTest {
}
}
@Nested
class TestBuildCreateCollaborationVorgangRequest {
private static final GrpcCollaborationRequest GRPC_COLLABORATION_REQUEST = GrpcCollaborationRequestTestFactory.create();
private static final CreateCollaborationVorgangRequest CREATE_COLLABORATION_VORGANG_REQUEST = CreateCollaborationVorgangRequestTestFactory.create();
private static final Vorgang VORGANG = VorgangTestFactory.create();
@BeforeEach
void init() {
when(createCollaborationVorgangRequestMapper.mapFrom(any())).thenReturn(CREATE_COLLABORATION_VORGANG_REQUEST);
when(vorgangService.getById(anyString())).thenReturn(VORGANG);
}
@Test
void shouldCallGetVorgang() {
buildCreateCollaborationVorgangRequest();
verify(vorgangService).getById(VorgangTestFactory.ID);
}
@Test
void shouldCallRequestMapper() {
buildCreateCollaborationVorgangRequest();
verify(createCollaborationVorgangRequestMapper).mapFrom(GRPC_COLLABORATION_REQUEST);
}
@Test
void shouldSetVorgang() {
var result = buildCreateCollaborationVorgangRequest();
assertThat(result.getVorgang()).isSameAs(VORGANG);
}
private CreateCollaborationVorgangRequest buildCreateCollaborationVorgangRequest() {
return service.buildCreateCollaborationVorgangRequest(GrpcCreateCollaborationVorgangRequest.newBuilder()
.setCollaborationRequest(GRPC_COLLABORATION_REQUEST).build());
}
}
}
\ 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