diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java index d15023c0eb9d045d05e9bf4860720f1d0ce32e56..f12c8e0da133a569546faddf1c2ec97676e11ef9 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import de.ozgcloud.collaboration.CollaborationManagerConfiguration; +import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor; import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub; import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; @@ -21,15 +22,26 @@ class FachstelleRemoteService { private final OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; @Qualifier(CollaborationManagerConfiguration.FACHSTELLE_MAPPER_NAME) // NOSONAR private final FachstelleMapper fachstelleMapper; + @Qualifier(CollaborationManagerConfiguration.CALL_CONTEXT_INTERCEPTOR_NAME) // NOSONAR + private final CollaborationManagerCallContextGrpcClientInterceptor callContextInterceptor; public Fachstelle getExterneFachstelle(String id) { - var externeFachstelle = fachstelleServiceBlockingStub.getById(GrpcFachstelleGetRequest.newBuilder().setId(id).build()).getFachstelle(); + var externeFachstelle = getFachstelleServiceBlockingStub().getById(GrpcFachstelleGetRequest.newBuilder().setId(id).build()).getFachstelle(); return fachstelleMapper.fromExterneFachstelle(externeFachstelle); } + FachstelleServiceBlockingStub getFachstelleServiceBlockingStub() { + return fachstelleServiceBlockingStub.withInterceptors(callContextInterceptor); + } + public Fachstelle getOrganisationsEinheit(String id) { - var organisationsEinheit = organisationsEinheitServiceBlockingStub.getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build()) + var organisationsEinheit = getOrganisationsEinheitServiceBlockingStub() + .getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build()) .getOrganisationsEinheit(); return fachstelleMapper.fromOrganisationsEinheit(organisationsEinheit); } + + public OrganisationsEinheitServiceBlockingStub getOrganisationsEinheitServiceBlockingStub() { + return organisationsEinheitServiceBlockingStub.withInterceptors(callContextInterceptor); + } } diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java index 0d8a020b2e5c6892a89c71599d37b1c026886b4b..8be0851d6640764d12159c231bbb5a3a7c1e28ed 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java @@ -11,6 +11,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; +import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor; import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub; import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub; @@ -26,20 +27,33 @@ class FachstelleRemoteServiceTest { private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; @Mock private FachstelleMapper fachstelleMapper; + @Mock + private CollaborationManagerCallContextGrpcClientInterceptor callContextInterceptor; @Nested class TestGetExterneFachstelle { + @Mock + private FachstelleServiceBlockingStub fachstelleServiceBlockingStubWithInterceptor; + @BeforeEach void mock() { - when(fachstelleServiceBlockingStub.getById(any())).thenReturn(GrpcFachstelleGetResponseTestFactory.create()); + doReturn(fachstelleServiceBlockingStubWithInterceptor).when(service).getFachstelleServiceBlockingStub(); + when(fachstelleServiceBlockingStubWithInterceptor.getById(any())).thenReturn(GrpcFachstelleGetResponseTestFactory.create()); + } + + @Test + void shouldCallGetFachstelleServiceBlockingStub() { + getExterneFachstelle(); + + verify(service).getFachstelleServiceBlockingStub(); } @Test void shouldCallFachstelleServiceBlockingStub() { getExterneFachstelle(); - verify(fachstelleServiceBlockingStub).getById(GrpcFachstelleGetRequestTestFactory.create()); + verify(fachstelleServiceBlockingStubWithInterceptor).getById(GrpcFachstelleGetRequestTestFactory.create()); } @Test @@ -64,19 +78,54 @@ class FachstelleRemoteServiceTest { } } + @Nested + class TestGetFachstelleServiceBlockingStub { + + @Mock + private FachstelleServiceBlockingStub fachstelleServiceBlockingStubWithInterceptor; + + @Test + void shouldAttachInterceptor() { + service.getFachstelleServiceBlockingStub(); + + verify(fachstelleServiceBlockingStub).withInterceptors(callContextInterceptor); + } + + @Test + void shouldReturnStubWithInterceptor() { + when(fachstelleServiceBlockingStub.withInterceptors(any())).thenReturn(fachstelleServiceBlockingStubWithInterceptor); + + var stub = service.getFachstelleServiceBlockingStub(); + + assertThat(stub).isSameAs(fachstelleServiceBlockingStubWithInterceptor); + } + } + @Nested class TestGetOrganisationsEinheit { + @Mock + private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStubWithInterceptor; + @BeforeEach void mock() { - when(organisationsEinheitServiceBlockingStub.getById(any())).thenReturn(GrpcOrganisationsEinheitGetResponseTestFactory.create()); + doReturn(organisationsEinheitServiceBlockingStubWithInterceptor).when(service).getOrganisationsEinheitServiceBlockingStub(); + when(organisationsEinheitServiceBlockingStubWithInterceptor.getById(any())) + .thenReturn(GrpcOrganisationsEinheitGetResponseTestFactory.create()); + } + + @Test + void shouldCallGetOrganisationsEinheitServiceBlockingStub() { + getOrganisationsEinheit(); + + verify(service).getOrganisationsEinheitServiceBlockingStub(); } @Test void shouldCallOrganisationsEinheitServiceBlockingStub() { getOrganisationsEinheit(); - verify(organisationsEinheitServiceBlockingStub).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create()); + verify(organisationsEinheitServiceBlockingStubWithInterceptor).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create()); } @Test @@ -100,4 +149,27 @@ class FachstelleRemoteServiceTest { return service.getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID); } } + + @Nested + class TestGetOrganisationsEinheitServiceBlockingStub { + + @Mock + private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStubWithInterceptor; + + @Test + void shouldAttachInterceptor() { + service.getOrganisationsEinheitServiceBlockingStub(); + + verify(organisationsEinheitServiceBlockingStub).withInterceptors(callContextInterceptor); + } + + @Test + void shouldReturnStubWithInterceptor() { + when(organisationsEinheitServiceBlockingStub.withInterceptors(any())).thenReturn(organisationsEinheitServiceBlockingStubWithInterceptor); + + var stub = service.getOrganisationsEinheitServiceBlockingStub(); + + assertThat(stub).isSameAs(organisationsEinheitServiceBlockingStubWithInterceptor); + } + } }