fix(file-move): ensure library monitoring is restored after file move and update tests (#2057)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+5
-1
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.service.file;
|
|||||||
import com.adityachandel.booklore.mapper.BookMapper;
|
import com.adityachandel.booklore.mapper.BookMapper;
|
||||||
import com.adityachandel.booklore.mapper.LibraryMapper;
|
import com.adityachandel.booklore.mapper.LibraryMapper;
|
||||||
import com.adityachandel.booklore.model.dto.FileMoveResult;
|
import com.adityachandel.booklore.model.dto.FileMoveResult;
|
||||||
|
import com.adityachandel.booklore.model.dto.Library;
|
||||||
import com.adityachandel.booklore.model.dto.request.FileMoveRequest;
|
import com.adityachandel.booklore.model.dto.request.FileMoveRequest;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||||
@@ -182,7 +183,10 @@ public class FileMoveService {
|
|||||||
} finally {
|
} finally {
|
||||||
if (isLibraryMonitoredWhenCalled) {
|
if (isLibraryMonitoredWhenCalled) {
|
||||||
log.debug("Registering library paths for library {} with root {}", libraryId, libraryRoot);
|
log.debug("Registering library paths for library {} with root {}", libraryId, libraryRoot);
|
||||||
fileMoveHelper.registerLibraryPaths(libraryId, libraryRoot);
|
LibraryEntity libraryEntity = bookEntity.getLibraryPath().getLibrary();
|
||||||
|
Library library = libraryMapper.toLibrary(libraryEntity);
|
||||||
|
library.setWatch(true);
|
||||||
|
monitoringRegistrationService.registerLibrary(library);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-2
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.service.file;
|
|||||||
import com.adityachandel.booklore.mapper.BookMapper;
|
import com.adityachandel.booklore.mapper.BookMapper;
|
||||||
import com.adityachandel.booklore.mapper.LibraryMapper;
|
import com.adityachandel.booklore.mapper.LibraryMapper;
|
||||||
import com.adityachandel.booklore.model.dto.FileMoveResult;
|
import com.adityachandel.booklore.model.dto.FileMoveResult;
|
||||||
|
import com.adityachandel.booklore.model.dto.Library;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||||
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
||||||
@@ -85,14 +86,30 @@ class FileMoveServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void moveSingleFile_whenLibraryMonitored_reRegistersLibraryPaths() {
|
void moveSingleFile_whenLibraryMonitored_reRegistersLibraryPaths() {
|
||||||
when(monitoringRegistrationService.isLibraryMonitored(42L)).thenReturn(true);
|
when(monitoringRegistrationService.isLibraryMonitored(42L)).thenReturn(true);
|
||||||
|
Library libraryDto = Library.builder().watch(true).build();
|
||||||
|
when(libraryMapper.toLibrary(any(LibraryEntity.class))).thenReturn(libraryDto);
|
||||||
|
|
||||||
FileMoveResult result = fileMoveService.moveSingleFile(bookEntity);
|
FileMoveResult result = fileMoveService.moveSingleFile(bookEntity);
|
||||||
|
|
||||||
assertTrue(result.isMoved());
|
assertTrue(result.isMoved());
|
||||||
|
|
||||||
verify(fileMoveHelper).unregisterLibrary(42L);
|
verify(fileMoveHelper).unregisterLibrary(42L);
|
||||||
Path expectedRoot = Paths.get(bookEntity.getLibraryPath().getPath()).toAbsolutePath().normalize();
|
verify(monitoringRegistrationService).registerLibrary(libraryDto);
|
||||||
verify(fileMoveHelper).registerLibraryPaths(42L, expectedRoot);
|
assertTrue(libraryDto.isWatch());
|
||||||
|
verify(fileMoveHelper, never()).registerLibraryPaths(anyLong(), any(Path.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void moveSingleFile_ensuresLibraryWatchStatusIsRestored() {
|
||||||
|
when(monitoringRegistrationService.isLibraryMonitored(42L)).thenReturn(true);
|
||||||
|
|
||||||
|
Library libraryDto = Library.builder().watch(false).build();
|
||||||
|
when(libraryMapper.toLibrary(any(LibraryEntity.class))).thenReturn(libraryDto);
|
||||||
|
|
||||||
|
fileMoveService.moveSingleFile(bookEntity);
|
||||||
|
|
||||||
|
verify(monitoringRegistrationService).registerLibrary(libraryDto);
|
||||||
|
assertTrue(libraryDto.isWatch(), "Library watch status must be set to true before re-registering");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user