Commit 354a93db authored by Jonas Waeber's avatar Jonas Waeber

Remove dummy value from being set.

Add some pseudo tests to agent mapper.
parent dc4fcbdb
Pipeline #18479 passed with stage
in 2 minutes and 9 seconds
......@@ -134,14 +134,8 @@ abstract class RecordResource(institutionId: String) : IResource {
) {
val relation = model.createResource()
relation.addProperty(RICO.type, KEYS.relationTypeMap[relationType])
if (relationName.isEmpty()) {
// NOTE: If this constant is changed it needs to be changed in the normalization
// ExtractCreationRelationNameTransform as well.
relation.addProperty(RICO.name, "DUMMY-VALUE")
} else {
relationName.forEach {
relation.addProperty(RICO.name, it)
}
relationName.forEach {
relation.addProperty(RICO.name, it)
}
relation.addProperty(RICO.creationRelationHasSource, resource)
relation.addProperty(RDF.type, RICO.CreationRelation)
......
......@@ -159,7 +159,7 @@ object MapperParsers {
}
}
fun extractAgentTypeMapper(key: String, value: Map<String, Any>): List<AbstractFieldMapper> {
private fun extractAgentTypeMapper(key: String, value: Map<String, Any>): List<AbstractFieldMapper> {
return value.entries.map {
extractEntityFields<AgentFieldMapper>(it.key, it.value as Map<String, Any>, KEYS.allowedAgentProperties)
}.map {
......@@ -193,7 +193,7 @@ object MapperParsers {
}
}
inline fun <reified T : TypeFieldMapper> extractEntityFields(
private inline fun <reified T : TypeFieldMapper> extractEntityFields(
key: String,
value: Map<String, Any>,
validationList: List<String>
......
/*
* mapper-service
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ch.memobase.test
import ch.memobase.builder.Record
import ch.memobase.mapping.MapperParsers
import java.io.FileOutputStream
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestAgentMapper {
private val mapper = MapperParsers.buildAgentMapper(
"creators",
listOf(
mapOf(
Pair(
"person", mapOf(
Pair("name", "creatorPerson.name"),
Pair("relationName", "creatorPerson.relationName")
)
)
)
)
)[0]
private val resourcePath = "src/test/resources/turtleOutput"
// TODO: Actually test this.
@Test
fun `test agent mapper with name only`() {
val source: Map<String, Any> = mapOf(
Pair("creatorPerson", mapOf(Pair("name", "Hans Zimmer")))
)
val record = Record(
"1",
"Foto",
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
)
mapper.apply(source, record)
RDFDataMgr.write(FileOutputStream("$resourcePath/agent-mapper-with-name-only.ttl"), record.model, Lang.TURTLE)
}
// TODO: Actually test this.
@Test
fun `test agent mapper with name and relation`() {
val source: Map<String, Any> = mapOf(
Pair("creatorPerson",
mapOf(Pair("name", "Hans Zimmer"), Pair("relationName", "Author")))
)
val record = Record(
"1",
"Foto",
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
)
mapper.apply(source, record)
RDFDataMgr.write(FileOutputStream("$resourcePath/agent-mapper-with-name-and-relation.ttl"), record.model, Lang.TURTLE)
}
}
package ch.memobase.test
import ch.memobase.mapping.MapperParsers
import ch.memobase.mapping.mappers.AgentFieldMapper
import java.util.function.Consumer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestMapperParseHelpers {
@Test
fun `test extractAgentTypeMapper`() {
val mappers = MapperParsers.buildAgentMapper(
"creators",
listOf(
mapOf(
Pair(
"person", mapOf(
Pair("name", "creatorPerson.name"),
Pair("relationName", "creatorPerson.relationName")
)
)
)
)
)
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
}
val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper)
.satisfies(mapperReqs)
}
// TODO: Test that there is nothing else.
@Test
fun `test extractAgentTypeMapper without relation`() {
val mappers = MapperParsers.buildAgentMapper(
"creators",
listOf(
mapOf(
Pair(
"person", mapOf(
Pair("name", "creatorPerson.name")
)
)
)
)
)
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
}
val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper)
.satisfies(mapperReqs)
}
// TODO: This should fail!
@Test
fun `test extractAgentTypeMapper empty`() {
val mappers = MapperParsers.buildAgentMapper(
"creators",
listOf(
mapOf(
Pair(
"person", emptyMap<String, Any>()
)
)
)
)
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
}
val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper)
.satisfies(mapperReqs)
}
// TODO: This throws an exception. Which needs to be handled. currently it will just fail the program.
@Test
@Disabled
fun `test extractAgentTypeMapper with different property`() {
val mappers = MapperParsers.buildAgentMapper(
"creators",
listOf(
mapOf(
Pair(
"person", mapOf(
Pair("people", "creatorPerson.name")
)
)
)
)
)
val mapperReqs: Consumer<AgentFieldMapper> = Consumer { agentFieldMapper: AgentFieldMapper ->
assertThat(agentFieldMapper.sourceKey).isEqualTo("creators")
assertThat(agentFieldMapper.agentClassType).isEqualTo("person")
assertThat(agentFieldMapper.type).isEqualTo("agent")
}
val mapper = mappers[0] as AgentFieldMapper
assertThat(mapper)
.satisfies(mapperReqs)
}
}
......@@ -20,10 +20,6 @@ package ch.memobase.test
import ch.memobase.builder.Record
import ch.memobase.mapping.MapperParsers
import ch.memobase.mapping.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.mappers.AgentFieldMapper
import ch.memobase.rdf.RDF
import ch.memobase.rdf.RICO
import org.apache.jena.rdf.model.Resource
......@@ -32,46 +28,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestMapperFunctions {
@Test
fun `test agent mapper`() {
val agentMapper = AgentFieldMapper()
agentMapper.setFields(
"creator",
listOf(
DirectMapField("name", "person.name"),
ListField(
"relationName", listOf(
ConstantField("relationName", "Schauspieler"),
ConstantField("relationName", "DUMMY-VALUE")
)
)
)
)
agentMapper.sourceKey = "creators"
val source: Map<String, Any> = mapOf(
Pair("person", Pair("name", "TEST NAME"))
)
val record = Record(
"1",
"Foto",
"rs1",
"ins1",
hasSponsoringAgent = true,
isPublished = false
)
agentMapper.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")
}
}
class TestSkosConceptMapper {
@Test
fun `test skos concept mapper`() {
val skosConceptFieldMapper = MapperParsers.buildSkosConceptMappers("subject",
......
@prefix rdau: <http://rdaregistry.info/Elements/u/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rico: <https://www.ica.org/standards/RiC/ontology#> .
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Hans Zimmer"
] ;
rico:name "Author" ;
rico:type "creator" .
<https://memobase.ch/record/rs1-1>
a rico:Record ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
rico:type "main"
] ;
rico:isPartOf <https://memobase.ch/recordSet/rs1> ;
rico:recordResourceOrInstantiationIsSourceOfCreationRelation
_:b0 ;
rico:type "Foto" .
@prefix rdau: <http://rdaregistry.info/Elements/u/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rico: <https://www.ica.org/standards/RiC/ontology#> .
@prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
_:b0 a rico:CreationRelation ;
rico:creationRelationHasSource <https://memobase.ch/record/rs1-1> ;
rico:creationRelationHasTarget [ a rico:Person ;
rico:agentIsTargetOfCreationRelation
_:b0 ;
rico:name "Hans Zimmer"
] ;
rico:type "creator" .
<https://memobase.ch/record/rs1-1>
a rico:Record ;
rdau:P60451 <https://memobase.ch/institution/mrv> ;
<https://memobase.ch/internal/isPublished>
false ;
rico:heldBy <https://memobase.ch/institution/ins1> ;
rico:identifiedBy [ a rico:Identifier ;
rico:identifier "rs1-1" ;
rico:type "main"
] ;
rico:isPartOf <https://memobase.ch/recordSet/rs1> ;
rico:recordResourceOrInstantiationIsSourceOfCreationRelation
_:b0 ;
rico:type "Foto" .
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