diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidRemoteService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidRemoteService.java index d3abd51e1b51c33463a08dfc920ad21581534e44..61e2022de3c09c46d1b0ad6084f6402aa44575df 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidRemoteService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidRemoteService.java @@ -26,28 +26,28 @@ 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.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; - @Autowired - private BescheidManagerFeaturesMapper bescheidManagerFeaturesMapper; + private final BescheidServiceBlockingStub bescheidServiceStub; + private final BescheidMapper bescheidMapper; + private final BescheidManagerFeaturesMapper bescheidManagerFeaturesMapper; public Optional<Bescheid> getBescheidDraft(String vorgangId) { var request = buildGetBescheidDraftRequest(vorgangId); @@ -85,8 +85,15 @@ class BescheidRemoteService { return GrpcGetAllBescheidRequest.newBuilder().setVorgangId(vorgangId).build(); } - public Optional<BescheidManagerFeatures> getBescheidManagerFeatures() { - var response = bescheidServiceStub.getConfig(GrpcBescheidManagerConfigRequest.newBuilder().build()); - return response.hasFeatures() ? Optional.of(bescheidManagerFeaturesMapper.fromGrpc(response.getFeatures())) : Optional.empty(); + 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 diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidService.java index df312594f141d23efcb3a5dfaab0c63bb54d3de2..347586b0793d1d1af3f9da2b2931c87031595b7b 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/bescheid/BescheidService.java @@ -59,7 +59,7 @@ public class BescheidService { } public boolean canCreateBescheidDocumentAutomatically() { - return remoteService.getBescheidManagerFeatures().map(BescheidManagerFeatures::isCanCreateBescheidDocument).orElse(false); + return remoteService.getBescheidManagerFeatures().isCanCreateBescheidDocument(); } public boolean existsBescheid(String vorgangId) { diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidRemoteServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidRemoteServiceTest.java index e5aae0f2f5e0d79ec00e80e0086b3d31ccf95691..8b2de8c267d910580a8bf6f02fc0caad59a5be35 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidRemoteServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidRemoteServiceTest.java @@ -212,64 +212,33 @@ class BescheidRemoteServiceTest { private final GrpcBescheidManagerConfigRequest request = GrpcBescheidManagerConfigRequestTestFactory.create(); private final GrpcBescheidManagerConfigResponse respone = GrpcBescheidManagerConfigResponseTestFactory.create(); + private final BescheidManagerFeatures mappedFeatures = BescheidManagerFeatures.builder().build(); - @Test - void shouldCallGrpcService() { + @BeforeEach + void setUp() { when(bescheidServiceStub.getConfig(request)).thenReturn(respone); - when(featuresMapper.fromGrpc(any())).thenReturn(BescheidManagerFeatures.builder().build()); + when(featuresMapper.fromGrpc(any())).thenReturn(mappedFeatures); + } + @Test + void shouldCallGrpcService() { service.getBescheidManagerFeatures(); verify(bescheidServiceStub).getConfig(request); } - @Nested - class OnFeaturesArePresent { - - private final BescheidManagerFeatures mappedFeatures = BescheidManagerFeatures.builder().build(); - - @BeforeEach - void setUp() { - when(bescheidServiceStub.getConfig(request)).thenReturn(respone); - when(featuresMapper.fromGrpc(any())).thenReturn(mappedFeatures); - } - - @Test - void shouldCallMapper() { - service.getBescheidManagerFeatures(); - - verify(featuresMapper).fromGrpc(GrpcBescheidManagerFeaturesTestFactory.create()); - } - - @Test - void shouldReturnMappedFeatures() { - var features = service.getBescheidManagerFeatures(); + @Test + void shouldCallMapper() { + service.getBescheidManagerFeatures(); - assertThat(features).isNotEmpty().get().isSameAs(mappedFeatures); - } + verify(featuresMapper).fromGrpc(GrpcBescheidManagerFeaturesTestFactory.create()); } - @Nested - class OnFeaturesAreAbsent { - - @BeforeEach - void init() { - when(bescheidServiceStub.getConfig(request)).thenReturn(GrpcBescheidManagerConfigResponse.newBuilder().build()); - } - - @Test - void shouldNotCallMapper() { - service.getBescheidManagerFeatures(); - - verify(featuresMapper, never()).fromGrpc(any()); - } - - @Test - void shouldReturnEmpty() { - var features = service.getBescheidManagerFeatures(); + @Test + void shouldReturnMappedFeatures() { + var features = service.getBescheidManagerFeatures(); - assertThat(features).isEmpty(); - } + assertThat(features).isSameAs(mappedFeatures); } } diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidServiceTest.java index 95914f9d613d54b55aecc4d4e578397f3fd654cc..64f4c2b236348edaf26714e88dd10e1f73a357bb 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/bescheid/BescheidServiceTest.java @@ -168,27 +168,18 @@ class BescheidServiceTest { @Test void shouldCallRemoteService() { - when(remoteService.getBescheidManagerFeatures()).thenReturn(Optional.of(BescheidManagerFeatures.builder().build())); + when(remoteService.getBescheidManagerFeatures()).thenReturn(BescheidManagerFeatures.builder().build()); service.canCreateBescheidDocumentAutomatically(); verify(remoteService).getBescheidManagerFeatures(); } - @Test - void shouldReturnFalseIfFeaturesAreEmpty() { - when(remoteService.getBescheidManagerFeatures()).thenReturn(Optional.empty()); - - var canCreate = service.canCreateBescheidDocumentAutomatically(); - - assertThat(canCreate).isFalse(); - } - @ParameterizedTest @ValueSource(booleans = { true, false }) void shouldReturnFeatureValue(boolean featureValue) { when(remoteService.getBescheidManagerFeatures()).thenReturn( - Optional.of(BescheidManagerFeatures.builder().canCreateBescheidDocument(featureValue).build())); + BescheidManagerFeatures.builder().canCreateBescheidDocument(featureValue).build()); var canCreate = service.canCreateBescheidDocumentAutomatically(); diff --git a/lombok.config b/lombok.config index 32903abaf7760ff694e6cc45854316eb10f87137..d248ae3c4da552a1948c74ed6736e9e9d72655bd 100644 --- a/lombok.config +++ b/lombok.config @@ -27,4 +27,5 @@ lombok.log.slf4j.flagUsage = ERROR lombok.log.log4j.flagUsage = ERROR lombok.data.flagUsage = ERROR lombok.nonNull.exceptionType = IllegalArgumentException -lombok.addLombokGeneratedAnnotation = true \ No newline at end of file +lombok.addLombokGeneratedAnnotation = true +lombok.copyableAnnotations += net.devh.boot.grpc.client.inject.GrpcClient \ No newline at end of file