Commit 96e697b1 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add mapper function tests

parent 934ee15b
/*
* 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.fields.ConstantField
import ch.memobase.mapping.fields.DirectMapField
import ch.memobase.mapping.fields.ListField
import ch.memobase.mapping.mappers.AgentFieldMapper
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.rdf.RDF
import org.memobase.rdf.RICO
@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")
}
}
}
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