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

OZG-7350 implement zustaendigeStelle as Fachstelle

parent a42a41a1
Branches
Tags
No related merge requests found
Showing
with 668 additions and 66 deletions
......@@ -41,6 +41,7 @@
<properties>
<vorgang-manager.version>2.18.0</vorgang-manager.version>
<zufi-manager.version>1.6.0</zufi-manager.version>
<api-lib.version>0.13.0</api-lib.version>
</properties>
......@@ -61,6 +62,11 @@
<artifactId>vorgang-manager-interface</artifactId>
<version>${vorgang-manager.version}</version>
</dependency>
<dependency>
<groupId>de.ozgcloud.zufi</groupId>
<artifactId>zufi-manager-interface</artifactId>
<version>${zufi-manager.version}</version>
</dependency>
<dependency>
<groupId>de.ozgcloud.api-lib</groupId>
<artifactId>api-lib-core</artifactId>
......
......@@ -73,6 +73,7 @@ public class CollaborationManagerConfiguration {
public static final String GRPC_COMMAND_MANAGER_NAME = "command-manager";
public static final String GRPC_FILE_MANAGER_NAME = "file-manager";
public static final String GRPC_USER_MANAGER_NAME = "user-manager";
public static final String GRPC_ZUFI_MANAGER_NAME = "zufi-manager";
@GrpcClient(GRPC_COMMAND_MANAGER_NAME)
private CommandServiceBlockingStub commandServiceStub;
......
......@@ -23,8 +23,10 @@
*/
package de.ozgcloud.collaboration;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import de.ozgcloud.collaboration.fachstelle.Fachstelle;
import de.ozgcloud.collaboration.request.CollaborationRequestId;
import lombok.Builder;
import lombok.Getter;
......@@ -59,6 +61,6 @@ public class CollaborationRequest {
private String titel;
@NotBlank
private String beschreibung;
@NotBlank
private String zustaendigeStelle;
@Valid
private Fachstelle zustaendigeStelle;
}
......@@ -28,54 +28,51 @@ import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.mapstruct.AnnotateWith;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor;
import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem;
import de.ozgcloud.collaboration.fachstelle.Fachstelle;
import de.ozgcloud.collaboration.fachstelle.FachstelleMapper;
import de.ozgcloud.collaboration.fachstelle.FachstelleService;
import de.ozgcloud.collaboration.request.CollaborationRequestId;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
import de.ozgcloud.command.Command;
import de.ozgcloud.vorgang.vorgang.GrpcCreateCollaborationRequestData;
@AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.COLLABORATION_REQUEST_MAPPER_NAME))
@Mapper(uses = { CommandMapper.class },
unmappedTargetPolicy = ReportingPolicy.WARN,
unmappedSourcePolicy = ReportingPolicy.WARN,
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public interface CollaborationRequestMapper {
@Mapper(uses = {
CommandMapper.class }, unmappedTargetPolicy = ReportingPolicy.WARN, unmappedSourcePolicy = ReportingPolicy.WARN, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public abstract class CollaborationRequestMapper {
String ITEM_NAME = "CollaborationRequest";
static final String ITEM_NAME = "CollaborationRequest";
String FIELD_ITEM_CLIENT = "client";
String FIELD_ITEM_VORGANG_ID = "vorgangId";
String FIELD_ITEM_NAME = "itemName";
String FIELD_ITEM_BODY = "item";
static final String FIELD_ITEM_CLIENT = "client";
static final String FIELD_ITEM_VORGANG_ID = "vorgangId";
static final String FIELD_ITEM_NAME = "itemName";
static final String FIELD_ITEM_BODY = "item";
@Autowired
private FachstelleService fachstelleService;
@Autowired
private FachstelleMapper fachstelleMapper;
@Mapping(target = "collaborationVorgangId", ignore = true)
@Mapping(target = "createdBy", ignore = true)
@Mapping(target = "commandId", source = "id")
@Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, command.getBodyObject()))")
@Mapping(target = "zustaendigeStelle", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, command.getBodyObject()))")
@Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(command.getBodyObject()))")
@Mapping(target = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, command.getBodyObject()))")
@Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, command.getBodyObject()))")
CollaborationRequest toCollaborationRequest(Command command);
default String getStringProperty(String key, Map<String, Object> propertyMap) {
return MapUtils.getString(propertyMap, key);
}
public abstract CollaborationRequest toCollaborationRequest(Command command);
@Mapping(target = "id", ignore = true)
@Mapping(target = "status", ignore = true)
......@@ -89,9 +86,9 @@ public interface CollaborationRequestMapper {
@Mapping(target = "vorgangId", source = "request.vorgangId")
@Mapping(target = "relationId", expression = "java(commandMapper.mapRelationId(request.getVorgangId()))")
@Mapping(target = "bodyObject", expression = "java(toBodyObject(request))")
OzgCloudCommand toOzgCloudCommand(CollaborationRequest request, String order);
public abstract OzgCloudCommand toOzgCloudCommand(CollaborationRequest request, String order);
default Map<String, Object> toBodyObject(CollaborationRequest request) {
Map<String, Object> toBodyObject(CollaborationRequest request) {
return Map.of(
FIELD_ITEM_VORGANG_ID, request.getVorgangId(),
FIELD_ITEM_CLIENT, CollaborationManagerCallContextGrpcClientInterceptor.COLLABORATION_MANAGER_CLIENT_NAME,
......@@ -99,16 +96,17 @@ public interface CollaborationRequestMapper {
FIELD_ITEM_BODY, toItemMap(request));
}
default Map<String, Object> toItemMap(CollaborationRequest request) {
Map<String, Object> toItemMap(CollaborationRequest request) {
return Map.of(
CollaborationRequest.PROPERTY_TITEL, request.getTitel(),
CollaborationRequest.PROPERTY_BESCHREIBUNG, request.getBeschreibung(),
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, request.getZustaendigeStelle(),
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, fachstelleMapper.toMap(request.getZustaendigeStelle()),
CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, request.getCollaborationLevel(),
CollaborationRequest.PROPERTY_COLLABORATION_VORGANG_ID, request.getCollaborationVorgangId());
}
@Mapping(target = "titel", source = "titel")
@Mapping(target = "zustaendigeStelle", source = "zustaendigeStelle.technicalId")
@Mapping(target = "idBytes", ignore = true)
@Mapping(target = "mergeFrom", ignore = true)
@Mapping(target = "clearField", ignore = true)
......@@ -121,8 +119,9 @@ public interface CollaborationRequestMapper {
@Mapping(target = "unknownFields", ignore = true)
@Mapping(target = "zustaendigeStelleBytes", ignore = true)
@Mapping(target = "allFields", ignore = true)
GrpcCollaborationRequest toGrpcCollaborationRequest(CollaborationRequest request);
public abstract GrpcCollaborationRequest toGrpcCollaborationRequest(CollaborationRequest request);
@Mapping(target = "zustaendigeStelle", source = "zustaendigeStelle.subjectId")
@Mapping(target = "mergeFrom", ignore = true)
@Mapping(target = "clearField", ignore = true)
@Mapping(target = "clearOneof", ignore = true)
......@@ -131,7 +130,7 @@ public interface CollaborationRequestMapper {
@Mapping(target = "vorgangIdBytes", ignore = true)
@Mapping(target = "zustaendigeStelleBytes", ignore = true)
@Mapping(target = "allFields", ignore = true)
GrpcCreateCollaborationRequestData toGrpcCreateCollaborationRequestData(CollaborationRequest request);
public abstract GrpcCreateCollaborationRequestData toGrpcCreateCollaborationRequestData(CollaborationRequest request);
@Mapping(target = "id", expression = "java(toCollaborationRequestId(getStringProperty(CollaborationRequest.PROPERTY_ID, item.getItem())))")
@Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, item.getItem()))")
......@@ -141,14 +140,24 @@ public interface CollaborationRequestMapper {
@Mapping(target = "createdBy", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_CREATED_BY, item.getItem()))")
@Mapping(target = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, item.getItem()))")
@Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, item.getItem()))")
@Mapping(target = "zustaendigeStelle", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, item.getItem()))")
CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item);
@Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(item.getItem()))")
public abstract CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item);
default CollaborationRequestId toCollaborationRequestId(String id) {
CollaborationRequestId toCollaborationRequestId(String id) {
return CollaborationRequestId.from(id);
}
default int getIntProperty(String key, Map<String, Object> propertyMap) {
int getIntProperty(String key, Map<String, Object> propertyMap) {
return MapUtils.getIntValue(propertyMap, key);
}
Fachstelle getZustaendigeStelle(Map<String, Object> propertyMap) {
var technicalId = getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, propertyMap);
var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap);
return fachstelleService.getFachstelle(technicalId, collaborationLevel);
}
String getStringProperty(String key, Map<String, Object> propertyMap) {
return MapUtils.getString(propertyMap, key);
}
}
......@@ -132,7 +132,7 @@ public class CollaborationService {
}
OzgCloudCommand buildSendPostfachNachrichtCommand(CollaborationRequest collaborationRequest) {
var bodyObject = buildPostfachSendNachrichtCommandBody(buildMukPostfachAddress(collaborationRequest.getZustaendigeStelle()),
var bodyObject = buildPostfachSendNachrichtCommandBody(buildMukPostfachAddress(collaborationRequest.getZustaendigeStelle().getSubjectId()),
collaborationRequest.getVorgangId());
return OzgCloudCommand.builder()
.vorgangId(commandMapper.toOzgCloudVorgangId(collaborationRequest.getVorgangId()))
......
package de.ozgcloud.collaboration.fachstelle;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@Builder
@Getter
@EqualsAndHashCode
public class Fachstelle {
public static final String PROPERTY_TECHNICAL_ID = "technicalId";
public static final String PROPERTY_SUBJECT_ID = "subjectId";
public static final String PROPERTY_TYPE = "type";
@NotBlank
private String technicalId;
@NotBlank
private String subjectId;
private FachstelleType type;
public enum FachstelleType {
EXTERNE_FACHSTELLE, ORGANISATIONS_EINHEIT;
}
}
package de.ozgcloud.collaboration.fachstelle;
import java.util.Map;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit;
@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface FachstelleMapper {
@Mapping(target = "technicalId", source = "id")
@Mapping(target = "subjectId", source = "mukId")
@Mapping(target = "type", constant = "EXTERNE_FACHSTELLE")
Fachstelle fromExterneFachstelle(GrpcFachstelle externeFachstelle);
@Mapping(target = "technicalId", source = "id")
@Mapping(target = "subjectId", source = "xzufiId.id")
@Mapping(target = "type", constant = "ORGANISATIONS_EINHEIT")
Fachstelle fromOrganisationsEinheit(GrpcOrganisationsEinheit organisationsEinheit);
default Map<String, Object> toMap(Fachstelle fachstelle) {
return Map.of(
Fachstelle.PROPERTY_TECHNICAL_ID, fachstelle.getTechnicalId(),
Fachstelle.PROPERTY_SUBJECT_ID, fachstelle.getSubjectId(),
Fachstelle.PROPERTY_TYPE, fachstelle.getType().name());
}
}
package de.ozgcloud.collaboration.fachstelle;
import org.springframework.stereotype.Service;
import de.ozgcloud.collaboration.CollaborationManagerConfiguration;
import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.client.inject.GrpcClient;
@Service
@RequiredArgsConstructor
class FachstelleRemoteService {
@GrpcClient(CollaborationManagerConfiguration.GRPC_ZUFI_MANAGER_NAME)
private final FachstelleServiceBlockingStub fachstelleServiceBlockingStub;
@GrpcClient(CollaborationManagerConfiguration.GRPC_ZUFI_MANAGER_NAME)
private final OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub;
private final FachstelleMapper fachstelleMapper;
public Fachstelle getExterneFachstelle(String id) {
var externeFachstelle = fachstelleServiceBlockingStub.getById(GrpcFachstelleGetRequest.newBuilder().setId(id).build()).getFachstelle();
return fachstelleMapper.fromExterneFachstelle(externeFachstelle);
}
public Fachstelle getOrganisationsEinheit(String id) {
var organisationsEinheit = organisationsEinheitServiceBlockingStub.getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build())
.getOrganisationsEinheit();
return fachstelleMapper.fromOrganisationsEinheit(organisationsEinheit);
}
}
package de.ozgcloud.collaboration.fachstelle;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class FachstelleService {
private final FachstelleRemoteService remoteService;
public Fachstelle getFachstelle(String technicalId, int collaborationLevel) {
if (collaborationLevel == 1) {
return remoteService.getOrganisationsEinheit(technicalId);
}
if (collaborationLevel == 4) {
return remoteService.getExterneFachstelle(technicalId);
}
throw new IllegalArgumentException(
"Unknown collaboration level! Collaboration level has to be either 1 or 4, but was %s.".formatted(collaborationLevel));
}
}
......@@ -44,7 +44,13 @@ import de.ozgcloud.apilib.common.datatypes.GenericId;
import de.ozgcloud.apilib.user.OzgCloudUserId;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor;
import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem;
import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItemTestFactory;
import de.ozgcloud.collaboration.fachstelle.FachstelleMapper;
import de.ozgcloud.collaboration.fachstelle.FachstelleService;
import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory;
import de.ozgcloud.collaboration.request.GrpcCreateCollaborationRequestDataTestFactory;
import de.ozgcloud.collaboration.vorgang.GrpcCollaborationRequestTestFactory;
import de.ozgcloud.collaboration.vorgang.VorgangTestFactory;
import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandTestFactory;
......@@ -58,27 +64,68 @@ class CollaborationRequestMapperTest {
@Mock
private CommandMapper commandMapper;
@Mock
private FachstelleService fachstelleService;
@Mock
private FachstelleMapper fachstelleMapper;
@Nested
class TestToCreateCollaborationRequest {
private static final Command COMMAND = CommandTestFactory.createBuilder().bodyObject(
Map.of(
private static final Map<String, Object> BODY_OBJECT = Map.of(
CollaborationRequest.PROPERTY_TITEL, CollaborationRequestTestFactory.TITEL,
CollaborationRequest.PROPERTY_BESCHREIBUNG, CollaborationRequestTestFactory.BESCHREIBUNG,
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE))
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID,
CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, CollaborationRequestTestFactory.COLLABORATION_LEVEL);
private static final Command COMMAND = CommandTestFactory.createBuilder().bodyObject(
BODY_OBJECT)
.vorgangId(VorgangTestFactory.ID_STR)
.build();
@Test
void shouldCallGetZustaendigeStelle() {
mapper.toCollaborationRequest(COMMAND);
verify(mapper).getZustaendigeStelle(BODY_OBJECT);
}
@Test
void shouldMapCommand() {
doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelle(any());
var result = mapper.toCollaborationRequest(COMMAND);
assertThat(result).usingRecursiveComparison()
.ignoringFields("id", "createdBy", "vorgangId", "commandId", "collaborationVorgangId", "collaborationLevel", "createdBy")
.ignoringFields("id", "createdBy", "collaborationVorgangId")
.isEqualTo(CollaborationRequestTestFactory.create());
}
}
@Nested
class TestGetZustaendigeStelle {
private static final Map<String, Object> PROPERTY_MAP = Map.of(
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID,
CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, CollaborationRequestTestFactory.COLLABORATION_LEVEL);
@Test
void shouldCallFachstelleService() {
mapper.getZustaendigeStelle(PROPERTY_MAP);
verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL);
}
@Test
void shouldReturnFachstelle() {
var expectedFachstelle = FachstelleTestFactory.create();
when(fachstelleService.getFachstelle(any(), anyInt())).thenReturn(expectedFachstelle);
var actualFachstelle = mapper.getZustaendigeStelle(PROPERTY_MAP);
assertThat(actualFachstelle).isSameAs(expectedFachstelle);
}
}
@Nested
class TestToOzgCloudCommand {
......@@ -231,11 +278,21 @@ class CollaborationRequestMapperTest {
assertThat(result).containsEntry(CollaborationRequest.PROPERTY_BESCHREIBUNG, CollaborationRequestTestFactory.BESCHREIBUNG);
}
@Test
void shouldCallFachstelleMapper() {
toItemMap();
verify(fachstelleMapper).toMap(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
}
@Test
void shouldSetZustaendigeStelle() {
var fachstelleMap = FachstelleTestFactory.createAsMap();
when(fachstelleMapper.toMap(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE)).thenReturn(fachstelleMap);
var result = toItemMap();
assertThat(result).containsEntry(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
assertThat(result).containsEntry(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, fachstelleMap);
}
@Test
......@@ -261,17 +318,57 @@ class CollaborationRequestMapperTest {
@DisplayName("Map from vorgangAttachedItem")
@Nested
class TestMapFromVorgangAttachedItem {
private static final Map<String, Object> COLLABORATION_REQUEST_MAP = CollaborationRequestTestFactory.createAsMap();
private static final VorgangAttachedItem VORGANG_ATTACHED_ITEM = VorgangAttachedItemTestFactory.createBuilder()
.itemName("CollaborationRequest")
.item(COLLABORATION_REQUEST_MAP)
.build();
@Test
void shouldCallGetZustaendigeStelle() {
mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM);
verify(mapper).getZustaendigeStelle(COLLABORATION_REQUEST_MAP);
}
@Test
void shouldMap() {
var vorgangAttachedItem = VorgangAttachedItemTestFactory.createBuilder()
.itemName("CollaborationRequest")
.item(CollaborationRequestTestFactory.createAsMap())
.build();
doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelle(any());
var item = mapper.mapFromVorgangAttachedItem(vorgangAttachedItem);
var item = mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM);
assertThat(item).usingRecursiveComparison().isEqualTo(CollaborationRequestTestFactory.create());
}
}
@Nested
class TestToGrpcCollaborationRequest {
@BeforeEach
void callCommandMapper() {
when(commandMapper.valueToString(any())).thenCallRealMethod();
}
@Test
void shouldMap() {
var request = mapper.toGrpcCollaborationRequest(CollaborationRequestTestFactory.create());
assertThat(request).isEqualTo(GrpcCollaborationRequestTestFactory.create());
}
}
@Nested
class TestToGrpcCreateCollaborationRequestData {
@Test
void shouldMap() {
var expectedRequestData = GrpcCreateCollaborationRequestDataTestFactory.createBuilder()
.setVorgangId(VorgangTestFactory.ID_STR)
.build();
var requestData = mapper.toGrpcCreateCollaborationRequestData(CollaborationRequestTestFactory.create());
assertThat(requestData).isEqualTo(expectedRequestData);
}
}
}
\ No newline at end of file
......@@ -29,6 +29,8 @@ import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.collaboration.CollaborationRequest.CollaborationRequestBuilder;
import de.ozgcloud.collaboration.fachstelle.Fachstelle;
import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory;
import de.ozgcloud.collaboration.request.CollaborationRequestId;
import de.ozgcloud.collaboration.vorgang.VorgangTestFactory;
import de.ozgcloud.command.CommandTestFactory;
......@@ -40,9 +42,9 @@ public class CollaborationRequestTestFactory {
public static final String TITEL = LoremIpsum.getInstance().getWords(5);
public static final String BESCHREIBUNG = LoremIpsum.getInstance().getWords(10);
public static final String ZUSTAENDIGE_STELLE = UUID.randomUUID().toString();
public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString();
public static final int COLLABORATION_LEVEL = 1;
public static final Fachstelle ZUSTAENDIGE_STELLE = FachstelleTestFactory.create();
public static CollaborationRequest create() {
return createBuilder().build();
......@@ -71,6 +73,6 @@ public class CollaborationRequestTestFactory {
CollaborationRequest.PROPERTY_CREATED_BY, CommandTestFactory.CREATED_BY,
CollaborationRequest.PROPERTY_TITEL, TITEL,
CollaborationRequest.PROPERTY_BESCHREIBUNG, BESCHREIBUNG,
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, ZUSTAENDIGE_STELLE);
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.createAsMap());
}
}
......@@ -36,6 +36,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory;
import de.ozgcloud.common.test.ITCase;
@ITCase
......@@ -68,12 +69,26 @@ class CollaborationServiceITCase {
assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request));
}
@DisplayName("should validate technicalId of zustaendigeStelle")
@ParameterizedTest(name = "fail when technicalId: \"{0}\"")
@NullAndEmptySource
@ValueSource(strings = { StringUtils.SPACE })
void shouldValidateCollaborationZustaendigeStelleTechnicalId(String technicalId) {
var request = CollaborationRequestTestFactory.createBuilder()
.zustaendigeStelle(FachstelleTestFactory.createBuilder().technicalId(technicalId).build())
.build();
assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request));
}
@DisplayName("should validate zustaendigeStelle")
@ParameterizedTest(name = "fail when zustaendigeStelle: \"{0}\"")
@ParameterizedTest(name = "fail when subjectId: \"{0}\"")
@NullAndEmptySource
@ValueSource(strings = { StringUtils.SPACE })
void shouldValidateCollaborationRequestTitel(String zustaendigeStelle) {
var request = CollaborationRequestTestFactory.createBuilder().zustaendigeStelle(zustaendigeStelle).build();
void shouldValidateCollaborationZustaendigeStelleSubjectId(String subjectId) {
var request = CollaborationRequestTestFactory.createBuilder()
.zustaendigeStelle(FachstelleTestFactory.createBuilder().subjectId(subjectId).build())
.build();
assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request));
}
......@@ -92,22 +107,26 @@ class CollaborationServiceITCase {
assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request));
}
@DisplayName("validate beschreibung")
@ParameterizedTest(name = "should throw exception on beschreibung: \"{0}\"")
@DisplayName("should validate technicalId of zustaendigeStelle")
@ParameterizedTest(name = "fail when technicalId: \"{0}\"")
@NullAndEmptySource
@ValueSource(strings = { StringUtils.SPACE })
void shouldValidateBeschreibung(String beschreibung) {
var request = CollaborationRequestTestFactory.createBuilder().beschreibung(beschreibung).build();
void shouldValidateCollaborationZustaendigeStelleTechnicalId(String technicalId) {
var request = CollaborationRequestTestFactory.createBuilder()
.zustaendigeStelle(FachstelleTestFactory.createBuilder().technicalId(technicalId).build())
.build();
assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request));
}
@DisplayName("validate zustaendigeStelle")
@ParameterizedTest(name = "should throw exception oon zustaendigeStelle: \"{0}\"")
@DisplayName("should validate zustaendigeStelle")
@ParameterizedTest(name = "fail when subjectId: \"{0}\"")
@NullAndEmptySource
@ValueSource(strings = { StringUtils.SPACE })
void shouldValidateCollaborationRequestTitel(String zustaendigeStelle) {
var request = CollaborationRequestTestFactory.createBuilder().zustaendigeStelle(zustaendigeStelle).build();
void shouldValidateCollaborationZustaendigeStelleSubjectId(String subjectId) {
var request = CollaborationRequestTestFactory.createBuilder()
.zustaendigeStelle(FachstelleTestFactory.createBuilder().subjectId(subjectId).build())
.build();
assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request));
}
......
......@@ -24,6 +24,7 @@
package de.ozgcloud.collaboration;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.InstanceOfAssertFactories.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
......@@ -53,9 +54,8 @@ import de.ozgcloud.collaboration.common.freemarker.TemplateHandler;
import de.ozgcloud.collaboration.common.user.UserId;
import de.ozgcloud.collaboration.common.user.UserProfile;
import de.ozgcloud.collaboration.common.user.UserProfileService;
import de.ozgcloud.collaboration.vorgang.PostfachAddressTestFactory;
import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory;
import de.ozgcloud.collaboration.vorgang.ServiceKonto;
import de.ozgcloud.collaboration.vorgang.ServiceKontoTestFactory;
import de.ozgcloud.collaboration.vorgang.Vorgang;
import de.ozgcloud.collaboration.vorgang.VorgangService;
import de.ozgcloud.collaboration.vorgang.VorgangTestFactory;
......@@ -410,8 +410,6 @@ class CollaborationServiceTest {
class TestBuildSendPostfachNachrichtCommand {
private static final CollaborationRequest COLLABORATION_REQUEST = CollaborationRequestTestFactory.create();
private static final ServiceKonto.PostfachAddress POSTFACH_ADDRESS = PostfachAddressTestFactory.create();
private static final ServiceKonto SERVICE_KONTO = ServiceKontoTestFactory.createBuilder().clearAddresses().address(POSTFACH_ADDRESS).build();
private static final OzgCloudUserId OZG_CLOUD_ID = OzgCloudUserId.from(CommandTestFactory.CREATED_BY);
private static final Map<String, Object> OBJECT_MAP = Map.of("key", "value");
private static final OzgCloudVorgangId VORGANG_ID = OzgCloudVorgangId.from(VorgangTestFactory.ID.toString());
......@@ -429,7 +427,7 @@ class CollaborationServiceTest {
void shouldCallBuildPostfachAddress() {
buildSendPostfachNachrichtCommand();
verify(service).buildMukPostfachAddress(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
verify(service).buildMukPostfachAddress(FachstelleTestFactory.SUBJECT_ID);
}
@Test
......@@ -525,7 +523,7 @@ class CollaborationServiceTest {
var result = buildPostfachAddress();
assertThat(result).extracting(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER, MAP)
.containsEntry(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER_POSTFACH_ID, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
.containsEntry(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER_POSTFACH_ID, FachstelleTestFactory.SUBJECT_ID);
}
@Test
......@@ -536,7 +534,7 @@ class CollaborationServiceTest {
}
private Map<String, Object> buildPostfachAddress() {
return service.buildMukPostfachAddress(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE);
return service.buildMukPostfachAddress(FachstelleTestFactory.SUBJECT_ID);
}
}
......
package de.ozgcloud.collaboration.fachstelle;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType;
class FachstelleMapperTest {
private final FachstelleMapper mapper = Mappers.getMapper(FachstelleMapper.class);
@Nested
class TestFromExterneFachstelle {
@Test
void shouldMapToFachstelle() {
var expectedFachstelle = FachstelleTestFactory.createBuilder().type(FachstelleType.EXTERNE_FACHSTELLE).build();
var fachstelle = mapper.fromExterneFachstelle(GrpcFachstelleTestFactory.create());
assertThat(fachstelle).usingRecursiveComparison().isEqualTo(expectedFachstelle);
}
}
@Nested
class TestFromOrganisationsEinheit {
@Test
void shouldMapToFachstelle() {
var expectedFachstelle = FachstelleTestFactory.createBuilder().type(FachstelleType.ORGANISATIONS_EINHEIT).build();
var fachstelle = mapper.fromOrganisationsEinheit(GrpcOrganisationsEinheitTestFactory.create());
assertThat(fachstelle).usingRecursiveComparison().isEqualTo(expectedFachstelle);
}
}
@Nested
class TestToMap {
@Test
void shouldMapToFachstelle() {
var expectedMap = FachstelleTestFactory.createAsMap();
var actualMap = mapper.toMap(FachstelleTestFactory.create());
assertThat(actualMap).usingRecursiveComparison().isEqualTo(expectedMap);
}
}
}
package de.ozgcloud.collaboration.fachstelle;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub;
import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub;
class FachstelleRemoteServiceTest {
@Spy
@InjectMocks
private FachstelleRemoteService service;
@Mock
private FachstelleServiceBlockingStub fachstelleServiceBlockingStub;
@Mock
private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub;
@Mock
private FachstelleMapper fachstelleMapper;
@Nested
class TestGetExterneFachstelle {
@BeforeEach
void mock() {
when(fachstelleServiceBlockingStub.getById(any())).thenReturn(GrpcFachstelleGetResponseTestFactory.create());
}
@Test
void shouldCallFachstelleServiceBlockingStub() {
getExterneFachstelle();
verify(fachstelleServiceBlockingStub).getById(GrpcFachstelleGetRequestTestFactory.create());
}
@Test
void shouldCallFachstelleMapper() {
getExterneFachstelle();
verify(fachstelleMapper).fromExterneFachstelle(GrpcFachstelleGetResponseTestFactory.EXTERNE_FACHSTELLE);
}
@Test
void shouldReturnFachstelle() {
var expectedFachstelle = FachstelleTestFactory.create();
when(fachstelleMapper.fromExterneFachstelle(any())).thenReturn(expectedFachstelle);
var returnFachstelle = getExterneFachstelle();
assertThat(returnFachstelle).isSameAs(expectedFachstelle);
}
private Fachstelle getExterneFachstelle() {
return service.getExterneFachstelle(FachstelleTestFactory.TECHNICAL_ID);
}
}
@Nested
class TestGetOrganisationsEinheit {
@BeforeEach
void mock() {
when(organisationsEinheitServiceBlockingStub.getById(any())).thenReturn(GrpcOrganisationsEinheitGetResponseTestFactory.create());
}
@Test
void shouldCallOrganisationsEinheitServiceBlockingStub() {
getOrganisationsEinheit();
verify(organisationsEinheitServiceBlockingStub).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create());
}
@Test
void shouldCallFachstelleMapper() {
getOrganisationsEinheit();
verify(fachstelleMapper).fromOrganisationsEinheit(GrpcOrganisationsEinheitGetResponseTestFactory.ORGANISATIONS_EINHEIT);
}
@Test
void shouldReturnFachstelle() {
var expectedFachstelle = FachstelleTestFactory.create();
when(fachstelleMapper.fromOrganisationsEinheit(any())).thenReturn(expectedFachstelle);
var returnFachstelle = getOrganisationsEinheit();
assertThat(returnFachstelle).isSameAs(expectedFachstelle);
}
private Fachstelle getOrganisationsEinheit() {
return service.getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID);
}
}
}
package de.ozgcloud.collaboration.fachstelle;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
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;
class FachstelleServiceTest {
@InjectMocks
private FachstelleService service;
@Mock
private FachstelleRemoteService remoteService;
@Nested
class TestGetFachstelle {
@Nested
class TestOnCollaborationLevel1 {
@Test
void shouldGetOrganisationsEinheit() {
service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 1);
verify(remoteService).getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID);
}
@Test
void shouldReturnFachstelle() {
var expectedFachstelle = FachstelleTestFactory.create();
when(remoteService.getOrganisationsEinheit(any())).thenReturn(expectedFachstelle);
var actualFachstelle = service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 1);
assertThat(actualFachstelle).isSameAs(expectedFachstelle);
}
}
@Nested
class TestOnCollaborationLevel4 {
@Test
void shouldGetExterneFachstelle() {
service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 4);
verify(remoteService).getExterneFachstelle(FachstelleTestFactory.TECHNICAL_ID);
}
@Test
void shouldReturnFachstelle() {
var expectedFachstelle = FachstelleTestFactory.create();
when(remoteService.getExterneFachstelle(any())).thenReturn(expectedFachstelle);
var actualFachstelle = service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 4);
assertThat(actualFachstelle).isSameAs(expectedFachstelle);
}
}
@Nested
class TestOnUnknownCollaborationLevel {
@Test
void shouldThrowIlleagalArgumentException() {
assertThrows(IllegalArgumentException.class, () -> service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 5));
}
}
}
}
package de.ozgcloud.collaboration.fachstelle;
import java.util.Map;
import java.util.UUID;
import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleBuilder;
import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType;
public class FachstelleTestFactory {
public static final FachstelleType TYPE = FachstelleType.ORGANISATIONS_EINHEIT;
public static final String SUBJECT_ID = UUID.randomUUID().toString();
public static final String TECHNICAL_ID = UUID.randomUUID().toString();
public static Fachstelle create() {
return createBuilder().build();
}
public static FachstelleBuilder createBuilder() {
return Fachstelle.builder()
.subjectId(SUBJECT_ID)
.technicalId(TECHNICAL_ID)
.type(TYPE);
}
public static Map<String, Object> createAsMap() {
return Map.of(
Fachstelle.PROPERTY_TECHNICAL_ID, TECHNICAL_ID,
Fachstelle.PROPERTY_SUBJECT_ID, SUBJECT_ID,
Fachstelle.PROPERTY_TYPE, TYPE.name());
}
}
/*
* Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den
* Ministerpräsidenten des Landes Schleswig-Holstein
* Staatskanzlei
* Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
*
* Lizenziert unter der EUPL, Version 1.2 oder - sobald
* diese von der Europäischen Kommission genehmigt wurden -
* Folgeversionen der EUPL ("Lizenz");
* Sie dürfen dieses Werk ausschließlich gemäß
* dieser Lizenz nutzen.
* Eine Kopie der Lizenz finden Sie hier:
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* Sofern nicht durch anwendbare Rechtsvorschriften
* gefordert oder in schriftlicher Form vereinbart, wird
* die unter der Lizenz verbreitete Software "so wie sie
* ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
* ausdrücklich oder stillschweigend - verbreitet.
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
package de.ozgcloud.collaboration.fachstelle;
import java.util.Random;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcAnschrift;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcAnschrift.Builder;
public class GrpcAnschriftTestFactory {
public static final String PLZ = LoremIpsum.getInstance().getZipCode();
public static final String ORT = LoremIpsum.getInstance().getCity();
public static final String STRASSE = LoremIpsum.getInstance().getWords(2);
public static final String HAUSNUMMER = String.valueOf(new Random().nextInt());
public static GrpcAnschrift create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcAnschrift.newBuilder()
.setStrasse(STRASSE)
.setHausnummer(HAUSNUMMER)
.setPlz(PLZ)
.setOrt(ORT);
}
}
package de.ozgcloud.collaboration.fachstelle;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest.Builder;
public class GrpcFachstelleGetRequestTestFactory {
private static final String ID = FachstelleTestFactory.TECHNICAL_ID;
public static GrpcFachstelleGetRequest create() {
return createBuilder().build();
}
private static Builder createBuilder() {
return GrpcFachstelleGetRequest.newBuilder().setId(ID);
}
}
package de.ozgcloud.collaboration.fachstelle;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetResponse;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetResponse.Builder;
public class GrpcFachstelleGetResponseTestFactory {
public static final GrpcFachstelle EXTERNE_FACHSTELLE = GrpcFachstelleTestFactory.create();
public static GrpcFachstelleGetResponse create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcFachstelleGetResponse.newBuilder()
.setFachstelle(EXTERNE_FACHSTELLE);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment