diff --git a/src/main/java/org/folio/list/controller/ListController.java b/src/main/java/org/folio/list/controller/ListController.java index 773ac9fe..f225bb2d 100644 --- a/src/main/java/org/folio/list/controller/ListController.java +++ b/src/main/java/org/folio/list/controller/ListController.java @@ -1,5 +1,9 @@ package org.folio.list.controller; +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.folio.list.domain.dto.ListDTO; import org.folio.list.domain.dto.ListRefreshDTO; @@ -19,11 +23,6 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RestController; -import java.time.OffsetDateTime; -import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.UUID; - @RequiredArgsConstructor @RestController public class ListController implements ListApi { @@ -34,8 +33,10 @@ public class ListController implements ListApi { public ResponseEntity getAllLists(List ids, List entityTypeIds, Integer offset, - Integer size, Boolean active, + Integer size, + Boolean active, Boolean isPrivate, // Note: query param name is "private" + Boolean includeDeleted, String updatedAsOf ) { OffsetDateTime providedTimestamp; @@ -43,7 +44,17 @@ public ResponseEntity getAllLists(List ids, // In the backend, the plus sign (+) that is received through RequestParams within the provided timestamp gets substituted with a blank space. providedTimestamp = !StringUtils.hasText(updatedAsOf) ? null : OffsetDateTime.parse(updatedAsOf.replace(' ', '+'), formatter); Pageable pageable = new OffsetRequest(offset, size); - return ResponseEntity.ok(listService.getAllLists(pageable, ids, entityTypeIds, active, isPrivate, providedTimestamp)); + return ResponseEntity.ok( + listService.getAllLists( + pageable, + ids, + entityTypeIds, + active, + isPrivate, + Boolean.TRUE.equals(includeDeleted), + providedTimestamp + ) + ); } @Override diff --git a/src/main/java/org/folio/list/domain/ListEntity.java b/src/main/java/org/folio/list/domain/ListEntity.java index 18877706..1c7d69d6 100644 --- a/src/main/java/org/folio/list/domain/ListEntity.java +++ b/src/main/java/org/folio/list/domain/ListEntity.java @@ -18,12 +18,15 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.With; + import org.folio.list.domain.dto.ListUpdateRequestDTO; import org.folio.list.exception.AbstractListException; import org.folio.list.rest.UsersClient.User; import org.folio.list.util.TaskTimer; @Data +@With @Entity @AllArgsConstructor @NoArgsConstructor @@ -101,12 +104,15 @@ public class ListEntity { private ListRefreshDetails failedRefresh; @Column(name = "version") - @NotNull private int version; @Column(name = "user_friendly_query") private String userFriendlyQuery; + @Column(name = "is_deleted") + @NotNull + private Boolean isDeleted; + public boolean isRefreshing() { return inProgressRefresh != null; } diff --git a/src/main/java/org/folio/list/mapper/ListEntityMapper.java b/src/main/java/org/folio/list/mapper/ListEntityMapper.java index 76a315fc..aaad93a1 100644 --- a/src/main/java/org/folio/list/mapper/ListEntityMapper.java +++ b/src/main/java/org/folio/list/mapper/ListEntityMapper.java @@ -22,6 +22,7 @@ public interface ListEntityMapper { @Mapping(target = "updatedBy", expression = "java(createdBy.id())") @Mapping(target = "updatedByUsername", expression = "java(createdBy.getFullName().orElse(createdBy.id().toString()))") @Mapping(target = "isCanned", constant = "false") + @Mapping(target = "isDeleted", constant = "false") @Mapping(target = "version", constant = "1") ListEntity toListEntity(ListRequestDTO request, UsersClient.User createdBy); } diff --git a/src/main/java/org/folio/list/repository/ListRepository.java b/src/main/java/org/folio/list/repository/ListRepository.java index d96de5ef..5947feb6 100644 --- a/src/main/java/org/folio/list/repository/ListRepository.java +++ b/src/main/java/org/folio/list/repository/ListRepository.java @@ -10,11 +10,14 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Optional; import java.util.UUID; @Repository public interface ListRepository extends CrudRepository, PagingAndSortingRepository { + Optional findByIdAndIsDeletedFalse(UUID id); + @Query( value = """ SELECT l @@ -24,6 +27,7 @@ public interface ListRepository extends CrudRepository, Paging AND (l.isPrivate = false OR l.updatedBy = :currentUserId OR ( l.updatedBy IS NULL AND l.createdBy = :currentUserId)) AND (:isPrivate IS NULL OR l.isPrivate = :isPrivate) AND (:active IS NULL OR l.isActive = :active) + AND (:includeDeleted = true OR l.isDeleted = false) AND (TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS') IS NULL OR (l.createdDate>= TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS') OR l.updatedDate>= TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS'))) @@ -37,12 +41,22 @@ SELECT count(*) AND (l.isPrivate = false OR l.updatedBy = :currentUserId OR ( l.updatedBy IS NULL AND l.createdBy = :currentUserId)) AND (:isPrivate IS NULL OR l.isPrivate = :isPrivate) AND (:active IS NULL OR l.isActive = :active) + AND (:includeDeleted = true OR l.isDeleted = false) AND (TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS') IS NULL OR (l.createdDate>= TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS') OR l.updatedDate>= TO_TIMESTAMP(CAST(:updatedAsOf AS text), 'YYYY-MM-DD HH24:MI:SS.MS'))) """ - ) - Page searchList(Pageable pageable, List ids, List entityTypeIds, UUID currentUserId, Boolean active, Boolean isPrivate, OffsetDateTime updatedAsOf); + ) + Page searchList( + Pageable pageable, + List ids, + List entityTypeIds, + UUID currentUserId, + Boolean active, + Boolean isPrivate, + boolean includeDeleted, + OffsetDateTime updatedAsOf + ); } diff --git a/src/main/java/org/folio/list/services/ListService.java b/src/main/java/org/folio/list/services/ListService.java index 2329e912..6b12e6b1 100644 --- a/src/main/java/org/folio/list/services/ListService.java +++ b/src/main/java/org/folio/list/services/ListService.java @@ -77,13 +77,21 @@ public class ListService { private final ListVersionRepository listVersionRepository; private final ListVersionMapper listVersionMapper; - public ListSummaryResultsDTO getAllLists(Pageable pageable, List ids, - List entityTypeIds, Boolean active, Boolean isPrivate, OffsetDateTime updatedAsOf) { + public ListSummaryResultsDTO getAllLists(Pageable pageable, List ids, List entityTypeIds, Boolean active, + Boolean isPrivate, boolean includeDeleted, OffsetDateTime updatedAsOf) { log.info("Attempting to get all lists"); UUID currentUserId = executionContext.getUserId(); - Page lists = listRepository.searchList(pageable, isEmpty(ids) ? null : ids, - isEmpty(entityTypeIds) ? null : entityTypeIds, currentUserId, active, isPrivate, updatedAsOf); + Page lists = listRepository.searchList( + pageable, + isEmpty(ids) ? null : ids, + isEmpty(entityTypeIds) ? null : entityTypeIds, + currentUserId, + active, + isPrivate, + includeDeleted, + updatedAsOf + ); // List database do not store entity type labels. Only entity type ID is available in List database. // Get the corresponding entity type labels from FQM @@ -129,7 +137,7 @@ public ListDTO createList(ListRequestDTO listRequest) { public Optional updateList(UUID id, ListUpdateRequestDTO request) { log.info("Attempting to update a list with id : {}", id); - Optional listEntity = listRepository.findById(id); + Optional listEntity = listRepository.findByIdAndIsDeletedFalse(id); listEntity.ifPresent(list -> { EntityType entityType = getEntityType(list.getEntityTypeId()); validationService.validateUpdate(list, request, entityType); @@ -165,7 +173,7 @@ public Optional updateList(UUID id, ListUpdateRequestDTO request) { public Optional getListById(UUID id) { log.info("Attempting to get specific list for id {}", id); - return listRepository.findById(id) + return listRepository.findByIdAndIsDeletedFalse(id) .map(list -> { validationService.assertSharedOrOwnedByUser(list, ListActions.READ); return listMapper.toListDTO(list); @@ -174,7 +182,7 @@ public Optional getListById(UUID id) { public Optional performRefresh(UUID listId) { log.info("Attempting to refresh list with listId {}", listId); - return listRepository.findById(listId) + return listRepository.findByIdAndIsDeletedFalse(listId) .map(list -> { validationService.validateRefresh(list); list.refreshStarted(getCurrentUser()); @@ -201,7 +209,7 @@ public Optional performRefresh(UUID listId) { public Optional getListContents(UUID listId, Integer offset, Integer size) { log.info("Attempting to get contents for list with listId {}, tenantId {}, offset {}, size {}", listId, executionContext.getTenantId(), offset, size); - return listRepository.findById(listId) + return listRepository.findByIdAndIsDeletedFalse(listId) .map(list -> { validationService.assertSharedOrOwnedByUser(list, ListActions.READ); return getListContents(list, offset, size); @@ -209,7 +217,7 @@ public Optional getListContents(UUID listId, Integer offset, Inte } public void deleteList(UUID id) { - ListEntity list = listRepository.findById(id) + ListEntity list = listRepository.findByIdAndIsDeletedFalse(id) .orElseThrow(() -> new ListNotFoundException(id, ListActions.DELETE)); validationService.validateDelete(list); deleteListAndContents(list); @@ -217,7 +225,7 @@ public void deleteList(UUID id) { public void cancelRefresh(UUID listId) { log.info("Cancelling refresh for list {}", listId); - ListEntity list = listRepository.findById(listId) + ListEntity list = listRepository.findByIdAndIsDeletedFalse(listId) .orElseThrow(() -> new ListNotFoundException(listId, ListActions.CANCEL_REFRESH)); validationService.validateCancelRefresh(list); list.refreshCancelled(executionContext.getUserId()); @@ -227,7 +235,7 @@ public void cancelRefresh(UUID listId) { public List getListVersions(UUID listId) { log.info("Checking that list {} is accessible and exists before getting versions", listId); - ListEntity list = listRepository.findById(listId).orElseThrow(() -> new ListNotFoundException(listId, ListActions.READ)); + ListEntity list = listRepository.findByIdAndIsDeletedFalse(listId).orElseThrow(() -> new ListNotFoundException(listId, ListActions.READ)); validationService.assertSharedOrOwnedByUser(list, ListActions.READ); log.info("Getting all versions of the list {}", listId); @@ -243,7 +251,9 @@ public List getListVersions(UUID listId) { public ListVersionDTO getListVersion(UUID listId, int version) { log.info("Checking that list {} is accessible and exists before getting version {}", listId, version); - ListEntity list = listRepository.findById(listId).orElseThrow(() -> new ListNotFoundException(listId, ListActions.READ)); + ListEntity list = listRepository + .findByIdAndIsDeletedFalse(listId) + .orElseThrow(() -> new ListNotFoundException(listId, ListActions.READ)); validationService.assertSharedOrOwnedByUser(list, ListActions.READ); log.info("Getting version {} of the list {}", version, listId); @@ -256,7 +266,7 @@ public ListVersionDTO getListVersion(UUID listId, int version) { private void deleteListAndContents(ListEntity list) { listContentsRepository.deleteContents(list.getId()); - listRepository.deleteById(list.getId()); + listRepository.save(list.withIsDeleted(true)); } private ResultsetPage getListContents(ListEntity list, Integer offset, Integer limit) { diff --git a/src/main/java/org/folio/list/services/export/ListExportService.java b/src/main/java/org/folio/list/services/export/ListExportService.java index 1d3d3670..e8856c14 100644 --- a/src/main/java/org/folio/list/services/export/ListExportService.java +++ b/src/main/java/org/folio/list/services/export/ListExportService.java @@ -44,7 +44,7 @@ public class ListExportService { @Transactional public ListExportDTO createExport(UUID listId) { - ListEntity list = listRepository.findById(listId) + ListEntity list = listRepository.findByIdAndIsDeletedFalse(listId) .orElseThrow(() -> new ListNotFoundException(listId, ListActions.EXPORT)); validationService.validateCreateExport(list); ExportDetails exportDetails = createExportDetails(list); diff --git a/src/main/java/org/folio/list/services/refresh/RefreshFailedCallback.java b/src/main/java/org/folio/list/services/refresh/RefreshFailedCallback.java index 69e29b23..f2adb80c 100644 --- a/src/main/java/org/folio/list/services/refresh/RefreshFailedCallback.java +++ b/src/main/java/org/folio/list/services/refresh/RefreshFailedCallback.java @@ -10,7 +10,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.UUID; -import java.util.function.BiConsumer; import java.util.function.Predicate; @Service @@ -51,7 +50,7 @@ private void saveFailedRefresh(ListEntity entity, TaskTimer timer, Throwable fai * inProgressRefreshId for this list in database. */ private boolean isActiveRefresh(UUID listId, UUID refreshId) { - return listRepository.findById(listId) + return listRepository.findByIdAndIsDeletedFalse(listId) .flatMap(ListEntity::getInProgressRefreshId) .filter(Predicate.isEqual(refreshId)) .isPresent(); diff --git a/src/main/java/org/folio/list/services/refresh/RefreshSuccessCallback.java b/src/main/java/org/folio/list/services/refresh/RefreshSuccessCallback.java index 3782ef13..c4c73bda 100644 --- a/src/main/java/org/folio/list/services/refresh/RefreshSuccessCallback.java +++ b/src/main/java/org/folio/list/services/refresh/RefreshSuccessCallback.java @@ -56,7 +56,7 @@ private void saveSuccessRefresh(ListEntity entity, Integer recordsCount, TaskTim * inProgressRefreshId for this list in database. */ private boolean isActiveRefresh(UUID listId, UUID refreshId) { - return listRepository.findById(listId) + return listRepository.findByIdAndIsDeletedFalse(listId) .flatMap(ListEntity::getInProgressRefreshId) .filter(Predicate.isEqual(refreshId)) .isPresent(); diff --git a/src/main/resources/db/changelog/changes/v1.1.0/changelog-v1.1.0.xml b/src/main/resources/db/changelog/changes/v1.1.0/changelog-v1.1.0.xml index 345a133f..45344e39 100644 --- a/src/main/resources/db/changelog/changes/v1.1.0/changelog-v1.1.0.xml +++ b/src/main/resources/db/changelog/changes/v1.1.0/changelog-v1.1.0.xml @@ -8,4 +8,5 @@ + diff --git a/src/main/resources/db/changelog/changes/v1.1.0/yml/add-list-details-is-deleted-column.yaml b/src/main/resources/db/changelog/changes/v1.1.0/yml/add-list-details-is-deleted-column.yaml new file mode 100644 index 00000000..a780356e --- /dev/null +++ b/src/main/resources/db/changelog/changes/v1.1.0/yml/add-list-details-is-deleted-column.yaml @@ -0,0 +1,14 @@ +databaseChangeLog: + - changeSet: + id: add-list-details-is-deleted-column + author: novercash@ebsco.com + changes: + - addColumn: + tableName: list_details + columns: + - column: + name: is_deleted + type: boolean + defaultValueBoolean: false + constraints: + nullable: false diff --git a/src/main/resources/swagger.api/list.yaml b/src/main/resources/swagger.api/list.yaml index cd675ad7..de26c227 100644 --- a/src/main/resources/swagger.api/list.yaml +++ b/src/main/resources/swagger.api/list.yaml @@ -57,6 +57,12 @@ paths: required: false schema: type: boolean + - name: includeDeleted + in: query + description: Indicates if deleted lists should be included in the results (default false) + required: false + schema: + type: boolean - name: updatedAsOf in: query description: Indicates the minimum create/update timestamp to filter lists by diff --git a/src/main/resources/swagger.api/schemas/ListDTO.json b/src/main/resources/swagger.api/schemas/ListDTO.json index 76b4af4f..8773ed64 100644 --- a/src/main/resources/swagger.api/schemas/ListDTO.json +++ b/src/main/resources/swagger.api/schemas/ListDTO.json @@ -66,6 +66,10 @@ "description": "Indicates if a List is canned or not", "type": "boolean" }, + "isDeleted" : { + "description": "Indicates if a List has been deleted", + "type": "boolean" + }, "updatedBy": { "description": "ID of the user who last updated the record (when available)", "type": "string", diff --git a/src/main/resources/swagger.api/schemas/ListSummaryResultsDTO.json b/src/main/resources/swagger.api/schemas/ListSummaryResultsDTO.json index b1768638..7e6794a2 100644 --- a/src/main/resources/swagger.api/schemas/ListSummaryResultsDTO.json +++ b/src/main/resources/swagger.api/schemas/ListSummaryResultsDTO.json @@ -69,6 +69,10 @@ "description": "Indicates if a List is canned or not", "type": "boolean" }, + "isDeleted" : { + "description": "Indicates if a List has been deleted", + "type": "boolean" + }, "updatedBy": { "description": "ID of the user who last updated the record (when available)", "type": "string", diff --git a/src/test/java/org/folio/list/controller/ListControllerGetListsTest.java b/src/test/java/org/folio/list/controller/ListControllerGetListsTest.java index 3cbba41f..e54cdbf4 100644 --- a/src/test/java/org/folio/list/controller/ListControllerGetListsTest.java +++ b/src/test/java/org/folio/list/controller/ListControllerGetListsTest.java @@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -54,8 +56,8 @@ void testGetAllLists() throws Exception { .contentType(APPLICATION_JSON) .header(XOkapiHeaders.TENANT, TENANT_ID); - when(listService.getAllLists(any(Pageable.class), Mockito.eq(null), - Mockito.eq(null), Mockito.eq(null), Mockito.eq(null), Mockito.eq(null))).thenReturn(listSummaryResultsDto); + when(listService.getAllLists(any(Pageable.class), isNull(), isNull(), + isNull(), isNull(), eq(false), isNull())).thenReturn(listSummaryResultsDto); mockMvc.perform(requestBuilder) .andExpect(status().isOk()) @@ -87,11 +89,12 @@ void testGetAllListsWithIdsParameter() throws Exception { .queryParam("entityTypeIds", listDto1.getEntityTypeId().toString(), listDto2.getEntityTypeId().toString()) .queryParam("active", "true") .queryParam("private", "true") + .queryParam("includeDeleted", "false") .queryParam("updatedAsOf", "2023-01-27T20:54:41.528281+05:30"); when(listService.getAllLists(any(Pageable.class), Mockito.eq(listIds), - Mockito.eq(listEntityIds), Mockito.eq(true), Mockito.eq(true), Mockito.eq(providedTimestamp))) + Mockito.eq(listEntityIds), Mockito.eq(true), Mockito.eq(true), Mockito.eq(false), Mockito.eq(providedTimestamp))) .thenReturn(listSummaryResultsDto); mockMvc.perform(requestBuilder) @@ -127,7 +130,7 @@ void testGetAllListsWithVariableOffsetAndSize() throws Exception { .queryParam("private", "false"); when(listService.getAllLists(pageable, null, - null, false, false, null)).thenReturn(listSummaryResultsDto); + null, false, false, false, null)).thenReturn(listSummaryResultsDto); mockMvc.perform(requestBuilder) .andExpect(status().isOk()) diff --git a/src/test/java/org/folio/list/mapper/ListEntityMapperTest.java b/src/test/java/org/folio/list/mapper/ListEntityMapperTest.java index e70f8cd6..5c6516a3 100644 --- a/src/test/java/org/folio/list/mapper/ListEntityMapperTest.java +++ b/src/test/java/org/folio/list/mapper/ListEntityMapperTest.java @@ -42,5 +42,6 @@ void shouldMapDtoToEntity() { assertEquals(user.id(), listEntity.getCreatedBy()); assertNotNull(listEntity.getCreatedDate()); assertFalse(listEntity.getIsCanned()); + assertFalse(listEntity.getIsDeleted()); } } diff --git a/src/test/java/org/folio/list/service/ListServiceCancelRefreshTest.java b/src/test/java/org/folio/list/service/ListServiceCancelRefreshTest.java index 76487aeb..af83e2a2 100644 --- a/src/test/java/org/folio/list/service/ListServiceCancelRefreshTest.java +++ b/src/test/java/org/folio/list/service/ListServiceCancelRefreshTest.java @@ -1,5 +1,10 @@ package org.folio.list.service; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.Optional; +import java.util.UUID; import org.folio.list.domain.AsyncProcessStatus; import org.folio.list.domain.ListEntity; import org.folio.list.domain.ListRefreshDetails; @@ -14,14 +19,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Optional; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class ListServiceCancelRefreshTest { + @InjectMocks private ListService listService; @@ -39,7 +39,8 @@ void shouldCancelListRefresh() { UUID userId = UUID.randomUUID(); ListEntity list = TestDataFixture.getListEntityWithInProgressRefresh(); ListRefreshDetails refreshDetails = list.getInProgressRefresh(); - when(listRepository.findById(list.getId())).thenReturn(Optional.of(list)); + when(listRepository.findByIdAndIsDeletedFalse(list.getId())) + .thenReturn(Optional.of(list)); when(executionContext.getUserId()).thenReturn(userId); doNothing().when(listValidationService).validateCancelRefresh(list); listService.cancelRefresh(list.getId()); diff --git a/src/test/java/org/folio/list/service/ListServiceDeleteListTest.java b/src/test/java/org/folio/list/service/ListServiceDeleteListTest.java index 7d70116c..095fe7a5 100644 --- a/src/test/java/org/folio/list/service/ListServiceDeleteListTest.java +++ b/src/test/java/org/folio/list/service/ListServiceDeleteListTest.java @@ -10,6 +10,7 @@ import org.folio.list.utils.TestDataFixture; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -18,6 +19,8 @@ import java.util.Optional; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; @@ -39,17 +42,23 @@ class ListServiceDeleteListTest { @Test void shouldDeleteList() { ListEntity entity = TestDataFixture.getListEntityWithSuccessRefresh(); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); + listValidationService.validateDelete(entity); listService.deleteList(entity.getId()); - verify(listRepository, times(1)).deleteById(entity.getId()); + verify(listContentsRepository, times(1)).deleteContents(entity.getId()); + + // soft delete saves the entity with is_deleted=true + ArgumentCaptor captor = ArgumentCaptor.forClass(ListEntity.class); + verify(listRepository, times(1)).save(captor.capture()); + assertThat(captor.getValue().getIsDeleted()).isTrue(); } @Test void shouldNotDeleteIfValidationFailed() { ListEntity entity = TestDataFixture.getPrivateListEntity(); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); doThrow(new PrivateListOfAnotherUserException(entity, ListActions.DELETE)) .when(listValidationService).validateDelete(entity); UUID entityId = entity.getId(); diff --git a/src/test/java/org/folio/list/service/ListServiceGetListContentsTest.java b/src/test/java/org/folio/list/service/ListServiceGetListContentsTest.java index 378df381..ccf677ca 100644 --- a/src/test/java/org/folio/list/service/ListServiceGetListContentsTest.java +++ b/src/test/java/org/folio/list/service/ListServiceGetListContentsTest.java @@ -84,7 +84,7 @@ void shouldReturnValidContentPage() { expectedEntity.getSuccessRefresh().setRecordsCount(2); when(executionContext.getTenantId()).thenReturn(tenantId); - when(listRepository.findById(listId)).thenReturn(Optional.of(expectedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(expectedEntity)); when(listContentsRepository.getContents(listId, successRefresh.getId(), new OffsetRequest(offset, size))).thenReturn(listContents); when(queryClient.getContents(contentsRequest)).thenReturn(expectedList); Optional actualContent = listService.getListContents(listId, offset, size); @@ -126,7 +126,7 @@ void shouldReturnRequestedFieldsPlusIdsIfIdsNotIncludedInFields() { expectedEntity.getSuccessRefresh().setRecordsCount(2); when(executionContext.getTenantId()).thenReturn(tenantId); - when(listRepository.findById(listId)).thenReturn(Optional.of(expectedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(expectedEntity)); when(listContentsRepository.getContents(listId, successRefresh.getId(), new OffsetRequest(offset, size))).thenReturn(listContents); when(queryClient.getContents(contentsRequest)).thenReturn(expectedList); Optional actualContent = listService.getListContents(listId, offset, size); @@ -168,7 +168,7 @@ void shouldReturnContentPageWithIdsForEmptyFields() { expectedEntity.getSuccessRefresh().setRecordsCount(2); when(executionContext.getTenantId()).thenReturn(tenantId); - when(listRepository.findById(listId)).thenReturn(Optional.of(expectedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(expectedEntity)); when(listContentsRepository.getContents(listId, successRefresh.getId(), new OffsetRequest(offset, size))).thenReturn(listContents); when(queryClient.getContents(contentsRequest)).thenReturn(expectedList); Optional actualContent = listService.getListContents(listId, offset, size); @@ -209,7 +209,7 @@ void shouldReturnContentPageWithIdsForNullFields() { expectedEntity.getSuccessRefresh().setRecordsCount(2); when(executionContext.getTenantId()).thenReturn(tenantId); - when(listRepository.findById(listId)).thenReturn(Optional.of(expectedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(expectedEntity)); when(listContentsRepository.getContents(listId, successRefresh.getId(), new OffsetRequest(offset, size))).thenReturn(listContents); when(queryClient.getContents(contentsRequest)).thenReturn(expectedList); Optional actualContent = listService.getListContents(listId, offset, size); @@ -221,7 +221,7 @@ void shouldReturnEmptyContentPageIfNotRefreshed() { UUID listId = UUID.randomUUID(); Optional emptyContent = Optional.of(new ResultsetPage().content(List.of()).totalRecords(0)); ListEntity neverRefreshedList = TestDataFixture.getNeverRefreshedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(neverRefreshedList)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(neverRefreshedList)); Optional actualContent = listService.getListContents(listId, 0, 100); assertThat(actualContent).isEqualTo(emptyContent); } @@ -230,7 +230,7 @@ void shouldReturnEmptyContentPageIfNotRefreshed() { void shouldThrowExceptionWhenValidationFailed() { UUID listId = UUID.randomUUID(); ListEntity listEntity = TestDataFixture.getNeverRefreshedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); doThrow(new PrivateListOfAnotherUserException(listEntity, ListActions.READ)) .when(listValidationService).assertSharedOrOwnedByUser(listEntity, ListActions.READ); Assertions.assertThrows(PrivateListOfAnotherUserException.class, () -> listService.getListContents(listId, 0, 100)); diff --git a/src/test/java/org/folio/list/service/ListServiceGetListIdTest.java b/src/test/java/org/folio/list/service/ListServiceGetListIdTest.java index f4618515..55b7ff45 100644 --- a/src/test/java/org/folio/list/service/ListServiceGetListIdTest.java +++ b/src/test/java/org/folio/list/service/ListServiceGetListIdTest.java @@ -45,7 +45,7 @@ void testGetListById() { ListEntity entity = TestDataFixture.getListEntityWithSuccessRefresh(UUID.randomUUID()); ListDTO listDto = TestDataFixture.getListDTOSuccessRefresh(listId); - when(listRepository.findById(listId)).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(entity)); when(listMapper.toListDTO(entity)).thenReturn(listDto); var actual = listService.getListById(listId); assertThat(actual).contains(listDto); @@ -55,7 +55,7 @@ void testGetListById() { void shouldThrowExceptionWhenValidationFailed() { UUID listId = UUID.randomUUID(); ListEntity listEntity = TestDataFixture.getNeverRefreshedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); doThrow(new PrivateListOfAnotherUserException(listEntity, ListActions.READ)) .when(listValidationService).assertSharedOrOwnedByUser(listEntity, ListActions.READ); Assertions.assertThrows(PrivateListOfAnotherUserException.class, () -> listService.getListById(listId)); diff --git a/src/test/java/org/folio/list/service/ListServicePostRefreshTest.java b/src/test/java/org/folio/list/service/ListServicePostRefreshTest.java index 8d22c6f2..0812dd6d 100644 --- a/src/test/java/org/folio/list/service/ListServicePostRefreshTest.java +++ b/src/test/java/org/folio/list/service/ListServicePostRefreshTest.java @@ -73,7 +73,7 @@ void shouldPerformRefresh() { savedEntity.setInProgressRefresh(inProgressRefreshEntity); - when(listRepository.findById(savedEntity.getId())).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(savedEntity.getId())).thenReturn(Optional.of(fetchedEntity)); when(listRepository.save(fetchedEntity)).thenReturn(savedEntity); when(refreshMapper.toListRefreshDTO(inProgressRefreshEntity)).thenReturn(inProgressRefreshDTO); when(executionContext.getUserId()).thenReturn(userId); @@ -94,7 +94,7 @@ void shouldSaveInProgressRefreshDetails() { ListEntity fetchedEntity = TestDataFixture.getListEntityWithSuccessRefresh(); ArgumentCaptor listEntityCaptor = ArgumentCaptor.forClass(ListEntity.class); - when(listRepository.findById(listId)).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(fetchedEntity)); when(listRepository.save(listEntityCaptor.capture())).thenReturn(fetchedEntity); when(refreshMapper.toListRefreshDTO(any(ListRefreshDetails.class))).thenReturn(mock(org.folio.list.domain.dto.ListRefreshDTO.class)); when(executionContext.getUserId()).thenReturn(userId); @@ -115,7 +115,7 @@ void shouldSaveInProgressRefreshForInvalidUserId() { ListEntity fetchedEntity = TestDataFixture.getListEntityWithSuccessRefresh(); ArgumentCaptor listEntityCaptor = ArgumentCaptor.forClass(ListEntity.class); - when(listRepository.findById(listId)).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(fetchedEntity)); when(listRepository.save(listEntityCaptor.capture())).thenReturn(fetchedEntity); when(refreshMapper.toListRefreshDTO(any(ListRefreshDetails.class))).thenReturn(mock(org.folio.list.domain.dto.ListRefreshDTO.class)); when(executionContext.getUserId()).thenReturn(userId); @@ -133,10 +133,9 @@ void shouldSaveInProgressRefreshForInvalidUserId() { void shouldThrowExceptionWhenValidationFailed() { UUID listId = UUID.randomUUID(); ListEntity listEntity = TestDataFixture.getNeverRefreshedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); doThrow(new PrivateListOfAnotherUserException(listEntity, ListActions.REFRESH)) .when(listValidationService).validateRefresh(listEntity); Assertions.assertThrows(PrivateListOfAnotherUserException.class, () -> listService.performRefresh(listId)); } } - diff --git a/src/test/java/org/folio/list/service/ListServiceTest.java b/src/test/java/org/folio/list/service/ListServiceTest.java index eb9d4529..2792dc06 100644 --- a/src/test/java/org/folio/list/service/ListServiceTest.java +++ b/src/test/java/org/folio/list/service/ListServiceTest.java @@ -125,8 +125,16 @@ void testGetAllLists() { Page listEntities = new PageImpl<>(List.of(entity1, entity2)); when(executionContext.getUserId()).thenReturn(currentUserId); - when(listRepository.searchList(any(Pageable.class), Mockito.eq(List.of(entity1.getId(), entity2.getId())), Mockito.eq(List.of(entity1.getEntityTypeId(), entity2.getEntityTypeId())), any(UUID.class), Mockito.eq(true), Mockito.eq(false), any()) - ).thenReturn(listEntities); + when(listRepository.searchList( + any(Pageable.class), + Mockito.eq(List.of(entity1.getId(), entity2.getId())), + Mockito.eq(List.of(entity1.getEntityTypeId(), entity2.getEntityTypeId())), + any(UUID.class), + Mockito.eq(true), + Mockito.eq(false), + Mockito.eq(false), + any() + )).thenReturn(listEntities); when(listSummaryMapper.toListSummaryDTO(entity1, "Item")).thenReturn(listSummaryDto1.entityTypeName("Item")); when(listSummaryMapper.toListSummaryDTO(entity2, "Loan")).thenReturn(listSummaryDto2.entityTypeName("Loan")); when(entityTypeClient.getEntityTypeSummary(List.of(listSummaryDto1.getEntityTypeId(), @@ -134,12 +142,15 @@ void testGetAllLists() { Page expected = new PageImpl<>(List.of(listSummaryDto1, listSummaryDto2)); - var actual = listService.getAllLists(Pageable.ofSize(100), + var actual = listService.getAllLists( + Pageable.ofSize(100), List.of(entity1.getId(), entity2.getId()), List.of(entity1.getEntityTypeId(), entity2.getEntityTypeId()), true, false, - null); + false, + null + ); assertThat(actual.getContent()).isEqualTo(expected.getContent()); } @@ -298,7 +309,7 @@ void testUpdateListForExistingList() { when(entityTypeClient.getEntityType(entity.getEntityTypeId())).thenReturn(entityType); when(fqlService.getFql(entity.getFqlQuery())).thenReturn(new Fql(equalsCondition)); when(userFriendlyQueryService.getUserFriendlyQuery(equalsCondition, entityType)).thenReturn(userFriendlyQuery); - when(listRepository.findById(listId)).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(entity)); when(listVersionRepository.save(any(ListVersion.class))).thenReturn(previousVersions); when(listMapper.toListDTO(entity)).thenReturn(expected); doNothing().when(validationService).validateUpdate(entity, listUpdateRequestDto, entityType); @@ -347,7 +358,7 @@ void updateListShouldUseDefaultFieldsIfFieldsNotProvidedInRequest() { when(entityTypeClient.getEntityType(entity.getEntityTypeId())).thenReturn(entityType); when(fqlService.getFql(entity.getFqlQuery())).thenReturn(new Fql(equalsCondition)); when(userFriendlyQueryService.getUserFriendlyQuery(equalsCondition, entityType)).thenReturn(userFriendlyQuery); - when(listRepository.findById(listId)).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(entity)); when(listMapper.toListDTO(entity)).thenReturn(expected); doNothing().when(validationService).validateUpdate(entity, listUpdateRequestDto, entityType); @@ -370,7 +381,7 @@ void testDeactivateListShouldRemoveContents() { when(usersClient.getUser(userId)).thenReturn(user); when(executionContext.getUserId()).thenReturn(userId); when(entityTypeClient.getEntityType(entity.getEntityTypeId())).thenReturn(entityType); - when(listRepository.findById(listId)).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(entity)); doNothing().when(validationService).validateUpdate(entity, deactivateRequest, entityType); assertThat(entity.getIsActive()) @@ -399,7 +410,7 @@ void testUpdateListFromQueryId() { when(usersClient.getUser(userId)).thenReturn(user); when(executionContext.getUserId()).thenReturn(userId); when(entityTypeClient.getEntityType(entity.getEntityTypeId())).thenReturn(entityType); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); when(listRepository.save(entity)).thenReturn(entity); int oldVersion = entity.getVersion(); // Save the original version, since updateList modifies entity var actual = listService.updateList(entity.getId(), listUpdateRequestDto); @@ -430,7 +441,7 @@ void testUpdateInactiveListFromQueryIdDoesNotImportQueryData() { when(usersClient.getUser(userId)).thenReturn(user); when(executionContext.getUserId()).thenReturn(userId); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); when(entityTypeClient.getEntityType(entity.getEntityTypeId())).thenReturn(entityType); int oldVersion = entity.getVersion(); // Save the original version, since updateList modifies entity @@ -449,7 +460,7 @@ void testGetAllListVersions() { // prepare the list we want to fetch // must be shared as the method verifies access ListEntity listEntity = TestDataFixture.getSharedNonCannedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); // prepare the list versions we want to return ListVersion listVersion = TestDataFixture.getListVersion(); @@ -459,7 +470,7 @@ void testGetAllListVersions() { List result = listService.getListVersions(listId); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verify(listVersionRepository, times(1)).findByListId(listId); verify(listVersionMapper, times(1)).toListVersionDTO(any()); verify(validationService, times(1)).assertSharedOrOwnedByUser(listEntity, ListActions.READ); @@ -476,14 +487,14 @@ void testGetAllListVersionsPrivate() { // prepare the list we want to fetch // must be shared as the method verifies access ListEntity listEntity = TestDataFixture.getPrivateListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); doThrow(new PrivateListOfAnotherUserException(listEntity, ListActions.READ)) .when(validationService) .assertSharedOrOwnedByUser(listEntity, ListActions.READ); assertThrows(PrivateListOfAnotherUserException.class, () -> listService.getListVersions(listId)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verify(validationService, times(1)).assertSharedOrOwnedByUser(listEntity, ListActions.READ); verifyNoMoreInteractions(listRepository, validationService); @@ -494,11 +505,11 @@ void testGetAllListVersionsPrivate() { void testGetAllListVersionsListDoesNotExist() { UUID listId = UUID.fromString("19a2569b-524e-51f3-a5df-c3877a1eec93"); - when(listRepository.findById(listId)).thenReturn(Optional.empty()); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.empty()); assertThrows(ListNotFoundException.class, () -> listService.getListVersions(listId)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verifyNoMoreInteractions(listRepository); verifyNoInteractions(validationService, listVersionRepository, listVersionMapper); @@ -512,7 +523,7 @@ void testGetSingleListVersion() { // prepare the list we want to fetch // must be shared as the method verifies access ListEntity listEntity = TestDataFixture.getSharedNonCannedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); // prepare the list versions we want to return ListVersion listVersion = TestDataFixture.getListVersion(); @@ -522,7 +533,7 @@ void testGetSingleListVersion() { assertEquals(listVersionDTO, listService.getListVersion(listId, versionNumber)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verify(listVersionRepository, times(1)).findByListIdAndVersion(listId, versionNumber); verify(listVersionMapper, times(1)).toListVersionDTO(any()); verify(validationService, times(1)).assertSharedOrOwnedByUser(listEntity, ListActions.READ); @@ -537,14 +548,14 @@ void testGetSingleListVersionPrivate() { // prepare the list we want to fetch // must be shared as the method verifies access ListEntity listEntity = TestDataFixture.getPrivateListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); doThrow(new PrivateListOfAnotherUserException(listEntity, ListActions.READ)) .when(validationService) .assertSharedOrOwnedByUser(listEntity, ListActions.READ); assertThrows(PrivateListOfAnotherUserException.class, () -> listService.getListVersion(listId, versionNumber)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verify(validationService, times(1)).assertSharedOrOwnedByUser(listEntity, ListActions.READ); verifyNoMoreInteractions(listRepository, validationService); @@ -556,11 +567,11 @@ void testGetSingleListVersionListDoesNotExist() { UUID listId = UUID.fromString("19a2569b-524e-51f3-a5df-c3877a1eec93"); int versionNumber = 3; - when(listRepository.findById(listId)).thenReturn(Optional.empty()); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.empty()); assertThrows(ListNotFoundException.class, () -> listService.getListVersion(listId, versionNumber)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verifyNoMoreInteractions(listRepository); verifyNoInteractions(validationService, listVersionRepository, listVersionMapper); @@ -574,14 +585,14 @@ void testGetSingleListVersionVersionDoesNotExist() { // prepare the list we want to fetch // must be shared as the method verifies access ListEntity listEntity = TestDataFixture.getSharedNonCannedListEntity(); - when(listRepository.findById(listId)).thenReturn(Optional.of(listEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(listEntity)); // no version found when(listVersionRepository.findByListIdAndVersion(listId, versionNumber)).thenReturn(Optional.empty()); assertThrows(VersionNotFoundException.class, () -> listService.getListVersion(listId, versionNumber)); - verify(listRepository, times(1)).findById(listId); + verify(listRepository, times(1)).findByIdAndIsDeletedFalse(listId); verify(listVersionRepository, times(1)).findByListIdAndVersion(listId, versionNumber); verify(validationService, times(1)).assertSharedOrOwnedByUser(listEntity, ListActions.READ); verifyNoMoreInteractions(listRepository, listVersionRepository, validationService); diff --git a/src/test/java/org/folio/list/service/export/ListExportServiceTest.java b/src/test/java/org/folio/list/service/export/ListExportServiceTest.java index e7d8a124..029d95ac 100644 --- a/src/test/java/org/folio/list/service/export/ListExportServiceTest.java +++ b/src/test/java/org/folio/list/service/export/ListExportServiceTest.java @@ -76,7 +76,7 @@ void shouldSaveExport() { ListEntity fetchedEntity = TestDataFixture.getListExportDetails().getList(); ExportDetails exportDetails = TestDataFixture.getListExportDetails(); ArgumentCaptor exportDetailsArgumentCaptor = ArgumentCaptor.forClass(ExportDetails.class); - when(listRepository.findById(listId)).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(fetchedEntity)); when(listExportRepository.save(exportDetailsArgumentCaptor.capture())).thenReturn(exportDetails); when(listExportMapper.toListExportDTO(any(ExportDetails.class))) @@ -112,7 +112,7 @@ void shouldSaveFailedExportIfRefreshFail() { ListEntity fetchedEntity = TestDataFixture.getListExportDetails().getList(); ExportDetails exportDetails = TestDataFixture.getListExportDetails(); ArgumentCaptor exportDetailsArgumentCaptor = ArgumentCaptor.forClass(ExportDetails.class); - when(listRepository.findById(listId)).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(fetchedEntity)); when(listExportRepository.save(exportDetailsArgumentCaptor.capture())).thenReturn(exportDetails); when(listExportMapper.toListExportDTO(any(ExportDetails.class))) @@ -239,7 +239,7 @@ void shouldRegisterShutdownTask() { ExportDetails exportDetails = TestDataFixture.getListExportDetails(); ListEntity fetchedEntity = exportDetails.getList(); UUID listId = fetchedEntity.getId(); - when(listRepository.findById(listId)).thenReturn(Optional.of(fetchedEntity)); + when(listRepository.findByIdAndIsDeletedFalse(listId)).thenReturn(Optional.of(fetchedEntity)); when(listExportRepository.save(any(ExportDetails.class))).thenReturn(exportDetails); when(listExportMapper.toListExportDTO(exportDetails)).thenReturn(mock(ListExportDTO.class)); when(listExportWorkerService.doAsyncExport(exportDetails)).thenReturn(CompletableFuture.completedFuture(null)); diff --git a/src/test/java/org/folio/list/service/refresh/RefreshFailedCallbackTest.java b/src/test/java/org/folio/list/service/refresh/RefreshFailedCallbackTest.java index 74cc9a91..52bc3a4c 100644 --- a/src/test/java/org/folio/list/service/refresh/RefreshFailedCallbackTest.java +++ b/src/test/java/org/folio/list/service/refresh/RefreshFailedCallbackTest.java @@ -32,7 +32,7 @@ void shouldCallRefreshFailed() { ListEntity entity = TestDataFixture.getListEntityWithInProgressRefresh(); Throwable failureReason = new RuntimeException("Something Went Wrong"); String expectedErrorCode = "unexpected.error"; - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); failedRefreshService.accept(entity, new TaskTimer(), failureReason); assertThat(entity.getFailedRefresh().getErrorMessage()).isEqualTo(failureReason.getMessage()); diff --git a/src/test/java/org/folio/list/service/refresh/RefreshSuccessCallbackTest.java b/src/test/java/org/folio/list/service/refresh/RefreshSuccessCallbackTest.java index 4b8f187e..f8ac50f4 100644 --- a/src/test/java/org/folio/list/service/refresh/RefreshSuccessCallbackTest.java +++ b/src/test/java/org/folio/list/service/refresh/RefreshSuccessCallbackTest.java @@ -39,7 +39,7 @@ class RefreshSuccessCallbackTest { void shouldCompleteRefreshForNeverRefreshedList() { int recordsCount = 10; ListEntity entity = TestDataFixture.getListEntityWithInProgressRefresh(); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); successRefreshService.accept(entity, recordsCount, new TaskTimer()); assertEquals(entity.getSuccessRefresh().getRecordsCount(), recordsCount); @@ -53,7 +53,7 @@ void shouldCompleteRefreshForPreviouslyRefreshedList() { int recordsCount = 10; ListEntity entity = TestDataFixture.getListEntityWithInProgressAndSuccessRefresh(); UUID originalRefreshId = entity.getSuccessRefresh().getId(); - when(listRepository.findById(entity.getId())).thenReturn(Optional.of(entity)); + when(listRepository.findByIdAndIsDeletedFalse(entity.getId())).thenReturn(Optional.of(entity)); successRefreshService.accept(entity, recordsCount, new TaskTimer()); assertEquals(entity.getSuccessRefresh().getRecordsCount(), recordsCount);