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

OZG-6867 OZG-6900 Implement getByOrganisationsEinheitId in GrpcService

parent 0e31c143
Branches
Tags
No related merge requests found
...@@ -2,6 +2,8 @@ package de.ozgcloud.zufi.organisationseinheit; ...@@ -2,6 +2,8 @@ package de.ozgcloud.zufi.organisationseinheit;
import java.util.List; import java.util.List;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitSearchRequest; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitSearchRequest;
...@@ -48,4 +50,19 @@ class OrganisationsEinheitGrpcService extends OrganisationsEinheitServiceImplBas ...@@ -48,4 +50,19 @@ class OrganisationsEinheitGrpcService extends OrganisationsEinheitServiceImplBas
return responseBuilder.build(); return responseBuilder.build();
} }
@Override
public void getByOrganisationsEinheitId(GrpcGetByOrganisationsEinheitIdRequest request,
StreamObserver<GrpcGetByOrganisationsEinheitIdResponse> responseObserver) {
var organisationsEinheiten = searchService.getByOrganisationsEinheitId(request.getId());
responseObserver.onNext(buildGetByOrganisationsEinheitIdResponse(organisationsEinheiten));
responseObserver.onCompleted();
}
GrpcGetByOrganisationsEinheitIdResponse buildGetByOrganisationsEinheitIdResponse(List<OrganisationsEinheit> organisationsEinheiten) {
var responseBuilder = GrpcGetByOrganisationsEinheitIdResponse.newBuilder();
organisationsEinheiten.stream()
.map(mapper::fromOrganisationsEinheit)
.forEach(responseBuilder::addOrganisationsEinheiten);;
return responseBuilder.build();
}
} }
...@@ -17,6 +17,10 @@ class OrganisationsEinheitSearchService { ...@@ -17,6 +17,10 @@ class OrganisationsEinheitSearchService {
return repository.findById(id).orElseThrow(() -> new OrganisationsEinheitNotFoundException(id)); return repository.findById(id).orElseThrow(() -> new OrganisationsEinheitNotFoundException(id));
} }
public List<OrganisationsEinheit> getByOrganisationsEinheitId(String id) {
return List.of();
}
public List<OrganisationsEinheit> search(String text, String ars) { public List<OrganisationsEinheit> search(String text, String ars) {
if (StringUtils.isEmpty(ars)) { if (StringUtils.isEmpty(ars)) {
return repository.findAllContaining(text); return repository.findAllContaining(text);
......
package de.ozgcloud.zufi.organisationseinheit;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdRequest;
class GrpcGetByOrganisationsEinheitIdRequestTestFactory {
public static GrpcGetByOrganisationsEinheitIdRequest create() {
return createBuilder().build();
}
public static GrpcGetByOrganisationsEinheitIdRequest.Builder createBuilder() {
return GrpcGetByOrganisationsEinheitIdRequest.newBuilder()
.setId(OrganisationsEinheitTestFactory.XZUFI_ID.getId());
}
}
package de.ozgcloud.zufi.organisationseinheit;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit;
class GrpcGetByOrganisationsEinheitIdResponseTestFactory {
public static final GrpcOrganisationsEinheit GRPC_ORGANISATIONS_EINHEIT = GrpcOrganisationsEinheitTestFactory.create();
public static GrpcGetByOrganisationsEinheitIdResponse create() {
return createBuilder().build();
}
public static GrpcGetByOrganisationsEinheitIdResponse.Builder createBuilder() {
return GrpcGetByOrganisationsEinheitIdResponse.newBuilder()
.addOrganisationsEinheiten(GRPC_ORGANISATIONS_EINHEIT);
}
}
...@@ -14,6 +14,7 @@ import org.mockito.InjectMocks; ...@@ -14,6 +14,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse;
...@@ -26,7 +27,7 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -26,7 +27,7 @@ class OrganisationsEinheitGrpcServiceTest {
@InjectMocks @InjectMocks
private OrganisationsEinheitGrpcService service; private OrganisationsEinheitGrpcService service;
@Mock @Mock
private OrganisationsEinheitSearchService organisationsEinheitSearchService; private OrganisationsEinheitSearchService searchService;
@Mock @Mock
private GrpcOrganisationsEinheitMapper mapper; private GrpcOrganisationsEinheitMapper mapper;
...@@ -52,7 +53,7 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -52,7 +53,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach @BeforeEach
void setUpMocks() { void setUpMocks() {
when(organisationsEinheitSearchService.search(request.getSearchBy(), request.getArs())).thenReturn(organisationsEinheiten); when(searchService.search(request.getSearchBy(), request.getArs())).thenReturn(organisationsEinheiten);
when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit); when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit);
when(mapper.fromOrganisationsEinheit(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2); when(mapper.fromOrganisationsEinheit(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2);
} }
...@@ -61,11 +62,11 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -61,11 +62,11 @@ class OrganisationsEinheitGrpcServiceTest {
void shouldCallService() { void shouldCallService() {
callService(); callService();
verify(organisationsEinheitSearchService).search(request.getSearchBy(), request.getArs()); verify(searchService).search(request.getSearchBy(), request.getArs());
} }
@Test @Test
void shouldCreateResponse() { void shouldBuildResponse() {
callService(); callService();
verify(service).buildOrganisationsEinheitSearchResponse(organisationsEinheiten); verify(service).buildOrganisationsEinheitSearchResponse(organisationsEinheiten);
...@@ -93,7 +94,7 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -93,7 +94,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach @BeforeEach
void setUpMocks() { void setUpMocks() {
when(organisationsEinheitSearchService.search(request.getSearchBy(), request.getArs())).thenReturn(organisationsEinheiten); when(searchService.search(request.getSearchBy(), request.getArs())).thenReturn(organisationsEinheiten);
when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit); when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit);
when(mapper.fromOrganisationsEinheit(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2); when(mapper.fromOrganisationsEinheit(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2);
} }
...@@ -139,7 +140,7 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -139,7 +140,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach @BeforeEach
void setUpMocks() { void setUpMocks() {
when(organisationsEinheitSearchService.getById(organisationsEinheitId)).thenReturn(organisationsEinheit); when(searchService.getById(organisationsEinheitId)).thenReturn(organisationsEinheit);
when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit); when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit);
} }
...@@ -147,11 +148,11 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -147,11 +148,11 @@ class OrganisationsEinheitGrpcServiceTest {
void shouldCallService() { void shouldCallService() {
callService(); callService();
verify(organisationsEinheitSearchService).getById(organisationsEinheitId); verify(searchService).getById(organisationsEinheitId);
} }
@Test @Test
void shouldCreateResponse() { void shouldBuildResponse() {
callService(); callService();
verify(service).buildOrganisationsEinheitGetResponse(organisationsEinheit); verify(service).buildOrganisationsEinheitGetResponse(organisationsEinheit);
...@@ -206,4 +207,86 @@ class OrganisationsEinheitGrpcServiceTest { ...@@ -206,4 +207,86 @@ class OrganisationsEinheitGrpcServiceTest {
} }
@Nested
class TestGetByOrganisationsEinheitId {
public static final String ORGANISATIONS_EINHEIT_ID = OrganisationsEinheitTestFactory.XZUFI_ID.getId();
private final List<OrganisationsEinheit> organisationsEinheiten = List.of(organisationsEinheit);
private final GrpcGetByOrganisationsEinheitIdResponse response = GrpcGetByOrganisationsEinheitIdResponseTestFactory.create();
@Mock
private StreamObserver<GrpcGetByOrganisationsEinheitIdResponse> responseObserver;
@Captor
private ArgumentCaptor<GrpcGetByOrganisationsEinheitIdResponse> responseCaptor;
@BeforeEach
void init() {
when(searchService.getByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID)).thenReturn(organisationsEinheiten);
doReturn(response).when(service).buildGetByOrganisationsEinheitIdResponse(organisationsEinheiten);
}
@Test
void shouldCallService() {
callService();
verify(searchService).getByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID);
}
@Test
void shouldBuildResponse() {
callService();
verify(service).buildGetByOrganisationsEinheitIdResponse(organisationsEinheiten);
}
@Test
void shouldReturnResponse() {
callService();
verify(responseObserver).onNext(responseCaptor.capture());
assertThat(responseCaptor.getValue()).isEqualTo(response);
}
@Test
void shouldCompleteResponse() {
callService();
verify(responseObserver).onCompleted();
}
private void callService() {
service.getByOrganisationsEinheitId(GrpcGetByOrganisationsEinheitIdRequestTestFactory.create(), responseObserver);
}
}
@Nested
class TestBuildGetByOrganisationsEinheitIdResponse {
private final List<OrganisationsEinheit> organisationsEinheiten = List.of(organisationsEinheit);
@BeforeEach
void setup() {
when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit);
}
@Test
void shouldMapOrganisationsEinheit() {
callService();
verify(mapper).fromOrganisationsEinheit(organisationsEinheit);
}
@Test
void shouldReturnResponse() {
var result = callService();
assertThat(result.getOrganisationsEinheitenList()).containsExactly(GrpcGetByOrganisationsEinheitIdResponseTestFactory.GRPC_ORGANISATIONS_EINHEIT);
}
private GrpcGetByOrganisationsEinheitIdResponse callService() {
return service.buildGetByOrganisationsEinheitIdResponse(organisationsEinheiten);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment