diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/CountVorgangResponse.java b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/CountVorgangResponse.java deleted file mode 100644 index 219546eb83065256a476c14426ebbdb93e01a87b..0000000000000000000000000000000000000000 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/CountVorgangResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -// TODO sebo: diese Datei soll später komplett gelöscht werden -package de.ozgcloud.alfa.statistic; - -import java.util.Map; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -class CountVorgangResponse { - - private ByStatus byStatus; - private Map<String, Integer> pathCountResult; -} diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticController.java b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticController.java index d3d08b9d3ee2215ead724fddd2e9fbda20ea9c91..9e8f79b4c0c54b059dad310b1835a164b687666a 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticController.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticController.java @@ -10,20 +10,6 @@ public class StatisticController { private StatisticService statisticService; public Statistic getVorgaengeStatistic() { - var countStatistic = statisticService.countVorgang(); - var statistic = statisticService.getVorgaengeStatistic(); - return Statistic.builder() - .existsWiedervorlageOverdue(statistic.isExistsWiedervorlageOverdue()) - .wiedervorlagen(countStatistic.getWiedervorlagen()) - .byStatus(ByStatus.builder() - .verworfen(countStatistic.getByStatus().getVerworfen()) - .inBearbeitung(countStatistic.getByStatus().getInBearbeitung()) - .angenommen(countStatistic.getByStatus().getAngenommen()) - .beschieden(countStatistic.getByStatus().getBeschieden()) - .neu(countStatistic.getByStatus().getNeu()) - .abgeschlossen(countStatistic.getByStatus().getAbgeschlossen()) - .zuLoeschen(statistic.getByStatus().getZuLoeschen()) - .build()) - .build(); + return statisticService.getVorgaengeStatistic(); } } diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticMapper.java b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticMapper.java index 3be93cd822823c832f3e0aa3f6c26f4cb716b838..cb23df8599c51b4f7cbdf3b99d8ab0d19120466f 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticMapper.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticMapper.java @@ -1,17 +1,11 @@ package de.ozgcloud.alfa.statistic; -import java.util.Map; -import java.util.stream.Collectors; - import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.ReportingPolicy; -import de.ozgcloud.vorgang.statistic.GrpcByStatusResult; -import de.ozgcloud.vorgang.statistic.GrpcPathCountResult; -import de.ozgcloud.vorgang.statistic.GrpcVorgangCountResponse; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticResult; @Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, @@ -23,16 +17,4 @@ interface StatisticMapper { @Mapping(target = "boolValue", source = "resultBoolValue") @Mapping(target = "intValue", source = "resultIntValue") StatisticResult toResult(GrpcVorgangStatisticResult grpcVorgangStatisticResult); - - // TODO sebo: der Code muss später gelöscht werden - @Mapping(target = "pathCountResult", expression = "java(toMap(response))") - CountVorgangResponse fromCountVorgangResponse(GrpcVorgangCountResponse response); - - ByStatus fromByStatus(GrpcByStatusResult byStatus); - - default Map<String, Integer> toMap(GrpcVorgangCountResponse response) { - return response.getPathCountResultList().stream() - .collect(Collectors.toMap(GrpcPathCountResult::getName, pathCountResult -> Integer.valueOf(pathCountResult.getValue()))); - } - // END: code löschen } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticRemoteService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticRemoteService.java index b97fcadbc07f1dc8d1d4c8ce2eaa3803fac49a90..cd508d6198827251fd4f661a7e0a4815570fa898 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticRemoteService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticRemoteService.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Service; import de.ozgcloud.alfa.AlfaProperties; import de.ozgcloud.alfa.common.GrpcUtil; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; -import de.ozgcloud.vorgang.statistic.GrpcVorgangCountRequest; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery.GroupMethod; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery.Operator; @@ -41,8 +40,9 @@ class StatisticRemoteService { public Map<String, StatisticResult> getVorgaengeStatistics(List<VorgangStatus> countByVorgangStatus) { var grpcRequest = GrpcVorgangStatisticRequest.newBuilder() - .addQuery(buildExistsWiedervorlageOverdueQuery()) .addAllQuery(buildCountByStatusQueries(countByVorgangStatus)) + .addQuery(buildCountWiedervorlageNextFristQuery()) + .addQuery(buildExistsWiedervorlageOverdueQuery()) .build(); var grpcResponse = statisticServiceStub.getVorgangStatistic(grpcRequest); @@ -64,6 +64,15 @@ class StatisticRemoteService { .build(); } + GrpcVorgangStatisticQuery buildCountWiedervorlageNextFristQuery() { + return GrpcVorgangStatisticQuery.newBuilder() + .setResultName(COUNT_WIEDERVORLAGE_NEXT_FRIST_RESULT_NAME) + .setPath(String.format(WIEDERVORLAGE_NEXT_FRIST_PATH_TEMPLATE, alfaProperties.getApplicationName())) + .setGroupMethod(GroupMethod.COUNT) + .setOperator(Operator.UNEQUAL) + .build(); + } + GrpcVorgangStatisticQuery buildExistsWiedervorlageOverdueQuery() { return GrpcVorgangStatisticQuery.newBuilder() .setResultName(EXISTS_WIEDERVORLAGE_OVERDUE_RESULT_NAME) @@ -84,16 +93,4 @@ class StatisticRemoteService { .map(mapper::toResult) .collect(Collectors.toMap(StatisticResult::getName, Function.identity())); } - - // TODO sebo: der Code muss später gelöscht werden - public CountVorgangResponse countVorgang(List<String> countByPath) { - var response = statisticServiceStub.countVorgang(buildVorgangCountRequest(countByPath)); - - return mapper.fromCountVorgangResponse(response); - } - - GrpcVorgangCountRequest buildVorgangCountRequest(List<String> countByPath) { - return GrpcVorgangCountRequest.newBuilder().addAllCountByPath(countByPath).build(); - } - // END: code löschen } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticService.java index b868bf8f05d5ff708e6284556e3a80ec92ea5b4f..68b9ab06c4d73f5b6810035b9b1312a6d3edbd2c 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/statistic/StatisticService.java @@ -8,7 +8,6 @@ import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import de.ozgcloud.alfa.AlfaProperties; import de.ozgcloud.alfa.common.user.CurrentUserService; import de.ozgcloud.alfa.common.user.UserRole; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; @@ -16,15 +15,10 @@ import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; @Service class StatisticService { - // TODO sebo: dieser Code wird später gelöscht - static final String COUNT_WIEDERVORLAGE_NEXT_FRIST_KEY = "countWiedervorlage"; - static final String COUNT_WIEDERVORLAGE_NEXT_FRIST_TEMPLATE = COUNT_WIEDERVORLAGE_NEXT_FRIST_KEY + ":ClientAttribute.%s.nextWiedervorlageFrist"; - // END: code löschen - - static final List<VorgangStatus> VORGAENGE_STATUS_COUNT_VERWALTUNG_USER = List.of(VorgangStatus.NEU, VorgangStatus.ANGENOMMEN, + static final List<VorgangStatus> COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER = List.of(VorgangStatus.NEU, VorgangStatus.ANGENOMMEN, VorgangStatus.IN_BEARBEITUNG, VorgangStatus.BESCHIEDEN, VorgangStatus.ABGESCHLOSSEN, VorgangStatus.VERWORFEN, VorgangStatus.ZU_LOESCHEN); - static final List<VorgangStatus> VORGAENGE_STATUS_COUNT_POSTSTELLE_USER = Collections.emptyList(); - static final List<VorgangStatus> VORGAENGE_STATUS_COUNT_EINHEITLICHER_ANSPRECHPARTNER = Collections.emptyList(); + static final List<VorgangStatus> COUNT_BY_VORGANG_STATUS_POSTSTELLE_USER = Collections.emptyList(); + static final List<VorgangStatus> COUNT_BY_VORGANG_EINHEITLICHER_ANSPRECHPARTNER = Collections.emptyList(); @Autowired private StatisticRemoteService remoteService; @@ -32,23 +26,20 @@ class StatisticService { @Autowired private CurrentUserService currentUserService; - @Autowired - private AlfaProperties alfaProperties; - public Statistic getVorgaengeStatistic() { - var response = remoteService.getVorgaengeStatistics(List.of(VorgangStatus.ZU_LOESCHEN)); + var response = remoteService.getVorgaengeStatistics(getCountByVorgangStatusList()); return buildGetVorgaengeStatisticResult(response); } List<VorgangStatus> getCountByVorgangStatusList() { if (currentUserService.hasRole(UserRole.VERWALTUNG_USER)) { - return VORGAENGE_STATUS_COUNT_VERWALTUNG_USER; + return COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER; } if (currentUserService.hasRole(UserRole.VERWALTUNG_POSTSTELLE)) { - return VORGAENGE_STATUS_COUNT_POSTSTELLE_USER; + return COUNT_BY_VORGANG_STATUS_POSTSTELLE_USER; } if (currentUserService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER)) { - return VORGAENGE_STATUS_COUNT_EINHEITLICHER_ANSPRECHPARTNER; + return COUNT_BY_VORGANG_EINHEITLICHER_ANSPRECHPARTNER; } return Collections.emptyList(); } @@ -76,26 +67,4 @@ class StatisticService { private boolean getBooleanResult(Map<String, StatisticResult> response, String resultName) { return Optional.ofNullable(response.get(resultName)).map(StatisticResult::getBoolValue).orElse(false); } - - // TODO sebo: dieser Code wird später gelöscht - public Statistic countVorgang() { - var response = remoteService.countVorgang(createCountByPathList()); - - return buildStatistic(response); - } - - List<String> createCountByPathList() { - return List.of(String.format(COUNT_WIEDERVORLAGE_NEXT_FRIST_TEMPLATE, alfaProperties.getApplicationName())); - } - - Statistic buildStatistic(CountVorgangResponse response) { - return Statistic.builder().byStatus(response.getByStatus()).wiedervorlagen(extractWiedervorlageCount(response)).build(); - } - - Integer extractWiedervorlageCount(CountVorgangResponse response) { - return Optional.ofNullable(response.getPathCountResult()) - .map(pathResultEntry -> pathResultEntry.get(COUNT_WIEDERVORLAGE_NEXT_FRIST_KEY)) - .orElse(0); - } - // END: code löschen } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/CountVorgangResponseTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/CountVorgangResponseTestFactory.java deleted file mode 100644 index 027627fd544456c5e896602dd59a5891bad4e6a3..0000000000000000000000000000000000000000 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/CountVorgangResponseTestFactory.java +++ /dev/null @@ -1,20 +0,0 @@ -// TODO sebo: diese Datei später löschen -package de.ozgcloud.alfa.statistic; - -import java.util.Map; - -public class CountVorgangResponseTestFactory { - - public static final String PATH_COUNT_NAME = "name:of:path"; - public static final Integer PATH_COUNT_VALUE = 6; - - public static CountVorgangResponse create() { - return createBuilder().build(); - } - - public static CountVorgangResponse.CountVorgangResponseBuilder createBuilder() { - return CountVorgangResponse.builder() - .byStatus(ByStatusTestFactory.create()) - .pathCountResult(Map.of(PATH_COUNT_NAME, PATH_COUNT_VALUE)); - } -} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangCountTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangCountTestFactory.java deleted file mode 100644 index fc67c39367135c10296c3ddf0f34ce99765e1bb8..0000000000000000000000000000000000000000 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangCountTestFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -// TODO sebo: diese Datei später löschen -package de.ozgcloud.alfa.statistic; - -import de.ozgcloud.vorgang.statistic.GrpcByStatusResult; -import de.ozgcloud.vorgang.statistic.GrpcPathCountResult; -import de.ozgcloud.vorgang.statistic.GrpcVorgangCountResponse; - -public class GrpcVorgangCountTestFactory { - - public static final GrpcByStatusResult BY_STATUS = GrpcByStatusResultTestFactory.create(); - private static final GrpcPathCountResult PATH_COUNT_RESULT = GrpcPathCountResult.newBuilder() - .setName(CountVorgangResponseTestFactory.PATH_COUNT_NAME) - .setValue(CountVorgangResponseTestFactory.PATH_COUNT_VALUE) - .build(); - - public static GrpcVorgangCountResponse createResponse() { - return createResponseBuilder().build(); - } - - public static GrpcVorgangCountResponse.Builder createResponseBuilder() { - return GrpcVorgangCountResponse.newBuilder() - .setByStatus(BY_STATUS) - .addPathCountResult(PATH_COUNT_RESULT); - } -} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticControllerTest.java index e4f3a2739326e273d9f669dab84a58292d82bc4d..a8214c3dda215800d6fa3334f77123d7e961ae46 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticControllerTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticControllerTest.java @@ -1,9 +1,7 @@ package de.ozgcloud.alfa.statistic; -import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -20,95 +18,12 @@ class StatisticControllerTest { @Nested class TestGetVorgaengeStatistic { - private static final int ZU_LOESCHEN_COUNT = ByStatusTestFactory.ZU_LOESCHEN_COUNT + 1; - - private final Statistic getVorgangResult = StatisticTestFactory.createBuilder() - .byStatus(ByStatusTestFactory.createBuilder().zuLoeschen(ZU_LOESCHEN_COUNT).build()).build(); - private final Statistic countVorgangResult = StatisticTestFactory.create(); - - @BeforeEach - void beforeEach() { - when(service.countVorgang()).thenReturn(countVorgangResult); - when(service.getVorgaengeStatistic()).thenReturn(getVorgangResult); - } - @Test - void shouldCallGetVorgaengeStatistic() { + void shouldCallService() { controller.getVorgaengeStatistic(); verify(service).getVorgaengeStatistic(); } - - // TODO sebo: später löschen after only new api will be in use - @Test - void shouldCallCountVorgang() { - controller.getVorgaengeStatistic(); - - verify(service).countVorgang(); - } - - @Test - void shouldHaveExistsWiedervorlageOverdue() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.isExistsWiedervorlageOverdue()).isEqualTo(StatisticTestFactory.EXISTS_WIEDERVORLAGE_OVERDUE); - } - - @Test - void shouldHaveWiedervorlagenCount() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getWiedervorlagen()).isEqualTo(StatisticTestFactory.COUNT_WIEDERVORLAGEN); - } - - @Test - void shouldHaveCountByVerworfenStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getVerworfen()).isEqualTo(ByStatusTestFactory.VERWORFEN_COUNT); - } - - @Test - void shouldHaveCountByInBearbeitungStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getInBearbeitung()).isEqualTo(ByStatusTestFactory.IN_BEARBEITUNG_COUNT); - } - - @Test - void shouldHaveCountByAngenommenStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getAngenommen()).isEqualTo(ByStatusTestFactory.ANGENOMMEN_COUNT); - } - - @Test - void shouldHaveCountByBeschiedenStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getBeschieden()).isEqualTo(ByStatusTestFactory.BESCHIEDEN_COUNT); - } - - @Test - void shouldHaveCountByAbgeschlossenStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getAbgeschlossen()).isEqualTo(ByStatusTestFactory.ABGESCHLOSSEN_COUNT); - } - - @Test - void shouldHaveCountByZuLoeschenStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getZuLoeschen()).isEqualTo(ZU_LOESCHEN_COUNT); - } - - @Test - void shouldHaveCountByNeuStatus() { - var statistic = controller.getVorgaengeStatistic(); - - assertThat(statistic.getByStatus().getNeu()).isEqualTo(ByStatusTestFactory.NEU_COUNT); - } } } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticRemoteServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticRemoteServiceTest.java index 56b85f9f3f14bf8e70f73c11d834721b7c923754..5716d65c2197741fbf8d03e498f3b283e398cc17 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticRemoteServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticRemoteServiceTest.java @@ -23,7 +23,7 @@ import com.thedeanda.lorem.LoremIpsum; import de.ozgcloud.alfa.AlfaProperties; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; -import de.ozgcloud.vorgang.statistic.GrpcVorgangCountResponse; +import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery.GroupMethod; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery.Operator; import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticResponse; @@ -103,6 +103,35 @@ class StatisticRemoteServiceTest { } } + @Nested + class TestBuildCountWiedervorlageNextFristQuery { + + private final String applicationName = LoremIpsum.getInstance().getFirstName(); + + @BeforeEach + void init() { + when(alfaProperties.getApplicationName()).thenReturn(applicationName); + } + + @Test + void shouldBuildQuery() { + var query = service.buildCountWiedervorlageNextFristQuery(); + + assertThat(query) + .extracting( + GrpcVorgangStatisticQuery::getResultName, + GrpcVorgangStatisticQuery::getPath, + GrpcVorgangStatisticQuery::getOperator, + GrpcVorgangStatisticQuery::getGroupMethod) + .contains( + COUNT_WIEDERVORLAGE_NEXT_FRIST_RESULT_NAME, + String.format(StatisticRemoteService.WIEDERVORLAGE_NEXT_FRIST_PATH_TEMPLATE, applicationName), + Operator.UNEQUAL, + GroupMethod.COUNT + ); + } + } + @Nested class TestBuildExistsWiedervorlageOverdueQuery { @@ -183,6 +212,13 @@ class StatisticRemoteServiceTest { verify(service).buildCountByStatusQueries(STATUSES_TO_COUNT); } + @Test + void shouldCallBuildCountByVorgangStatusQuery() { + service.getVorgaengeStatistics(STATUSES_TO_COUNT); + + verify(service).buildCountWiedervorlageNextFristQuery(); + } + @Test void shouldCallBuildExistsWiedervorlageOverdueQuery() { service.getVorgaengeStatistics(STATUSES_TO_COUNT); @@ -234,58 +270,4 @@ class StatisticRemoteServiceTest { .hasEntrySatisfying(RESULT_NAME, statisticResult -> assertThat(statisticResult.getIntValue()).isEqualTo(RESULT_INT)); } } - - // TODO sebo: später löschen - @DisplayName("Get statistic") - @Nested - class TestGetStatistic { - - private String countByPath = "DummyCountPath"; - private List<String> countByPathList = List.of(countByPath); - private final GrpcVorgangCountResponse response = GrpcVorgangCountTestFactory.createResponse(); - - @DisplayName("prozess flow") - @Nested - class TestProzessFlow { - - @BeforeEach - void mockServiceStub() { - when(serviceStub.countVorgang(any())).thenReturn(response); - } - - @Test - void shouldCallStub() { - service.countVorgang(countByPathList); - - verify(serviceStub).countVorgang(any()); - } - - @Test - void shouldBuildRequest() { - service.countVorgang(countByPathList); - - verify(service).buildVorgangCountRequest(countByPathList); - } - - @Test - void shouldMapCountVorgangResponse() { - service.countVorgang(countByPathList); - - verify(mapper).fromCountVorgangResponse(response); - } - } - - @DisplayName("build vorgang count request") - @Nested - class TestBuildVorgangCountRequest { - - @Test - void shouldHaveCountByPath() { - var request = service.buildVorgangCountRequest(countByPathList); - - assertThat(request.getCountByPathList()).hasSize(1).containsExactly(countByPath); - } - } - } - } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticServiceTest.java index 58326fa8570d3d65e80125785c0cb862579c22ee..1b030d675d4eec8e8cee9f8c2bcb0f3f83e339e1 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/StatisticServiceTest.java @@ -7,21 +7,15 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.Collections; -import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import com.thedeanda.lorem.LoremIpsum; - -import de.ozgcloud.alfa.AlfaProperties; import de.ozgcloud.alfa.common.user.CurrentUserService; import de.ozgcloud.alfa.common.user.UserRole; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; @@ -35,8 +29,6 @@ class StatisticServiceTest { private StatisticRemoteService remoteService; @Mock private CurrentUserService currentUserService; - @Mock - private AlfaProperties alfaProperties; @Nested class TestBuildGetVorgaengeStatisticResult { @@ -157,7 +149,7 @@ class StatisticServiceTest { var result = service.getCountByVorgangStatusList(); - assertThat(result).containsAll(VORGAENGE_STATUS_COUNT_VERWALTUNG_USER); + assertThat(result).containsAll(COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER); } @Test @@ -167,7 +159,7 @@ class StatisticServiceTest { var result = service.getCountByVorgangStatusList(); - assertThat(result).containsAll(VORGAENGE_STATUS_COUNT_POSTSTELLE_USER); + assertThat(result).containsAll(COUNT_BY_VORGANG_STATUS_POSTSTELLE_USER); } @Test @@ -178,7 +170,7 @@ class StatisticServiceTest { var result = service.getCountByVorgangStatusList(); - assertThat(result).containsAll(VORGAENGE_STATUS_COUNT_EINHEITLICHER_ANSPRECHPARTNER); + assertThat(result).containsAll(COUNT_BY_VORGANG_EINHEITLICHER_ANSPRECHPARTNER); } @Test @@ -196,111 +188,43 @@ class StatisticServiceTest { @Nested class TestGetVorgaengeStatistics { - private final List<VorgangStatus> countByVorgangStatus = List.of(VorgangStatus.ZU_LOESCHEN); + private final Statistic statistic = StatisticTestFactory.create(); + private final Map<String, StatisticResult> getVorgangStatisticsResponse = Map.of(COUNT_WIEDERVORLAGE_NEXT_FRIST_RESULT_NAME, + StatisticResultTestFactory.create()); @BeforeEach void beforeEach() { - when(remoteService.buildCountByStatusResultName(any())).thenCallRealMethod(); - } - - @Test - void shouldCallRemoteService() { - service.getVorgaengeStatistic(); - - verify(remoteService).getVorgaengeStatistics(countByVorgangStatus); + doReturn(COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER).when(service).getCountByVorgangStatusList(); + when(remoteService.getVorgaengeStatistics(COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER)).thenReturn(getVorgangStatisticsResponse); + doReturn(statistic).when(service).buildGetVorgaengeStatisticResult(getVorgangStatisticsResponse); } @Test - void shouldBuildResult() { - var response = Map.of(COUNT_WIEDERVORLAGE_NEXT_FRIST_RESULT_NAME, StatisticResultTestFactory.create()); - when(remoteService.getVorgaengeStatistics(countByVorgangStatus)).thenReturn(response); - - service.getVorgaengeStatistic(); - - verify(service).buildGetVorgaengeStatisticResult(response); - } - - @Test - @Disabled("activate if new grpc api in use") void shouldCallGetCountByVorgangStatusList() { service.getVorgaengeStatistic(); verify(service).getCountByVorgangStatusList(); } - } - - // TODO sebo: später löschen - @DisplayName("Count vorgang") - @Nested - class TestCountVorgang { - - private static final int WIEDERVORLAGE_COUNT = 8; - private CountVorgangResponse response = CountVorgangResponseTestFactory.createBuilder() - .pathCountResult(Map.of(StatisticService.COUNT_WIEDERVORLAGE_NEXT_FRIST_KEY, WIEDERVORLAGE_COUNT)).build(); - private final String applicationName = LoremIpsum.getInstance().getFirstName(); @Test void shouldCallRemoteService() { - when(alfaProperties.getApplicationName()).thenReturn(applicationName); - when(remoteService.countVorgang(any())).thenReturn(response); - - service.countVorgang(); + service.getVorgaengeStatistic(); - verify(remoteService).countVorgang(List.of(String.format(StatisticService.COUNT_WIEDERVORLAGE_NEXT_FRIST_TEMPLATE, applicationName))); + verify(remoteService).getVorgaengeStatistics(COUNT_BY_VORGANG_STATUS_VERWALTUNG_USER); } @Test - void shouldBuildStatistic() { - when(alfaProperties.getApplicationName()).thenReturn(applicationName); - when(remoteService.countVorgang(any())).thenReturn(response); - - service.countVorgang(); + void shouldBuildResult() { + service.getVorgaengeStatistic(); - verify(service).buildStatistic(response); + verify(service).buildGetVorgaengeStatisticResult(getVorgangStatisticsResponse); } - @DisplayName("build statistic") - @Nested - class TestBuildStatistic { - - @Test - void shouldSetByStatus() { - var statistic = service.buildStatistic(response); - - assertThat(statistic.getByStatus()).usingRecursiveComparison().isEqualTo(ByStatusTestFactory.create()); - } - - @Test - void shouldSetWiedervorlagen() { - var statistic = service.buildStatistic(response); - - assertThat(statistic.getWiedervorlagen()).isEqualTo(WIEDERVORLAGE_COUNT); - } - - @DisplayName("extract wiedervorlage") - @Nested - class TestExtractWiedervorlage { - - @Test - void shouldReturnValueIfExists() { - var count = 5; - var countVorgangResponse = CountVorgangResponseTestFactory.createBuilder() - .pathCountResult(Map.of(StatisticService.COUNT_WIEDERVORLAGE_NEXT_FRIST_KEY, count)).build(); - - var wiedervorlageCount = service.extractWiedervorlageCount(countVorgangResponse); - - assertThat(wiedervorlageCount).isEqualTo(count); - } - - @Test - void shouldReturnZeroIfNotExists() { - var wiedervorlageCount = service.extractWiedervorlageCount( - CountVorgangResponseTestFactory.createBuilder().pathCountResult(Collections.emptyMap()).build()); + @Test + void shouldReturnStatistic() { + var result = service.getVorgaengeStatistic(); - assertThat(wiedervorlageCount).isZero(); - } - } + assertThat(result).isEqualTo(statistic); } } - }