-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/org/folio/search/service/reindex/ReindexOrchestrationServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.folio.search.service.reindex; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.folio.search.domain.dto.FolioIndexOperationResponse; | ||
import org.folio.search.domain.dto.ResourceEvent; | ||
import org.folio.search.exception.ReindexException; | ||
import org.folio.search.model.event.ReindexRangeIndexEvent; | ||
import org.folio.search.model.index.SearchDocumentBody; | ||
import org.folio.search.model.types.IndexActionType; | ||
import org.folio.search.model.types.IndexingDataFormat; | ||
import org.folio.search.repository.PrimaryResourceRepository; | ||
import org.folio.search.service.converter.MultiTenantSearchDocumentConverter; | ||
import org.folio.spring.testing.type.UnitTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@UnitTest | ||
@ExtendWith(MockitoExtension.class) | ||
class ReindexOrchestrationServiceTest { | ||
|
||
@Mock | ||
private ReindexRangeIndexService rangeIndexService; | ||
@Mock | ||
private PrimaryResourceRepository elasticRepository; | ||
@Mock | ||
private MultiTenantSearchDocumentConverter documentConverter; | ||
|
||
@InjectMocks | ||
private ReindexOrchestrationService service; | ||
|
||
@Test | ||
void process_shouldProcessSuccessfully() { | ||
// Arrange | ||
ReindexRangeIndexEvent event = new ReindexRangeIndexEvent(); | ||
ResourceEvent resourceEvent = new ResourceEvent(); | ||
FolioIndexOperationResponse folioIndexOperationResponse = | ||
new FolioIndexOperationResponse().status(FolioIndexOperationResponse.StatusEnum.SUCCESS); | ||
|
||
when(rangeIndexService.fetchRecordRange(event)).thenReturn(List.of(resourceEvent)); | ||
when(documentConverter.convert(List.of(resourceEvent))).thenReturn(Map.of("key", List.of(SearchDocumentBody.of(null, | ||
IndexingDataFormat.JSON, resourceEvent, IndexActionType.INDEX)))); | ||
when(elasticRepository.indexResources(any())).thenReturn(folioIndexOperationResponse); | ||
|
||
// Act | ||
boolean result = service.process(event); | ||
|
||
// Assert | ||
assertTrue(result); | ||
verify(rangeIndexService).fetchRecordRange(event); | ||
verify(documentConverter).convert(List.of(resourceEvent)); | ||
verify(elasticRepository).indexResources(any()); | ||
} | ||
|
||
@Test | ||
void process_shouldThrowReindexException_whenElasticSearchReportsError() { | ||
// Arrange | ||
ReindexRangeIndexEvent event = new ReindexRangeIndexEvent(); | ||
ResourceEvent resourceEvent = new ResourceEvent(); | ||
FolioIndexOperationResponse folioIndexOperationResponse = new FolioIndexOperationResponse() | ||
.status(FolioIndexOperationResponse.StatusEnum.ERROR) | ||
.errorMessage("Error occurred during indexing."); | ||
|
||
when(rangeIndexService.fetchRecordRange(event)).thenReturn(List.of(resourceEvent)); | ||
when(documentConverter.convert(List.of(resourceEvent))).thenReturn(Map.of("key", List.of(SearchDocumentBody.of(null, | ||
IndexingDataFormat.JSON, resourceEvent, IndexActionType.INDEX)))); | ||
when(elasticRepository.indexResources(any())).thenReturn(folioIndexOperationResponse); | ||
|
||
// Act & Assert | ||
assertThrows(ReindexException.class, () -> service.process(event)); | ||
|
||
verify(rangeIndexService).fetchRecordRange(event); | ||
verify(documentConverter).convert(List.of(resourceEvent)); | ||
verify(elasticRepository).indexResources(any()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters