-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MET-6199 add coverage unit tests part 1
- Loading branch information
1 parent
8472654
commit a0f3a13
Showing
5 changed files
with
363 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...t/java/eu/europeana/metis/sandbox/service/debias/RecordPublishDeBiasQueueServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package eu.europeana.metis.sandbox.service.debias; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import eu.europeana.metis.sandbox.common.locale.Country; | ||
import eu.europeana.metis.sandbox.common.locale.Language; | ||
import eu.europeana.metis.sandbox.domain.Record; | ||
import eu.europeana.metis.sandbox.domain.RecordInfo; | ||
import eu.europeana.metis.sandbox.domain.RecordProcessEvent; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.amqp.AmqpException; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RecordPublishDeBiasQueueServiceTest { | ||
|
||
@Mock | ||
private AmqpTemplate amqpTemplate; | ||
|
||
private RecordPublishDeBiasQueueService service; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
service = new RecordPublishDeBiasQueueService(amqpTemplate, "deBiasReadyQueue"); | ||
} | ||
|
||
@Test | ||
void publishToDeBiasQueue() { | ||
var testRecord = Record.builder() | ||
.datasetId("1") | ||
.datasetName("") | ||
.recordId(1L) | ||
.europeanaId("1") | ||
.country(Country.NETHERLANDS) | ||
.language(Language.NL) | ||
.content("content".getBytes()) | ||
.build(); | ||
service.publishToDeBiasQueue(new RecordInfo(testRecord)); | ||
verify(amqpTemplate, times(1)) | ||
.convertAndSend(eq("deBiasReadyQueue"), any(RecordProcessEvent.class)); | ||
} | ||
|
||
@Test | ||
void publishToDeBiasQueueException() { | ||
doThrow(new AmqpException("error in queue")).when(amqpTemplate).convertAndSend(eq("deBiasReadyQueue"), any(RecordProcessEvent.class)); | ||
var testRecord = Record.builder() | ||
.datasetId("1") | ||
.datasetName("") | ||
.recordId(1L) | ||
.europeanaId("1") | ||
.country(Country.NETHERLANDS) | ||
.language(Language.NL) | ||
.content("content".getBytes()) | ||
.build(); | ||
service.publishToDeBiasQueue(new RecordInfo(testRecord)); | ||
verify(amqpTemplate, times(1)) | ||
.convertAndSend(eq("deBiasReadyQueue"), any(RecordProcessEvent.class)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/test/java/eu/europeana/metis/sandbox/service/workflow/DeBiasProcessServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package eu.europeana.metis.sandbox.service.workflow; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import eu.europeana.metis.debias.detect.client.DeBiasClient; | ||
import eu.europeana.metis.sandbox.common.TestUtils; | ||
import eu.europeana.metis.sandbox.common.locale.Country; | ||
import eu.europeana.metis.sandbox.common.locale.Language; | ||
import eu.europeana.metis.sandbox.domain.Record; | ||
import eu.europeana.metis.sandbox.repository.RecordLogRepository; | ||
import eu.europeana.metis.sandbox.repository.RecordRepository; | ||
import eu.europeana.metis.sandbox.repository.debias.DatasetDeBiasRepository; | ||
import eu.europeana.metis.sandbox.repository.debias.RecordDeBiasDetailRepository; | ||
import eu.europeana.metis.sandbox.repository.debias.RecordDeBiasMainRepository; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DeBiasProcessServiceImplTest { | ||
|
||
@Mock | ||
DeBiasClient deBiasClient; | ||
@Mock | ||
RecordDeBiasMainRepository recordDeBiasMainRepository; | ||
@Mock | ||
RecordDeBiasDetailRepository recordDeBiasDetailRepository; | ||
@Mock | ||
DatasetDeBiasRepository datasetDeBiasRepository; | ||
@Mock | ||
RecordLogRepository recordLogRepository; | ||
@Mock | ||
RecordRepository recordRepository; | ||
|
||
@InjectMocks | ||
DeBiasProcessServiceImpl deBiasProcessService; | ||
|
||
@Test | ||
void processSuccess() throws IOException { | ||
String testRecord1 = new TestUtils().readFileToString("record"+ File.separator+"debias"+File.separator+"debias-text-record.xml"); | ||
String testRecord2 = new TestUtils().readFileToString("record"+ File.separator+"debias"+File.separator+"debias-video-record.xml"); | ||
var testRecords = List.of( | ||
Record.builder() | ||
.recordId(1L) | ||
.europeanaId("europeanaId1") | ||
.content(testRecord1.getBytes(StandardCharsets.UTF_8)) | ||
.language(Language.NL).country(Country.NETHERLANDS) | ||
.datasetName("datasetName") | ||
.datasetId("1") | ||
.build(), | ||
Record.builder() | ||
.recordId(2L) | ||
.europeanaId("europeanaId2") | ||
.content(testRecord2.getBytes()) | ||
.language(Language.NL).country(Country.NETHERLANDS) | ||
.datasetName("datasetName") | ||
.datasetId("1") | ||
.build()); | ||
|
||
deBiasProcessService.process(testRecords); | ||
|
||
verify(deBiasClient,times(5)).detect(any()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<rdf:RDF | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:dcterms="http://purl.org/dc/terms/" | ||
xmlns:edm="http://www.europeana.eu/schemas/edm/" | ||
xmlns:ore="http://www.openarchives.org/ore/terms/" | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns:skos="http://www.w3.org/2004/02/skos/core#" | ||
> | ||
<edm:ProvidedCHO rdf:about="/352/_nnhSX08"/> | ||
<edm:WebResource rdf:about="http://mbc.malopolska.pl/Content/48386/d2j:big,0/0437_0001.djvu.jpg"> | ||
<edm:rights rdf:resource="http://rightsstatements.org/vocab/InC/1.0/"/> | ||
</edm:WebResource> | ||
<edm:TimeSpan rdf:about="#1923"> | ||
<skos:prefLabel xml:lang="zxx">1923</skos:prefLabel> | ||
<dcterms:isPartOf rdf:resource="http://data.europeana.eu/timespan/20"/> | ||
<edm:begin>1923-01-01</edm:begin> | ||
<edm:end>1923-12-31</edm:end> | ||
<skos:notation rdf:datatype="http://id.loc.gov/datatypes/edtf/EDTF-level1">1923</skos:notation> | ||
</edm:TimeSpan> | ||
<ore:Aggregation rdf:about="/aggregation/provider/352/_nnhSX08"> | ||
<edm:aggregatedCHO rdf:resource="/352/_nnhSX08"/> | ||
<edm:dataProvider>Małopolska Biblioteka Cyfrowa</edm:dataProvider> | ||
<edm:isShownAt rdf:resource="http://fbc.pionier.net.pl/id/oai:mbc.malopolska.pl:48386"/> | ||
<edm:object rdf:resource="http://mbc.malopolska.pl/Content/48386/d2j:big,0/0437_0001.djvu.jpg"/> | ||
<edm:provider>Federacja Bibliotek Cyfrowych</edm:provider> | ||
<edm:rights rdf:resource="http://rightsstatements.org/vocab/InC/1.0/"/> | ||
</ore:Aggregation> | ||
<ore:Proxy rdf:about="/proxy/provider/352/_nnhSX08"> | ||
<dc:contributor xml:lang="pl">Beaupre, Antoni.(Red.)</dc:contributor> | ||
<dc:date xml:lang="pl">1923</dc:date> | ||
<dc:description xml:lang="pl">Pan i niewolnik Wojewódzka Biblioteka Publiczna w Krakowie dla ludzkości</dc:description> | ||
<dc:description xml:lang="en">Master and slave Provincial Public Library in Krakow</dc:description> | ||
<dc:description xml:lang="de">Herr und Sklave Öffentliche Provinzbibliothek in Krakau für die Menschheit</dc:description> | ||
<dc:description xml:lang="it">Biblioteca pubblica provinciale del padrone e dello schiavo di Cracovia per l'umanità | ||
</dc:description> | ||
<dc:description xml:lang="fr">Bibliothèque publique provinciale Maître et esclave de Cracovie pour l'humanité</dc:description> | ||
<dc:description xml:lang="nl">Meester en slaaf Provinciale Openbare Bibliotheek in Krakau voor de mensheid</dc:description> | ||
<dc:format>image/vnd.djvu</dc:format> | ||
<dc:language>pol</dc:language> | ||
<dc:publisher xml:lang="pl">Spółka Wydawnicza "Czas"</dc:publisher> | ||
<dc:rights xml:lang="pl">Biblioteka Książąt Czartoryskich</dc:rights> | ||
<dc:subject xml:lang="pl">20 w.</dc:subject> | ||
<dc:subject xml:lang="pl">gazety polskie</dc:subject> | ||
<dc:title xml:lang="pl">Czas. 1923, nr 251 (10 XI)</dc:title> | ||
<dc:type xml:lang="pl">czasopismo</dc:type> | ||
|
||
<dcterms:extent>Dziennik polityczny i literacko-społeczny; organ konserwatystów. - Opis fiz.: 4 s. ; 61 cm.</dcterms:extent> | ||
<edm:europeanaProxy>false</edm:europeanaProxy> | ||
<ore:proxyFor rdf:resource="/352/_nnhSX08"/> | ||
<ore:proxyIn rdf:resource="/aggregation/provider/352/_nnhSX08"/> | ||
<edm:type>TEXT</edm:type> | ||
</ore:Proxy> | ||
<ore:Proxy rdf:about="/proxy/europeana/352/_nnhSX08"> | ||
<dc:date rdf:resource="#1923"/> | ||
<dc:identifier>#nnhSX08</dc:identifier> | ||
<dc:language>pl</dc:language> | ||
<edm:europeanaProxy>true</edm:europeanaProxy> | ||
<ore:proxyFor rdf:resource="/352/_nnhSX08"/> | ||
<ore:proxyIn rdf:resource="/aggregation/europeana/352/_nnhSX08"/> | ||
<ore:lineage rdf:resource="/proxy/provider/352/_nnhSX08"/> | ||
</ore:Proxy> | ||
<edm:EuropeanaAggregation rdf:about="/aggregation/europeana/352/_nnhSX08"> | ||
<edm:aggregatedCHO rdf:resource="/352/_nnhSX08"/> | ||
<edm:dataProvider xml:lang="en">Europeana Foundation</edm:dataProvider> | ||
<edm:provider xml:lang="en">Europeana Foundation</edm:provider> | ||
<edm:datasetName>352_local_23102024_1633</edm:datasetName> | ||
<edm:country>Netherlands</edm:country> | ||
<edm:language>nl</edm:language> | ||
</edm:EuropeanaAggregation> | ||
</rdf:RDF> |
Oops, something went wrong.