1
0
Fork 0

Added assertion on CrossrefMappingTest

This commit is contained in:
sandro.labruzzo 2024-11-20 09:50:09 +01:00
parent a1297082e2
commit 496007188a
1 changed files with 15 additions and 2 deletions

View File

@ -3,12 +3,15 @@ package eu.dnetlib.dhp.collection.crossref
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import eu.dnetlib.dhp.aggregation.AbstractVocabularyTest import eu.dnetlib.dhp.aggregation.AbstractVocabularyTest
import eu.dnetlib.dhp.collection.crossref.Crossref2Oaf.TransformationType import eu.dnetlib.dhp.collection.crossref.Crossref2Oaf.TransformationType
import eu.dnetlib.dhp.schema.oaf.Publication
import org.apache.commons.io.IOUtils import org.apache.commons.io.IOUtils
import org.junit.jupiter.api.{BeforeEach, Test} import org.junit.jupiter.api.{Assertions, BeforeEach, Test}
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.junit.jupiter.MockitoExtension import org.mockito.junit.jupiter.MockitoExtension
import org.slf4j.{Logger, LoggerFactory} import org.slf4j.{Logger, LoggerFactory}
import scala.collection.JavaConverters.asScalaBufferConverter
@ExtendWith(Array(classOf[MockitoExtension])) @ExtendWith(Array(classOf[MockitoExtension]))
class CrossrefMappingTest extends AbstractVocabularyTest { class CrossrefMappingTest extends AbstractVocabularyTest {
@ -26,7 +29,7 @@ class CrossrefMappingTest extends AbstractVocabularyTest {
IOUtils.toString(getClass.getResourceAsStream("/eu/dnetlib/dhp/collection/crossref/issn_pub.json"), "utf-8") IOUtils.toString(getClass.getResourceAsStream("/eu/dnetlib/dhp/collection/crossref/issn_pub.json"), "utf-8")
Crossref2Oaf.convert(input, vocabularies, TransformationType.All).foreach(record => { Crossref2Oaf.convert(input, vocabularies, TransformationType.All).foreach(record => {
println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(record)) Assertions.assertNotNull(record)
}) })
} }
@ -37,6 +40,16 @@ class CrossrefMappingTest extends AbstractVocabularyTest {
val input = val input =
IOUtils.toString(getClass.getResourceAsStream("/eu/dnetlib/dhp/collection/crossref/affiliationTest.json"), "utf-8") IOUtils.toString(getClass.getResourceAsStream("/eu/dnetlib/dhp/collection/crossref/affiliationTest.json"), "utf-8")
val data = Crossref2Oaf.convert(input, vocabularies, TransformationType.OnlyResult) val data = Crossref2Oaf.convert(input, vocabularies, TransformationType.OnlyResult)
data.foreach(record => {
Assertions.assertNotNull(record)
Assertions.assertTrue(record.isInstanceOf[Publication])
val publication = record.asInstanceOf[Publication]
publication.getAuthor.asScala.foreach(author => {
Assertions.assertNotNull(author.getRawAffiliationString)
Assertions.assertTrue(author.getRawAffiliationString.size()>0)
})
})
println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data.head)) println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data.head))
} }
} }