AggregationSpec.scala 4.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * rico2edm
 * Copyright (C) 2021  UB Basel
 *
 * 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.rico2edm.edm

Günter Hipler's avatar
Günter Hipler committed
23
import ch.memobase.Utils
24
25
26
27
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.Aggregation
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Günter Hipler's avatar
Günter Hipler committed
28
29
import ujson.Value.Value

30
31
32
33
34

class AggregationSpec extends AnyFunSuite with Matchers {

  private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
  private lazy val rawCertainty = loadFile("src/test/resources/rico.certainty.json")
Günter Hipler's avatar
Günter Hipler committed
35
  private lazy val rawNoFoto = loadFile("src/test/resources/rico.duration.json")
36
37
38
  private lazy val rawEdmRights = loadFile("src/test/resources/rico.certainty.json")


39

Günter Hipler's avatar
Günter Hipler committed
40
41
42
43
44
45
  private def testAggregation = {
    val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    Aggregation(shortRecordId.get)
  }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

  test ("id creation for Aggregation") {
    val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  s"https://memobase.ch/object/${shortRecordId.get}" == "https://memobase.ch/object/ati-001-L_44_13")
  }

  test ("edm:aggregatedCHO") {

    //entspricht id - identifier (keine http URI)
    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  shortRecordId.get == "lmz-001--597216")

  }

  test ("edm:isShownAt") {

Günter Hipler's avatar
Günter Hipler committed
66
   //entspricht id - identifier (keine http URI)
67
68
69
70
71
72
    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  shortRecordId.get == "lmz-001--597216")


Günter Hipler's avatar
Günter Hipler committed
73

74
75
76
77
78
79
    /*
    val agg = Aggregation(shortRecordId.get)
    agg.addIsShownAt(shortRecordId)

    val rdfWriter = new EDMRdfXmlWriter(System.out)
    Rio.write(agg.getModel, rdfWriter)
Günter Hipler's avatar
Günter Hipler committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    */


  }


  test ("edm:isShownBy") {

    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val doObj = Extractors.digitalObject(graph).get
    val shortDobjectId = Extractors.digitalObjectIdShort(graph)(doObj)
    assert(shortDobjectId.isDefined && shortDobjectId.get == "lmz-001--597216-1")

  }

  private def createAgg(rawGraph: String): Aggregation = {
    val graph = Extractors.jsonGraph(rawGraph).get.arr
    val record = Extractors.record(graph).get
    val doObj = Extractors.digitalObject(graph).get
    val digiObjIdShort = Extractors.digitalObjectIdShort(graph)(doObj)
    val tempTestAgg = testAggregation
    Extractors.ricoType(record) match {
      case Some(value) =>
        if (value == "Foto") {
          tempTestAgg.addEDMObjectFoto(digiObjIdShort)
        }else {
          tempTestAgg.addEDMObjectNoFoto(digiObjIdShort)
        }
      case None =>

    }
    tempTestAgg

  }


  test ("aggregation edm:object") {
117

Günter Hipler's avatar
Günter Hipler committed
118
119
120
    val aggFoto = createAgg(rawCertainty)
    assert(Utils.serializeRDFModel(aggFoto.getModel).contains(
      s"<edm:object>https://media.memobase.ch/memo/lmz-001--597216-1/master</edm:object>"))
121

Günter Hipler's avatar
Günter Hipler committed
122
123
124
    val aggNoFoto = createAgg(rawNoFoto)
    assert(Utils.serializeRDFModel(aggNoFoto.getModel).contains(
      s"<edm:object>https://media.memobase.ch/memo/raf-001-2893-1-poster</edm:object>"))
125
126
127

  }

128
129
130
131
132
133
134
135
136
137
  test ("edm:rights property for aggregation ") {

    val graphGet: Value = Extractors.jsonGraph(rawEdmRights).get
    val dObj = Extractors.digitalObject(graphGet.arr)
    val usage = Extractors.usageRegulationDigitalObject(graphGet.arr)(dObj.get)
    assert(usage.head == "http://rightsstatements.org/vocab/CNE/1.0/")

  }


138
139

}