Skip to content

Commit 67c9047

Browse files
committed
Fixed not updating the comic state after batch scraping [#2447]
1 parent e1277de commit 67c9047

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

comixed-batch/src/main/java/org/comixedproject/batch/comicbooks/ScrapeMetadataConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.comixedproject.batch.comicbooks.listeners.ScrapeMetadataJobListener;
2424
import org.comixedproject.batch.comicbooks.processors.ScrapeMetadataProcessor;
2525
import org.comixedproject.batch.comicbooks.readers.ScrapeMetadataReader;
26-
import org.comixedproject.batch.writers.NoopWriter;
26+
import org.comixedproject.batch.comicbooks.writers.ScrapeMetadataWriter;
2727
import org.comixedproject.model.comicbooks.ComicBook;
2828
import org.springframework.batch.core.Job;
2929
import org.springframework.batch.core.Step;
@@ -92,7 +92,7 @@ public Step scrapeMetadataStep(
9292
final PlatformTransactionManager platformTransactionManager,
9393
final ScrapeMetadataReader reader,
9494
final ScrapeMetadataProcessor processor,
95-
final NoopWriter<ComicBook> writer,
95+
final ScrapeMetadataWriter writer,
9696
final ScrapeMetadataChunkListener chunkListener) {
9797
return new StepBuilder("scrapeMetadataStep", jobRepository)
9898
.<ComicBook, ComicBook>chunk(this.chunkSize, platformTransactionManager)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* ComiXed - A digital comic book library management application.
3+
* Copyright (C) 2025, The ComiXed Project
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses>
17+
*/
18+
19+
package org.comixedproject.batch.comicbooks.writers;
20+
21+
import lombok.extern.log4j.Log4j2;
22+
import org.comixedproject.state.comicbooks.ComicEvent;
23+
import org.springframework.batch.core.configuration.annotation.StepScope;
24+
import org.springframework.stereotype.Component;
25+
26+
/**
27+
* <code>ScrapeMetadataWriter</code> writes the comic books after they have been batch scraped.
28+
*
29+
* @author Darryl L. Pierce
30+
*/
31+
@Component
32+
@StepScope
33+
@Log4j2
34+
public class ScrapeMetadataWriter extends AbstractComicBookWriter {
35+
public ScrapeMetadataWriter() {
36+
super(ComicEvent.metadataUpdated);
37+
}
38+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* ComiXed - A digital comic book library management application.
3+
* Copyright (C) 2025, The ComiXed Project
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses>
17+
*/
18+
19+
package org.comixedproject.batch.comicbooks.writers;
20+
21+
import java.util.ArrayList;
22+
import org.comixedproject.model.comicbooks.ComicBook;
23+
import org.comixedproject.state.comicbooks.ComicEvent;
24+
import org.comixedproject.state.comicbooks.ComicStateHandler;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.extension.ExtendWith;
27+
import org.mockito.InjectMocks;
28+
import org.mockito.Mock;
29+
import org.mockito.Mockito;
30+
import org.mockito.junit.jupiter.MockitoExtension;
31+
import org.springframework.batch.item.Chunk;
32+
33+
@ExtendWith(MockitoExtension.class)
34+
class ScrapeMetadataWriterTest {
35+
@InjectMocks private ScrapeMetadataWriter writer;
36+
@Mock private ComicStateHandler comicStateHandler;
37+
@Mock private ComicBook comicBook;
38+
39+
private Chunk<ComicBook> comicBookList = new Chunk<>(new ArrayList<>());
40+
41+
@Test
42+
void write() {
43+
for (int index = 0; index < 25; index++) comicBookList.add(comicBook);
44+
45+
writer.write(comicBookList);
46+
47+
Mockito.verify(comicStateHandler, Mockito.times(comicBookList.size()))
48+
.fireEvent(comicBook, ComicEvent.metadataUpdated);
49+
}
50+
}

0 commit comments

Comments
 (0)