From b9241040fb3de49bfe0517bbe9bc1be104f0b8f2 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 21 Feb 2024 18:47:23 +0100
Subject: [PATCH] OZG-4994 OZG-5061 add query

---
 .../statistic/StatisticRemoteService.java     |  1 +
 .../GrpcVorgangStatisticQueryTestFactory.java |  7 ++++-
 .../statistic/StatisticRemoteServiceTest.java | 28 ++++++++++++++++++-
 3 files changed, 34 insertions(+), 2 deletions(-)

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 149ade586a..95b0494fd7 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
@@ -45,6 +45,7 @@ class StatisticRemoteService {
 				.addAllQuery(buildCountByStatusQueries(countByVorgangStatus))
 				.addQuery(buildCountWiedervorlageNextFristQuery())
 				.addQuery(buildExistsWiedervorlageOverdueQuery())
+				.addQuery(buildCountVorgaengeWithUnreadMessagesQuery())
 				.build();
 
 		var grpcResponse = statisticServiceStub.getVorgangStatistic(grpcRequest);
diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangStatisticQueryTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangStatisticQueryTestFactory.java
index 0d26d330dc..517f2f4495 100644
--- a/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangStatisticQueryTestFactory.java
+++ b/alfa-service/src/test/java/de/ozgcloud/alfa/statistic/GrpcVorgangStatisticQueryTestFactory.java
@@ -1,14 +1,19 @@
 package de.ozgcloud.alfa.statistic;
 
+import com.thedeanda.lorem.LoremIpsum;
+
 import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticQuery;
 
 public class GrpcVorgangStatisticQueryTestFactory {
 
+	public static final String RESULT_NAME = LoremIpsum.getInstance().getWords(1);
+
 	public static GrpcVorgangStatisticQuery create() {
 		return createBuilder().build();
 	}
 
 	public static GrpcVorgangStatisticQuery.Builder createBuilder() {
-		return GrpcVorgangStatisticQuery.newBuilder();
+		return GrpcVorgangStatisticQuery.newBuilder()
+				.setResultName(RESULT_NAME);
 	}
 }
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 d105d32840..d65fb73e49 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
@@ -15,6 +15,8 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.EnumSource;
 import org.junit.jupiter.params.provider.EnumSource.Mode;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Spy;
@@ -26,6 +28,7 @@ import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus;
 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.GrpcVorgangStatisticRequest;
 import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticResponse;
 import de.ozgcloud.vorgang.statistic.GrpcVorgangStatisticResult;
 import de.ozgcloud.vorgang.statistic.StatisticServiceGrpc.StatisticServiceBlockingStub;
@@ -190,12 +193,20 @@ class StatisticRemoteServiceTest {
 	class TestGetVorgaengeStatistics {
 
 		private final GrpcVorgangStatisticResponse response = GrpcVorgangStatisticResponseTestFactory.create();
+		private final GrpcVorgangStatisticQuery countVorgaengeWithUnreadMessagesQuery = GrpcVorgangStatisticQueryTestFactory.createBuilder()
+				.setResultName("unread messages").build();
+		private final GrpcVorgangStatisticQuery existsWiedervorlageOverdueQuery = GrpcVorgangStatisticQueryTestFactory.createBuilder()
+				.setResultName("exists overdue").build();
+
+		@Captor
+		private ArgumentCaptor<GrpcVorgangStatisticRequest> grpcRequestCaptor;
 
 		@BeforeEach
 		void beforeEach() {
 			when(serviceStub.getVorgangStatistic(any())).thenReturn(response);
 
-			doReturn(GrpcVorgangStatisticQueryTestFactory.create()).when(service).buildExistsWiedervorlageOverdueQuery();
+			doReturn(existsWiedervorlageOverdueQuery).when(service).buildExistsWiedervorlageOverdueQuery();
+			doReturn(countVorgaengeWithUnreadMessagesQuery).when(service).buildCountVorgaengeWithUnreadMessagesQuery();
 		}
 
 		@Test
@@ -232,6 +243,21 @@ class StatisticRemoteServiceTest {
 
 			verify(service).buildStatisticResult(response);
 		}
+
+		@Test
+		void shouldCallBuildCountVorgaengeWithUnreadMessagesQuery() {
+			service.getVorgaengeStatistics(STATUSES_TO_COUNT);
+
+			verify(service).buildCountVorgaengeWithUnreadMessagesQuery();
+		}
+
+		@Test
+		void shouldAddCountVorgaengeWithUnreadMessagesQuery() {
+			service.getVorgaengeStatistics(STATUSES_TO_COUNT);
+
+			verify(serviceStub).getVorgangStatistic(grpcRequestCaptor.capture());
+			assertThat(grpcRequestCaptor.getValue().getQueryList()).contains(countVorgaengeWithUnreadMessagesQuery);
+		}
 	}
 
 	@Nested
-- 
GitLab