Commit eb920a7d authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix tests

parent 6d98c20e
Pipeline #16118 passed with stage
in 2 minutes and 29 seconds
...@@ -23,6 +23,7 @@ import ch.memobase.mapping.fields.ConstantField ...@@ -23,6 +23,7 @@ import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.ListField import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.mappers.AgentFieldMapper import ch.memobase.mapping.mappers.AgentFieldMapper
import mapping.MapperParsers
import org.apache.jena.rdf.model.Resource import org.apache.jena.rdf.model.Resource
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
...@@ -70,4 +71,36 @@ class TestMapperFunctions { ...@@ -70,4 +71,36 @@ class TestMapperFunctions {
it.hasProperty(RICO.name, "Schauspieler") && it.hasProperty(RICO.name, "DUMMY-VALUE") it.hasProperty(RICO.name, "Schauspieler") && it.hasProperty(RICO.name, "DUMMY-VALUE")
} }
} }
@Test
fun `test skos concept mapper`() {
val skosConceptFieldMapper = MapperParsers.buildSkosConceptMappers("subject",
listOf(
mapOf(Pair("prefLabel", mapOf(Pair("de", "Schlagworte")))),
mapOf(Pair("editorialNote", mapOf(Pair("const", "Ursprungsfeld: Schlagworte"))))
)
)[0]
val source: Map<String, Any> = mapOf(
Pair("Schlagworte", "Subject 1, Subject 2")
)
val record = Record(
"1",
"Foto",
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
)
skosConceptFieldMapper.apply(source, record)
assertThat(record.model.listSubjectsWithProperty(RDF.type, RICO.CreationRelation).toList())
.asList()
.allMatch {
it as Resource
it.hasProperty(RICO.name, "Schauspieler") && it.hasProperty(RICO.name, "DUMMY-VALUE")
}
}
} }
...@@ -2,21 +2,27 @@ package ch.memobase.test ...@@ -2,21 +2,27 @@ package ch.memobase.test
import ch.memobase.mapping.MappingConfigurationParser import ch.memobase.mapping.MappingConfigurationParser
import ch.memobase.mapping.fields.FieldParsers import ch.memobase.mapping.fields.FieldParsers
import ch.memobase.mapping.mappers.RicoConceptMapper import com.beust.klaxon.Klaxon
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.nio.charset.Charset
import mapping.MapperConfiguration import mapping.MapperConfiguration
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestMappingParser { class TestMappingParser {
private fun readFile(fileName: String): String {
return FileInputStream("src/test/resources/output/$fileName.json").readBytes().toString(Charset.defaultCharset())
}
private val klaxon = Klaxon()
@Test @Test
fun `test minimal mapping parser`() { fun `test minimal mapping parser`() {
val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mappings1/test_mapping.yml")).readBytes()) val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mapping1.yml")).readBytes())
assertThat(mapping.get()) assertThat(mapping.get())
.isEqualTo( .isEqualTo(
MapperConfiguration( MapperConfiguration(
...@@ -32,7 +38,7 @@ class TestMappingParser { ...@@ -32,7 +38,7 @@ class TestMappingParser {
@Test @Test
fun `test sponsor field parser`() { fun `test sponsor field parser`() {
val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mappings2/test_mapping.yml")).readBytes()) val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mapping2.yml")).readBytes())
assertThat(mapping.get()) assertThat(mapping.get())
.isEqualTo( .isEqualTo(
MapperConfiguration( MapperConfiguration(
...@@ -47,20 +53,18 @@ class TestMappingParser { ...@@ -47,20 +53,18 @@ class TestMappingParser {
} }
@Test @Test
@Disabled
fun `test record parser`() { fun `test record parser`() {
// TODO: Find an easy way to compare the field mappers. val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mapping3.yml")).readBytes())
val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mappings3/test_mapping.yml")).readBytes()) val string = klaxon.toJsonString(mapping.get())
assertThat(mapping.get()) assertThat(string)
.isEqualTo( .isEqualTo(readFile("output3"))
MapperConfiguration( }
"TestField",
true, @Test
FieldParsers.parseSimpleAnnotationField("type", mapOf(Pair("const", "Foto"))), fun `test skos field parser`() {
listOf(RicoConceptMapper("main", FieldParsers.parseSimpleAnnotationField("main", "MainID"))), val mapping = MappingConfigurationParser(FileInputStream(File("src/test/resources/mapping4.yml")).readBytes())
emptyList(), val string = klaxon.toJsonString(mapping.get())
emptyList() assertThat(string)
) .isEqualTo(readFile("output4"))
)
} }
} }
record:
uri: id
type:
const: Foto
subject: # blank node skos:Concept with rico:hasSubject
prefLabel:
fr: Schlagworte
editorialNote:
const: "Ursprungsfeld: Mots clés"
genre:
- prefLabel:
fr: Genre
editorialNote:
const: "Ursprungsfeld: Genre"
{"digitalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "annotationFieldType" : "direct", "field" : "MainID", "fieldType" : "direct", "key" : "main", "simpleFieldType" : "direct"}, "rdfType" : "identifiers", "type" : "rico-concept"}], "physicalFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "annotationFieldType" : "direct", "field" : "MainID", "fieldType" : "direct", "key" : "main", "simpleFieldType" : "direct"}, "rdfType" : "identifiers", "type" : "rico-concept"}], "recordFieldMappers" : [{"field" : {"directField" : "MainID", "directKey" : "main", "annotationFieldType" : "direct", "field" : "MainID", "fieldType" : "direct", "key" : "main", "simpleFieldType" : "direct"}, "rdfType" : "identifiers", "type" : "rico-concept"}], "recordType" : {"constant" : "Foto", "key" : "type", "annotationFieldType" : "constant", "fieldType" : "constant", "simpleFieldType" : "constant"}, "sponsoredByMemoriav" : true, "uri" : "TestField"}
\ No newline at end of file
{"digitalFieldMappers" : [], "physicalFieldMappers" : [], "recordFieldMappers" : [{"agentClassType" : "subject", "fields" : [{"fields" : [{"sources" : [{"directField" : "Schlagworte", "directKey" : "prefLabel", "annotationFieldType" : "direct", "field" : "Schlagworte", "fieldType" : "direct", "key" : "prefLabel", "simpleFieldType" : "direct"}], "tag" : "fr"}], "key" : "prefLabel", "annotationFieldType" : "language", "complexAnnotationFieldType" : "language", "fieldType" : "language"}, {"constant" : "Ursprungsfeld: Mots clés", "key" : "editorialNote", "annotationFieldType" : "constant", "fieldType" : "constant", "simpleFieldType" : "constant"}], "type" : "skos-concept"}, {"agentClassType" : "genre", "fields" : [{"fields" : [{"sources" : [{"directField" : "Genre", "directKey" : "prefLabel", "annotationFieldType" : "direct", "field" : "Genre", "fieldType" : "direct", "key" : "prefLabel", "simpleFieldType" : "direct"}], "tag" : "fr"}], "key" : "prefLabel", "annotationFieldType" : "language", "complexAnnotationFieldType" : "language", "fieldType" : "language"}, {"constant" : "Ursprungsfeld: Genre", "key" : "editorialNote", "annotationFieldType" : "constant", "fieldType" : "constant", "simpleFieldType" : "constant"}], "type" : "skos-concept"}], "recordType" : {"constant" : "Foto", "key" : "type", "annotationFieldType" : "constant", "fieldType" : "constant", "simpleFieldType" : "constant"}, "sponsoredByMemoriav" : false, "uri" : "id"}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment