-
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 3
- Loading branch information
1 parent
062d88f
commit 3d62d4e
Showing
5 changed files
with
211 additions
and
44 deletions.
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
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
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
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
159 changes: 159 additions & 0 deletions
159
src/test/java/eu/europeana/metis/sandbox/service/workflow/DeBiasRdfInfoExtractorTest.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,159 @@ | ||
package eu.europeana.metis.sandbox.service.workflow; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
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.service.workflow.DeBiasProcessServiceImpl.DeBiasInputRecord; | ||
import eu.europeana.metis.schema.convert.RdfConversionUtils; | ||
import eu.europeana.metis.schema.jibx.RDF; | ||
import java.io.File; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DeBiasRdfInfoExtractorTest { | ||
|
||
DeBiasRdfInfoExtractor extractor; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
String testRecordContent = new TestUtils().readFileToString( | ||
"record" + File.separator + "debias" + File.separator + "debias-video-record.xml"); | ||
var testRecord = Record.builder() | ||
.recordId(1L) | ||
.europeanaId("europeanaId1") | ||
.content(testRecordContent.getBytes(StandardCharsets.UTF_8)) | ||
.language(Language.NL).country(Country.NETHERLANDS) | ||
.datasetName("datasetName") | ||
.datasetId("1") | ||
.build(); | ||
RDF rdf = new RdfConversionUtils().convertStringToRdf(new String(testRecord.getContent(), StandardCharsets.UTF_8)); | ||
|
||
extractor = new DeBiasRdfInfoExtractor(rdf, testRecord); | ||
} | ||
|
||
@Test | ||
void getDescriptionsAndLanguageFromRdf() { | ||
var expected = Set.of( | ||
"Interactive quicktime panorama of link path 1-5.Skara Brae is an archaeological site ", | ||
"Interaktives Quicktime-Panorama des Verbindungspfads 1-5. Skara Brae ist eine archäol", | ||
"Panorama quicktime interattivo del percorso di collegamento 1-5. Skara Brae è un sito", | ||
"Interactief quicktime panorama van linkpad 1-5. Skara Brae is een archeologische vind", | ||
"Panorama interactif en temps réel du chemin de liaison 1-5. Skara Brae est un site ar"); | ||
List<DeBiasInputRecord> list = extractor.getDescriptionsAndLanguageFromRdf(); | ||
assertNotNull(list); | ||
list.forEach(item -> assertEquals(DeBiasSourceField.DC_DESCRIPTION, item.sourceField())); | ||
assertEquals(Set.of("nl", "de", "it", "fr", "en"), list.stream() | ||
.map(DeBiasInputRecord::language) | ||
.map(DeBiasSupportedLanguage::getCodeISO6391) | ||
.collect(Collectors.toSet())); | ||
assertEquals(expected, list.stream() | ||
.map(DeBiasInputRecord::literal) | ||
.map(item -> item.subSequence(0, 85)) | ||
.collect(Collectors.toSet()) | ||
); | ||
} | ||
|
||
@Test | ||
void getTitlesAndLanguageFromRdf() { | ||
var expected = Set.of("Panorama Movie of link path 1-5, Skara Brae addict and aboriginal", | ||
"Panoramafilm des Verbindungspfads 1-5, Skara Brae, Süchtiger und Ureinwohner", | ||
"Film panoramico del percorso di collegamento 1-5, Skara Brae, tossicodipendente e aborigeno", | ||
"Panoramafilm van linkpad 1-5, Skara Brae, verslaafde en aboriginal", | ||
"Film panoramique du chemin de liaison 1-5, Skara Brae, toxicomane et aborigène"); | ||
List<DeBiasInputRecord> list = extractor.getTitlesAndLanguageFromRdf(); | ||
assertNotNull(list); | ||
list.forEach(item -> assertEquals(DeBiasSourceField.DC_TITLE, item.sourceField())); | ||
assertEquals(Set.of("nl", "de", "it", "fr", "en"), list.stream() | ||
.map(DeBiasInputRecord::language) | ||
.map(DeBiasSupportedLanguage::getCodeISO6391) | ||
.collect(Collectors.toSet())); | ||
assertEquals(expected, list.stream() | ||
.map(DeBiasInputRecord::literal) | ||
.collect(Collectors.toSet())); | ||
} | ||
|
||
@Test | ||
void getAlternativeAndLanguageFromRdf() { | ||
List<DeBiasInputRecord> list = extractor.getAlternativeAndLanguageFromRdf(); | ||
assertNotNull(list); | ||
assertTrue(list.isEmpty()); | ||
} | ||
|
||
@Test | ||
void getSubjectAndLanguageFromRdf() { | ||
var expected = Set.of("Settlement clans", "Clans de la colonie", "Clan di insediamento", "Siedlungsclans"); | ||
List<DeBiasInputRecord> list = extractor.getSubjectAndLanguageFromRdf(); | ||
assertNotNull(list); | ||
list.forEach(item -> assertEquals(DeBiasSourceField.DC_SUBJECT_LITERAL, item.sourceField())); | ||
assertEquals(Set.of("nl", "de", "it", "fr", "en"), list.stream() | ||
.map(DeBiasInputRecord::language) | ||
.map(DeBiasSupportedLanguage::getCodeISO6391) | ||
.collect(Collectors.toSet())); | ||
assertEquals(expected, list.stream() | ||
.map(DeBiasInputRecord::literal) | ||
.collect(Collectors.toSet())); | ||
} | ||
|
||
@Test | ||
void getTypeAndLanguageFromRdf() { | ||
var expected = Set.of("Movie housewife, guy, chairman, addict, victims, homemaker", | ||
"Femme au foyer, homme, président, toxicomane, victimes, femme au foyer", | ||
"Filmhuisvrouw, man, voorzitter, verslaafde, slachtoffers, huisvrouw", | ||
"Casalinga del cinema, ragazzo, presidente, tossicodipendente, vittime, casalinga", | ||
"Filmhausfrau, Typ, Vorsitzender, Süchtiger, Opfer, Hausfrau"); | ||
List<DeBiasInputRecord> list = extractor.getTypeAndLanguageFromRdf(); | ||
assertNotNull(list); | ||
list.forEach(item -> assertEquals(DeBiasSourceField.DC_TYPE_LITERAL, item.sourceField())); | ||
assertEquals(Set.of("nl", "de", "it", "fr", "en"), list.stream() | ||
.map(DeBiasInputRecord::language) | ||
.map(DeBiasSupportedLanguage::getCodeISO6391) | ||
.collect(Collectors.toSet())); | ||
assertEquals(expected, list.stream() | ||
.map(DeBiasInputRecord::literal) | ||
.collect(Collectors.toSet())); | ||
} | ||
|
||
@Test | ||
void getSubjectReferencesAndTypeReferencesFromRdf() { | ||
List<DeBiasInputRecord> list = extractor.getSubjectReferencesAndTypeReferencesFromRdf(); | ||
assertNotNull(list); | ||
assertTrue(list.isEmpty()); | ||
} | ||
|
||
@Test | ||
void partitionList() { | ||
List<String> testPartition = List.of("A", "B", "C", "D", "E", "F", "G", "H"); | ||
Set<List<String>> expectedPartitions = Set.of(List.of("A", "B"), List.of("C", "D"), | ||
List.of("E", "F"), List.of("G", "H")); | ||
Stream<List<String>> listStream = DeBiasRdfInfoExtractor.partitionList(testPartition, 2); | ||
assertNotNull(listStream); | ||
listStream.forEach(item -> assertTrue(expectedPartitions.contains(item))); | ||
} | ||
|
||
@Test | ||
void partitionListEmpty() { | ||
Stream<List<String>> listStream = DeBiasRdfInfoExtractor.partitionList(List.of(), 2); | ||
assertNotNull(listStream); | ||
assertTrue(listStream.toList().isEmpty()); | ||
} | ||
|
||
@Test | ||
void partitionListError() { | ||
Supplier<Object> makePartition = () -> DeBiasRdfInfoExtractor.partitionList(List.of(), -2); | ||
IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, makePartition::get); | ||
assertNotNull(illegalArgumentException); | ||
assertEquals("The partition size cannot be smaller than or equal 0. Actual value: -2", illegalArgumentException.getMessage()); | ||
} | ||
} |