2021-10-20 17:37:42 +02:00
|
|
|
package eu.dnetlib.dhp.datacite
|
2021-03-31 15:45:58 +02:00
|
|
|
|
2021-04-20 09:44:44 +02:00
|
|
|
|
2021-10-20 17:37:42 +02:00
|
|
|
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
|
2021-03-31 15:45:58 +02:00
|
|
|
import eu.dnetlib.dhp.aggregation.AbstractVocabularyTest
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Oaf
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith
|
|
|
|
import org.junit.jupiter.api.{BeforeEach, Test}
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension
|
2021-06-04 10:14:22 +02:00
|
|
|
|
2021-07-27 16:09:30 +02:00
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.Locale
|
2021-03-31 15:45:58 +02:00
|
|
|
import scala.io.Source
|
|
|
|
|
|
|
|
@ExtendWith(Array(classOf[MockitoExtension]))
|
|
|
|
class DataciteToOAFTest extends AbstractVocabularyTest{
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
def setUp() :Unit = {
|
2021-04-20 09:44:44 +02:00
|
|
|
|
2021-03-31 15:45:58 +02:00
|
|
|
super.setUpVocabulary()
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:09:30 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
def testDateMapping:Unit = {
|
|
|
|
val inputDate = "2021-07-14T11:52:54+0000"
|
|
|
|
val ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US)
|
|
|
|
val dt = ISO8601FORMAT.parse(inputDate)
|
|
|
|
println(dt.getTime)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-31 15:45:58 +02:00
|
|
|
@Test
|
|
|
|
def testMapping() :Unit = {
|
|
|
|
val record =Source.fromInputStream(getClass.getResourceAsStream("record.json")).mkString
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 10:14:22 +02:00
|
|
|
val mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
|
|
|
|
val res:List[Oaf] =DataciteToOAFTransformation.generateOAF(record, 0L,0L, vocabularies, true )
|
|
|
|
|
|
|
|
res.foreach(r => {
|
|
|
|
println (mapper.writeValueAsString(r))
|
|
|
|
println("----------------------------")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2021-03-31 15:45:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|