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

Merge branch 'master' into OZG-6710-update-common-lib

# Conflicts:
#	zufi-manager-interface/pom.xml
parents 00f9e98c 21eda9ce
No related branches found
No related tags found
No related merge requests found
Showing with 179 additions and 24 deletions
package de.ozgcloud.zufi.fachstelle;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleRegistrationRequest;
class GrpcFachstelleRegistrationRequestTestFactory {
public static final GrpcFachstelle GRPC_FACHSTELLE = GrpcFachstelleTestFactory.create();
public static GrpcFachstelleRegistrationRequest create() {
return createBuilder().build();
}
public static GrpcFachstelleRegistrationRequest createWithoutMukId() {
return createBuilder(false).build();
}
public static GrpcFachstelleRegistrationRequest.Builder createBuilder() {
return GrpcFachstelleRegistrationRequest.newBuilder().setFachstelle(GRPC_FACHSTELLE);
return createBuilder(true);
}
private static GrpcFachstelleRegistrationRequest.Builder createBuilder(boolean withMukId) {
var builder = GrpcFachstelleRegistrationRequest.newBuilder();
if (withMukId) {
builder = builder.setMukId(FachstelleTestFactory.MUK_ID);
}
return builder
.setFirmenName(FachstelleTestFactory.FIRMEN_NAME)
.setRechtsform(FachstelleTestFactory.RECHTSFORM)
.setRechtsformText(FachstelleTestFactory.RECHTSFORM_TEXT)
.setRegisterNummer(FachstelleTestFactory.REGISTER_NUMMER)
.setRegisterArt(FachstelleTestFactory.REGISTER_ART)
.setEmailAdresse(FachstelleTestFactory.EMAIL_ADRESSE)
.setAnschrift(FachstelleTestFactory.ANSCHRIFT);
}
}
......@@ -8,20 +8,14 @@ class GrpcFachstelleTestFactory {
return createBuilder().build();
}
public static GrpcFachstelle createWithoutMukId() {
return createBuilder(false).build();
}
public static GrpcFachstelle.Builder createBuilder() {
return createBuilder(true);
}
private static GrpcFachstelle.Builder createBuilder(boolean withMukId) {
var builder = GrpcFachstelle.newBuilder();
if (withMukId) {
builder = builder.setMukId(FachstelleTestFactory.MUK_ID);
}
return builder
return GrpcFachstelle.newBuilder()
.setId(FachstelleTestFactory.ID)
.setMukId(FachstelleTestFactory.MUK_ID)
.setFirmenName(FachstelleTestFactory.FIRMEN_NAME)
.setRechtsform(FachstelleTestFactory.RECHTSFORM)
.setRechtsformText(FachstelleTestFactory.RECHTSFORM_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()
.setOrganisationsEinheitId(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;
import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcGetByOrganisationsEinheitIdResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse;
......@@ -26,7 +27,7 @@ class OrganisationsEinheitGrpcServiceTest {
@InjectMocks
private OrganisationsEinheitGrpcService service;
@Mock
private OrganisationsEinheitSearchService organisationsEinheitSearchService;
private OrganisationsEinheitSearchService searchService;
@Mock
private GrpcOrganisationsEinheitMapper mapper;
......@@ -52,7 +53,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach
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(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2);
}
......@@ -61,11 +62,11 @@ class OrganisationsEinheitGrpcServiceTest {
void shouldCallService() {
callService();
verify(organisationsEinheitSearchService).search(request.getSearchBy(), request.getArs());
verify(searchService).search(request.getSearchBy(), request.getArs());
}
@Test
void shouldCreateResponse() {
void shouldBuildResponse() {
callService();
verify(service).buildOrganisationsEinheitSearchResponse(organisationsEinheiten);
......@@ -93,7 +94,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach
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(organisationsEinheit2)).thenReturn(grpcOrganisationsEinheit2);
}
......@@ -139,7 +140,7 @@ class OrganisationsEinheitGrpcServiceTest {
@BeforeEach
void setUpMocks() {
when(organisationsEinheitSearchService.getById(organisationsEinheitId)).thenReturn(organisationsEinheit);
when(searchService.getById(organisationsEinheitId)).thenReturn(organisationsEinheit);
when(mapper.fromOrganisationsEinheit(organisationsEinheit)).thenReturn(grpcOrganisationsEinheit);
}
......@@ -147,11 +148,11 @@ class OrganisationsEinheitGrpcServiceTest {
void shouldCallService() {
callService();
verify(organisationsEinheitSearchService).getById(organisationsEinheitId);
verify(searchService).getById(organisationsEinheitId);
}
@Test
void shouldCreateResponse() {
void shouldBuildResponse() {
callService();
verify(service).buildOrganisationsEinheitGetResponse(organisationsEinheit);
......@@ -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);
}
}
}
......@@ -19,8 +19,6 @@ import org.mockito.Spy;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.zufi.common.errorhandling.OrganisationsEinheitNotFoundException;
class OrganisationsEinheitSearchServiceTest {
@InjectMocks
@Spy
......@@ -66,6 +64,37 @@ class OrganisationsEinheitSearchServiceTest {
}
}
@Nested
class TestGetByOrganisationsEinheitId {
public static final String ORGANISATIONS_EINHEIT_ID = OrganisationsEinheitTestFactory.XZUFI_ID.getId();
private final OrganisationsEinheit organisationsEinheit = OrganisationsEinheitTestFactory.create();
@BeforeEach
void init() {
when(repository.findByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID)).thenReturn(List.of(organisationsEinheit));
}
@Test
void shouldFindByOrganisationsEinheitId() {
callService();
verify(repository).findByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID);
}
@Test
void shouldReturnOrganisationsEinheiten() {
var result = callService();
assertThat(result).containsExactly(organisationsEinheit);
}
private List<OrganisationsEinheit> callService() {
return service.getByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID);
}
}
@Nested
class TestSearch {
......
......@@ -47,7 +47,6 @@ import org.mockito.Spy;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.zufi.common.errorhandling.MissingRequiredGrpcArgumentException;
import de.ozgcloud.zufi.common.errorhandling.OrganisationsEinheitNotFoundException;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcVorgangManagerGetAddressRequest;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcVorgangManagerGetAddressResponse;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcVorgangManagerRegistrationRequest;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment