Skip to content

Commit

Permalink
Revisit tests and new search options
Browse files Browse the repository at this point in the history
  • Loading branch information
jmendeza committed Apr 24, 2023
1 parent 65e968c commit a973208
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ public SearchRequestWrapper(SearchRequest request, Map<String, Object> 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());
Expand All @@ -258,8 +256,6 @@ public SearchRequestWrapper(SearchRequest request, Map<String, Object> parameter
timeout(request.timeout());
trackScores(request.trackScores());
trackTotalHits(request.trackTotalHits());
// TODO: JM: Review
// type(request.type());
version(request.version());

// override values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -112,7 +111,7 @@ public void testUpdateMetadataWithRemovedBinaries() {


// TODO: JM: Revisit test case
// @Test
@Test
public void testUpdateBinary() {
setupMetadataSearchResult();

Expand All @@ -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
Expand All @@ -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()));
}

Expand Down

0 comments on commit a973208

Please sign in to comment.