Feat/lubimyczytac metadata provider (#2019)
* feat: add LubimyCzytac metadata provider - Add LubimyCzytac parser with web scraping for lubimyczytac.pl - Extract book metadata including title, authors, description, ratings - Parse JSON-LD structured data for reliable metadata extraction - Add database migration with columns and JSON property name updates - Add comprehensive test coverage for parser * feat: add LubimyCzytac UI integration - Add LC ID and LC Rating fields to metadata picker - Update settings page with Lubimyczytac provider toggle - Add LubimyCzytac to metadata searcher provider list - Display Lubimyczytac in all metadata viewer sections - Add Lubimyczytac to advanced fetch options - Update TypeScript models to match backend serialization
This commit is contained in:
+156
@@ -0,0 +1,156 @@
|
||||
package com.adityachandel.booklore.service.metadata.parser;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataProviderSettings;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class LubimyCzytacParserTest {
|
||||
|
||||
@Mock
|
||||
private AppSettingService appSettingService;
|
||||
|
||||
@InjectMocks
|
||||
private LubimyCzytacParser parser;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchMetadata_ProviderDisabled() {
|
||||
// Given
|
||||
Book book = Book.builder()
|
||||
.title("Test Book")
|
||||
.build();
|
||||
|
||||
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
||||
.title("Test Book")
|
||||
.build();
|
||||
|
||||
// Mock disabled provider
|
||||
AppSettings appSettings = new AppSettings();
|
||||
MetadataProviderSettings providerSettings = new MetadataProviderSettings();
|
||||
MetadataProviderSettings.Lubimyczytac lubimyCzytac = new MetadataProviderSettings.Lubimyczytac();
|
||||
lubimyCzytac.setEnabled(false);
|
||||
providerSettings.setLubimyczytac(lubimyCzytac);
|
||||
appSettings.setMetadataProviderSettings(providerSettings);
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
// When
|
||||
List<BookMetadata> results = parser.fetchMetadata(book, request);
|
||||
|
||||
// Then
|
||||
assertNotNull(results);
|
||||
assertTrue(results.isEmpty(), "Should return empty list when provider is disabled");
|
||||
verify(appSettingService).getAppSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchMetadata_ProviderSettingsNull() {
|
||||
// Given
|
||||
Book book = Book.builder()
|
||||
.title("Test Book")
|
||||
.build();
|
||||
|
||||
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
||||
.title("Test Book")
|
||||
.build();
|
||||
|
||||
// Mock null settings
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataProviderSettings(null);
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
// When
|
||||
List<BookMetadata> results = parser.fetchMetadata(book, request);
|
||||
|
||||
// Then
|
||||
assertNotNull(results);
|
||||
assertTrue(results.isEmpty(), "Should return empty list when settings are null");
|
||||
verify(appSettingService).getAppSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchMetadata_EmptyQuery() {
|
||||
// Given
|
||||
Book book = Book.builder()
|
||||
.title("Test Book")
|
||||
.build();
|
||||
|
||||
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
||||
.build();
|
||||
// Empty query - no title or ISBN
|
||||
|
||||
// Mock enabled provider
|
||||
AppSettings appSettings = new AppSettings();
|
||||
MetadataProviderSettings providerSettings = new MetadataProviderSettings();
|
||||
MetadataProviderSettings.Lubimyczytac lubimyCzytac = new MetadataProviderSettings.Lubimyczytac();
|
||||
lubimyCzytac.setEnabled(true);
|
||||
providerSettings.setLubimyczytac(lubimyCzytac);
|
||||
appSettings.setMetadataProviderSettings(providerSettings);
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
// When
|
||||
List<BookMetadata> results = parser.fetchMetadata(book, request);
|
||||
|
||||
// Then
|
||||
assertNotNull(results);
|
||||
assertTrue(results.isEmpty(), "Should return empty list when query is empty");
|
||||
verify(appSettingService).getAppSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("Integration test - requires network access to LubimyCzytac.pl")
|
||||
void testFetchMetadata_Integration_RealBook() {
|
||||
// Given
|
||||
Book book = Book.builder()
|
||||
.title("Wiedźmin")
|
||||
.build();
|
||||
|
||||
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
||||
.title("Wiedźmin")
|
||||
.author("Andrzej Sapkowski")
|
||||
.build();
|
||||
|
||||
// Mock enabled provider
|
||||
AppSettings appSettings = new AppSettings();
|
||||
MetadataProviderSettings providerSettings = new MetadataProviderSettings();
|
||||
MetadataProviderSettings.Lubimyczytac lubimyCzytac = new MetadataProviderSettings.Lubimyczytac();
|
||||
lubimyCzytac.setEnabled(true);
|
||||
providerSettings.setLubimyczytac(lubimyCzytac);
|
||||
appSettings.setMetadataProviderSettings(providerSettings);
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
// When
|
||||
List<BookMetadata> results = parser.fetchMetadata(book, request);
|
||||
|
||||
// Then
|
||||
assertNotNull(results);
|
||||
assertFalse(results.isEmpty(), "Should return results for real book");
|
||||
|
||||
BookMetadata firstResult = results.get(0);
|
||||
assertNotNull(firstResult.getTitle(), "Title should be present");
|
||||
assertNotNull(firstResult.getLubimyczytacId(), "LubimyCzytac ID should be present");
|
||||
assertTrue(firstResult.getAuthors() != null && !firstResult.getAuthors().isEmpty(),
|
||||
"Authors should be present");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user