chore: drop chapter cache service (#2773)

This commit is contained in:
James Ward
2026-10-01 19:20:18 -06:00
committed by GitHub
parent 003345b07c
commit 84a6097f8a
7 changed files with 2 additions and 381 deletions
@@ -11,10 +11,8 @@ import org.booklore.service.metadata.writer.CbxMetadataWriter;
import org.booklore.service.reader.CbxReaderService;
import org.booklore.repository.BookRepository;
import org.booklore.service.appsettings.AppSettingService;
import org.booklore.service.reader.ChapterCacheService;
import org.booklore.util.FileUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -66,13 +64,12 @@ class Rar5IntegrationTest {
book.setId(99L);
BookRepository mockRepo = Mockito.mock(BookRepository.class);
Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(Optional.of(book));
ChapterCacheService mockCache = Mockito.mock(ChapterCacheService.class);
try (var fileUtilsStatic = Mockito.mockStatic(FileUtils.class)) {
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(book))
.thenReturn(cbrCopy);
CbxReaderService readerService = new CbxReaderService(mockRepo, new ArchiveService(), mockCache);
CbxReaderService readerService = new CbxReaderService(mockRepo, new ArchiveService());
List<Integer> pages = readerService.getAvailablePages(99L);
assertThat(pages).hasSize(3);
@@ -89,7 +86,6 @@ class Rar5IntegrationTest {
book.setId(99L);
BookRepository mockRepo = Mockito.mock(BookRepository.class);
Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(Optional.of(book));
ChapterCacheService mockCache = Mockito.mock(ChapterCacheService.class);
try (
var fileUtilsStatic = Mockito.mockStatic(FileUtils.class)
@@ -97,7 +93,7 @@ class Rar5IntegrationTest {
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(book))
.thenReturn(cbrCopy);
CbxReaderService readerService = new CbxReaderService(mockRepo, new ArchiveService(), mockCache);
CbxReaderService readerService = new CbxReaderService(mockRepo, new ArchiveService());
ByteArrayOutputStream out = new ByteArrayOutputStream();
readerService.streamPageImage(99L, 1, out);
@@ -32,15 +32,9 @@ class CbxReaderServiceTest {
@Mock
ArchiveService archiveService;
@Mock
ChapterCacheService chapterCacheService;
@InjectMocks
CbxReaderService cbxReaderService;
@Captor
ArgumentCaptor<Long> longCaptor;
BookEntity bookEntity;
Path cbzPath;
@@ -69,8 +63,6 @@ class CbxReaderServiceTest {
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
filesStatic.when(() -> Files.getLastModifiedTime(cbzPath)).thenReturn(FileTime.from(Instant.now()));
cbxReaderService.initCache(1L, null);
List<Integer> pages = cbxReaderService.getAvailablePages(1L);
assertEquals(List.of(1), pages);
}
@@ -90,8 +82,6 @@ class CbxReaderServiceTest {
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
filesStatic.when(() -> Files.getLastModifiedTime(cbzPath)).thenReturn(FileTime.from(Instant.now()));
cbxReaderService.initCache(1L, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
cbxReaderService.streamPageImage(1L, 1, out);
assertArrayEquals(new byte[]{1, 2, 3}, out.toByteArray());
@@ -109,8 +99,6 @@ class CbxReaderServiceTest {
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
filesStatic.when(() -> Files.getLastModifiedTime(cbzPath)).thenReturn(FileTime.from(Instant.now()));
cbxReaderService.initCache(1L, null);
assertThrows(
FileNotFoundException.class,
() -> cbxReaderService.streamPageImage(1L, 2, new ByteArrayOutputStream())
@@ -144,13 +132,4 @@ class CbxReaderServiceTest {
);
assertTrue(ex.getMessage().contains("Invalid book type"), "Expected INVALID_INPUT, got: " + ex.getMessage());
}
@Test
void testInitCache_InvalidBookType_Throws() {
when(bookRepository.findByIdForStreaming(1L)).thenReturn(Optional.of(bookEntity));
APIException ex = assertThrows(APIException.class, () ->
cbxReaderService.initCache(1L, "../traversal")
);
assertTrue(ex.getMessage().contains("Invalid book type"), "Expected INVALID_INPUT, got: " + ex.getMessage());
}
}
@@ -1,54 +0,0 @@
package org.booklore.service.reader;
import org.booklore.config.AppProperties;
import org.booklore.service.ArchiveService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.booklore.exception.APIException;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ChapterCacheServiceTest {
@Mock
private AppProperties appProperties;
@Mock
private ArchiveService archiveService;
private ChapterCacheService chapterCacheService;
@BeforeEach
void setUp() {
chapterCacheService = new ChapterCacheService(appProperties, archiveService);
}
@Test
void getCachedPage_withTraversal_throwsException() {
assertThrows(APIException.class, () ->
chapterCacheService.getCachedPage("../outside", 1)
);
}
@Test
void getCachedPage_withPathSeparator_throwsException() {
assertThrows(APIException.class, () ->
chapterCacheService.getCachedPage("sub/folder", 1)
);
}
@Test
void hasPage_withTraversal_throwsException() {
assertThrows(APIException.class, () ->
chapterCacheService.hasPage("../outside", 1)
);
}
}
@@ -31,20 +31,15 @@ class PdfReaderServiceTest {
@Mock
private BookRepository bookRepository;
@Mock
private ChapterCacheService chapterCacheService;
@InjectMocks
private PdfReaderService pdfReaderService;
private BookEntity bookEntity;
private Path pdfPath;
@BeforeEach
void setup() {
bookEntity = new BookEntity();
bookEntity.setId(1L);
pdfPath = Path.of("/tmp/test.pdf");
}
@Test
@@ -55,13 +50,4 @@ class PdfReaderServiceTest {
);
assertTrue(ex.getMessage().contains("Invalid book type"), "Expected INVALID_INPUT, got: " + ex.getMessage());
}
@Test
void testInitCache_InvalidBookType_Throws() {
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
APIException ex = assertThrows(APIException.class, () ->
pdfReaderService.initCache(1L, "../traversal")
);
assertTrue(ex.getMessage().contains("Invalid book type"), "Expected INVALID_INPUT, got: " + ex.getMessage());
}
}