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

OZG-7350 attach client interceptor in FachstelleRemoteService

parent 9eb06942
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Qualifier; ...@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.collaboration.CollaborationManagerConfiguration; 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.FachstelleServiceGrpc.FachstelleServiceBlockingStub;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest; import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest;
...@@ -21,15 +22,26 @@ class FachstelleRemoteService { ...@@ -21,15 +22,26 @@ class FachstelleRemoteService {
private final OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; private final OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub;
@Qualifier(CollaborationManagerConfiguration.FACHSTELLE_MAPPER_NAME) // NOSONAR @Qualifier(CollaborationManagerConfiguration.FACHSTELLE_MAPPER_NAME) // NOSONAR
private final FachstelleMapper fachstelleMapper; private final FachstelleMapper fachstelleMapper;
@Qualifier(CollaborationManagerConfiguration.CALL_CONTEXT_INTERCEPTOR_NAME) // NOSONAR
private final CollaborationManagerCallContextGrpcClientInterceptor callContextInterceptor;
public Fachstelle getExterneFachstelle(String id) { 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); return fachstelleMapper.fromExterneFachstelle(externeFachstelle);
} }
FachstelleServiceBlockingStub getFachstelleServiceBlockingStub() {
return fachstelleServiceBlockingStub.withInterceptors(callContextInterceptor);
}
public Fachstelle getOrganisationsEinheit(String id) { public Fachstelle getOrganisationsEinheit(String id) {
var organisationsEinheit = organisationsEinheitServiceBlockingStub.getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build()) var organisationsEinheit = getOrganisationsEinheitServiceBlockingStub()
.getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build())
.getOrganisationsEinheit(); .getOrganisationsEinheit();
return fachstelleMapper.fromOrganisationsEinheit(organisationsEinheit); return fachstelleMapper.fromOrganisationsEinheit(organisationsEinheit);
} }
public OrganisationsEinheitServiceBlockingStub getOrganisationsEinheitServiceBlockingStub() {
return organisationsEinheitServiceBlockingStub.withInterceptors(callContextInterceptor);
}
} }
...@@ -11,6 +11,7 @@ import org.mockito.InjectMocks; ...@@ -11,6 +11,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor;
import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub; import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub;
import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub; import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub;
...@@ -26,20 +27,33 @@ class FachstelleRemoteServiceTest { ...@@ -26,20 +27,33 @@ class FachstelleRemoteServiceTest {
private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub;
@Mock @Mock
private FachstelleMapper fachstelleMapper; private FachstelleMapper fachstelleMapper;
@Mock
private CollaborationManagerCallContextGrpcClientInterceptor callContextInterceptor;
@Nested @Nested
class TestGetExterneFachstelle { class TestGetExterneFachstelle {
@Mock
private FachstelleServiceBlockingStub fachstelleServiceBlockingStubWithInterceptor;
@BeforeEach @BeforeEach
void mock() { 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 @Test
void shouldCallFachstelleServiceBlockingStub() { void shouldCallFachstelleServiceBlockingStub() {
getExterneFachstelle(); getExterneFachstelle();
verify(fachstelleServiceBlockingStub).getById(GrpcFachstelleGetRequestTestFactory.create()); verify(fachstelleServiceBlockingStubWithInterceptor).getById(GrpcFachstelleGetRequestTestFactory.create());
} }
@Test @Test
...@@ -64,19 +78,54 @@ class FachstelleRemoteServiceTest { ...@@ -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 @Nested
class TestGetOrganisationsEinheit { class TestGetOrganisationsEinheit {
@Mock
private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStubWithInterceptor;
@BeforeEach @BeforeEach
void mock() { 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 @Test
void shouldCallOrganisationsEinheitServiceBlockingStub() { void shouldCallOrganisationsEinheitServiceBlockingStub() {
getOrganisationsEinheit(); getOrganisationsEinheit();
verify(organisationsEinheitServiceBlockingStub).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create()); verify(organisationsEinheitServiceBlockingStubWithInterceptor).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create());
} }
@Test @Test
...@@ -100,4 +149,27 @@ class FachstelleRemoteServiceTest { ...@@ -100,4 +149,27 @@ class FachstelleRemoteServiceTest {
return service.getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID); 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);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment