feat(metadata): RanobeDB search improvements (#1804)

Co-authored-by: James Ward <james@notjam.es>
This commit is contained in:
NichaesMol
2026-07-18 08:01:56 +00:00
committed by GitHub
co-authored by James Ward
parent fbd1d5e30a
commit b68e022fc0
10 changed files with 303 additions and 74 deletions
@@ -10,19 +10,65 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import tools.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.net.http.HttpClient;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class RanobeDbParserTest {
@Spy
private ObjectMapper objectMapper = new ObjectMapper();
@Mock
private AppSettingService appSettingService;
@Mock
private HttpClient httpClient;
@InjectMocks
private RanobeDbParser parser;
@SuppressWarnings("unchecked")
private HttpResponse<String> getResponse(int statusCode, String payload) {
HttpResponse<String> mockResponse = mock(HttpResponse.class);
when(mockResponse.statusCode()).thenReturn(statusCode);
when(mockResponse.body()).thenReturn(payload);
return mockResponse;
}
private void mockResponse(String uri, int statusCode, String payload) throws IOException, InterruptedException {
HttpResponse<String> response = getResponse(statusCode, payload);
when(
httpClient.<String>send(
argThat(arg -> arg != null && arg.uri().toString().contains(uri)),
any()
)
).thenReturn(response);
}
private String readFixture(String fixtureName) throws IOException {
String filename = "ranobedb/" + fixtureName + ".fixture";
try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) {
assert is != null;
return new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
}
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
@@ -48,16 +94,19 @@ class RanobeDbParserTest {
}
@Test
@Disabled("Integration test - requires network access to RanobeDB.org")
void testFetchMetadata_Integration_RealBook() {
void testFetchMetadata_Integration_RealBook() throws Exception {
mockResponse("/books", 200, readFixture("books.json"));
mockResponse("/book/", 200, readFixture("book.json"));
mockResponse("/staff", 200, readFixture("staff.json"));
// Given
Book book = Book.builder()
.title("That Time I Got Reincarnated as a Slime, Vol. 1")
.title("seishun buta yarou")
.build();
FetchMetadataRequest request = FetchMetadataRequest.builder()
.title("That Time I Got Reincarnated as a Slime, Vol. 1")
.author("Fuse")
.title("seishun buta yarou")
.author("Kamoshida Hajime")
.build();
// When
File diff suppressed because one or more lines are too long
@@ -0,0 +1,27 @@
{
"books":[
{
"id":47136,
"image_id":47609,
"lang":"en",
"romaji":null,
"romaji_orig":"Seishun Buta Yarou wa Beach Queen no Yume o Minai+",
"title":"Rascal Does Not Dream of a Beach Queen +",
"title_orig":"青春ブタ野郎はビーチクイーンの夢を見ない+",
"c_release_date":20250710,
"olang":"ja",
"image":{
"id":47609,
"width":220,
"height":312,
"spoiler":true,
"nsfw":false,
"filename":"xUJgJ0V2i98PwYrx.jpg"
},
"sim_score":1
}
],
"count":"1",
"currentPage":1,
"totalPages":1
}
@@ -0,0 +1 @@
{"staff":[{"id":961,"name":"鴨志田一","romaji":"Kamoshida Hajime","sim_score":1}],"count":"1","currentPage":1,"totalPages":1}