From b68a9a02dec9b553486799518397a46026234b89 Mon Sep 17 00:00:00 2001 From: Viacheslav_Poliakov Date: Tue, 11 Jun 2024 11:42:04 +0300 Subject: [PATCH] fix(mod-search): fix export of cql files - Add test case Closes: MSEARCH-762 --- .../search/service/ResourceIdServiceTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/org/folio/search/service/ResourceIdServiceTest.java b/src/test/java/org/folio/search/service/ResourceIdServiceTest.java index 7ce396b3a..bf35f642d 100644 --- a/src/test/java/org/folio/search/service/ResourceIdServiceTest.java +++ b/src/test/java/org/folio/search/service/ResourceIdServiceTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.folio.search.model.service.CqlResourceIdsRequest.INSTANCE_ID_PATH; +import static org.folio.search.utils.TestConstants.CENTRAL_TENANT_ID; import static org.folio.search.utils.TestConstants.RESOURCE_NAME; import static org.folio.search.utils.TestConstants.TENANT_ID; import static org.folio.search.utils.TestUtils.OBJECT_MAPPER; @@ -13,6 +14,8 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.opensearch.index.query.QueryBuilders.termQuery; @@ -183,6 +186,24 @@ void streamResourceIds_positive_NotSharedActiveAffiliation() throws IOException assertThat(actual).isEqualTo(new ResourceIds().ids(emptyList()).totalRecords(0)); } + @Test + void streamResourceIds_negative_NotSharedActiveAffiliation() { + String query = "shared==\"false\""; + CqlResourceIdsRequest request = CqlResourceIdsRequest.of(RESOURCE_NAME, CENTRAL_TENANT_ID, query, INSTANCE_ID_PATH); + var expectedSearchSource = searchSource().size(QUERY_SIZE).sort("_doc"); + doAnswer(invocation -> { + invocation.>>getArgument(2).accept(emptyList()); + return null; + }).when(searchRepository).streamResourceIds(eq(request), eq(expectedSearchSource), any()); + when(queryConverter.convertForConsortia(query, RESOURCE_NAME)).thenReturn(searchSource()); + when(properties.getScrollQuerySize()).thenReturn(QUERY_SIZE); + + var outputStream = new ByteArrayOutputStream(); + resourceIdService.streamResourceIdsAsJson(request, outputStream); + + verify(queryConverter, times(0)).convertNotSharedActiveAffiliation(any(), any(), any()); + } + @Test void streamResourceIdsInTextTextType_positive_emptyCollectionProvided() { mockSearchRepositoryCall(emptyList());