From a973208d3ca0193943743eac28f3cd0f07003d3f Mon Sep 17 00:00:00 2001 From: Jonathan Mendez Date: Mon, 24 Apr 2023 13:22:35 -0600 Subject: [PATCH] Revisit tests and new search options --- .../AbstractOpenSearchClientWrapper.java | 4 --- ...inaryFileWithMetadataBatchIndexerTest.java | 31 +++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crafter-search-opensearch/src/main/java/org/craftercms/search/opensearch/impl/client/AbstractOpenSearchClientWrapper.java b/crafter-search-opensearch/src/main/java/org/craftercms/search/opensearch/impl/client/AbstractOpenSearchClientWrapper.java index c7362d9d..b8254738 100644 --- a/crafter-search-opensearch/src/main/java/org/craftercms/search/opensearch/impl/client/AbstractOpenSearchClientWrapper.java +++ b/crafter-search-opensearch/src/main/java/org/craftercms/search/opensearch/impl/client/AbstractOpenSearchClientWrapper.java @@ -233,8 +233,6 @@ public SearchRequestWrapper(SearchRequest request, Map parameter maxConcurrentShardRequests(request.maxConcurrentShardRequests()); minCompatibleShardNode(request.minCompatibleShardNode()); minScore(request.minScore()); - // TODO: JM: Review -// pit(request.pit()); postFilter(request.postFilter()); preFilterShardSize(request.preFilterShardSize()); preference(request.preference()); @@ -258,8 +256,6 @@ public SearchRequestWrapper(SearchRequest request, Map parameter timeout(request.timeout()); trackScores(request.trackScores()); trackTotalHits(request.trackTotalHits()); - // TODO: JM: Review -// type(request.type()); version(request.version()); // override values diff --git a/crafter-search-opensearch/src/test/java/org/craftercms/search/opensearch/batch/BinaryFileWithMetadataBatchIndexerTest.java b/crafter-search-opensearch/src/test/java/org/craftercms/search/opensearch/batch/BinaryFileWithMetadataBatchIndexerTest.java index 246a8e93..f7fa5fc5 100644 --- a/crafter-search-opensearch/src/test/java/org/craftercms/search/opensearch/batch/BinaryFileWithMetadataBatchIndexerTest.java +++ b/crafter-search-opensearch/src/test/java/org/craftercms/search/opensearch/batch/BinaryFileWithMetadataBatchIndexerTest.java @@ -23,17 +23,16 @@ import org.craftercms.search.batch.UpdateStatus; import org.junit.Before; import org.junit.Test; +import org.mockito.verification.VerificationMode; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; /** * Unit tests for {@link OpenSearchBinaryFileWithMetadataBatchIndexer}. @@ -112,7 +111,7 @@ public void testUpdateMetadataWithRemovedBinaries() { // TODO: JM: Revisit test case -// @Test + @Test public void testUpdateBinary() { setupMetadataSearchResult(); @@ -121,24 +120,24 @@ public void testUpdateBinary() { batchIndexer.updateIndex(INDEX_ID, SITE_NAME, contentStoreService, context, updateSet, updateStatus); - assertEquals(1, updateStatus.getAttemptedUpdatesAndDeletes()); - assertTrue(updateStatus.getSuccessfulUpdates().contains(BINARY_FILENAME1)); - verify(searchService).indexBinary( - eq(INDEX_ID), eq(SITE_NAME), eq(BINARY_FILENAME1), any(Content.class), eq(getExpectedMetadata())); + // Binary files are no longer processed by AbstractBinaryFileWithMetadataBatchIndexer + assertEquals(0, updateStatus.getAttemptedUpdatesAndDeletes()); + assertFalse(updateStatus.getSuccessfulUpdates().contains(BINARY_FILENAME1)); + verify(searchService, times(0)).indexBinary( + eq(INDEX_ID), eq(SITE_NAME), eq(BINARY_FILENAME1), any(Content.class), eq(getExpectedMetadata())); } - - // TODO: JM: Revisit test case -// @Test + @Test public void testDeleteBinary() { UpdateSet updateSet = new UpdateSet(Collections.emptyList(), Collections.singletonList(BINARY_FILENAME1)); UpdateStatus updateStatus = new UpdateStatus(); batchIndexer.updateIndex(INDEX_ID, SITE_NAME, contentStoreService, context, updateSet, updateStatus); - assertEquals(1, updateStatus.getAttemptedUpdatesAndDeletes()); - assertTrue(updateStatus.getSuccessfulDeletes().contains(BINARY_FILENAME1)); - verify(searchService).delete(eq(INDEX_ID), eq(SITE_NAME), eq(BINARY_FILENAME1)); + // Binary files are no longer processed by AbstractBinaryFileWithMetadataBatchIndexer + assertEquals(0, updateStatus.getAttemptedUpdatesAndDeletes()); + assertFalse(updateStatus.getSuccessfulDeletes().contains(BINARY_FILENAME1)); + verify(searchService, times(0)).delete(eq(INDEX_ID), eq(SITE_NAME), eq(BINARY_FILENAME1)); } @Test @@ -165,7 +164,7 @@ protected void setupBinariesSearchResults() { } protected void setupMetadataSearchResult() { - when(searchService.searchField(eq(INDEX_ID), eq("metadataPath"), any())) + lenient().when(searchService.searchField(eq(INDEX_ID), eq("metadataPath"), any())) .thenReturn(List.of(getExpectedMetadata().get("metadataPath").toString())); }