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

Add mapper unit test for AgentFieldMapper

parent b0feaa83
/*
* 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 org.memobase
import org.apache.jena.rdf.model.Resource
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.memobase.builder.Record
import org.memobase.mapping.fields.ConstantField
import org.memobase.mapping.fields.DirectMapField
import org.memobase.mapping.fields.ListField
import org.memobase.mapping.mappers.AgentFieldMapper
import org.memobase.rdf.RDF
import org.memobase.rdf.RICO
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestMappers {
@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", true)
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")
}
}
}
\ No newline at end of file
......@@ -11,4 +11,9 @@ record:
de: person.name
relationName:
de: person.role
- agent:
name: person.name
relationName:
- const: "Schauspieler"
- const: "DUMMY-VALUE"
......@@ -4,23 +4,33 @@
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#recordResourceOrInstantiationIsSourceOfCreationRelation> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#recordResourceOrInstantiationIsSourceOfCreationRelation> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#recordResourceOrInstantiationIsSourceOfCreationRelation> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#type> "Foto" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Agent> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#CorporateBody> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#CreationRelation> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#CreationRelation> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#CreationRelation> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Person> .
_:B <https://www.ica.org/standards/RiC/ontology#agentIsTargetOfCreationRelation> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#agentIsTargetOfCreationRelation> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#agentIsTargetOfCreationRelation> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasSource> <https://memobase.ch/record/TEST-ID_1> .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasSource> <https://memobase.ch/record/TEST-ID_1> .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasSource> <https://memobase.ch/record/TEST-ID_1> .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasTarget> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasTarget> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#creationRelationHasTarget> _:B .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-ID_1" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "DUMMY-VALUE" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Schauspieler" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Test Name" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Test Name" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Test Name"@de .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Test Role" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "Test Role"@de .
_:B <https://www.ica.org/standards/RiC/ontology#type> "creator" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "creator" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "creator" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
Supports Markdown
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