Skip to content

Commit

Permalink
fix(mod-search): fix export of cql files
Browse files Browse the repository at this point in the history
- Add test case

Closes: MSEARCH-762
  • Loading branch information
viacheslavpoliakov committed Jun 11, 2024
1 parent f2ff26d commit b68a9a0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/org/folio/search/service/ResourceIdServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.<Consumer<List<String>>>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());
Expand Down

0 comments on commit b68a9a0

Please sign in to comment.