Skip to content
Snippets Groups Projects
Commit 1ea3cbf6 authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

Merge branch 'main' into OZG-6461-historie-refactoring

parents 1e76d90d a71dd855
No related branches found
No related tags found
1 merge request!5Ozg 6461 historie refactoring
Showing
with 363 additions and 210 deletions
......@@ -24,13 +24,15 @@
unter der Lizenz sind dem Lizenztext zu entnehmen.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.ozgcloud.alfa</groupId>
<artifactId>alfa</artifactId>
<version>2.19.0-SNAPSHOT</version>
<version>2.20.0-SNAPSHOT</version>
</parent>
<artifactId>alfa-server</artifactId>
......
......@@ -24,7 +24,8 @@
unter der Lizenz sind dem Lizenztext zu entnehmen.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
......@@ -32,7 +33,7 @@
<parent>
<groupId>de.ozgcloud.alfa</groupId>
<artifactId>alfa</artifactId>
<version>2.19.0-SNAPSHOT</version>
<version>2.20.0-SNAPSHOT</version>
</parent>
<artifactId>alfa-service</artifactId>
......
......@@ -23,7 +23,6 @@
*/
package de.ozgcloud.alfa.bescheid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.ResponseEntity;
......@@ -35,7 +34,6 @@ import org.springframework.web.bind.annotation.RestController;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileController;
import de.ozgcloud.alfa.common.file.OzgFile;
import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.RequiredArgsConstructor;
@RestController
......@@ -54,23 +52,12 @@ public class BescheidController {
return ResponseEntity.of(bescheidService.getBescheidDraft(vorgangId).map(assembler::toModel));
}
// TODO Sobald Grpc Schnittstelle zum Laden eines einzelnen Bescheids existiert,
// den Endpoint auf bescheidId beschraenken und ueber den Service ->
// den Bescheid laden
@GetMapping("/{bescheidId}/attachments")
public CollectionModel<EntityModel<OzgFile>> getAttachments(@PathVariable String bescheidId, @RequestParam String vorgangId) {
var bescheid = getBescheid(bescheidId, vorgangId);
public CollectionModel<EntityModel<OzgFile>> getAttachments(@PathVariable String bescheidId) {
var bescheid = bescheidService.getBescheid(bescheidId);
return binaryFileController.getFiles(bescheid.getAttachments());
}
Bescheid getBescheid(String bescheidId, String vorgangId) {
var bescheid = bescheidService.findByVorgangId(vorgangId)
.filter(oneBescheid -> StringUtils.equals(oneBescheid.getId(), bescheidId))
.findFirst();
return bescheid.orElseThrow(() -> new TechnicalException(String.format("No Bescheid exists for id %s.", bescheidId)));
}
//
@RestController
@RequestMapping(BescheidByVorgangController.BESCHEID_BY_VORGANG_PATH)
@RequiredArgsConstructor
......
/*
* Copyright (C) 2025 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.alfa.bescheid;
import lombok.Builder;
import lombok.Getter;
@Builder
@Getter
class BescheidManagerFeatures {
private boolean canCreateBescheidDocument;
}
/*
* Copyright (C) 2025 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.alfa.bescheid;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerFeatures;
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
interface BescheidManagerFeaturesMapper {
BescheidManagerFeatures fromGrpc(GrpcBescheidManagerFeatures grpcBescheidManagerFeatures);
}
......@@ -35,15 +35,19 @@ import com.google.protobuf.ProtocolStringList;
import de.ozgcloud.alfa.common.binaryfile.FileId;
import de.ozgcloud.alfa.common.binaryfile.FileIdMapper;
import de.ozgcloud.alfa.common.user.UserIdMapper;
import de.ozgcloud.bescheid.GrpcBescheid;
import de.ozgcloud.bescheid.GrpcSentInfo;
import de.ozgcloud.document.bescheid.GrpcBescheid;
import de.ozgcloud.document.bescheid.GrpcSentInfo;
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, uses = { FileIdMapper.class,
UserIdMapper.class })
interface BescheidMapper {
@Mapping(target = "vorgangId", ignore = true)
@Mapping(target = "attachments", source = "grpcBescheid.attachmentsList")
Bescheid fromGrpc(GrpcBescheid grpcBescheid, String vorgangId);
Bescheid fromGrpc(GrpcBescheid grpcBescheid);
@Mapping(target = "attachments", source = "grpcBescheid.attachmentsList")
Bescheid fromGrpcAndVorgangId(GrpcBescheid grpcBescheid, String vorgangId);
List<FileId> fromProtocolStringList(ProtocolStringList value);
......
......@@ -81,7 +81,7 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc
methodOn(CommandByRelationController.class).createCommand(bescheid.getVorgangId(), bescheid.getId(), bescheid.getVersion(), null));
var uploadBescheidFileLink = linkTo(methodOn(BinaryFileController.class).uploadFile(bescheid.getVorgangId(), "bescheidFile", null));
var uploadAttachmentLink = linkTo(methodOn(BinaryFileController.class).uploadFile(bescheid.getVorgangId(), "bescheidAttachment", null));
var attachmentsLink = linkTo(methodOn(BescheidController.class).getAttachments(bescheid.getId(), bescheid.getVorgangId()));
var attachmentsLink = linkTo(methodOn(BescheidController.class).getAttachments(bescheid.getId()));
var createCommandLink = buildCreateCommandLink(bescheid);
var vorgangWithEingang = vorgangController.getVorgang(bescheid.getVorgangId());
var bescheidenUndSendenLink = linkTo(
......
......@@ -26,57 +26,74 @@ package de.ozgcloud.alfa.bescheid;
import java.util.Optional;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.ozgcloud.alfa.common.GrpcUtil;
import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.bescheid.GrpcBescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.bescheid.GrpcGetAllBescheidRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse;
import de.ozgcloud.document.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.document.bescheid.GrpcBescheid;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigResponse;
import de.ozgcloud.document.bescheid.GrpcGetAllBescheidRequest;
import de.ozgcloud.document.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.document.bescheid.GrpcGetBescheidDraftResponse;
import de.ozgcloud.document.bescheid.GrpcGetBescheidRequest;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.client.inject.GrpcClient;
@Service
@RequiredArgsConstructor
class BescheidRemoteService {
@GrpcClient(GrpcUtil.VORGANG_MANAGER_GRPC_CLIENT)
private BescheidServiceBlockingStub bescheidServiceStub;
@Autowired
private BescheidMapper bescheidMapper;
private final BescheidServiceBlockingStub bescheidServiceStub;
private final BescheidMapper bescheidMapper;
private final BescheidManagerFeaturesMapper bescheidManagerFeaturesMapper;
public Optional<Bescheid> getBescheidDraft(String vorgangId) {
var request = buildGetBescheidDraftRequest(vorgangId);
var response = bescheidServiceStub.getBescheidDraft(request);
return getBescheidFromResponse(response).map(bescheid -> bescheidMapper.fromGrpc(bescheid, vorgangId));
return getBescheidFromResponse(response).map(bescheid -> bescheidMapper.fromGrpcAndVorgangId(bescheid, vorgangId));
}
GrpcGetBescheidDraftRequest buildGetBescheidDraftRequest(String vorgangId) {
return GrpcGetBescheidDraftRequest.newBuilder()
.setVorgangId(vorgangId)
.build();
return GrpcGetBescheidDraftRequest.newBuilder().setVorgangId(vorgangId).build();
}
Optional<GrpcBescheid> getBescheidFromResponse(GrpcGetBescheidDraftResponse response) {
return response.hasBescheid() ? Optional.of(response.getBescheid()) : Optional.empty();
}
public Bescheid getBescheid(String bescheidId) {
var request = buildGetBescheidRequest(bescheidId);
var response = bescheidServiceStub.getBescheid(request);
return bescheidMapper.fromGrpc(response.getBescheid());
}
GrpcGetBescheidRequest buildGetBescheidRequest(String bescheidId) {
return GrpcGetBescheidRequest.newBuilder().setId(bescheidId).build();
}
public Stream<Bescheid> findByVorgangId(String vorgangId) {
var request = buildGetAllBescheidRequest(vorgangId);
var response = bescheidServiceStub.getAll(request);
return response.getBescheidList().stream().map(grpcBescheid -> bescheidMapper.fromGrpc(grpcBescheid, vorgangId));
return response.getBescheidList().stream().map(grpcBescheid -> bescheidMapper.fromGrpcAndVorgangId(grpcBescheid, vorgangId));
}
GrpcGetAllBescheidRequest buildGetAllBescheidRequest(String vorgangId) {
return GrpcGetAllBescheidRequest.newBuilder().setVorgangId(vorgangId).build();
}
// TODO Logik in den Service verschieben
public boolean canCreateBescheidDocument() {
var response = bescheidServiceStub.getConfig(GrpcBescheidManagerConfigRequest.newBuilder().build());
return response.hasFeatures() && response.getFeatures().getCanCreateBescheidDocument();
public BescheidManagerFeatures getBescheidManagerFeatures() {
return getFeatures(getConfig());
}
private GrpcBescheidManagerConfigResponse getConfig() {
return bescheidServiceStub.getConfig(GrpcBescheidManagerConfigRequest.newBuilder().build());
}
private BescheidManagerFeatures getFeatures(GrpcBescheidManagerConfigResponse configResponse) {
return bescheidManagerFeaturesMapper.fromGrpc(configResponse.getFeatures());
}
}
\ No newline at end of file
......@@ -42,6 +42,10 @@ public class BescheidService {
return remoteService.getBescheidDraft(vorgangId);
}
public Bescheid getBescheid(String bescheidId) {
return remoteService.getBescheid(bescheidId);
}
public Stream<Bescheid> findByVorgangId(String vorgangId) {
return remoteService.findByVorgangId(vorgangId);
}
......@@ -55,7 +59,7 @@ public class BescheidService {
}
public boolean canCreateBescheidDocumentAutomatically() {
return remoteService.canCreateBescheidDocument();
return remoteService.getBescheidManagerFeatures().isCanCreateBescheidDocument();
}
public boolean existsBescheid(String vorgangId) {
......
......@@ -23,14 +23,13 @@
*/
package de.ozgcloud.alfa.bescheid;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
......@@ -39,14 +38,15 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileController;
import de.ozgcloud.alfa.common.file.OzgFileTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.SneakyThrows;
class BescheidControllerTest {
......@@ -129,15 +129,16 @@ class BescheidControllerTest {
@BeforeEach
void mock() {
doReturn(BescheidTestFactory.create()).when(controller).getBescheid(anyString(), anyString());
when(bescheidService.getBescheid(any())).thenReturn(BescheidTestFactory.create());
when(binaryFileController.getFiles(any())).thenReturn(CollectionModel.of(List.of(EntityModel.of(OzgFileTestFactory.create()))));
}
@SneakyThrows
@Test
void shouldGetBescheid() {
void shouldCallBescheidService() {
doRequest();
verify(controller).getBescheid(BescheidTestFactory.ID, BescheidTestFactory.VORGANG_ID);
verify(bescheidService).getBescheid(BescheidTestFactory.ID);
}
@SneakyThrows
......@@ -157,47 +158,34 @@ class BescheidControllerTest {
}
@SneakyThrows
private ResultActions doRequest() {
return mockMvc.perform(
get(BescheidController.PATH + "/{bescheidId}/attachments", BescheidTestFactory.ID).param("vorgangId",
BescheidTestFactory.VORGANG_ID));
}
}
@DisplayName("Get Bescheid")
@Nested
class TestGetBescheid {
private final Bescheid matchingBescheid = BescheidTestFactory.create();
private final Bescheid notMatchingBescheid = BescheidTestFactory.createBuilder().id("NOT_MATCH").build();
@Test
void shouldHaveAttachmentName() {
var response = doRequest();
@BeforeEach
void mock() {
when(bescheidService.findByVorgangId(anyString())).thenReturn(Stream.of(matchingBescheid, notMatchingBescheid));
response.andExpect(jsonPath("$.content[0].name").value(OzgFileTestFactory.NAME));
}
@DisplayName("should call service to find all bescheid by vorgang")
@SneakyThrows
@Test
void shouldCallFindByVorgangId() {
controller.getBescheid(BescheidTestFactory.ID, VorgangHeaderTestFactory.ID);
void shouldHaveAttachmentSize() {
var response = doRequest();
verify(bescheidService).findByVorgangId(VorgangHeaderTestFactory.ID);
response.andExpect(jsonPath("$.content[0].size").value(OzgFileTestFactory.SIZE));
}
@SneakyThrows
@Test
void shouldReturnMatchingEntry() {
var bescheid = controller.getBescheid(BescheidTestFactory.ID, VorgangHeaderTestFactory.ID);
void shouldHaveAttachmentContentType() {
var response = doRequest();
assertThat(bescheid).isEqualTo(matchingBescheid);
response.andExpect(jsonPath("$.content[0].contentType").value(OzgFileTestFactory.CONTENT_TYPE));
}
@Test
void shouldThrowExceptionIfNoBescheidExists() {
when(bescheidService.findByVorgangId(anyString())).thenReturn(Stream.empty());
assertThatThrownBy(() -> controller.getBescheid(BescheidTestFactory.ID, VorgangHeaderTestFactory.ID))
.isInstanceOf(TechnicalException.class)
.hasMessageContaining("No Bescheid exists for id " + BescheidTestFactory.ID);
@SneakyThrows
private ResultActions doRequest() {
return mockMvc.perform(
get(BescheidController.PATH + "/{bescheidId}/attachments", BescheidTestFactory.ID).param("vorgangId",
BescheidTestFactory.VORGANG_ID));
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2025 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.alfa.bescheid;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mapstruct.factory.Mappers;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerFeatures;
class BescheidManagerFeaturesMapperTest {
private final BescheidManagerFeaturesMapper mapper = Mappers.getMapper(BescheidManagerFeaturesMapper.class);
@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldMapCanCreateBescheidDocument(boolean canCreate) {
var grpcFeatures = GrpcBescheidManagerFeatures.newBuilder().setCanCreateBescheidDocument(canCreate).build();
var features = mapper.fromGrpc(grpcFeatures);
assertThat(features.isCanCreateBescheidDocument()).isEqualTo(canCreate);
}
}
......@@ -27,8 +27,8 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.time.ZonedDateTime;
import org.assertj.core.api.recursive.comparison.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
......@@ -36,7 +36,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import de.ozgcloud.alfa.common.binaryfile.FileIdMapper;
import de.ozgcloud.alfa.common.user.UserId;
import de.ozgcloud.alfa.common.user.UserIdMapper;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
......@@ -49,100 +48,60 @@ class BescheidMapperTest {
@InjectMocks
private final BescheidMapper mapper = Mappers.getMapper(BescheidMapper.class);
@BeforeEach
void init() {
when(fileIdMapper.toFileId(any())).thenReturn(BescheidTestFactory.ATTACHMENT_ID);
when(userIdMapper.fromString(any())).thenReturn(BescheidTestFactory.SENT_INFO.getSentBy());
}
@Nested
class TestFromGrpc {
@Test
void shouldMapId() {
var bescheid = map();
void shouldMapAttachments() {
mapper.fromGrpc(GrpcBescheidTestFactory.create());
assertThat(bescheid.getId()).isEqualTo(GrpcBescheidTestFactory.ID);
verify(fileIdMapper).toFileId(GrpcBescheidTestFactory.ATTACHMENT_ID);
}
@Test
void shouldMapVorgangId() {
var bescheid = map();
void shouldMapSentBy() {
mapper.fromGrpc(GrpcBescheidTestFactory.create());
assertThat(bescheid.getVorgangId()).isEqualTo(VorgangHeaderTestFactory.ID);
verify(userIdMapper).fromString(GrpcSentInfoTestFactory.SENT_BY);
}
@Test
void shouldMapBewilligt() {
var bescheid = map();
void shouldMapAllFields() {
var bescheid = mapper.fromGrpc(GrpcBescheidTestFactory.create());
assertThat(bescheid.getBewilligt()).isEqualTo(GrpcBescheidTestFactory.BEWILLIGT);
assertThat(bescheid).usingRecursiveComparison(RecursiveComparisonConfiguration.builder().withIgnoredFields("vorgangId").build())
.isEqualTo(BescheidTestFactory.create());
}
@Test
void shouldMapBeschiedenAm() {
var bescheid = map();
assertThat(bescheid.getBeschiedenAm()).isEqualTo(GrpcBescheidTestFactory.BESCHIEDEN_AM);
}
@Test
void shouldMapBescheidDocument() {
var bescheid = map();
assertThat(bescheid.getBescheidDocument()).isEqualTo(GrpcBescheidTestFactory.BESCHEID_DOCUMENT);
}
@Nested
class TestFromGrpcAndVorgangId {
@Test
void shouldMapAttachments() {
when(fileIdMapper.toFileId(any())).thenCallRealMethod();
mapper.fromGrpc(GrpcBescheidTestFactory.create());
var bescheid = map();
assertThat(bescheid.getAttachments()).containsExactlyInAnyOrderElementsOf(BescheidTestFactory.ATTACHMENTS);
verify(fileIdMapper).toFileId(GrpcBescheidTestFactory.ATTACHMENT_ID);
}
@Test
void shouldMapNachrichtText() {
var bescheid = map();
assertThat(bescheid.getNachrichtText()).isEqualTo(GrpcBescheidTestFactory.NACHRICHT_TEXT);
}
@Test
void shouldMapNachrichtSubject() {
var bescheid = map();
assertThat(bescheid.getNachrichtSubject()).isEqualTo(GrpcBescheidTestFactory.NACHRICHT_SUBJECT);
}
@Test
void shouldMapStatus() {
var bescheid = map();
assertThat(bescheid.getStatus()).isEqualTo(BescheidTestFactory.STATUS);
}
@Nested
class TestMapSentInfo {
private final SentInfo expectedSentInfo = SentInfoTestFactory.createBuilder()
.sentAt(ZonedDateTime.parse(GrpcSentInfoTestFactory.SENT_AT))
.sentBy(UserId.from(GrpcSentInfoTestFactory.SENT_BY))
.build();
@Test
void shouldMapSentBy() {
when(userIdMapper.fromString(GrpcSentInfoTestFactory.SENT_BY)).thenCallRealMethod();
var bescheid = map();
mapper.fromGrpc(GrpcBescheidTestFactory.create());
assertThat(bescheid.getSentInfo().getSentBy()).isEqualTo(expectedSentInfo.getSentBy());
verify(userIdMapper).fromString(GrpcSentInfoTestFactory.SENT_BY);
}
@Test
void shouldMapSentAt() {
var bescheid = map();
assertThat(bescheid.getSentInfo().getSentAt()).isEqualTo(expectedSentInfo.getSentAt());
}
}
void shouldMapAllFields() {
var bescheid = mapper.fromGrpcAndVorgangId(GrpcBescheidTestFactory.create(), VorgangHeaderTestFactory.ID);
private Bescheid map() {
return mapper.fromGrpc(GrpcBescheidTestFactory.create(), VorgangHeaderTestFactory.ID);
assertThat(bescheid).usingRecursiveComparison().isEqualTo(BescheidTestFactory.create());
}
}
}
......@@ -137,8 +137,7 @@ class BescheidModelAssemblerTest {
var model = callToModel();
assertThat(model.getLink(REL_ATTACHMENTS)).isPresent().get().extracting(Link::getHref)
.isEqualTo(String.format("%s/%s/attachments?vorgangId=%s", BescheidController.PATH, BescheidTestFactory.ID,
BescheidTestFactory.VORGANG_ID));
.isEqualTo(String.format("%s/%s/attachments", BescheidController.PATH, BescheidTestFactory.ID));
}
@Test
......
......@@ -38,13 +38,15 @@ import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigResponse;
import de.ozgcloud.bescheid.GrpcGetAllBescheidRequest;
import de.ozgcloud.bescheid.GrpcGetAllBescheidResponse;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse;
import de.ozgcloud.document.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigResponse;
import de.ozgcloud.document.bescheid.GrpcGetAllBescheidRequest;
import de.ozgcloud.document.bescheid.GrpcGetAllBescheidResponse;
import de.ozgcloud.document.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.document.bescheid.GrpcGetBescheidDraftResponse;
import de.ozgcloud.document.bescheid.GrpcGetBescheidRequest;
import de.ozgcloud.document.bescheid.GrpcGetBescheidResponse;
class BescheidRemoteServiceTest {
......@@ -55,6 +57,8 @@ class BescheidRemoteServiceTest {
private BescheidServiceBlockingStub bescheidServiceStub;
@Mock
private BescheidMapper bescheidMapper;
@Mock
private BescheidManagerFeaturesMapper featuresMapper;
@Nested
class TestGetBescheidDraft {
......@@ -83,18 +87,25 @@ class BescheidRemoteServiceTest {
verify(bescheidServiceStub).getBescheidDraft(request);
}
@Test
void shouldGetBescheidFromResponse() {
service.getBescheidDraft(VorgangHeaderTestFactory.ID);
verify(service).getBescheidFromResponse(response);
}
@Test
void shouldCallMapper() {
doReturn(Optional.of(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID)).when(service).getBescheidFromResponse(response);
service.getBescheidDraft(VorgangHeaderTestFactory.ID);
verify(bescheidMapper).fromGrpc(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID);
verify(bescheidMapper).fromGrpcAndVorgangId(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID);
}
@Test
void shouldReturnBescheid() {
when(bescheidMapper.fromGrpc(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID)).thenReturn(
when(bescheidMapper.fromGrpcAndVorgangId(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID)).thenReturn(
bescheidDraft);
var bescheidDraft = service.getBescheidDraft(VorgangHeaderTestFactory.ID);
......@@ -110,13 +121,6 @@ class BescheidRemoteServiceTest {
assertThat(bescheidDraft).isEmpty();
}
@Test
void shouldGetBescheidFromResponse() {
service.getBescheidDraft(VorgangHeaderTestFactory.ID);
verify(service).getBescheidFromResponse(response);
}
}
@Nested
......@@ -149,51 +153,92 @@ class BescheidRemoteServiceTest {
}
@Nested
class TestCanCreateBescheidDocument {
class TestGetBescheid {
private final GrpcBescheidManagerConfigRequest request = GrpcBescheidManagerConfigRequestTestFactory.create();
private final GrpcBescheidManagerConfigResponse respone = GrpcBescheidManagerConfigResponseTestFactory.create();
private final GrpcGetBescheidRequest request = GrpcGetBescheidRequestTestFactory.create();
private final GrpcGetBescheidResponse response = GrpcGetBescheidResponseTestFactory.create();
@BeforeEach
void setUp() {
when(bescheidServiceStub.getConfig(request)).thenReturn(respone);
doReturn(request).when(service).buildGetBescheidRequest(any());
when(bescheidServiceStub.getBescheid(any())).thenReturn(response);
}
@Test
void shouldCallRemoteService() {
service.canCreateBescheidDocument();
void shouldBuildGetBescheidRequest() {
service.getBescheid(BescheidTestFactory.ID);
verify(bescheidServiceStub).getConfig(request);
verify(service).buildGetBescheidRequest(BescheidTestFactory.ID);
}
@Test
void shouldCallGrpcService() {
service.getBescheid(BescheidTestFactory.ID);
verify(bescheidServiceStub).getBescheid(request);
}
@Test
void shouldReturnTrue() {
var canCreate = service.canCreateBescheidDocument();
void shouldCallMapper() {
service.getBescheid(BescheidTestFactory.ID);
assertThat(canCreate).isTrue();
verify(bescheidMapper).fromGrpc(GrpcGetBescheidResponseTestFactory.GRPC_BESCHEID);
}
@Test
void shouldReturnFalseIfNoFeaturesAvailable() {
when(bescheidServiceStub.getConfig(request)).thenReturn(GrpcBescheidManagerConfigResponse.newBuilder().build());
void shouldReturnBescheid() {
var mappedBescheid = BescheidTestFactory.create();
when(bescheidMapper.fromGrpc(GrpcGetBescheidDraftResponseTestFactory.GRPC_BESCHEID)).thenReturn(mappedBescheid);
var canCreate = service.canCreateBescheidDocument();
var bescheid = service.getBescheid(BescheidTestFactory.ID);
assertThat(canCreate).isFalse();
assertThat(bescheid).isEqualTo(mappedBescheid);
}
}
@Nested
class TestBuildGetBescheidRequest {
@Test
void shouldReturnFalseIfFeatureDisabled() {
var respones = GrpcBescheidManagerConfigResponseTestFactory.createBuilder()
.setFeatures(GrpcBescheidManagerFeaturesTestFactory.createBuilder()
.setCanCreateBescheidDocument(false)
.build())
.build();
when(bescheidServiceStub.getConfig(request)).thenReturn(respones);
void shouldHaveId() {
var request = service.buildGetBescheidRequest(BescheidTestFactory.ID);
assertThat(request.getId()).isEqualTo(BescheidTestFactory.ID);
}
}
@Nested
class TestGetBescheidManagerFeatures {
var canCreate = service.canCreateBescheidDocument();
private final GrpcBescheidManagerConfigRequest request = GrpcBescheidManagerConfigRequestTestFactory.create();
private final GrpcBescheidManagerConfigResponse respone = GrpcBescheidManagerConfigResponseTestFactory.create();
private final BescheidManagerFeatures mappedFeatures = BescheidManagerFeatures.builder().build();
@BeforeEach
void setUp() {
when(bescheidServiceStub.getConfig(request)).thenReturn(respone);
when(featuresMapper.fromGrpc(any())).thenReturn(mappedFeatures);
}
@Test
void shouldCallGrpcService() {
service.getBescheidManagerFeatures();
verify(bescheidServiceStub).getConfig(request);
}
@Test
void shouldCallMapper() {
service.getBescheidManagerFeatures();
verify(featuresMapper).fromGrpc(GrpcBescheidManagerFeaturesTestFactory.create());
}
@Test
void shouldReturnMappedFeatures() {
var features = service.getBescheidManagerFeatures();
assertThat(canCreate).isFalse();
assertThat(features).isSameAs(mappedFeatures);
}
}
......@@ -231,12 +276,12 @@ class BescheidRemoteServiceTest {
void shouldMapBescheid() {
service.findByVorgangId(VorgangHeaderTestFactory.ID).toList();
verify(bescheidMapper).fromGrpc(GrpcGetAllBescheidResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID);
verify(bescheidMapper).fromGrpcAndVorgangId(GrpcGetAllBescheidResponseTestFactory.GRPC_BESCHEID, VorgangHeaderTestFactory.ID);
}
@Test
void shouldReturnStreamOfBescheide() {
when(bescheidMapper.fromGrpc(any(), any())).thenReturn(bescheid);
when(bescheidMapper.fromGrpcAndVorgangId(any(), any())).thenReturn(bescheid);
var bescheide = service.findByVorgangId(VorgangHeaderTestFactory.ID);
......
......@@ -74,6 +74,27 @@ class BescheidServiceTest {
}
}
@Nested
class TestGetBescheid {
@Test
void shouldCallRemoteService() {
service.getBescheid(BescheidTestFactory.ID);
verify(remoteService).getBescheid(BescheidTestFactory.ID);
}
@Test
void shouldReturnResultFromRemoteService() {
var remoteServiceResult = BescheidTestFactory.create();
when(remoteService.getBescheid(BescheidTestFactory.ID)).thenReturn(remoteServiceResult);
var result = service.getBescheid(BescheidTestFactory.ID);
assertThat(result).isEqualTo(remoteServiceResult);
}
}
@Nested
class TestFindByVorgangId {
private final Stream<Bescheid> bescheidsUnsorted = Stream.of(BescheidTestFactory.create());
......@@ -147,19 +168,22 @@ class BescheidServiceTest {
@Test
void shouldCallRemoteService() {
when(remoteService.getBescheidManagerFeatures()).thenReturn(BescheidManagerFeatures.builder().build());
service.canCreateBescheidDocumentAutomatically();
verify(remoteService).canCreateBescheidDocument();
verify(remoteService).getBescheidManagerFeatures();
}
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldRetrun(boolean canCreateBescheidDocument) {
when(remoteService.canCreateBescheidDocument()).thenReturn(canCreateBescheidDocument);
void shouldReturnFeatureValue(boolean featureValue) {
when(remoteService.getBescheidManagerFeatures()).thenReturn(
BescheidManagerFeatures.builder().canCreateBescheidDocument(featureValue).build());
var canCreateAutomatically = service.canCreateBescheidDocumentAutomatically();
var canCreate = service.canCreateBescheidDocumentAutomatically();
assertThat(canCreateAutomatically).isEqualTo(canCreateBescheidDocument);
assertThat(canCreate).isEqualTo(featureValue);
}
}
......
......@@ -42,7 +42,9 @@ public class BescheidTestFactory {
public static final String BESCHIEDEN_AM = "2024-05-27";
public static final boolean BEWILLIGT = true;
public static final String BESCHEID_DOCUMENT = UUID.randomUUID().toString();
public static final List<FileId> ATTACHMENTS = List.of(FileId.from(UUID.randomUUID().toString()), FileId.from(UUID.randomUUID().toString()));
public static final String ATTACHMENT_ID_VALUE = UUID.randomUUID().toString();
public static final FileId ATTACHMENT_ID = FileId.from(ATTACHMENT_ID_VALUE);
public static final List<FileId> ATTACHMENTS = List.of(ATTACHMENT_ID);
public static final String NACHRICHT_TEXT = LoremIpsum.getInstance().getWords(10);
public static final String NACHRICHT_SUBJECT = LoremIpsum.getInstance().getWords(3);
public static final SendBy SEND_BY = SendBy.MANUAL;
......
......@@ -23,7 +23,7 @@
*/
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigRequest;
public class GrpcBescheidManagerConfigRequestTestFactory {
......
......@@ -23,7 +23,7 @@
*/
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigResponse;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerConfigResponse;
public class GrpcBescheidManagerConfigResponseTestFactory {
......
......@@ -23,7 +23,7 @@
*/
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerFeatures;
import de.ozgcloud.document.bescheid.GrpcBescheidManagerFeatures;
public class GrpcBescheidManagerFeaturesTestFactory {
......
......@@ -25,19 +25,22 @@ package de.ozgcloud.alfa.bescheid;
import java.util.List;
import de.ozgcloud.bescheid.GrpcBescheid;
import de.ozgcloud.bescheid.GrpcSentInfo;
import de.ozgcloud.common.datatype.StringBasedValue;
import de.ozgcloud.document.bescheid.GrpcBescheid;
import de.ozgcloud.document.bescheid.GrpcSentInfo;
public class GrpcBescheidTestFactory {
public static final String ID = BescheidTestFactory.ID;
public static final String STATUS = BescheidTestFactory.STATUS.toString();
public static final long VERSION = BescheidTestFactory.VERSION;
public static final boolean BEWILLIGT = BescheidTestFactory.BEWILLIGT;
public static final String BESCHIEDEN_AM = BescheidTestFactory.BESCHIEDEN_AM;
public static final String BESCHEID_DOCUMENT = BescheidTestFactory.BESCHEID_DOCUMENT;
public static final List<String> ATTACHMENTS = BescheidTestFactory.ATTACHMENTS.stream().map(StringBasedValue::toString).toList();
public static final String ATTACHMENT_ID = BescheidTestFactory.ATTACHMENT_ID_VALUE;
public static final List<String> ATTACHMENTS = List.of(ATTACHMENT_ID);
public static final String NACHRICHT_TEXT = BescheidTestFactory.NACHRICHT_TEXT;
public static final String NACHRICHT_SUBJECT = BescheidTestFactory.NACHRICHT_SUBJECT;
public static final String SEND_BY = BescheidTestFactory.SEND_BY.toString();
public static final GrpcSentInfo SENT_INFO = GrpcSentInfoTestFactory.create();
public static GrpcBescheid create() {
......@@ -47,14 +50,15 @@ public class GrpcBescheidTestFactory {
public static GrpcBescheid.Builder createBuilder() {
return GrpcBescheid.newBuilder()
.setId(ID)
.setStatus(BescheidTestFactory.STATUS.toString())
.setStatus(STATUS)
.setVersion(VERSION)
.setBewilligt(BEWILLIGT)
.setBeschiedenAm(BESCHIEDEN_AM)
.setBescheidDocument(BESCHEID_DOCUMENT)
.addAllAttachments(ATTACHMENTS)
.setNachrichtText(NACHRICHT_TEXT)
.setNachrichtSubject(NACHRICHT_SUBJECT)
.setSendBy(BescheidTestFactory.SEND_BY.toString())
.setSendBy(SEND_BY)
.setSentInfo(SENT_INFO);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment